WingMan – Diff between revs 22 and 23

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 22 Rev 23
Line 9... Line 9...
9 using System.Threading.Tasks; 9 using System.Threading.Tasks;
10 using System.Windows.Forms; 10 using System.Windows.Forms;
11 using Gma.System.MouseKeyHook; 11 using Gma.System.MouseKeyHook;
12 using MQTTnet.Extensions.ManagedClient; 12 using MQTTnet.Extensions.ManagedClient;
13 using MQTTnet.Server; 13 using MQTTnet.Server;
-   14 using WingMan.AutoCompletion;
14 using WingMan.Bindings; 15 using WingMan.Bindings;
15 using WingMan.Communication; 16 using WingMan.Communication;
16 using WingMan.Lobby; 17 using WingMan.Lobby;
17 using WingMan.Properties; 18 using WingMan.Properties;
18 using WingMan.Utilities; 19 using WingMan.Utilities;
Line 26... Line 27...
26 InitializeComponent(); 27 InitializeComponent();
Line 27... Line 28...
27   28  
28 FormTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext(); 29 FormTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
Line -... Line 30...
-   30 FormCancellationTokenSource = new CancellationTokenSource();
-   31  
-   32 // Set up autocompletion.
-   33 AutoCompletion = new AutoCompletion.AutoCompletion(FormTaskScheduler, FormCancellationTokenSource.Token);
-   34 AutoCompletion.OnSaveFailed += AutoCompletionOnSaveFailed;
-   35 AutoCompletion.OnLoadFailed += AutoCompletionOnLoadFailed;
-   36  
-   37 Task.Run(() => AutoCompletion.Load(Address.Name, Address.AutoCompleteCustomSource));
-   38 Task.Run(() => AutoCompletion.Load(Port.Name, Address.AutoCompleteCustomSource));
29 FormCancellationTokenSource = new CancellationTokenSource(); 39 Task.Run(() => AutoCompletion.Load(Nick.Name, Nick.AutoCompleteCustomSource));
30   40  
31 MqttCommunication = new MqttCommunication(FormTaskScheduler, FormCancellationTokenSource.Token); 41 MqttCommunication = new MqttCommunication(FormTaskScheduler, FormCancellationTokenSource.Token);
32 MqttCommunication.OnClientAuthenticationFailed += OnMqttClientAuthenticationFailed; 42 MqttCommunication.OnClientAuthenticationFailed += OnMqttClientAuthenticationFailed;
33 MqttCommunication.OnClientConnectionFailed += OnMqttClientConnectionFailed; 43 MqttCommunication.OnClientConnectionFailed += OnMqttClientConnectionFailed;
Line 82... Line 92...
82 KeySimulator = new KeySimulator(LocalKeyBindings, MqttCommunication, FormTaskScheduler, 92 KeySimulator = new KeySimulator(LocalKeyBindings, MqttCommunication, FormTaskScheduler,
83 FormCancellationTokenSource.Token); 93 FormCancellationTokenSource.Token);
84 KeySimulator.OnMouseKeyBindingExecuting += OnMouseKeyBindingExecuting; 94 KeySimulator.OnMouseKeyBindingExecuting += OnMouseKeyBindingExecuting;
85 } 95 }
Line -... Line 96...
-   96  
86   97 private static AutoCompletion.AutoCompletion AutoCompletion { get; set; }
Line 87... Line 98...
87 private static CancellationTokenSource FormCancellationTokenSource { get; set; } 98 private static CancellationTokenSource FormCancellationTokenSource { get; set; }
Line 88... Line 99...
88   99  
Line 110... Line 121...
110   121  
Line 111... Line 122...
111 public KeyInterceptor KeyInterceptor { get; set; } 122 public KeyInterceptor KeyInterceptor { get; set; }
Line -... Line 123...
-   123  
-   124 public KeySimulator KeySimulator { get; set; }
-   125  
-   126 private void AutoCompletionOnLoadFailed(object sender, AutoCompletionFailedEventArgs args)
-   127 {
-   128 ActivityTextBox.AppendText(
-   129 $"{Strings.Failed_loading_autocomplete_source} : {args.Name} : {args.Exception.Message}{Environment.NewLine}");
-   130 }
-   131  
-   132 private void AutoCompletionOnSaveFailed(object sender, AutoCompletionFailedEventArgs args)
-   133 {
-   134 ActivityTextBox.AppendText(
112   135 $"{Strings.Failed_saving_autocomplete_source} : {args.Name} : {args.Exception.Message}{Environment.NewLine}");
113 public KeySimulator KeySimulator { get; set; } 136 }
114   137  
115 /// <inheritdoc /> 138 /// <inheritdoc />
116 /// <summary> 139 /// <summary>
Line 290... Line 313...
290 } 313 }
Line 291... Line 314...
291   314  
292 if (!ValidateConnectionParameters(out var ipAddress, out var port, out var nick, out var password)) 315 if (!ValidateConnectionParameters(out var ipAddress, out var port, out var nick, out var password))
Line -... Line 316...
-   316 return;
-   317  
293 return; 318 StoreConnectionAutocomplete();
294   319  
295 // Start the MQTT server. 320 // Start the MQTT server.
296 if (!await MqttCommunication 321 if (!await MqttCommunication
297 .Start(MqttCommunicationType.Server, ipAddress, port, nick, password)) 322 .Start(MqttCommunicationType.Server, ipAddress, port, nick, password))
Line 309... Line 334...
309 Port.Enabled = false; 334 Port.Enabled = false;
310 Nick.Enabled = false; 335 Nick.Enabled = false;
311 Password.Enabled = false; 336 Password.Enabled = false;
312 } 337 }
Line -... Line 338...
-   338  
-   339 private async void StoreConnectionAutocomplete()
-   340 {
-   341 Address.AutoCompleteCustomSource.Add(Address.Text);
-   342  
-   343 await AutoCompletion.Save(Address.Name, Address.AutoCompleteCustomSource);
-   344  
-   345 Port.AutoCompleteCustomSource.Add(Port.Text);
-   346  
-   347 await AutoCompletion.Save(Port.Name, Port.AutoCompleteCustomSource);
-   348  
-   349 Nick.AutoCompleteCustomSource.Add(Nick.Text);
-   350  
-   351 await AutoCompletion.Save(Nick.Name, Nick.AutoCompleteCustomSource);
-   352 }
313   353  
314 private bool ValidateConnectionParameters( 354 private bool ValidateConnectionParameters(
315 out IPAddress address, 355 out IPAddress address,
316 out int port, 356 out int port,
317 out string nick, 357 out string nick,
Line 397... Line 437...
397 } 437 }
Line 398... Line 438...
398   438  
399 if (!ValidateConnectionParameters(out var ipAddress, out var port, out var nick, out var password)) 439 if (!ValidateConnectionParameters(out var ipAddress, out var port, out var nick, out var password))
Line -... Line 440...
-   440 return;
-   441  
400 return; 442 StoreConnectionAutocomplete();
401   443  
402 if (!await MqttCommunication 444 if (!await MqttCommunication
403 .Start(MqttCommunicationType.Client, ipAddress, port, nick, password)) 445 .Start(MqttCommunicationType.Client, ipAddress, port, nick, password))
404 { 446 {
Line 618... Line 660...
618 RemoteBindingsBindToBox.Text = string.Join(" + ", binding.Keys); 660 RemoteBindingsBindToBox.Text = string.Join(" + ", binding.Keys);
619 break; 661 break;
620 } 662 }
621 } 663 }
Line -... Line 664...
-   664  
-   665 private void WingManFormResized(object sender, EventArgs e)
-   666 {
-   667 if (WindowState == FormWindowState.Minimized)
-   668 {
-   669 Hide();
-   670 notifyIcon1.Visible = true;
-   671 }
-   672 }
-   673  
-   674 private void NotifyIconDoubleClick(object sender, EventArgs e)
-   675 {
-   676 Show();
-   677 WindowState = FormWindowState.Normal;
-   678 notifyIcon1.Visible = false;
-   679 }
622   680  
Line 623... Line 681...
623 #region Saving and loading 681 #region Saving and loading
624   682  
625 private async Task SaveLocalMouseKeyBindings() 683 private async Task SaveLocalMouseKeyBindings()
Line 723... Line 781...
723 $"{Strings.Failed_loading_remote_bindings}{Environment.NewLine}"); 781 $"{Strings.Failed_loading_remote_bindings}{Environment.NewLine}");
724 } 782 }
725 } 783 }
Line 726... Line 784...
726   784  
727 #endregion -  
728   -  
729 private void WingManFormResized(object sender, EventArgs e) -  
730 { -  
731 if (WindowState == FormWindowState.Minimized) -  
732 { -  
733 Hide(); -  
734 notifyIcon1.Visible = true; -  
735 } -  
736 } -  
737   -  
738 private void NotifyIconDoubleClick(object sender, EventArgs e) -  
739 { -  
740 Show(); -  
741 WindowState = FormWindowState.Normal; -  
742 notifyIcon1.Visible = false; -  
743 } 785 #endregion
744 } 786 }