WingMan – Diff between revs 5 and 7

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 5 Rev 7
Line 1... Line 1...
1 using System; 1 using System;
2 using System.Collections.Generic; -  
3 using System.IO; 2 using System.IO;
4 using System.Linq; -  
5 using System.Text; 3 using System.Threading;
6 using System.Threading.Tasks; 4 using System.Threading.Tasks;
7 using MQTTnet; 5 using MQTTnet;
8 using WingMan.Communication; 6 using WingMan.Communication;
Line 9... Line 7...
9   7  
10 namespace WingMan 8 namespace WingMan.Lobby
11 { 9 {
12 public class LobbyMessageSynchronizer : IDisposable 10 public class LobbyMessageSynchronizer : IDisposable
13 { 11 {
Line 14... Line -...
14 public delegate void LobbyMessageReceived(object sender, LobbyMessageReceivedEventArgs e); -  
15   12 public delegate void LobbyMessageReceived(object sender, LobbyMessageReceivedEventArgs e);
16 public event LobbyMessageReceived OnLobbyMessageReceived; 13  
17 private MQTTCommunication MQTTCommunication { get; set; } 14 public LobbyMessageSynchronizer(MQTTCommunication MQTTCommunication, TaskScheduler taskScheduler,
18 public LobbyMessageSynchronizer(MQTTCommunication MQTTCommunication) 15 CancellationToken cancellationToken)
-   16 {
-   17 this.MQTTCommunication = MQTTCommunication;
Line 19... Line 18...
19 { 18 CancellationToken = cancellationToken;
20 this.MQTTCommunication = MQTTCommunication; 19 TaskScheduler = taskScheduler;
Line 21... Line 20...
21   20  
-   21 MQTTCommunication.OnMessageReceived += MqttCommunicationOnOnMessageReceived;
-   22 }
-   23  
-   24 private MQTTCommunication MQTTCommunication { get; }
-   25  
22 MQTTCommunication.OnMessageReceived += MqttCommunicationOnOnMessageReceived; 26 private CancellationToken CancellationToken { get; }
-   27 private TaskScheduler TaskScheduler { get; }
-   28  
-   29 public void Dispose()
-   30 {
-   31 MQTTCommunication.OnMessageReceived -= MqttCommunicationOnOnMessageReceived;
-   32 }
-   33  
-   34 public event LobbyMessageReceived OnLobbyMessageReceived;
23 } 35  
24   36 private async void MqttCommunicationOnOnMessageReceived(object sender,
Line 25... Line 37...
25 private void MqttCommunicationOnOnMessageReceived(object sender, MqttApplicationMessageReceivedEventArgs e) 37 MqttApplicationMessageReceivedEventArgs e)
26 { 38 {
27 if(e.ApplicationMessage.Topic != "lobby") 39 if (e.ApplicationMessage.Topic != "lobby")
Line -... Line 40...
-   40 return;
-   41  
-   42 using (var memoryStream = new MemoryStream(e.ApplicationMessage.Payload))
28 return; 43 {
-   44 var lobbyMessage = (LobbyMessage) LobbyMessage.XmlSerializer.Deserialize(memoryStream);
29   45  
30 using (var memoryStream = new MemoryStream(e.ApplicationMessage.Payload)) 46 await Task.Delay(0)
Line 31... Line 47...
31 { 47 .ContinueWith(
32 var lobbyMessage = (LobbyMessage)LobbyMessage.XmlSerializer.Deserialize(memoryStream); 48 _ => OnLobbyMessageReceived?.Invoke(sender,
Line 48... Line 64...
48 memoryStream.Position = 0L; 64 memoryStream.Position = 0L;
Line 49... Line 65...
49   65  
50 await MQTTCommunication.Broadcast("lobby", memoryStream.ToArray()).ConfigureAwait(false); 66 await MQTTCommunication.Broadcast("lobby", memoryStream.ToArray()).ConfigureAwait(false);
51 } 67 }
52 } -  
53   -  
54 public void Dispose() -  
55 { -  
56 MQTTCommunication.OnMessageReceived -= MqttCommunicationOnOnMessageReceived; -  
57 } 68 }
58 } 69 }