/trunk/WingMan/WingManForm.cs |
@@ -11,6 +11,7 @@ |
using Gma.System.MouseKeyHook; |
using MQTTnet.Extensions.ManagedClient; |
using MQTTnet.Server; |
using WingMan.AutoCompletion; |
using WingMan.Bindings; |
using WingMan.Communication; |
using WingMan.Lobby; |
@@ -28,6 +29,15 @@ |
FormTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext(); |
FormCancellationTokenSource = new CancellationTokenSource(); |
|
// Set up autocompletion. |
AutoCompletion = new AutoCompletion.AutoCompletion(FormTaskScheduler, FormCancellationTokenSource.Token); |
AutoCompletion.OnSaveFailed += AutoCompletionOnSaveFailed; |
AutoCompletion.OnLoadFailed += AutoCompletionOnLoadFailed; |
|
Task.Run(() => AutoCompletion.Load(Address.Name, Address.AutoCompleteCustomSource)); |
Task.Run(() => AutoCompletion.Load(Port.Name, Address.AutoCompleteCustomSource)); |
Task.Run(() => AutoCompletion.Load(Nick.Name, Nick.AutoCompleteCustomSource)); |
|
MqttCommunication = new MqttCommunication(FormTaskScheduler, FormCancellationTokenSource.Token); |
MqttCommunication.OnClientAuthenticationFailed += OnMqttClientAuthenticationFailed; |
MqttCommunication.OnClientConnectionFailed += OnMqttClientConnectionFailed; |
@@ -84,6 +94,7 @@ |
KeySimulator.OnMouseKeyBindingExecuting += OnMouseKeyBindingExecuting; |
} |
|
private static AutoCompletion.AutoCompletion AutoCompletion { get; set; } |
private static CancellationTokenSource FormCancellationTokenSource { get; set; } |
|
private static TaskScheduler FormTaskScheduler { get; set; } |
@@ -112,6 +123,18 @@ |
|
public KeySimulator KeySimulator { get; set; } |
|
private void AutoCompletionOnLoadFailed(object sender, AutoCompletionFailedEventArgs args) |
{ |
ActivityTextBox.AppendText( |
$"{Strings.Failed_loading_autocomplete_source} : {args.Name} : {args.Exception.Message}{Environment.NewLine}"); |
} |
|
private void AutoCompletionOnSaveFailed(object sender, AutoCompletionFailedEventArgs args) |
{ |
ActivityTextBox.AppendText( |
$"{Strings.Failed_saving_autocomplete_source} : {args.Name} : {args.Exception.Message}{Environment.NewLine}"); |
} |
|
/// <inheritdoc /> |
/// <summary> |
/// Clean up any resources being used. |
@@ -292,6 +315,8 @@ |
if (!ValidateConnectionParameters(out var ipAddress, out var port, out var nick, out var password)) |
return; |
|
StoreConnectionAutocomplete(); |
|
// Start the MQTT server. |
if (!await MqttCommunication |
.Start(MqttCommunicationType.Server, ipAddress, port, nick, password)) |
@@ -311,6 +336,21 @@ |
Password.Enabled = false; |
} |
|
private async void StoreConnectionAutocomplete() |
{ |
Address.AutoCompleteCustomSource.Add(Address.Text); |
|
await AutoCompletion.Save(Address.Name, Address.AutoCompleteCustomSource); |
|
Port.AutoCompleteCustomSource.Add(Port.Text); |
|
await AutoCompletion.Save(Port.Name, Port.AutoCompleteCustomSource); |
|
Nick.AutoCompleteCustomSource.Add(Nick.Text); |
|
await AutoCompletion.Save(Nick.Name, Nick.AutoCompleteCustomSource); |
} |
|
private bool ValidateConnectionParameters( |
out IPAddress address, |
out int port, |
@@ -399,6 +439,8 @@ |
if (!ValidateConnectionParameters(out var ipAddress, out var port, out var nick, out var password)) |
return; |
|
StoreConnectionAutocomplete(); |
|
if (!await MqttCommunication |
.Start(MqttCommunicationType.Client, ipAddress, port, nick, password)) |
{ |
@@ -620,6 +662,22 @@ |
} |
} |
|
private void WingManFormResized(object sender, EventArgs e) |
{ |
if (WindowState == FormWindowState.Minimized) |
{ |
Hide(); |
notifyIcon1.Visible = true; |
} |
} |
|
private void NotifyIconDoubleClick(object sender, EventArgs e) |
{ |
Show(); |
WindowState = FormWindowState.Normal; |
notifyIcon1.Visible = false; |
} |
|
#region Saving and loading |
|
private async Task SaveLocalMouseKeyBindings() |
@@ -725,21 +783,5 @@ |
} |
|
#endregion |
|
private void WingManFormResized(object sender, EventArgs e) |
{ |
if (WindowState == FormWindowState.Minimized) |
{ |
Hide(); |
notifyIcon1.Visible = true; |
} |
} |
|
private void NotifyIconDoubleClick(object sender, EventArgs e) |
{ |
Show(); |
WindowState = FormWindowState.Normal; |
notifyIcon1.Visible = false; |
} |
} |
} |