WingMan – Diff between revs 5 and 6

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 5 Rev 6
Line 1... Line 1...
1 using System; 1 using System;
2 using System.Collections.Generic; 2 using System.Collections.Generic;
3 using System.Drawing; 3 using System.Drawing;
4 using System.Linq; 4 using System.Linq;
5 using System.Net; 5 using System.Net;
-   6 using System.Threading.Tasks;
6 using System.Windows.Forms; 7 using System.Windows.Forms;
7 using Gma.System.MouseKeyHook; 8 using Gma.System.MouseKeyHook;
8 using WingMan.Communication; 9 using WingMan.Communication;
9 using WingMan.MouseKey; 10 using WingMan.MouseKey;
10 using WingMan.Properties; 11 using WingMan.Properties;
Line 15... Line 16...
15 { 16 {
16 public WingManForm() 17 public WingManForm()
17 { 18 {
18 InitializeComponent(); 19 InitializeComponent();
Line -... Line 20...
-   20  
-   21 FormTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
19   22  
Line 20... Line 23...
20 MQTTCommunication = new MQTTCommunication(); 23 MQTTCommunication = new MQTTCommunication(FormTaskScheduler);
Line 21... Line 24...
21   24  
22 MouseKeyBindings = new MouseKeyBindings(new List<MouseKeyBinding>()); 25 MouseKeyBindings = new MouseKeyBindings(new List<MouseKeyBinding>());
Line 47... Line 50...
47 MouseKeyBindingsSynchronizer.OnMouseKeyBindingsSynchronized += OnMouseKeyBindingsSynchronized; 50 MouseKeyBindingsSynchronizer.OnMouseKeyBindingsSynchronized += OnMouseKeyBindingsSynchronized;
48 } 51 }
Line 49... Line 52...
49   52  
50 private void OnMouseKeyBindingsSynchronized(object sender, MouseKeyBindingsSynchronizedEventArgs e) 53 private void OnMouseKeyBindingsSynchronized(object sender, MouseKeyBindingsSynchronizedEventArgs e)
51 { 54 {
52 this.Invoke((MethodInvoker) delegate 55 foreach (var binding in e.ExchangeBindings)
53 { -  
54 foreach (var binding in e.ExchangeBindings) -  
55 { 56 {
56 ActivityTextBox.AppendText( 57 ActivityTextBox.AppendText(
57 $"{Strings.Synchronized_bindings_with_client} : {binding.Nick} : {binding.Names.Count}{Environment.NewLine}"); -  
Line 58... Line -...
58   -  
59   -  
Line 60... Line -...
60 var exchangeBindings = MouseKeyBindingsExchange.ExchangeBindings.FirstOrDefault(exchangeBinding => -  
61 string.Equals(exchangeBinding.Nick, binding.Nick, StringComparison.Ordinal)); -  
62   -  
63 // If the nick has not been registered add it. 58 $"{Strings.Synchronized_bindings_with_client} : {binding.Nick} : {binding.Names.Count}{Environment.NewLine}");
64 if (exchangeBindings == null) -  
65 { -  
66 MouseKeyBindingsExchange.ExchangeBindings.Add(binding); -  
67 continue; -  
68 } -  
69   -  
70 // If the nick has been added, then update the binding names. -  
71 exchangeBindings.Names = binding.Names; 59  
72   -  
73 // Update wing list box. -  
74 var selectedExchangeBinding = (MouseKeyBindingExchange)WingBindingsComboBox.SelectedItem; -  
75 if (selectedExchangeBinding == null || !string.Equals(selectedExchangeBinding.Nick, binding.Nick)) -  
76 continue; -  
77   -  
78 WingBindingsListBox.Items.Clear(); -  
Line -... Line 60...
-   60  
-   61 var exchangeBindings = MouseKeyBindingsExchange.ExchangeBindings.FirstOrDefault(exchangeBinding =>
-   62 string.Equals(exchangeBinding.Nick, binding.Nick, StringComparison.Ordinal));
-   63  
-   64 // If the nick has not been registered add it.
79 WingBindingsListBox.DisplayMember = "Name"; 65 if (exchangeBindings == null)
Line -... Line 66...
-   66 {
80 WingBindingsListBox.ValueMember = "Name"; 67 MouseKeyBindingsExchange.ExchangeBindings.Add(binding);
Line -... Line 68...
-   68 continue;
-   69 }
-   70  
-   71 // If the nick has been added, then update the binding names.
-   72 exchangeBindings.Names = binding.Names;
-   73  
-   74 // Update wing list box.
-   75 var selectedExchangeBinding = (MouseKeyBindingExchange) WingBindingsComboBox.SelectedItem;
-   76 if (selectedExchangeBinding == null || !string.Equals(selectedExchangeBinding.Nick, binding.Nick))
-   77 continue;
81 WingBindingsListBox.Items.AddRange(exchangeBindings.Names.Select(name => (object)name).ToArray()); 78  
-   79 WingBindingsListBox.Items.Clear();
-   80 WingBindingsListBox.DisplayMember = "Name";
82   81 WingBindingsListBox.ValueMember = "Name";
Line -... Line 82...
-   82 WingBindingsListBox.Items.AddRange(exchangeBindings.Names.Select(name => (object) name).ToArray());
-   83  
83 } 84 }
Line 84... Line 85...
84   85  
Line 85... Line 86...
85 WingBindingSource.ResetBindings(false); 86 WingBindingSource.ResetBindings(false);
Line 327... Line 328...
327 await LobbyMessageSynchronizer.Broadcast(LobbySayTextBox.Text).ConfigureAwait(false); 328 await LobbyMessageSynchronizer.Broadcast(LobbySayTextBox.Text).ConfigureAwait(false);
Line 328... Line 329...
328   329  
329 LobbySayTextBox.Text = string.Empty; 330 LobbySayTextBox.Text = string.Empty;
Line 330... Line 331...
330 } 331 }
331   332  
332 private void WingBindingsComboBoxIndexChanged(object sender, EventArgs e) 333 private void WingBindingsComboBoxSelectionChangeCompleted(object sender, EventArgs e)
333 { 334 {
334 var exchangeBinding = (MouseKeyBindingExchange) WingBindingsComboBox.SelectedItem; 335 var exchangeBinding = (MouseKeyBindingExchange)WingBindingsComboBox.SelectedItem;
Line 335... Line 336...
335 if (exchangeBinding == null) 336 if (exchangeBinding == null)
336 return; 337 return;