Skip to content

Commit

Permalink
Some refactoring to add PropertyChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-dmxc committed Sep 30, 2023
1 parent 3e399c9 commit 2f8a075
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ArtNetSharp/Communication/RDMUID_ReceivedBag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
45 changes: 38 additions & 7 deletions ArtNetSharp/Communication/RemoteClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RemoteClient>();
public readonly string ID;
Expand All @@ -28,7 +29,7 @@ public IPv4Address IpAddress
return;

ipAddress = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IpAddress)));
onPropertyChanged();
}
}
private string shortName;
Expand All @@ -44,7 +45,7 @@ public string ShortName
return;

shortName = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ShortName)));
onPropertyChanged();
}
}
private string longName;
Expand All @@ -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
{
Expand All @@ -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;
Expand All @@ -93,6 +111,21 @@ public ArtPollReply Root
public event EventHandler<RDMUID_ReceivedBag> 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<EDataRequest, object> ArtDataCache
{
Expand Down Expand Up @@ -121,8 +154,6 @@ internal AbstractInstance Instance
}
}

public DateTime LastSeen { get; private set; }

public RemoteClient(in ArtPollReply artPollReply)
{
ID = getIDOf(artPollReply);
Expand Down
140 changes: 132 additions & 8 deletions ArtNetSharp/Communication/RemoteClientPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RemoteClientPort>();
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<RDMUID, RDMUID_ReceivedBag> knownRDMUIDs = new ConcurrentDictionary<RDMUID, RDMUID_ReceivedBag>();
public IReadOnlyCollection<RDMUID_ReceivedBag> KnownRDMUIDs;
public event EventHandler<RDMUID_ReceivedBag> RDMUIDReceived;
public event EventHandler<byte[]> 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
Expand All @@ -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)
{
Expand Down

0 comments on commit 2f8a075

Please sign in to comment.