Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions Console/ConsoleApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,7 @@ public ConsoleApp(IConfigurationService configurationService)

public void Run(string[] args)
{
if (args.Contains("--web"))
{
RestApi(args);
} else
{
MainMenu();
}
}

private void MainMenu()
{
throw new NotImplementedException();
RestApi(args);
}

private void RestApi(string[] args)
Expand Down
1 change: 1 addition & 0 deletions RestApi/Controllers/KeyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class KeyController : AbstractBase
[HttpPost]
public IActionResult Post([FromBody] Command value)
{
Program.ReceivedKey(value, false);
return SendKeystroke(value, false);
}
}
Expand Down
1 change: 1 addition & 0 deletions RestApi/Controllers/ToggleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class ToggleController : AbstractBase
[HttpPost]
public IActionResult Post([FromBody] Command value)
{
Program.ReceivedKey(value, true);
return SendKeystroke(value, true);
}
}
Expand Down
4 changes: 2 additions & 2 deletions RestApi/Controllers/VersionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public class VersionController : ControllerBase
[HttpPost]
public IActionResult Get()
{
Program.ReceivedVersionCheck();
Assembly assembly = Assembly.GetExecutingAssembly();
//FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
string version = API_VERSION;// fileVersionInfo.ProductVersion;
string version = API_VERSION;

return Ok(new { Version = version });
}
Expand Down
57 changes: 0 additions & 57 deletions RestApi/Crypto.cs

This file was deleted.

