diff --git a/ArtNetSharp/Communication/RDMUID_ReceivedBag.cs b/ArtNetSharp/Communication/RDMUID_ReceivedBag.cs index 26bd189..3c04d99 100644 --- a/ArtNetSharp/Communication/RDMUID_ReceivedBag.cs +++ b/ArtNetSharp/Communication/RDMUID_ReceivedBag.cs @@ -3,7 +3,7 @@ namespace ArtNetSharp.Communication { - public class RDMUID_ReceivedBag + public sealed class RDMUID_ReceivedBag { public readonly RDMUID Uid; public DateTime LastSeen { get; private set; } diff --git a/ArtNetSharp/Communication/RemoteClient.cs b/ArtNetSharp/Communication/RemoteClient.cs index 0828e35..7b2ac04 100644 --- a/ArtNetSharp/Communication/RemoteClient.cs +++ b/ArtNetSharp/Communication/RemoteClient.cs @@ -6,11 +6,12 @@ using System.ComponentModel; using System.Linq; using System.Net.Mail; +using System.Runtime.CompilerServices; using System.Threading.Tasks; namespace ArtNetSharp.Communication { - public class RemoteClient : INotifyPropertyChanged + public sealed class RemoteClient : INotifyPropertyChanged { private static ILogger Logger = ApplicationLogging.CreateLogger(); public readonly string ID; @@ -28,7 +29,7 @@ public IPv4Address IpAddress return; ipAddress = value; - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IpAddress))); + onPropertyChanged(); } } private string shortName; @@ -44,7 +45,7 @@ public string ShortName return; shortName = value; - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ShortName))); + onPropertyChanged(); } } private string longName; @@ -60,9 +61,26 @@ public string LongName return; longName = value; - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(LongName))); + onPropertyChanged(); } } + + private DateTime lastSeen; + public DateTime LastSeen + { + get + { + return lastSeen; + } + private set + { + if (lastSeen == value) + return; + lastSeen = value; + onPropertyChanged(); + } + } + private ArtPollReply root; public ArtPollReply Root { @@ -76,7 +94,7 @@ public ArtPollReply Root return; root = value; - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Root))); + onPropertyChanged(); this.IpAddress = root.OwnIp; this.ShortName = root.ShortName; this.LongName = root.LongName; @@ -93,6 +111,21 @@ public ArtPollReply Root public event EventHandler RDMUIDReceived; public event PropertyChangedEventHandler PropertyChanged; + private void onPropertyChanged([CallerMemberName] string membername = "") + { + onPropertyChanged(new PropertyChangedEventArgs(membername)); + } + private void onPropertyChanged(PropertyChangedEventArgs eventArgs) + { + try + { + PropertyChanged?.Invoke(this, eventArgs); + } + catch(Exception e) + { + Logger.LogError(e); + } + } public IReadOnlyDictionary ArtDataCache { @@ -121,8 +154,6 @@ internal AbstractInstance Instance } } - public DateTime LastSeen { get; private set; } - public RemoteClient(in ArtPollReply artPollReply) { ID = getIDOf(artPollReply); diff --git a/ArtNetSharp/Communication/RemoteClientPort.cs b/ArtNetSharp/Communication/RemoteClientPort.cs index e1b25ad..220efa6 100644 --- a/ArtNetSharp/Communication/RemoteClientPort.cs +++ b/ArtNetSharp/Communication/RemoteClientPort.cs @@ -3,31 +3,150 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; +using System.Runtime.CompilerServices; namespace ArtNetSharp.Communication { - public class RemoteClientPort + public sealed class RemoteClientPort : INotifyPropertyChanged { private static ILogger Logger = ApplicationLogging.CreateLogger(); public readonly IPv4Address IpAddress; + public readonly string ID; public readonly byte BindIndex; public readonly byte PortIndex; - public DateTime LastSeen { get; private set; } + private DateTime lastSeen; + public DateTime LastSeen + { + get + { + return lastSeen; + } + private set + { + if (lastSeen == value) + return; + lastSeen = value; + onPropertyChanged(); + } + } public ArtPollReply ArtPollReply { get; private set; } - public PortAddress? OutputPortAddress { get; private set; } - public PortAddress? InputPortAddress { get; private set; } - public EPortType PortType { get; private set; } - public EGoodOutput GoodOutput { get; private set; } - public EGoodInput GoodInput { get; private set; } + private PortAddress? outputPortAddress; + public PortAddress? OutputPortAddress + { + get + { + return outputPortAddress; + } + private set + { + if (outputPortAddress == value) + return; + outputPortAddress = value; + onPropertyChanged(); + } + } + private PortAddress? inputPortAddress; + public PortAddress? InputPortAddress + { + get + { + return inputPortAddress; + } + private set + { + if (inputPortAddress == value) + return; + inputPortAddress = value; + onPropertyChanged(); + } + } + private EPortType portType; + public EPortType PortType + { + get + { + return portType; + } + private set + { + if (portType == value) + return; + portType = value; + onPropertyChanged(); + } + } + private EGoodOutput goodOutput; + public EGoodOutput GoodOutput + { + get + { + return goodOutput; + } + private set + { + if (goodOutput == value) + return; + goodOutput = value; + onPropertyChanged(); + } + } + private EGoodInput goodInput; + public EGoodInput GoodInput + { + get + { + return goodInput; + } + private set + { + if (goodInput == value) + return; + goodInput = value; + onPropertyChanged(); + } + } - public bool IsRDMCapable { get; private set; } + private bool isRDMCapable; + public bool IsRDMCapable + { + get + { + return isRDMCapable; + } + private set + { + if (isRDMCapable == value) + return; + isRDMCapable = value; + onPropertyChanged(); + } + } private ConcurrentDictionary knownRDMUIDs = new ConcurrentDictionary(); public IReadOnlyCollection KnownRDMUIDs; public event EventHandler RDMUIDReceived; public event EventHandler RDMMessageReceived; + public event PropertyChangedEventHandler PropertyChanged; + + private void onPropertyChanged([CallerMemberName] string membername = "") + { + onPropertyChanged( new PropertyChangedEventArgs(membername)); + } + private void onPropertyChanged(PropertyChangedEventArgs eventArgs) + { + try + { + PropertyChanged?.Invoke(this, eventArgs); + } + catch (Exception e) + { + Logger.LogError(e); + } + } + private byte sequence = byte.MaxValue; internal byte Sequence @@ -41,12 +160,17 @@ internal byte Sequence public RemoteClientPort(in ArtPollReply artPollReply, byte portIndex = 0) { + ID = getIDOf(artPollReply); IpAddress = artPollReply.OwnIp; BindIndex = artPollReply.BindIndex; PortIndex = portIndex; processArtPollReply(artPollReply); KnownRDMUIDs = knownRDMUIDs.Values.ToList().AsReadOnly(); } + public static string getIDOf(ArtPollReply artPollReply) + { + return $"{RemoteClient.getIDOf(artPollReply)}==>{artPollReply.BindIndex}"; + } public void processArtPollReply(ArtPollReply artPollReply) {