Hush – Diff between revs 1 and 2

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 1 Rev 2
Line 12... Line 12...
12 public Discovery() 12 public Discovery()
13 { 13 {
14 NatDiscoverer = new NatDiscoverer(); 14 NatDiscoverer = new NatDiscoverer();
15 } 15 }
Line 16... Line 16...
16   16  
17 public Discovery(string mappingName, CancellationTokenSource cancellationTokenSource, 17 public Discovery(string mappingName, CancellationToken cancellationToken,
18 TaskScheduler taskScheduler) : this() 18 TaskScheduler taskScheduler) : this()
19 { 19 {
20 MappingName = mappingName; 20 MappingName = mappingName;
21 CancellationTokenSource = cancellationTokenSource; 21 CancellationToken = cancellationToken;
22 TaskScheduler = taskScheduler; 22 TaskScheduler = taskScheduler;
Line 23... Line 23...
23 } 23 }
24   24  
25 private static string MappingName { get; set; } 25 private static string MappingName { get; set; }
26 private static CancellationTokenSource CancellationTokenSource { get; set; } 26 private static CancellationToken CancellationToken { get; set; }
Line 27... Line 27...
27 private static NatDiscoverer NatDiscoverer { get; set; } 27 private static NatDiscoverer NatDiscoverer { get; set; }
28 private static TaskScheduler TaskScheduler { get; set; } 28 private static TaskScheduler TaskScheduler { get; set; }
Line 72... Line 72...
72 try 72 try
73 { 73 {
74 UpnPCancellationTokenSource = new CancellationTokenSource(); 74 UpnPCancellationTokenSource = new CancellationTokenSource();
75 var linkedCancellationTokenSource = 75 var linkedCancellationTokenSource =
76 CancellationTokenSource.CreateLinkedTokenSource(UpnPCancellationTokenSource.Token, 76 CancellationTokenSource.CreateLinkedTokenSource(UpnPCancellationTokenSource.Token,
77 CancellationTokenSource.Token); 77 CancellationToken);
78 var device = await NatDiscoverer.DiscoverDeviceAsync(PortMapper.Upnp, linkedCancellationTokenSource); 78 var device = await NatDiscoverer.DiscoverDeviceAsync(PortMapper.Upnp, linkedCancellationTokenSource);
79 await device.DeletePortMapAsync(new Mapping(Protocol.Tcp, port, port, MappingName)); 79 await device.DeletePortMapAsync(new Mapping(Protocol.Tcp, port, port, MappingName));
Line 80... Line 80...
80   80  
81 return true; 81 return true;
Line 91... Line 91...
91 try 91 try
92 { 92 {
93 UpnPCancellationTokenSource = new CancellationTokenSource(); 93 UpnPCancellationTokenSource = new CancellationTokenSource();
94 var linkedCancellationTokenSource = 94 var linkedCancellationTokenSource =
95 CancellationTokenSource.CreateLinkedTokenSource(UpnPCancellationTokenSource.Token, 95 CancellationTokenSource.CreateLinkedTokenSource(UpnPCancellationTokenSource.Token,
96 CancellationTokenSource.Token); 96 CancellationToken);
97 var device = await NatDiscoverer.DiscoverDeviceAsync(PortMapper.Upnp, linkedCancellationTokenSource); 97 var device = await NatDiscoverer.DiscoverDeviceAsync(PortMapper.Upnp, linkedCancellationTokenSource);
98 await device.CreatePortMapAsync(new Mapping(Protocol.Tcp, port, port, MappingName)); 98 await device.CreatePortMapAsync(new Mapping(Protocol.Tcp, port, port, MappingName));
Line 99... Line 99...
99   99  
100 return true; 100 return true;
101 } 101 }
102 catch (Exception ex) 102 catch (Exception ex)
103 { 103 {
104 await Task.Delay(0, CancellationTokenSource.Token).ContinueWith(_ => 104 await Task.Delay(0, CancellationToken).ContinueWith(_ =>
105 OnPortMapFailed?.Invoke(this, new DiscoveryFailedEventArgs(DiscoveryType.Upnp, ex)), 105 OnPortMapFailed?.Invoke(this, new DiscoveryFailedEventArgs(DiscoveryType.Upnp, ex)),
Line 106... Line 106...
106 CancellationTokenSource.Token, TaskContinuationOptions.None, TaskScheduler); 106 CancellationToken, TaskContinuationOptions.None, TaskScheduler);
107   107  
108 return false; 108 return false;
Line 114... Line 114...
114 try 114 try
115 { 115 {
116 PmpCancellationTokenSource = new CancellationTokenSource(); 116 PmpCancellationTokenSource = new CancellationTokenSource();
117 var linkedCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource( 117 var linkedCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(
118 PmpCancellationTokenSource.Token, 118 PmpCancellationTokenSource.Token,
119 CancellationTokenSource.Token); 119 CancellationToken);
120 var device = await NatDiscoverer.DiscoverDeviceAsync(PortMapper.Pmp, linkedCancellationTokenSource); 120 var device = await NatDiscoverer.DiscoverDeviceAsync(PortMapper.Pmp, linkedCancellationTokenSource);
121 await device.DeletePortMapAsync(new Mapping(Protocol.Tcp, port, port, MappingName)); 121 await device.DeletePortMapAsync(new Mapping(Protocol.Tcp, port, port, MappingName));
122 return true; 122 return true;
123 } 123 }
124 catch 124 catch
Line 132... Line 132...
132 try 132 try
133 { 133 {
134 PmpCancellationTokenSource = new CancellationTokenSource(); 134 PmpCancellationTokenSource = new CancellationTokenSource();
135 var linkedCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource( 135 var linkedCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(
136 PmpCancellationTokenSource.Token, 136 PmpCancellationTokenSource.Token,
137 CancellationTokenSource.Token); 137 CancellationToken);
138 var device = await NatDiscoverer.DiscoverDeviceAsync(PortMapper.Pmp, linkedCancellationTokenSource); 138 var device = await NatDiscoverer.DiscoverDeviceAsync(PortMapper.Pmp, linkedCancellationTokenSource);
139 await device.CreatePortMapAsync(new Mapping(Protocol.Tcp, port, port, MappingName)); 139 await device.CreatePortMapAsync(new Mapping(Protocol.Tcp, port, port, MappingName));
140 return true; 140 return true;
141 } 141 }
142 catch (Exception ex) 142 catch (Exception ex)
143 { 143 {
144 await Task.Delay(0, CancellationTokenSource.Token).ContinueWith(_ => 144 await Task.Delay(0, CancellationToken).ContinueWith(_ =>
145 OnPortMapFailed?.Invoke(this, new DiscoveryFailedEventArgs(DiscoveryType.Pmp, ex)), 145 OnPortMapFailed?.Invoke(this, new DiscoveryFailedEventArgs(DiscoveryType.Pmp, ex)),
146 CancellationTokenSource.Token, TaskContinuationOptions.None, TaskScheduler); 146 CancellationToken, TaskContinuationOptions.None, TaskScheduler);
Line 147... Line 147...
147   147  
148 return false; 148 return false;
149 } 149 }
150 } 150 }