13 changes: 13 additions & 0 deletions RestApi/IListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace GIC.RestApi
{
public interface IListener
{
void KeystrokeReceived(int activator, string key, string[] modifier, bool quickCommand);
void Output(string message);
}
}
23 changes: 19 additions & 4 deletions RestApi/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommandLine;
using GIC.Common;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using System.Collections.Generic;
Expand All @@ -11,8 +12,6 @@ public class Program
{
public class Options
{
[Option("web", Default = false, Required = false)]
public string Web { get; set; }
[Option("port", Default = false, Required = true, HelpText = "IP Port to Listen on")]
public int Port { get; set; }
[Option("password", Default = false, Required = true, HelpText = "Password to expect from client")]
Expand All @@ -21,7 +20,20 @@ public class Options
public string Application { get; set; }
}

internal static void ReceivedKey(Common.Command value, bool quickCommand)
{
if (AppListener != null)
AppListener.KeystrokeReceived(value.ActivatorType, value.Key, value.Modifier, quickCommand);
}

internal static void ReceivedVersionCheck()
{
if (AppListener != null)
AppListener.Output("Version check received");
}

public static string Key { get; internal set; }
public static IListener AppListener;

public static void Main(string[] args)
{
Expand All @@ -43,8 +55,10 @@ public static void Stop()
host.StopAsync();
}

public static bool Start(string[] args)
public static bool Start(string[] args, IListener listener = null)
{
if (listener != null)
AppListener = listener;
Parser.Default.ParseArguments<Options>(args)
.WithParsed(RunOptions)
.WithNotParsed(HandleParseError);
Expand All @@ -64,7 +78,8 @@ private static void RunOptions(Options opts)

private static void HandleParseError(IEnumerable<Error> errs)
{
//handle errors
//handle errorsE
System.Environment.Exit(1);
}

private static void CheckFirewall(int port)
Expand Down
5 changes: 5 additions & 0 deletions Wpf/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GIC.Common.Services;
using GIC.RestApi;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System.Windows;
Expand All @@ -12,6 +13,7 @@ public partial class App : Application
{
private ServiceProvider serviceProvider;
private IConfigurationRoot configuration;
internal static string[] Arguments;

public App()
{
Expand All @@ -34,6 +36,9 @@ private void ConfigureServices(ServiceCollection services)

protected void OnStartup(object sender, StartupEventArgs e)
{
if (e.Args.Length > 0)
Arguments = e.Args;

var mainWindow = serviceProvider.GetService<MainWindow>();
mainWindow.Show();
}
Expand Down
22 changes: 22 additions & 0 deletions Wpf/Listener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using GIC.RestApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GIC.Wpf
{
class Listener : IListener
{
public void KeystrokeReceived(int activator, string key, string[] modifier, bool quickCommand)
{
throw new NotImplementedException();
}

public void Output(string message)
{
throw new NotImplementedException();
}
}
}
7 changes: 4 additions & 3 deletions Wpf/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
Icon="app.ico"
mc:Ignorable="d"
Title="GIC Server" SizeToContent="WidthAndHeight" ResizeMode="NoResize">
<Grid Width="408" Height="267">
<Grid Width="408" Height="332">
<Label Content="Port" HorizontalContentAlignment ="Right" HorizontalAlignment="Left" Margin="240,83,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="txtPort" DataObject.Pasting="TextBoxPasting" PreviewTextInput="PreviewTextInput" HorizontalAlignment="Left" Margin="278,83,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Text="8091"/>
<Label Content="Password" HorizontalContentAlignment ="Right" HorizontalAlignment="Left" Margin="212,105,0,0" VerticalAlignment="Top" RenderTransformOrigin="2.875,0.886"/>
<PasswordBox x:Name="txtPassword" HorizontalAlignment="Left" Height="23" Margin="277,106,0,0" PasswordChar="*" VerticalAlignment="Top" Width="120"/>
<Label Content="Target" HorizontalContentAlignment ="Center" Margin="10,10,203,0" VerticalAlignment="Top" RenderTransformOrigin="-0.907,-2.615" Height="26"/>
<Button x:Name="btnStart" Content="Start" Margin="212,151,10,0" VerticalAlignment="Top" Height="60" Click="btnStart_Click"/>
<Button Content="About" x:Name="btnAbout" HorizontalAlignment="Left" Margin="323,38,0,0" VerticalAlignment="Top" Width="74" Height="20" Click="btnAbout_Click"/>
<ListBox Margin="10,36,203,37" x:Name="lstApps"/>
<ComboBox HorizontalAlignment="Left" Margin="10,229,0,0" VerticalAlignment="Top" Width="194" IsEditable="True" x:Name="cboApps" SelectionChanged="cboApps_SelectionChanged"/>
<ListBox Margin="10,36,203,0" x:Name="lstApps" Height="188" VerticalAlignment="Top"/>
<ComboBox HorizontalAlignment="Left" Margin="10,229,0,0" VerticalAlignment="Top" Width="195" IsEditable="True" x:Name="cboApps" SelectionChanged="cboApps_SelectionChanged"/>
<Button Content="Remove" x:Name="btnRemove" HorizontalAlignment="Left" Margin="148,11,0,0" VerticalAlignment="Top" Width="56" Click="btnRemove_Click"/>
<Button Content="Help" x:Name="btnHelp" HorizontalAlignment="Left" Margin="323,13,0,0" VerticalAlignment="Top" Width="74" Height="20" Click="btnHelp_Click"/>
<Button Content="Add" x:Name="btnAdd" HorizontalAlignment="Left" Margin="209,231,0,0" VerticalAlignment="Top" Width="56" Click="btnAdd_Click"/>
<TextBox x:Name="txtOutput" HorizontalAlignment="Center" Margin="0,256,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="387" Height="66" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" IsReadOnly="True"/>

</Grid>
</Window>
72 changes: 69 additions & 3 deletions Wpf/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
using GIC.Common;
using GIC.Common.Services;
using GIC.RestApi;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;

namespace GIC.Wpf
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
public partial class MainWindow : Window, IListener
{
private bool isRunning = false;
private bool cmdLinePassword;
private bool cmdLinePort;
private string cmdLineApp;
private readonly IConfigurationService configurationService;

public MainWindow(IConfigurationService configurationService)
Expand All @@ -23,6 +29,38 @@ public MainWindow(IConfigurationService configurationService)
InitializeComponent();
LoadSettings();
WindowHandles();
CheckArgs();
}

private void CheckArgs()
{
if (App.Arguments != null && App.Arguments.Length > 0)
{
for (int i = 0; i < App.Arguments.Length - 1; i++)
{
if (App.Arguments[i].ToLower().Equals("--password"))
{
i++;
txtPassword.Password = App.Arguments[i];
cmdLinePassword = true;
}
else if (App.Arguments[i].ToLower().Equals("--port"))
{
i++;
txtPort.Text = App.Arguments[i];
cmdLinePort = true;
}
else if (App.Arguments[i].ToLower().Equals("--app"))
{
i++;
cmdLineApp = App.Arguments[i];
}
if (!string.IsNullOrEmpty(cmdLineApp) && cmdLinePassword && cmdLinePort)
{
ToggleServer();
}
}
}
}

private static readonly Regex regex = new Regex("[^0-9.-]+"); //regex that matches disallowed text
Expand Down Expand Up @@ -102,18 +140,20 @@ private void ToggleServer()
}
else
{
cmdLineApp = lstApps.SelectedItem.ToString();
string[] args = new string[]
{
"--port",
port.ToString(),
"--password",
txtPassword.Password,
"--app",
lstApps.SelectedItem.ToString(),
cmdLineApp,
};

SaveSettings();
StartWeb(args);
Output($"Starting Server listening on Port {port} for App {cmdLineApp}");
isRunning = true;
txtPassword.IsEnabled = false;
txtPort.IsEnabled = false;
Expand All @@ -127,7 +167,7 @@ private void ToggleServer()

private void StartWeb(string[] args)
{
Task.Run(() => RestApi.Program.Start(args));
Task.Run(() => Program.Start(args, this));
}

private void ToggleText()
Expand Down Expand Up @@ -199,5 +239,31 @@ private void btnHelp_Click(object sender, RoutedEventArgs e)
Help window = new Help();
window.Show();
}

public void KeystrokeReceived(int activator, string key, string[] modifier, bool quickCommand)
{
string output = $"Key {key}";
foreach (string mod in modifier)
output += $"+{mod}";
if (activator == 0)
output += " pressed";
else
output += " let go";
Dispatcher.Invoke(() =>
{

txtOutput.Text += $"{output}\n";
txtOutput.ScrollToEnd();
});
}

public void Output(string message)
{
Dispatcher.Invoke(() =>
{
txtOutput.Text += $"{message}\n";
txtOutput.ScrollToEnd();
});
}
}
}
4 changes: 2 additions & 2 deletions Wpf/Wpf.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<AssemblyName>GIC.Wpf</AssemblyName>
<AssemblyName>GIC</AssemblyName>
<RootNamespace>GIC.Wpf</RootNamespace>
<Version>2.0.0</Version>
<PackageIcon>app.ico</PackageIcon>
Expand Down