diff --git a/ArtNetSharp/ApplicationLogging.cs b/ArtNetSharp/ApplicationLogging.cs index 38b9c85..1748b46 100644 --- a/ArtNetSharp/ApplicationLogging.cs +++ b/ArtNetSharp/ApplicationLogging.cs @@ -1,16 +1,12 @@ -using Microsoft.Extensions.Logging.Abstractions; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using System; -using System.ComponentModel; using System.IO; -using System.Reflection; -using static ArtNetSharp.ApplicationLogging; -using System.Net.Sockets; +using System.Linq; using System.Text; -using System.Security.Cryptography.X509Certificates; using System.Threading; using System.Threading.Tasks; -using System.Linq; +using static ArtNetSharp.ApplicationLogging; namespace ArtNetSharp { diff --git a/ArtNetSharp/ArtNet.cs b/ArtNetSharp/ArtNet.cs index 063286a..bc01e3c 100644 --- a/ArtNetSharp/ArtNet.cs +++ b/ArtNetSharp/ArtNet.cs @@ -33,7 +33,7 @@ public static ArtNet Instance private List instances = new List(); public ReadOnlyCollection Instances { get => instances.AsReadOnly(); } - private List networkClients= new List(); + private List networkClients = new List(); public IReadOnlyCollection NetworkClients => networkClients.AsReadOnly(); private System.Timers.Timer _updateNetworkClientsTimer = null; @@ -64,7 +64,7 @@ public bool Enabled } } - public event EventHandler> ReceivedData; + public event EventHandler> ReceivedData; internal NetworkClientBag(IPAddress broadcastIpAddress) { @@ -126,7 +126,7 @@ private async Task StartListening() ReceivedData?.Invoke(this, new Tuple(LocalIpAddress, received)); } } - catch(Exception e) { Logger.LogError(e); _ = openClient(); } + catch (Exception e) { Logger.LogError(e); _ = openClient(); } } private List notMatchingIpAdddresses = new List(); @@ -144,7 +144,7 @@ public async Task MatchIP(IPAddress ip) return true; var _ip = await GetLocalIP(ip); - if (IPAddress.Equals(LocalIpAddress , _ip)) + if (IPAddress.Equals(LocalIpAddress, _ip)) { matchingIpAdddresses.Add(ip); return true; @@ -252,7 +252,7 @@ private ArtNet() public static void SetLoggerFectory(ILoggerFactory loggerFactory) { - Tools.LoggerFactory= loggerFactory; + Tools.LoggerFactory = loggerFactory; ApplicationLogging.LoggerFactory = loggerFactory; } @@ -337,7 +337,7 @@ public static bool IsNetworkAvailable(long minimumSpeed) return true; } } - catch(Exception e) + catch (Exception e) { Logger.LogError(e); } @@ -415,7 +415,7 @@ internal async Task TrySendPacket(AbstractArtPacketCore packet, IPv4Address dest internal async Task TrySendBroadcastPacket(AbstractArtPacketCore packet) { List tasks = new List(); - foreach(var ncb in networkClients) + foreach (var ncb in networkClients) tasks.Add(Task.Run(async () => await ncb.TrySendBroadcastPacket(packet))); await Task.WhenAll(tasks); } diff --git a/ArtNetSharp/Communication/AbstractInstance.cs b/ArtNetSharp/Communication/AbstractInstance.cs index 0b8667f..2f4f8ff 100644 --- a/ArtNetSharp/Communication/AbstractInstance.cs +++ b/ArtNetSharp/Communication/AbstractInstance.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Logging; +using ArtNetSharp.Messages.Interfaces; +using Microsoft.Extensions.Logging; using RDMSharp; using System; using System.Collections.Concurrent; @@ -14,10 +15,12 @@ namespace ArtNetSharp.Communication public abstract class AbstractInstance : IInstance { protected static ILogger Logger { get; private set; } = null; - public bool IsDisposed { get; private set; } - public bool IsDisposing { get; private set; } + protected bool IsDisposed { get; private set; } + protected bool IsDisposing { get; private set; } + bool IDisposableExtended.IsDisposed { get => IsDisposed; } + bool IDisposableExtended.IsDisposing { get => IsDisposing; } - public bool IsDeactivated { get { return !artNet.Instances.Contains(this); } } + public bool IsDeactivated { get { return !artNet.Instances.Contains(this); } } private Random _random; private ArtNet artNet; @@ -46,10 +49,10 @@ public abstract class AbstractInstance : IInstance private readonly System.Timers.Timer _timerSendDMXKeepAlive; private List portConfigs = new List(); - public ReadOnlyCollection PortConfigs { get=> portConfigs.AsReadOnly(); } + public ReadOnlyCollection PortConfigs { get => portConfigs.AsReadOnly(); } - private ConcurrentDictionary> receivedDMXBuffer = new ConcurrentDictionary>(); - private object _receiveLock= new object(); + private ConcurrentDictionary> receivedDMXBuffer = new ConcurrentDictionary>(); + private object _receiveLock = new object(); private class DMXReceiveBag { @@ -83,7 +86,7 @@ internal bool Update(ArtDMX artDMX, IPv4Address source) if (_new == 0) return null; //SpezialCase - if(_old<_new) + if (_old < _new) return true; if (_old > _new && ((byte.MaxValue - _old) < _new)) @@ -95,7 +98,7 @@ internal bool Update(ArtDMX artDMX, IPv4Address source) private class DMXSendBag { public byte[] Data { get; internal set; } - public bool Updated{ get; internal set; } + public bool Updated { get; internal set; } public DMXSendBag(byte[] data) { @@ -160,7 +163,7 @@ protected AbstractInstance() } ~AbstractInstance() { - Dispose(); + ((IDisposable)this).Dispose(); } void IInstance.PacketReceived(AbstractArtPacketCore packet, IPv4Address localIp, IPv4Address sourceIp) @@ -176,7 +179,7 @@ void IInstance.PacketReceived(AbstractArtPacketCore packet, IPv4Address localIp, _ = sendArtPollReply(localIp, sourceIp, artPoll); break; case ArtPollReply artPollReply: - _ = processArtPollReply(artPollReply,localIp, sourceIp); + _ = processArtPollReply(artPollReply, localIp, sourceIp); break; case ArtDMX artDMX: @@ -205,7 +208,7 @@ void IInstance.PacketReceived(AbstractArtPacketCore packet, IPv4Address localIp, break; } } - catch(Exception e) + catch (Exception e) { Logger?.LogError(e); } @@ -233,10 +236,10 @@ private async Task sendArtPoll() if (this.IsDisposing || this.IsDisposed || this.IsDeactivated) return; - ArtPoll artPoll = new ArtPoll(OEMProductCode, ESTAManufacturerCode); + using ArtPoll artPoll = new ArtPoll(OEMProductCode, ESTAManufacturerCode); await TrySendBroadcastPacket(artPoll); } - private async Task sendArtPollReply(IPv4Address ownIp, IPv4Address destinationIp, ArtPoll artPoll=null) + private async Task sendArtPollReply(IPv4Address ownIp, IPv4Address destinationIp, ArtPoll artPoll = null) { if (this.IsDisposing || this.IsDisposed || this.IsDeactivated) return; @@ -252,7 +255,7 @@ private async Task sendArtPollReply(IPv4Address ownIp, IPv4Address destinationIp List tasks = new List(); var ports = portConfigs.OrderBy(pc => pc.PortAddress.Combined).ToList(); if (ports.Count != 0) - for (byte bindindex=0; bindindex< Math.Min(byte.MaxValue,ports.Count()); bindindex++) + for (byte bindindex = 0; bindindex < Math.Min(byte.MaxValue, ports.Count()); bindindex++) { PortConfig portConfig = ports[bindindex]; if (artPoll?.Flags.HasFlag(EArtPollFlags.EnableTargetedMode) ?? false) @@ -382,13 +385,13 @@ private async Task sendArtSync() { if (this.IsDisposing || this.IsDisposed || this.IsDeactivated) return; - - await TrySendBroadcastPacket(new ArtSync()); + using ArtSync artSync = new ArtSync(); + await TrySendBroadcastPacket(artSync); } #endregion #region Send ArtDMX - internal async Task sendArtDMX(RemoteClientPort remoteClientPort, byte sourcePort, byte[] data, bool broadcast=false) + internal async Task sendArtDMX(RemoteClientPort remoteClientPort, byte sourcePort, byte[] data, bool broadcast = false) { if (this.IsDisposing || this.IsDisposed || this.IsDeactivated) return; @@ -396,9 +399,9 @@ internal async Task sendArtDMX(RemoteClientPort remoteClientPort, byte sourcePor if (!remoteClientPort.OutputPortAddress.HasValue) return; - PortAddress portAddress= remoteClientPort.OutputPortAddress.Value; - ArtDMX artDMX = new ArtDMX(remoteClientPort.Sequence, sourcePort, portAddress.Net, portAddress.Address, data); - if(broadcast) + PortAddress portAddress = remoteClientPort.OutputPortAddress.Value; + using ArtDMX artDMX = new ArtDMX(remoteClientPort.Sequence, sourcePort, portAddress.Net, portAddress.Address, data); + if (broadcast) await TrySendBroadcastPacket(artDMX); else await TrySendPacket(artDMX, remoteClientPort.IpAddress); @@ -417,7 +420,7 @@ private async Task sendAllArtDMX(bool keepAlive = false) if (this.IsDisposing || this.IsDisposed || this.IsDeactivated) return; - if(pauseDMXOutput.CurrentCount == 0) + if (pauseDMXOutput.CurrentCount == 0) await pauseDMXOutput.WaitAsync(); if (semaphoreSlimDMXOutput.CurrentCount == 0) @@ -440,7 +443,7 @@ private async Task sendAllArtDMX(bool keepAlive = false) PortConfig config = portConfigs.FirstOrDefault(pc => PortAddress.Equals(pc.PortAddress, port.OutputPortAddress)); byte sourcePort = config?.PortNumber ?? 0; bag.Updated = false; - await sendArtDMX(port, sourcePort, bag.Data, config?.ForceBroadcast??false); + await sendArtDMX(port, sourcePort, bag.Data, config?.ForceBroadcast ?? false); sended++; if (config == null) return; @@ -451,7 +454,7 @@ private async Task sendAllArtDMX(bool keepAlive = false) } } } - catch(Exception e) { Logger.LogError(e); } + catch (Exception e) { Logger.LogError(e); } })); await Task.WhenAll(tasks); if (EnabelSync && sended != 0) @@ -476,7 +479,7 @@ private async Task sendArtTodRequest(IPv4Address ipAddress, PortAddress portAddr private async Task sendArtTodRequestBroadcast(PortAddress portAddress) { - ArtTodRequest artTodRequest = new ArtTodRequest(portAddress); + using ArtTodRequest artTodRequest = new ArtTodRequest(portAddress); await TrySendBroadcastPacket(artTodRequest); } private async Task sendArtTodControl(IPv4Address ipAddress, PortAddress portAddress, EArtTodControlCommand command) @@ -488,14 +491,14 @@ private async Task sendArtTodControl(IPv4Address ipAddress, PortAddress portAddr private async Task sendArtTodControlBroadcast(PortAddress portAddress, EArtTodControlCommand command) { - ArtTodControl artTodControl = new ArtTodControl(portAddress, command); + using ArtTodControl artTodControl = new ArtTodControl(portAddress, command); await TrySendBroadcastPacket(artTodControl); } protected async Task sendArtTodData(IPv4Address ipAddress, PortConfig portConfig) { ArtTodData artTodData = null; - List uids = portConfig.KnownRDMUIDs.Select(bag=>bag.Uid).ToList(); + List uids = portConfig.KnownRDMUIDs.Select(bag => bag.Uid).ToList(); ushort totalCount = (ushort)uids.Count(); byte blockCount = 0; EArtTodDataCommandResponse command = EArtTodDataCommandResponse.TodFull; @@ -515,7 +518,7 @@ protected async Task sendArtTodData(IPv4Address ipAddress, PortConfig portConfig } while (uids.Count != 0); } - public async Task SendArtRDM(RDMMessage rdmMessage) + public async Task SendArtRDM(RDMMessage rdmMessage) { if (!rdmMessage.Command.HasFlag(ERDM_Command.RESPONSE) && rdmMessage.SourceUID == RDMUID.Empty) rdmMessage.SourceUID = UID; @@ -524,7 +527,7 @@ public async Task SendArtRDM(RDMMessage rdmMessage) if (knownRDMUIDs.TryGetValue(rdmMessage.DestUID, out uidBag)) rdmMessage.TransactionCounter = uidBag.NewTransactionNumber(); - var ports = RemoteClientsPorts.Where(port => port.KnownRDMUIDs.Count != 0).Where(port => port.OutputPortAddress.HasValue && port.KnownRDMUIDs.Any(bag => bag.Uid==rdmMessage.DestUID)).ToList(); + var ports = RemoteClientsPorts.Where(port => port.KnownRDMUIDs.Count != 0).Where(port => port.OutputPortAddress.HasValue && port.KnownRDMUIDs.Any(bag => bag.Uid == rdmMessage.DestUID)).ToList(); List tasks = new List(); foreach (var port in ports) { @@ -539,7 +542,7 @@ protected async Task sendArtRDM(PortAddress portAddress, RDMMessage rdmMessage) rdmMessage.SourceUID = UID; RDMUID_ReceivedBag uidBag; - if (knownRDMUIDs.TryGetValue(rdmMessage.DestUID, out uidBag)) + if (knownRDMUIDs.TryGetValue(rdmMessage.DestUID, out uidBag)) rdmMessage.TransactionCounter = uidBag.NewTransactionNumber(); ArtRDM artRDM = new ArtRDM(portAddress, rdmMessage); @@ -602,13 +605,13 @@ private async Task processArtPollReply(ArtPollReply artPollReply, IPv4Address lo if (this.IsDisposing || this.IsDisposed || this.IsDeactivated) return; - if (MajorVersion == artPollReply.MajorVersion - && MinorVersion == artPollReply.MinorVersion - && IPv4Address.Equals(sourceIp, localIp) - && IPv4Address.Equals(artPollReply.OwnIp, localIp) - && string.Equals(artPollReply.ShortName, ShortName) - && string.Equals(artPollReply.LongName, Name)) - return; //break loopback + if (MajorVersion == artPollReply.MajorVersion + && MinorVersion == artPollReply.MinorVersion + && IPv4Address.Equals(sourceIp, localIp) + && IPv4Address.Equals(artPollReply.OwnIp, localIp) + && string.Equals(artPollReply.ShortName, ShortName) + && string.Equals(artPollReply.LongName, Name)) + return; //break loopback await semaphoreSlimAddRemoteClient.WaitAsync(); @@ -646,7 +649,7 @@ async Task add() semaphoreSlimAddRemoteClient.Release(); var deadline = 7500; // Spec 1.4dd page 12, doubled to allow one lost reply (6s is allowad, for some delay i add 1500 ms) - var timoutedClients = remoteClients.Where(p => (DateTime.UtcNow-p.Value.LastSeen).TotalMilliseconds > deadline); + var timoutedClients = remoteClients.Where(p => (DateTime.UtcNow - p.Value.LastSeen).TotalMilliseconds > deadline); if (timoutedClients.Count() != 0) { timoutedClients = timoutedClients.ToList(); @@ -670,7 +673,7 @@ private void processArtDMX(ArtDMX artDMX, IPv4Address sourceIp) if (this.IsDisposing || this.IsDisposed || this.IsDeactivated) return; - var port= portConfigs.FirstOrDefault(p => p.Universe == artDMX.Address.Universe && p.Subnet == artDMX.Address.Subnet && p.Net == artDMX.Net); + var port = portConfigs.FirstOrDefault(p => p.Universe == artDMX.Address.Universe && p.Subnet == artDMX.Address.Subnet && p.Net == artDMX.Net); if (port == null) return; @@ -695,7 +698,7 @@ private void processArtDMX(ArtDMX artDMX, IPv4Address sourceIp) if (success) DMXReceived?.Invoke(this, port.PortAddress); } - + protected async Task processArtTodRequest(ArtTodRequest artTodRequest, IPv4Address source) { @@ -902,7 +905,7 @@ public void ResumeDMXOutput() pauseDMXCountdown = 0; } - public byte[] GetReceivedDMX(in PortAddress portAddress, EMergeMode mergeMode= EMergeMode.HTP) + public byte[] GetReceivedDMX(in PortAddress portAddress, EMergeMode mergeMode = EMergeMode.HTP) { if (this.IsDisposing || this.IsDisposed) return null; @@ -911,7 +914,7 @@ public byte[] GetReceivedDMX(in PortAddress portAddress, EMergeMode mergeMode= E if (!receivedDMXBuffer.TryGetValue(portAddress, out cdb)) return null; - + var bags = cdb.Select(b => b.Value).ToList(); if (bags.Count == 0) @@ -923,9 +926,9 @@ public byte[] GetReceivedDMX(in PortAddress portAddress, EMergeMode mergeMode= E switch (mergeMode) { case EMergeMode.HTP: - int length = bags.Select(b=>b.Data.Length).OrderBy(b => b).Last(); + int length = bags.Select(b => b.Data.Length).OrderBy(b => b).Last(); byte[] dataResult = new byte[length]; - for(ushort i = 0; i < dataResult.Length; i++) + for (ushort i = 0; i < dataResult.Length; i++) { byte val = 0; bags.ForEach(b => { if (i < b.Data.Length) val = Math.Max(val, b.Data[i]); }); @@ -948,7 +951,7 @@ public RDMUID[] GetReceivedRDMUIDs() return KnownRDMUIDs.Where(k => !k.Timouted()).Select(k => k.Uid).ToArray(); } - protected async Task PerformRDMDiscovery(PortAddress? portAddress = null, bool flush = false, bool broadcast=false) + protected async Task PerformRDMDiscovery(PortAddress? portAddress = null, bool flush = false, bool broadcast = false) { if (this.IsDisposing || this.IsDisposed) return; @@ -959,7 +962,7 @@ protected async Task PerformRDMDiscovery(PortAddress? portAddress = null, bool f else ports = RemoteClientsPorts.Where(port => port.OutputPortAddress.HasValue && PortAddress.Equals(port.OutputPortAddress.Value, portAddress.Value)).ToList(); - List tasks= new List(); + List tasks = new List(); foreach (var port in ports) { if (!port.IsRDMCapable) @@ -993,7 +996,7 @@ protected virtual async Task PerformRDMDiscoverOnOutput(PortConfig portConfig) private ENodeStatus getOwnNodeStatus() { - ENodeStatus nodeStatus= ENodeStatus.None; + ENodeStatus nodeStatus = ENodeStatus.None; if (SupportRDM) nodeStatus |= ENodeStatus.RDM_Supported; @@ -1060,7 +1063,7 @@ private async void _timerSendPoll_Elapsed(object sender, ElapsedEventArgs e) } private async void _timerSendDMX_Elapsed(object sender, ElapsedEventArgs e) { - if (pauseDMXOutput.CurrentCount==0) + if (pauseDMXOutput.CurrentCount == 0) { pauseDMXCountdown--; if (pauseDMXCountdown == 0) @@ -1073,7 +1076,7 @@ private async void _timerSendDMXKeepAlive_Elapsed(object sender, ElapsedEventArg await sendAllArtDMX(true); } - public void Dispose() + void IDisposable.Dispose() { if (this.IsDisposed || this.IsDisposing) return; @@ -1101,9 +1104,9 @@ public void Dispose() remoteClients.Clear(); RemoteClients = null; - OnDispose(); + Dispose(); } - catch(Exception e) { Logger.LogError(e); } + catch (Exception e) { Logger.LogError(e); } finally { this.IsDisposed = true; @@ -1112,7 +1115,7 @@ public void Dispose() } } - protected virtual void OnDispose() + protected virtual void Dispose() { } diff --git a/ArtNetSharp/Communication/ControllerInstance.cs b/ArtNetSharp/Communication/ControllerInstance.cs index e125e20..668a062 100644 --- a/ArtNetSharp/Communication/ControllerInstance.cs +++ b/ArtNetSharp/Communication/ControllerInstance.cs @@ -1,5 +1,4 @@ using RDMSharp; -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -15,7 +14,7 @@ public class ControllerInstance : AbstractInstance protected override async void OnPacketReceived(AbstractArtPacketCore packet, IPv4Address localIp, IPv4Address sourceIp) { - switch(packet) + switch (packet) { case ArtDataReply artDataReply: @@ -35,7 +34,7 @@ private async Task processArtDataReply(ArtDataReply artDataReply, IPv4Address so public async Task PerformRDMDiscovery(PortAddress? portAddress = null, bool flush = false) { - await base.PerformRDMDiscovery(portAddress,flush); + await base.PerformRDMDiscovery(portAddress, flush); } } } diff --git a/ArtNetSharp/Communication/IInstance.cs b/ArtNetSharp/Communication/IInstance.cs index 0d66a31..52979d1 100644 --- a/ArtNetSharp/Communication/IInstance.cs +++ b/ArtNetSharp/Communication/IInstance.cs @@ -1,9 +1,9 @@ -using RDMSharp; -using System; +using ArtNetSharp.Messages.Interfaces; +using RDMSharp; namespace ArtNetSharp.Communication { - internal interface IInstance: IDisposable + internal interface IInstance : IDisposableExtended { string Name { get; set; } string ShortName { get; set; } diff --git a/ArtNetSharp/Communication/NodeInstance.cs b/ArtNetSharp/Communication/NodeInstance.cs index 7abbd8b..1eff319 100644 --- a/ArtNetSharp/Communication/NodeInstance.cs +++ b/ArtNetSharp/Communication/NodeInstance.cs @@ -65,7 +65,7 @@ protected async Task processArtData(ArtData artData, IPv4Address source) packet = buildArtDataReply(artData); if (packet != null) - await TrySendPacket(packet,source); + await TrySendPacket(packet, source); } catch (Exception ex) { Logger.LogError(ex); } } diff --git a/ArtNetSharp/Communication/PortConfig.cs b/ArtNetSharp/Communication/PortConfig.cs index 7533e58..424b192 100644 --- a/ArtNetSharp/Communication/PortConfig.cs +++ b/ArtNetSharp/Communication/PortConfig.cs @@ -64,7 +64,7 @@ public PortConfig(PortAddress portAddress, bool output, bool input) KnownRDMUIDs = knownRDMUIDs.Values.ToList().AsReadOnly(); } - public void AddAdditionalIPEndpoints(params IPv4Address[] addresses) + public void AddAdditionalIPEndpoints(params IPv4Address[] addresses) { foreach (IPv4Address address in addresses) if (!additionalIPEndpoints.Contains(address)) diff --git a/ArtNetSharp/Communication/RemoteClient.cs b/ArtNetSharp/Communication/RemoteClient.cs index 74c565f..b08159d 100644 --- a/ArtNetSharp/Communication/RemoteClient.cs +++ b/ArtNetSharp/Communication/RemoteClient.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.ComponentModel; using System.Linq; -using System.Net.Mail; using System.Runtime.CompilerServices; using System.Threading.Tasks; @@ -196,7 +195,7 @@ public ArtPollReply Root this.IsSACNCapable = root.Status.HasFlag(ENodeStatus.NodeSupportArtNet_sACN_Switching); } } - private ConcurrentDictionary ports= new ConcurrentDictionary(); + private ConcurrentDictionary ports = new ConcurrentDictionary(); public IReadOnlyCollection Ports { get; private set; } public event EventHandler PortDiscovered; public event EventHandler PortTimedOut; @@ -217,7 +216,7 @@ private void onPropertyChanged(PropertyChangedEventArgs eventArgs) { PropertyChanged?.Invoke(this, eventArgs); } - catch(Exception e) + catch (Exception e) { Logger.LogError(e); } @@ -332,7 +331,10 @@ public async Task processArtDataReply(ArtDataReply artDataReply) private async Task PollArtData() { if (Instance is ControllerInstance) - await ArtNet.Instance.TrySendPacket(new ArtData(instance.OEMProductCode, instance.ESTAManufacturerCode), IpAddress); + { + using ArtData artData = new ArtData(instance.OEMProductCode, instance.ESTAManufacturerCode); + await ArtNet.Instance.TrySendPacket(artData, IpAddress); + } } private async Task QueryArtData() { @@ -341,7 +343,10 @@ private async Task QueryArtData() EDataRequest[] todo = new[] { EDataRequest.UrlProduct, EDataRequest.UrlSupport, EDataRequest.UrlUserGuide, EDataRequest.UrlPersUdr, EDataRequest.UrlPersGdtf }; foreach (EDataRequest req in todo) - await ArtNet.Instance.TrySendPacket(new ArtData(instance.OEMProductCode, instance.ESTAManufacturerCode, req), IpAddress); + { + using ArtData artData = new ArtData(instance.OEMProductCode, instance.ESTAManufacturerCode, req); + await ArtNet.Instance.TrySendPacket(artData, IpAddress); + } } private void Port_RDMUIDReceived(object sender, RDMUID_ReceivedBag bag) diff --git a/ArtNetSharp/Communication/RemoteClientPort.cs b/ArtNetSharp/Communication/RemoteClientPort.cs index de8ff90..c3617c3 100644 --- a/ArtNetSharp/Communication/RemoteClientPort.cs +++ b/ArtNetSharp/Communication/RemoteClientPort.cs @@ -134,7 +134,7 @@ private set private void onPropertyChanged([CallerMemberName] string membername = "") { - onPropertyChanged( new PropertyChangedEventArgs(membername)); + onPropertyChanged(new PropertyChangedEventArgs(membername)); } private void onPropertyChanged(PropertyChangedEventArgs eventArgs) { @@ -226,7 +226,7 @@ internal void AddRdmUIDs(params RDMUID[] rdmuids) bag.Seen(); else { - bag= new RDMUID_ReceivedBag(rdmuid); + bag = new RDMUID_ReceivedBag(rdmuid); if (knownRDMUIDs.TryAdd(rdmuid, bag)) { RDMUIDReceived?.Invoke(this, bag); diff --git a/ArtNetSharp/Messages/Abstract/AbstractArtPacketCore.cs b/ArtNetSharp/Messages/Abstract/AbstractArtPacketCore.cs index acf218f..073c700 100644 --- a/ArtNetSharp/Messages/Abstract/AbstractArtPacketCore.cs +++ b/ArtNetSharp/Messages/Abstract/AbstractArtPacketCore.cs @@ -1,8 +1,9 @@ -using System; +using ArtNetSharp.Messages.Interfaces; +using System; namespace ArtNetSharp { - public abstract class AbstractArtPacketCore + public abstract class AbstractArtPacketCore : IDisposableExtended { public abstract EOpCodes OpCode { get; } protected abstract ushort PacketMinLength { get; } @@ -10,6 +11,14 @@ public abstract class AbstractArtPacketCore protected virtual ushort PacketBuildLength { get { return PacketMaxLength; } } protected bool PacketLengthIsMinimum { get { return PacketMinLength != PacketMaxLength; } } + + protected bool IsDisposing { get; private set; } + bool IDisposableExtended.IsDisposing { get => IsDisposing; } + protected bool IsDisposed { get; private set; } + bool IDisposableExtended.IsDisposed { get => IsDisposed; } + + protected int? HashCode { get; private set; } + protected AbstractArtPacketCore() { } @@ -27,9 +36,16 @@ public AbstractArtPacketCore(in byte[] packet) : this() else if (packet.Length != PacketMinLength) throw new ArgumentOutOfRangeException($"This Packet({packet.Length}) should be {PacketMinLength} bytes"); } + ~AbstractArtPacketCore() + { + ((IDisposable)this).Dispose(); + } public byte[] GetPacket() { + if (this.IsDisposing || this.IsDisposed) + throw new ObjectDisposedException(this.GetType().FullName); + byte[] p = new byte[(int)PacketBuildLength]; Tools.FillDefaultPacket(OpCode, ref p); @@ -52,7 +68,32 @@ public override bool Equals(object obj) public override int GetHashCode() { - return 483245663 + OpCode.GetHashCode(); + if (HashCode.HasValue) + return HashCode.Value; + + HashCode = 483245663 + OpCode.GetHashCode(); + return HashCode.Value; + } + + void IDisposable.Dispose() + { + if (this.IsDisposing || this.IsDisposed) + return; + + IsDisposing = true; + try + { + this.Dispose(); + } + catch { } + IsDisposed = true; + IsDisposing = false; + GC.SuppressFinalize(this); + } + + protected virtual void Dispose() + { + } } } \ No newline at end of file diff --git a/ArtNetSharp/Messages/Abstract/AbstractArtPacketNet.cs b/ArtNetSharp/Messages/Abstract/AbstractArtPacketNet.cs index abf765c..411eaad 100644 --- a/ArtNetSharp/Messages/Abstract/AbstractArtPacketNet.cs +++ b/ArtNetSharp/Messages/Abstract/AbstractArtPacketNet.cs @@ -7,7 +7,7 @@ public abstract class AbstractArtPacketNet : AbstractArtPacket /// The top 7 bits of the 15 bit Port-Address to which this packet is destined. /// public readonly Net Net; - + public AbstractArtPacketNet(in Net net, in ushort protocolVersion = Constants.PROTOCOL_VERSION) : base(protocolVersion) { @@ -29,7 +29,7 @@ public static implicit operator byte[](AbstractArtPacketNet abstractArtPacketNet public override bool Equals(object obj) { - return base.Equals(obj) && + return base.Equals(obj) && obj is AbstractArtPacketNet other && Net == other.Net; } diff --git a/ArtNetSharp/Messages/ArtAddress.cs b/ArtNetSharp/Messages/ArtAddress.cs index cb8a89d..a931f96 100644 --- a/ArtNetSharp/Messages/ArtAddress.cs +++ b/ArtNetSharp/Messages/ArtAddress.cs @@ -11,7 +11,7 @@ public sealed class ArtAddress : AbstractArtPacket protected override sealed ushort PacketMinLength => 107; public readonly Net? Net; - public readonly Subnet? Subnet; + public readonly Subnet? Subnet; public readonly ArtAddressCommand Command; public readonly byte BindIndex; public readonly string ShortName; @@ -83,7 +83,7 @@ public ArtAddress(in byte[] packet) : base(packet) for (int i = 0; i < 4; i++) if ((packet[100 + i] & 0x80) == 0x80) swOut.Add((Universe?)(byte)(packet[100 + i] & 0x0f)); - OutputUniverses= swOut.ToArray(); + OutputUniverses = swOut.ToArray(); if ((packet[104] & 0x80) == 0x80) Subnet = (byte)(packet[104] & 0x0f); diff --git a/ArtNetSharp/Messages/ArtDMX.cs b/ArtNetSharp/Messages/ArtDMX.cs index 70581e3..f1dbf4f 100644 --- a/ArtNetSharp/Messages/ArtDMX.cs +++ b/ArtNetSharp/Messages/ArtDMX.cs @@ -4,7 +4,7 @@ namespace ArtNetSharp { - public sealed class ArtDMX: AbstractArtPacketNetAddress + public sealed class ArtDMX : AbstractArtPacketNetAddress { /// /// The sequence number is used to ensure that ArtDmx packets are used in the correct order. diff --git a/ArtNetSharp/Messages/ArtDataReply.cs b/ArtNetSharp/Messages/ArtDataReply.cs index c8e832b..b37b0c6 100644 --- a/ArtNetSharp/Messages/ArtDataReply.cs +++ b/ArtNetSharp/Messages/ArtDataReply.cs @@ -9,7 +9,7 @@ public sealed class ArtDataReply : AbstractArtPacket { public override sealed EOpCodes OpCode => EOpCodes.OpDataReply; protected override sealed ushort PacketMinLength => 42; - protected override sealed ushort PacketMaxLength => (ushort)(PacketMinLength+512); + protected override sealed ushort PacketMaxLength => (ushort)(PacketMinLength + 512); protected override sealed ushort PacketBuildLength => (ushort)(PacketMinLength + (Data?.Length ?? 0)); public readonly EDataRequest Request; @@ -33,7 +33,7 @@ public ArtDataReply(in ushort oemCode = Constants.DEFAULT_OEM_CODE, in ushort manufacturerCode = Constants.DEFAULT_ESTA_MANUFACTURER_CODE, in EDataRequest request = EDataRequest.Poll, in string payload = null, - in ushort protocolVersion = Constants.PROTOCOL_VERSION) : this(oemCode,manufacturerCode,request, !string.IsNullOrWhiteSpace(payload)? Encoding.ASCII.GetBytes(payload):null,protocolVersion) + in ushort protocolVersion = Constants.PROTOCOL_VERSION) : this(oemCode, manufacturerCode, request, !string.IsNullOrWhiteSpace(payload) ? Encoding.ASCII.GetBytes(payload) : null, protocolVersion) { PayloadObject = payload; } @@ -53,13 +53,13 @@ public ArtDataReply(in byte[] packet) : base(packet) { if (packet.Length >= 13) - ManufacturerCode = (ushort)(packet[12] << 8 | packet[13]); + ManufacturerCode = (ushort)(packet[12] << 8 | packet[13]); OemCode = (ushort)(packet[14] << 8 | packet[15]); Request = (EDataRequest)(ushort)(packet[16] << 8 | packet[17]); - ushort payloadLength= (ushort)(packet[18] << 8 | packet[19]); + ushort payloadLength = (ushort)(packet[18] << 8 | packet[19]); Data = new byte[payloadLength]; Array.Copy(packet, 20, Data, 0, Data.Length); - if((ushort)Request <=8) // Data is String/URL + if ((ushort)Request <= 8) // Data is String/URL PayloadObject = Encoding.ASCII.GetString(Data, 0, Data.Length).TrimEnd('\0'); } diff --git a/ArtNetSharp/Messages/ArtNzs.cs b/ArtNetSharp/Messages/ArtNzs.cs index 91b542b..84751ab 100644 --- a/ArtNetSharp/Messages/ArtNzs.cs +++ b/ArtNetSharp/Messages/ArtNzs.cs @@ -4,7 +4,7 @@ namespace ArtNetSharp { - public sealed class ArtNzs: AbstractArtPacketNetAddress + public sealed class ArtNzs : AbstractArtPacketNetAddress { /// /// The sequence number is used to ensure that ArtDmx packets are used in the correct order. diff --git a/ArtNetSharp/Messages/ArtPoll.cs b/ArtNetSharp/Messages/ArtPoll.cs index 25e5e01..8f6dd04 100644 --- a/ArtNetSharp/Messages/ArtPoll.cs +++ b/ArtNetSharp/Messages/ArtPoll.cs @@ -37,7 +37,7 @@ public ArtPoll(in ushort oemCode = Constants.DEFAULT_OEM_CODE, Flags = flags; Priority = priority; } - public ArtPoll(in byte[] packet): base(packet) + public ArtPoll(in byte[] packet) : base(packet) { if (packet.Length >= 13) Flags = (EArtPollFlags)packet[12]; diff --git a/ArtNetSharp/Messages/ArtPollReply.cs b/ArtNetSharp/Messages/ArtPollReply.cs index bd30355..148b6da 100644 --- a/ArtNetSharp/Messages/ArtPollReply.cs +++ b/ArtNetSharp/Messages/ArtPollReply.cs @@ -6,7 +6,7 @@ namespace ArtNetSharp { - public sealed class ArtPollReply: AbstractArtPacketCore + public sealed class ArtPollReply : AbstractArtPacketCore { public override EOpCodes OpCode => EOpCodes.OpPollReply; protected override ushort PacketMinLength => 198; @@ -166,34 +166,34 @@ public ArtPollReply(in IPv4Address ownIp, defaulRespUID) { } - public ArtPollReply(in IPv4Address ownIp, - in IPv4Address bindIp, - in MACAddress mac, - in string shortName, - in string longName, - in byte bindIndex, - in ENodeStatus status, - in byte majorVersion, - in byte minorVersion, - in Net net, - in Subnet subNet, - in object[] outputUniverses, - in object[] inputUniverses, - in ushort oemCode = Constants.DEFAULT_OEM_CODE, - in ushort manufacturerCode = Constants.DEFAULT_ESTA_MANUFACTURER_CODE, - in byte ports = 1, - in NodeReport? nodeReport = null, - in EPortType[] portTypes = null, - in EGoodInput[] goodInput = null, - in EGoodOutput[] goodOutput = null, - in EMacroState macro = EMacroState.None, - in ERemoteState remote = ERemoteState.None, - in byte ubeaVersion = 0, - in byte acnPriority = 0, - in ushort user = 0, - in ushort refreshRate = 0, - in EStCodes style = EStCodes.StController, - in RDMUID? defaulRespUID = null) : base() + public ArtPollReply(in IPv4Address ownIp, + in IPv4Address bindIp, + in MACAddress mac, + in string shortName, + in string longName, + in byte bindIndex, + in ENodeStatus status, + in byte majorVersion, + in byte minorVersion, + in Net net, + in Subnet subNet, + in object[] outputUniverses, + in object[] inputUniverses, + in ushort oemCode = Constants.DEFAULT_OEM_CODE, + in ushort manufacturerCode = Constants.DEFAULT_ESTA_MANUFACTURER_CODE, + in byte ports = 1, + in NodeReport? nodeReport = null, + in EPortType[] portTypes = null, + in EGoodInput[] goodInput = null, + in EGoodOutput[] goodOutput = null, + in EMacroState macro = EMacroState.None, + in ERemoteState remote = ERemoteState.None, + in byte ubeaVersion = 0, + in byte acnPriority = 0, + in ushort user = 0, + in ushort refreshRate = 0, + in EStCodes style = EStCodes.StController, + in RDMUID? defaulRespUID = null) : base() { if ((outputUniverses?.Length ?? 0) > MaxPortCount) throw new ArgumentOutOfRangeException($"The argument {nameof(outputUniverses)} should be an array with max size of {MaxPortCount}."); @@ -212,7 +212,7 @@ public ArtPollReply(in IPv4Address ownIp, if (oemCode == 0) throw new ArgumentOutOfRangeException($"The argument {nameof(oemCode)} should be not 0x0000, insted use Constants.DEFAULT_OEM_CODE ({Constants.DEFAULT_OEM_CODE})."); - if (manufacturerCode == 0 ) + if (manufacturerCode == 0) throw new ArgumentOutOfRangeException($"The argument {nameof(manufacturerCode)} should be not 0x0000, insted use Constants.DEFAULT_ESTA_MANUFACTURER_CODE ({Constants.DEFAULT_ESTA_MANUFACTURER_CODE})."); OwnIp = ownIp; @@ -384,7 +384,7 @@ public ArtPollReply(in byte[] packet) : base(packet) } List goodOutput = new List(); - for(int i = 0; i < goodOutputA.Count; i++) + for (int i = 0; i < goodOutputA.Count; i++) { goodOutput.Add(goodOutputA[i] | goodOutputB[i]); } @@ -446,7 +446,7 @@ protected sealed override void fillPacketCore(ref byte[] p) //p[186] = ReceiveUniverse; if (InputUniverses != null) for (int i = 0; i < InputUniverses.Length; i++) - p[186 + i] = InputUniverses[i] is Universe? (Universe)InputUniverses[i]: (Address)InputUniverses[i]; + p[186 + i] = InputUniverses[i] is Universe ? (Universe)InputUniverses[i] : (Address)InputUniverses[i]; // 24 SwIn [4] Input Universe //p[190] = SendUniverse; @@ -479,7 +479,7 @@ protected sealed override void fillPacketCore(ref byte[] p) p[211] = (byte)BindIndex; // 39 BindIndex (0 and 1 are equal) - + p[212] = (byte)((uint)Status >> 8); // 40 Status 2 // 41 GoodOutputB diff --git a/ArtNetSharp/Messages/ArtRDM.cs b/ArtNetSharp/Messages/ArtRDM.cs index 3fcf5ea..c8f2d27 100644 --- a/ArtNetSharp/Messages/ArtRDM.cs +++ b/ArtNetSharp/Messages/ArtRDM.cs @@ -28,12 +28,12 @@ public ArtRDM(in PortAddress portAddress, in ushort protocolVersion = Constants.PROTOCOL_VERSION) : this(portAddress.Net, portAddress.Address, rdmMessage, command, rdmVersion, protocolVersion) { } - public ArtRDM(in Net net, - in Address address, - in RDMMessage rdmMessage, - in EArtRDMCommand command = EArtRDMCommand.ArProcess, - in ERDMVersion rdmVersion = ERDMVersion.STANDARD_V1_0, - in ushort protocolVersion = Constants.PROTOCOL_VERSION) : base(net, address, command, protocolVersion) + public ArtRDM(in Net net, + in Address address, + in RDMMessage rdmMessage, + in EArtRDMCommand command = EArtRDMCommand.ArProcess, + in ERDMVersion rdmVersion = ERDMVersion.STANDARD_V1_0, + in ushort protocolVersion = Constants.PROTOCOL_VERSION) : base(net, address, command, protocolVersion) { RDMMessage = rdmMessage; RdmVersion = rdmVersion; @@ -45,7 +45,7 @@ public ArtRDM(in byte[] packet) : base(packet) Data = new byte[(packet.Length - 24) + 1]; Data[0] = 0xcc; - Array.Copy(packet, 24, Data, 1, Data.Length-1); + Array.Copy(packet, 24, Data, 1, Data.Length - 1); RDMMessage = RDMMessageFactory.BuildResponse(Data); } @@ -65,7 +65,7 @@ protected sealed override void fillPacket(ref byte[] p) //p[21] = 0; // Net (done by Abstract part) //p[22] = 0; // Command (done by Abstract part) //p[23] = 0; // Address (done by Abstract part) - Array.Copy(Data, 1, p, 24, Data.Length-1); + Array.Copy(Data, 1, p, 24, Data.Length - 1); } public static implicit operator byte[](ArtRDM artRDM) diff --git a/ArtNetSharp/Messages/ArtSync.cs b/ArtNetSharp/Messages/ArtSync.cs index 263d8da..8854a04 100644 --- a/ArtNetSharp/Messages/ArtSync.cs +++ b/ArtNetSharp/Messages/ArtSync.cs @@ -1,8 +1,6 @@ -using System.Reflection.Emit; - -namespace ArtNetSharp +namespace ArtNetSharp { - public sealed class ArtSync :AbstractArtPacket + public sealed class ArtSync : AbstractArtPacket { public override sealed EOpCodes OpCode => EOpCodes.OpSync; protected override sealed ushort PacketMinLength => 14; diff --git a/ArtNetSharp/Messages/ArtTimeSync.cs b/ArtNetSharp/Messages/ArtTimeSync.cs index cc7ff81..c785482 100644 --- a/ArtNetSharp/Messages/ArtTimeSync.cs +++ b/ArtNetSharp/Messages/ArtTimeSync.cs @@ -44,7 +44,7 @@ protected sealed override void fillPacket(ref byte[] p) p[17] = (byte)DateTime.Hour; // Hours p[18] = (byte)DateTime.Day; // DayOfMonth p[19] = (byte)DateTime.Month; // Month - Tools.FromUShort((ushort)(DateTime.Year-1900), out p[21], out p[20]); + Tools.FromUShort((ushort)(DateTime.Year - 1900), out p[21], out p[20]); p[22] = (byte)DateTime.DayOfWeek; // DayOfWeek p[23] = (byte)DaylightSaving; // DaylightSaving } diff --git a/ArtNetSharp/Messages/ArtTodData.cs b/ArtNetSharp/Messages/ArtTodData.cs index 0dff233..12a1bd8 100644 --- a/ArtNetSharp/Messages/ArtTodData.cs +++ b/ArtNetSharp/Messages/ArtTodData.cs @@ -10,8 +10,8 @@ public sealed class ArtTodData : AbstractArtPacketNetAddressCommand EOpCodes.OpTodData; protected override sealed ushort PacketMinLength => 28; - protected override sealed ushort PacketMaxLength => (ushort)(PacketMinLength + (MaxUidsPerPacket*8)); - protected override sealed ushort PacketBuildLength => (ushort)(PacketMinLength + ((Uids?.Length ?? 0)*8)); + protected override sealed ushort PacketMaxLength => (ushort)(PacketMinLength + (MaxUidsPerPacket * 8)); + protected override sealed ushort PacketBuildLength => (ushort)(PacketMinLength + ((Uids?.Length ?? 0) * 8)); protected override sealed ushort NetByte => 21; protected override sealed ushort CommandByte => 22; protected override sealed ushort AddressByte => 23; @@ -63,20 +63,20 @@ public ArtTodData(in PortAddress portAddress, in RDMUID[] uids = default, in EArtTodDataCommandResponse command = EArtTodDataCommandResponse.TodNak, in ERDMVersion rdmVersion = ERDMVersion.STANDARD_V1_0, - in ushort protocolVersion = Constants.PROTOCOL_VERSION) : this(portAddress.Net, portAddress.Address, port,bindIndex,uidTotalCount, blockCount, uids, command, rdmVersion, protocolVersion) + in ushort protocolVersion = Constants.PROTOCOL_VERSION) : this(portAddress.Net, portAddress.Address, port, bindIndex, uidTotalCount, blockCount, uids, command, rdmVersion, protocolVersion) { } - public ArtTodData(in Net net, - in Address address, - in byte port, - in byte bindIndex, - in ushort uidTotalCount, - in byte blockCount, - in RDMUID[] uids = default, - in EArtTodDataCommandResponse command = EArtTodDataCommandResponse.TodNak, - in ERDMVersion rdmVersion = ERDMVersion.STANDARD_V1_0, - in ushort protocolVersion = Constants.PROTOCOL_VERSION) : base(net, address, command, protocolVersion) + public ArtTodData(in Net net, + in Address address, + in byte port, + in byte bindIndex, + in ushort uidTotalCount, + in byte blockCount, + in RDMUID[] uids = default, + in EArtTodDataCommandResponse command = EArtTodDataCommandResponse.TodNak, + in ERDMVersion rdmVersion = ERDMVersion.STANDARD_V1_0, + in ushort protocolVersion = Constants.PROTOCOL_VERSION) : base(net, address, command, protocolVersion) { if (uids.Length > MaxUidsPerPacket) throw new ArgumentOutOfRangeException($"The limit of UIDs per Package is {MaxUidsPerPacket}"); @@ -100,7 +100,7 @@ public ArtTodData(in byte[] packet) : base(packet) byte count = packet[27]; List uids = new List(); byte[] buffer = new byte[8]; - for( int i=0; i + public sealed class ArtTodRequest : AbstractArtPacketNetCommand { public sealed override EOpCodes OpCode => EOpCodes.OpTodRequest; protected sealed override ushort PacketMinLength => 24; @@ -33,10 +33,10 @@ public ArtTodRequest(in Net net, public ArtTodRequest(in byte net, in Address[] address, in EArtTodRequestCommand command = EArtTodRequestCommand.TodFull, - in ushort protocolVersion = Constants.PROTOCOL_VERSION) : base(net,command, protocolVersion) + in ushort protocolVersion = Constants.PROTOCOL_VERSION) : base(net, command, protocolVersion) { Addresses = address.Take(32).ToArray(); - PortAddresses = Addresses.Select(a=>new PortAddress(Net,a)).ToArray(); + PortAddresses = Addresses.Select(a => new PortAddress(Net, a)).ToArray(); } public ArtTodRequest(in byte[] packet) : base(packet) { diff --git a/ArtNetSharp/Messages/ArtVlc.cs b/ArtNetSharp/Messages/ArtVlc.cs index 5b3cfa1..4dd7493 100644 --- a/ArtNetSharp/Messages/ArtVlc.cs +++ b/ArtNetSharp/Messages/ArtVlc.cs @@ -4,7 +4,7 @@ namespace ArtNetSharp { - public sealed class ArtVlc: AbstractArtPacketNetAddress + public sealed class ArtVlc : AbstractArtPacketNetAddress { /// /// The sequence number is used to ensure that ArtDmx packets are used in the correct order. @@ -68,11 +68,11 @@ public ArtVlc(in byte sequence, in byte[] payload, in ushort transaction, in ushort payloadChecksum, - in ushort slotAddress= 0, - in byte depth= 0, - in ushort modulationFrequency= 0, - in ushort modulationType= 0, - in ushort beaconModeRepeatFrequency=0, + in ushort slotAddress = 0, + in byte depth = 0, + in ushort modulationFrequency = 0, + in ushort modulationType = 0, + in ushort beaconModeRepeatFrequency = 0, in EVlcFlags flags = EVlcFlags.None, in EPayloadLanguageCode payloadLanguageCode = EPayloadLanguageCode.BeaconURL, in ushort protocolVersion = Constants.PROTOCOL_VERSION) : base(net, address, protocolVersion) @@ -94,7 +94,7 @@ public ArtVlc(in byte sequence, } public ArtVlc(in byte[] packet) : base(packet) { - if(!IsArtVlc(packet)) + if (!IsArtVlc(packet)) throw new ArgumentException("This given data isn't an ArtVlcPacket!"); Sequence = packet[12]; // 5 Sequence diff --git a/ArtNetSharp/Messages/Interfaces/IDisposableExtended.cs b/ArtNetSharp/Messages/Interfaces/IDisposableExtended.cs new file mode 100644 index 0000000..fd03b4d --- /dev/null +++ b/ArtNetSharp/Messages/Interfaces/IDisposableExtended.cs @@ -0,0 +1,10 @@ +using System; + +namespace ArtNetSharp.Messages.Interfaces +{ + internal interface IDisposableExtended : IDisposable + { + bool IsDisposing { get; } + bool IsDisposed { get; } + } +} diff --git a/ArtNetSharp/Misc/Enums/EArtAddressCommand.cs b/ArtNetSharp/Misc/Enums/EArtAddressCommand.cs index cebd43a..3fd3935 100644 --- a/ArtNetSharp/Misc/Enums/EArtAddressCommand.cs +++ b/ArtNetSharp/Misc/Enums/EArtAddressCommand.cs @@ -1,10 +1,8 @@ -using System; - -namespace ArtNetSharp +namespace ArtNetSharp { public enum EArtAddressCommand : byte { - None=0x00, + None = 0x00, /// /// If Node is currently in merge mode, cancel merge mode upon receipt of next ArtDmx packet. /// See discussion of merge mode operation. diff --git a/ArtNetSharp/Misc/Enums/EArtIpProgCommand.cs b/ArtNetSharp/Misc/Enums/EArtIpProgCommand.cs index ff951dd..f61375d 100644 --- a/ArtNetSharp/Misc/Enums/EArtIpProgCommand.cs +++ b/ArtNetSharp/Misc/Enums/EArtIpProgCommand.cs @@ -5,14 +5,14 @@ namespace ArtNetSharp [Flags] public enum EArtIpProgCommand : byte { - None=0, - ProgramPort = 0b00000001, - ProgramSubnetMask = 0b00000010, - ProgramIP = 0b00000100, + None = 0, + ProgramPort = 0b00000001, + ProgramSubnetMask = 0b00000010, + ProgramIP = 0b00000100, ResetParametersToDefault = 0b00001000, - ResetDefaultGateway = 0b00010000, + ResetDefaultGateway = 0b00010000, // Not Used = 0b00100000, - EnableDHCP = 0b01000000, - EnableProgramming = 0b10000000, + EnableDHCP = 0b01000000, + EnableProgramming = 0b10000000, } } \ No newline at end of file diff --git a/ArtNetSharp/Misc/Enums/EArtIpProgReplyStatusFlags.cs b/ArtNetSharp/Misc/Enums/EArtIpProgReplyStatusFlags.cs index fd26226..5fb8841 100644 --- a/ArtNetSharp/Misc/Enums/EArtIpProgReplyStatusFlags.cs +++ b/ArtNetSharp/Misc/Enums/EArtIpProgReplyStatusFlags.cs @@ -5,7 +5,7 @@ namespace ArtNetSharp [Flags] public enum EArtIpProgReplyStatusFlags : byte { - None=0, - EnableDHCP = 0b01000000, + None = 0, + EnableDHCP = 0b01000000, } } \ No newline at end of file diff --git a/ArtNetSharp/Misc/Enums/EArtPollFlags.cs b/ArtNetSharp/Misc/Enums/EArtPollFlags.cs index 2842ab0..eacfe2c 100644 --- a/ArtNetSharp/Misc/Enums/EArtPollFlags.cs +++ b/ArtNetSharp/Misc/Enums/EArtPollFlags.cs @@ -5,7 +5,7 @@ namespace ArtNetSharp [Flags] public enum EArtPollFlags : byte { - None=0, + None = 0, ArtPollReplyOnChange = 0b00000010, DiagnosticEnabled = 0b00000100, DiagnosticUnicast = 0b00001000, diff --git a/ArtNetSharp/Misc/Enums/EGoodInput.cs b/ArtNetSharp/Misc/Enums/EGoodInput.cs index a46d028..cd1275c 100644 --- a/ArtNetSharp/Misc/Enums/EGoodInput.cs +++ b/ArtNetSharp/Misc/Enums/EGoodInput.cs @@ -5,7 +5,7 @@ namespace ArtNetSharp [Flags] public enum EGoodInput : byte { - None=0, + None = 0, ReceiveErrorsDetected = 0b00000100, InputIsDisabled = 0b00001000, DMX_TestPacketsSupported = 0b00010000, diff --git a/ArtNetSharp/Misc/Enums/EGoodOutput.cs b/ArtNetSharp/Misc/Enums/EGoodOutput.cs index d0013bd..9fc519c 100644 --- a/ArtNetSharp/Misc/Enums/EGoodOutput.cs +++ b/ArtNetSharp/Misc/Enums/EGoodOutput.cs @@ -5,7 +5,7 @@ namespace ArtNetSharp [Flags] public enum EGoodOutput : ushort { - OutputArtNet= 0b00000000, + OutputArtNet = 0b00000000, OutputSACN = 0b00000001, MergeModeIsLTP = 0b00000010, DMX_OutputShortCircuit = 0b00000100, diff --git a/ArtNetSharp/Misc/Enums/EMacroState.cs b/ArtNetSharp/Misc/Enums/EMacroState.cs index 4a93773..6388e42 100644 --- a/ArtNetSharp/Misc/Enums/EMacroState.cs +++ b/ArtNetSharp/Misc/Enums/EMacroState.cs @@ -5,7 +5,7 @@ namespace ArtNetSharp [Flags] public enum EMacroState : byte { - None=0, + None = 0, Macro1Active = 0b00000001, Macro2Active = 0b00000010, Macro3Active = 0b00000100, diff --git a/ArtNetSharp/Misc/Enums/EMergeMode.cs b/ArtNetSharp/Misc/Enums/EMergeMode.cs index f1b2f4a..722a7c6 100644 --- a/ArtNetSharp/Misc/Enums/EMergeMode.cs +++ b/ArtNetSharp/Misc/Enums/EMergeMode.cs @@ -2,7 +2,7 @@ { public enum EMergeMode { - HTP=0, - LTP=1 + HTP = 0, + LTP = 1 } } \ No newline at end of file diff --git a/ArtNetSharp/Misc/Enums/ENodeStatus.cs b/ArtNetSharp/Misc/Enums/ENodeStatus.cs index cdd0460..5fb3d3c 100644 --- a/ArtNetSharp/Misc/Enums/ENodeStatus.cs +++ b/ArtNetSharp/Misc/Enums/ENodeStatus.cs @@ -1,5 +1,4 @@ using System; -using System.Xml.Linq; namespace ArtNetSharp { diff --git a/ArtNetSharp/Misc/Enums/EPortType.cs b/ArtNetSharp/Misc/Enums/EPortType.cs index ef1fc14..989b7d3 100644 --- a/ArtNetSharp/Misc/Enums/EPortType.cs +++ b/ArtNetSharp/Misc/Enums/EPortType.cs @@ -5,15 +5,15 @@ namespace ArtNetSharp [Flags] public enum EPortType : byte { - DMX512 = 0b00000000, - MIDI = 0b00000001, - Avab = 0b00000010, - ColortranCMX = 0b00000011, - ADB62dot5 = 0b00000100, - ArtNet = 0b00000101, - DALI = 0b00000110, + DMX512 = 0b00000000, + MIDI = 0b00000001, + Avab = 0b00000010, + ColortranCMX = 0b00000011, + ADB62dot5 = 0b00000100, + ArtNet = 0b00000101, + DALI = 0b00000110, - InputToArtNet = 0b01000000, + InputToArtNet = 0b01000000, OutputFromArtNet = 0b10000000, } } \ No newline at end of file diff --git a/ArtNetSharp/Misc/ObjectTypes/Address.cs b/ArtNetSharp/Misc/ObjectTypes/Address.cs index 2516c41..4710420 100644 --- a/ArtNetSharp/Misc/ObjectTypes/Address.cs +++ b/ArtNetSharp/Misc/ObjectTypes/Address.cs @@ -7,7 +7,7 @@ namespace ArtNetSharp public readonly Subnet Subnet; public readonly Universe Universe; public readonly byte Combined; - + public Address(in Subnet subnet, Universe universe) { Subnet = subnet; diff --git a/ArtNetSharp/Misc/ObjectTypes/ArtAddressCommand.cs b/ArtNetSharp/Misc/ObjectTypes/ArtAddressCommand.cs index 15695a9..e6c2711 100644 --- a/ArtNetSharp/Misc/ObjectTypes/ArtAddressCommand.cs +++ b/ArtNetSharp/Misc/ObjectTypes/ArtAddressCommand.cs @@ -4,7 +4,7 @@ namespace ArtNetSharp { public readonly struct ArtAddressCommand : IEquatable { - public static ArtAddressCommand Default { get; }= new ArtAddressCommand(); + public static ArtAddressCommand Default { get; } = new ArtAddressCommand(); public readonly EArtAddressCommand Command; public readonly byte? Port; diff --git a/ArtNetSharp/Misc/ObjectTypes/NodeReport.cs b/ArtNetSharp/Misc/ObjectTypes/NodeReport.cs index 3770d38..2ae98d5 100644 --- a/ArtNetSharp/Misc/ObjectTypes/NodeReport.cs +++ b/ArtNetSharp/Misc/ObjectTypes/NodeReport.cs @@ -1,5 +1,4 @@ -using System; -using System.Text.RegularExpressions; +using System.Text.RegularExpressions; namespace ArtNetSharp { @@ -9,9 +8,9 @@ public readonly struct NodeReport public readonly uint Counter; public readonly string Text; - private const string REGEX= "#([A-Fa-f0-9]+) \\[([0-9]+)\\](.*)"; + private const string REGEX = "#([A-Fa-f0-9]+) \\[([0-9]+)\\](.*)"; - public NodeReport(in ENodeReportCodes reportCode, in string text="", in uint counter=0) + public NodeReport(in ENodeReportCodes reportCode, in string text = "", in uint counter = 0) { ReportCode = reportCode; Counter = counter; @@ -19,7 +18,7 @@ public NodeReport(in ENodeReportCodes reportCode, in string text="", in uint cou } public NodeReport(in string reportCode) { - var Matches=Regex.Matches(reportCode, REGEX); + var Matches = Regex.Matches(reportCode, REGEX); if (Matches.Count == 0) { ReportCode = 0; diff --git a/ArtNetSharp/Misc/ObjectTypes/PortAddress.cs b/ArtNetSharp/Misc/ObjectTypes/PortAddress.cs index 9d10b05..8c33526 100644 --- a/ArtNetSharp/Misc/ObjectTypes/PortAddress.cs +++ b/ArtNetSharp/Misc/ObjectTypes/PortAddress.cs @@ -9,7 +9,7 @@ namespace ArtNetSharp public readonly Universe Universe; public readonly Address Address; public readonly ushort Combined; - + public PortAddress(in Net net, in Subnet subnet, Universe universe) { Net = net; @@ -26,7 +26,7 @@ public PortAddress(in ushort combined) Address = new Address(Subnet, Universe); Combined = combined; } - public PortAddress(in Subnet subnet, Universe universe): this(0,subnet,universe) + public PortAddress(in Subnet subnet, Universe universe) : this(0, subnet, universe) { } diff --git a/ArtNetSharp/Misc/ObjectTypes/Universe.cs b/ArtNetSharp/Misc/ObjectTypes/Universe.cs index 21bd9b3..0d4d38d 100644 --- a/ArtNetSharp/Misc/ObjectTypes/Universe.cs +++ b/ArtNetSharp/Misc/ObjectTypes/Universe.cs @@ -4,7 +4,7 @@ namespace ArtNetSharp { public readonly struct Universe : IEquatable { - public static Universe Default { get; }= new Universe(); + public static Universe Default { get; } = new Universe(); public readonly byte Value; public Universe(in byte value)