@@ -12,7 +12,7 @@ namespace ArtNetSharp.Communication
1212{
1313 public sealed class RemoteClient : INotifyPropertyChanged
1414 {
15- private static ILogger Logger = ApplicationLogging . CreateLogger < RemoteClient > ( ) ;
15+ private static readonly ILogger Logger = ApplicationLogging . CreateLogger < RemoteClient > ( ) ;
1616 public readonly string ID ;
1717 public readonly MACAddress MacAddress ;
1818 private IPv4Address ipAddress ;
@@ -195,13 +195,13 @@ public ArtPollReply Root
195195 this . IsSACNCapable = root . Status . NodeSupportArtNet_sACN_Switching ;
196196 }
197197 }
198- private ConcurrentDictionary < int , RemoteClientPort > ports = new ConcurrentDictionary < int , RemoteClientPort > ( ) ;
198+ private readonly ConcurrentDictionary < int , RemoteClientPort > ports = new ConcurrentDictionary < int , RemoteClientPort > ( ) ;
199199 public IReadOnlyCollection < RemoteClientPort > Ports { get ; private set ; }
200200 public event EventHandler < RemoteClientPort > PortDiscovered ;
201201 public event EventHandler < RemoteClientPort > PortTimedOut ;
202202
203- private ConcurrentDictionary < RDMUID , RDMUID_ReceivedBag > knownRDMUIDs = new ConcurrentDictionary < RDMUID , RDMUID_ReceivedBag > ( ) ;
204- private ConcurrentDictionary < EDataRequest , object > artDataCache = new ConcurrentDictionary < EDataRequest , object > ( ) ;
203+ private readonly ConcurrentDictionary < RDMUID , RDMUID_ReceivedBag > knownRDMUIDs = new ConcurrentDictionary < RDMUID , RDMUID_ReceivedBag > ( ) ;
204+ private readonly ConcurrentDictionary < EDataRequest , object > artDataCache = new ConcurrentDictionary < EDataRequest , object > ( ) ;
205205 public IReadOnlyCollection < RDMUID_ReceivedBag > KnownRDMUIDs ;
206206 public event EventHandler < RDMUID_ReceivedBag > RDMUIDReceived ;
207207
@@ -214,7 +214,7 @@ private void onPropertyChanged(PropertyChangedEventArgs eventArgs)
214214 {
215215 try
216216 {
217- PropertyChanged ? . Invoke ( this , eventArgs ) ;
217+ PropertyChanged ? . InvokeFailSafe ( this , eventArgs ) ;
218218 }
219219 catch ( Exception e )
220220 {
@@ -284,15 +284,14 @@ public void processArtPollReply(ArtPollReply artPollReply)
284284 for ( byte portIndex = 0 ; portIndex < artPollReply . Ports ; portIndex ++ )
285285 {
286286 int physicalPort = ( Math . Max ( 0 , artPollReply . BindIndex - 1 ) * artPollReply . Ports ) + portIndex ;
287- RemoteClientPort port = null ;
288- if ( ports . TryGetValue ( physicalPort , out port ) )
287+ if ( ports . TryGetValue ( physicalPort , out RemoteClientPort port ) )
289288 port . processArtPollReply ( artPollReply ) ;
290289 else
291290 {
292291 port = new RemoteClientPort ( artPollReply , portIndex ) ;
293292 if ( ports . TryAdd ( physicalPort , port ) )
294293 {
295- PortDiscovered ? . Invoke ( this , port ) ;
294+ PortDiscovered ? . InvokeFailSafe ( this , port ) ;
296295 port . RDMUIDReceived += Port_RDMUIDReceived ;
297296 }
298297 }
@@ -311,7 +310,7 @@ public void processArtPollReply(ArtPollReply artPollReply)
311310 foreach ( var port in timoutedPorts )
312311 {
313312 ports . TryRemove ( port . Key , out _ ) ;
314- PortTimedOut ? . Invoke ( this , port . Value ) ;
313+ PortTimedOut ? . InvokeFailSafe ( this , port . Value ) ;
315314 }
316315 }
317316 Ports = ports . Select ( p => p . Value ) . ToList ( ) . AsReadOnly ( ) ;
@@ -333,26 +332,26 @@ private async Task PollArtData()
333332 if ( Instance is ControllerInstance )
334333 {
335334 using ArtData artData = new ArtData ( instance . OEMProductCode , instance . ESTAManufacturerCode ) ;
336- await ArtNet . Instance . TrySendPacket ( artData , IpAddress ) ;
335+ await Instance . ArtNetInstance . TrySendPacket ( artData , IpAddress ) ;
337336 }
338337 }
339338 private async Task QueryArtData ( )
340339 {
341- if ( ! ( Instance is ControllerInstance ) )
340+ if ( Instance is not ControllerInstance )
342341 return ;
343342
344343 EDataRequest [ ] todo = new [ ] { EDataRequest . UrlProduct , EDataRequest . UrlSupport , EDataRequest . UrlUserGuide , EDataRequest . UrlPersUdr , EDataRequest . UrlPersGdtf } ;
345344 foreach ( EDataRequest req in todo )
346345 {
347346 using ArtData artData = new ArtData ( instance . OEMProductCode , instance . ESTAManufacturerCode , req ) ;
348- await ArtNet . Instance . TrySendPacket ( artData , IpAddress ) ;
347+ await Instance . ArtNetInstance . TrySendPacket ( artData , IpAddress ) ;
349348 }
350349 }
351350
352351 private void Port_RDMUIDReceived ( object sender , RDMUID_ReceivedBag bag )
353352 {
354353 knownRDMUIDs . AddOrUpdate ( bag . Uid , bag , ( x , y ) => bag ) ;
355- RDMUIDReceived ? . Invoke ( this , bag ) ;
354+ RDMUIDReceived ? . InvokeFailSafe ( this , bag ) ;
356355 }
357356 public void RemoveOutdatedRdmUIDs ( )
358357 {
0 commit comments