From 0e4c7e9bb349209027530605adc3d05a59a1aa3f Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Tue, 14 May 2024 08:14:55 -0500 Subject: [PATCH] refactor: more C#10 updates --- .../Entities/NvxApplicationAudioReceiver.cs | 6 +-- .../Entities/NvxApplicationVideoReceiver.cs | 4 +- .../NvxApplicationVideoTransmitter.cs | 18 +++---- src/NvxEpi/Devices/NvxXioDirector.cs | 5 +- src/NvxEpi/Enums/Enumeration.cs | 10 ++-- src/NvxEpi/Factories/Nvx35XDeviceFactory.cs | 5 +- src/NvxEpi/Factories/Nvx36XDeviceFactory.cs | 5 +- src/NvxEpi/Factories/NvxBaseDeviceFactory.cs | 54 +++++++------------ src/NvxEpi/Factories/NvxD3XDeviceFactory.cs | 5 +- src/NvxEpi/Factories/NvxDirectorFactory.cs | 20 +++---- src/NvxEpi/Factories/NvxE3XDeviceFactory.cs | 5 +- .../AutomaticRouting/AutomaticInputRouter.cs | 15 ++---- src/NvxEpi/Features/Routing/NvxMatrixInput.cs | 2 +- .../Audio/CurrentSecondaryAudioStream.cs | 2 +- src/NvxEpi/Features/Streams/Usb/UsbStream.cs | 6 +-- .../Streams/Video/CurrentVideoStream.cs | 4 +- .../McMessengers/EndpointInfoMessenger.cs | 6 +-- src/NvxEpi/Services/Bridge/NvxDeviceBridge.cs | 37 +++++-------- .../Feedback/DmHdcpCapabilityValueFeedback.cs | 6 +-- .../Feedback/DmSyncDetectedFeedback.cs | 3 +- .../Feedback/MulticastAddressFeedback.cs | 3 +- .../Feedback/UsbRemoteAddressFeedback.cs | 3 +- .../Feedback/VideoAspectRatioModeFeedback.cs | 2 +- .../InputSwitching/SwitcherForStreamOutput.cs | 6 +-- 24 files changed, 75 insertions(+), 157 deletions(-) diff --git a/src/NvxEpi/Application/Entities/NvxApplicationAudioReceiver.cs b/src/NvxEpi/Application/Entities/NvxApplicationAudioReceiver.cs index 858a8e3..513a25b 100644 --- a/src/NvxEpi/Application/Entities/NvxApplicationAudioReceiver.cs +++ b/src/NvxEpi/Application/Entities/NvxApplicationAudioReceiver.cs @@ -58,12 +58,10 @@ public NvxApplicationAudioReceiver(string key, NvxApplicationDeviceAudioConfig c AddPostActivationAction(() => { - var feedback = Device.Feedbacks[CurrentSecondaryAudioStream.RouteNameKey] as StringFeedback; - var audioSourceFeedback = Device.Feedbacks[AudioInputFeedback.Key] as StringFeedback; - if (feedback == null) + if (Device.Feedbacks[CurrentSecondaryAudioStream.RouteNameKey] is not StringFeedback feedback) throw new NullReferenceException(CurrentSecondaryAudioStream.RouteNameKey); - if (audioSourceFeedback == null) + if (Device.Feedbacks[AudioInputFeedback.Key] is not StringFeedback audioSourceFeedback) throw new NullReferenceException(AudioInputFeedback.Key); var currentRouteFb = new IntFeedback(Key + "--appRouteAudioCurrentId", diff --git a/src/NvxEpi/Application/Entities/NvxApplicationVideoReceiver.cs b/src/NvxEpi/Application/Entities/NvxApplicationVideoReceiver.cs index c57b2b9..ec75cdd 100644 --- a/src/NvxEpi/Application/Entities/NvxApplicationVideoReceiver.cs +++ b/src/NvxEpi/Application/Entities/NvxApplicationVideoReceiver.cs @@ -98,14 +98,14 @@ public NvxApplicationVideoReceiver(string key, NvxApplicationDeviceVideoConfig c AspectRatioMode = new IntFeedback(() => 0); EdidManufacturer = new StringFeedback(() => string.Empty); - if (!(Device is IHdmiOutput hdmiOut)) + if (Device is not IHdmiOutput hdmiOut) return; DisabledByHdcp = hdmiOut.DisabledByHdcp; HorizontalResolution = hdmiOut.HorizontalResolution; EdidManufacturer = hdmiOut.EdidManufacturer; - if (!(Device is IVideowallMode aspect)) + if (Device is not IVideowallMode aspect) return; AspectRatioMode = aspect.VideoAspectRatioMode; diff --git a/src/NvxEpi/Application/Entities/NvxApplicationVideoTransmitter.cs b/src/NvxEpi/Application/Entities/NvxApplicationVideoTransmitter.cs index cd9f8b0..abd9397 100644 --- a/src/NvxEpi/Application/Entities/NvxApplicationVideoTransmitter.cs +++ b/src/NvxEpi/Application/Entities/NvxApplicationVideoTransmitter.cs @@ -115,8 +115,7 @@ private void LinkInputValues(string routingPortKey) if (string.IsNullOrEmpty(routingPortKey)) { - var hdmiInput = Device as IHdmiInput; - if (hdmiInput == null) + if (Device is not IHdmiInput hdmiInput) return; HdmiSyncDetected = hdmiInput.SyncDetected[1]; @@ -125,8 +124,7 @@ private void LinkInputValues(string routingPortKey) } else if (routingPortKey.Equals(DeviceInputEnum.Hdmi1.Name, StringComparison.OrdinalIgnoreCase)) { - var hdmiInput = Device as IHdmiInput; - if (hdmiInput == null) + if (Device is not IHdmiInput hdmiInput) return; HdmiSyncDetected = hdmiInput.SyncDetected[1]; @@ -135,8 +133,7 @@ private void LinkInputValues(string routingPortKey) } else if (routingPortKey.Equals(DeviceInputEnum.Hdmi2.Name, StringComparison.OrdinalIgnoreCase)) { - var hdmiInput = Device as IHdmiInput; - if (hdmiInput == null) + if (Device is not IHdmiInput hdmiInput) return; _useHdmiInput2 = true; @@ -146,12 +143,10 @@ private void LinkInputValues(string routingPortKey) } else if (routingPortKey.Equals(DeviceInputEnum.Automatic.Name, StringComparison.OrdinalIgnoreCase)) { - var hdmiInput = Device as IHdmiInput; - if (hdmiInput == null) + if (Device is not IHdmiInput hdmiInput) return; - var hdmiSwitcher = Device as ICurrentVideoInput; - if (hdmiSwitcher == null) + if (Device is not ICurrentVideoInput hdmiSwitcher) return; HdmiSyncDetected = hdmiInput.SyncDetected[1]; @@ -173,8 +168,7 @@ public BoolFeedback IsOnline public void SetHdcpState(ushort state) { - var hdmiInput = Device as IHdmiInput; - if (hdmiInput == null) + if (Device is not IHdmiInput hdmiInput) return; if (_useHdmiInput2) diff --git a/src/NvxEpi/Devices/NvxXioDirector.cs b/src/NvxEpi/Devices/NvxXioDirector.cs index 3474ab0..da5df42 100644 --- a/src/NvxEpi/Devices/NvxXioDirector.cs +++ b/src/NvxEpi/Devices/NvxXioDirector.cs @@ -12,10 +12,7 @@ public class NvxXioDirector : EssentialsDevice, INvxDirector, IOnline public NvxXioDirector(string key, string name, DmXioDirectorBase hardware) : base(key, name) { - if (hardware == null) - throw new ArgumentNullException("hardware"); - - _hardware = hardware; + _hardware = hardware ?? throw new ArgumentNullException("hardware"); _isOnline = new BoolFeedback("BuildFeedbacks", () => _hardware.IsOnline); _hardware.OnlineStatusChange += (device, args) => _isOnline.FireUpdate(); } diff --git a/src/NvxEpi/Enums/Enumeration.cs b/src/NvxEpi/Enums/Enumeration.cs index a32c5fe..312df65 100644 --- a/src/NvxEpi/Enums/Enumeration.cs +++ b/src/NvxEpi/Enums/Enumeration.cs @@ -41,9 +41,7 @@ public static IEnumerable GetAll() public override bool Equals(object obj) { - var otherValue = obj as Enumeration; - - if (otherValue == null) + if (obj is not Enumeration otherValue) return false; bool typeMatches = GetType().GetCType() == obj.GetType().GetCType(); @@ -56,8 +54,7 @@ public int CompareTo(object other) { if (other == null) return 1; - var otherEnum = other as Enumeration; - if (otherEnum != null) + if (other is Enumeration otherEnum) return Value.CompareTo(otherEnum.Value); throw new ArgumentException("Object is not an Enum Class"); @@ -113,8 +110,7 @@ private static void CheckAll() _lock.Enter(); try { - if (_all == null) - _all = GetAllOptions(); + _all ??= GetAllOptions(); } finally { diff --git a/src/NvxEpi/Factories/Nvx35XDeviceFactory.cs b/src/NvxEpi/Factories/Nvx35XDeviceFactory.cs index fc2478c..352277d 100644 --- a/src/NvxEpi/Factories/Nvx35XDeviceFactory.cs +++ b/src/NvxEpi/Factories/Nvx35XDeviceFactory.cs @@ -15,9 +15,7 @@ public Nvx35XDeviceFactory() { MinimumEssentialsFrameworkVersion = MinumumEssentialsVersion; - if (_typeNames == null) - { - _typeNames = new List + _typeNames ??= new List { "dmnvx350", "dmnvx350c", @@ -26,7 +24,6 @@ public Nvx35XDeviceFactory() "dmnvx352", "dmnvx352c", }; - } TypeNames = _typeNames.ToList(); } diff --git a/src/NvxEpi/Factories/Nvx36XDeviceFactory.cs b/src/NvxEpi/Factories/Nvx36XDeviceFactory.cs index acf1dd0..a98a726 100644 --- a/src/NvxEpi/Factories/Nvx36XDeviceFactory.cs +++ b/src/NvxEpi/Factories/Nvx36XDeviceFactory.cs @@ -15,9 +15,7 @@ public Nvx36XDeviceFactory() { MinimumEssentialsFrameworkVersion = MinumumEssentialsVersion; - if (_typeNames == null) - { - _typeNames = new List + _typeNames ??= new List { "dmnvx360", "dmnvx360c", @@ -26,7 +24,6 @@ public Nvx36XDeviceFactory() "dmnvxe760", "dmnvxe760c", }; - } TypeNames = _typeNames.ToList(); } diff --git a/src/NvxEpi/Factories/NvxBaseDeviceFactory.cs b/src/NvxEpi/Factories/NvxBaseDeviceFactory.cs index 5d12d54..bbe6dbf 100644 --- a/src/NvxEpi/Factories/NvxBaseDeviceFactory.cs +++ b/src/NvxEpi/Factories/NvxBaseDeviceFactory.cs @@ -38,9 +38,8 @@ protected static Func GetDeviceBuildAction(string type, NvxDevic return () => { var xio = GetDirector(props.ParentDeviceKey); - DmXioDirectorBase.DmXioDomain domain; - return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain) + return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain) ? new DmNvx350((uint)props.DeviceId, domain, !props.DeviceIsTransmitter()) : new DmNvx350((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault(), !props.DeviceIsTransmitter()); }; @@ -55,9 +54,8 @@ protected static Func GetDeviceBuildAction(string type, NvxDevic return () => { var xio = GetDirector(props.ParentDeviceKey); - DmXioDirectorBase.DmXioDomain domain; - return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain) + return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain) ? new DmNvx350C((uint)props.DeviceId, domain, !props.DeviceIsTransmitter()) : new DmNvx350C((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault(), !props.DeviceIsTransmitter()); }; @@ -72,9 +70,8 @@ protected static Func GetDeviceBuildAction(string type, NvxDevic return () => { var xio = GetDirector(props.ParentDeviceKey); - DmXioDirectorBase.DmXioDomain domain; - return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain) + return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain) ? new DmNvx351((uint)props.DeviceId, domain, !props.DeviceIsTransmitter()) : new DmNvx351((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault(), !props.DeviceIsTransmitter()); }; @@ -89,9 +86,8 @@ protected static Func GetDeviceBuildAction(string type, NvxDevic return () => { var xio = GetDirector(props.ParentDeviceKey); - DmXioDirectorBase.DmXioDomain domain; - return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain) + return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain) ? new DmNvx351C((uint)props.DeviceId, domain, !props.DeviceIsTransmitter()) : new DmNvx351C((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault(), !props.DeviceIsTransmitter()); }; @@ -106,9 +102,8 @@ protected static Func GetDeviceBuildAction(string type, NvxDevic return () => { var xio = GetDirector(props.ParentDeviceKey); - DmXioDirectorBase.DmXioDomain domain; - return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain) + return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain) ? new DmNvx352((uint)props.DeviceId, domain, !props.DeviceIsTransmitter()) : new DmNvx352((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault(), !props.DeviceIsTransmitter()); }; @@ -123,9 +118,8 @@ protected static Func GetDeviceBuildAction(string type, NvxDevic return () => { var xio = GetDirector(props.ParentDeviceKey); - DmXioDirectorBase.DmXioDomain domain; - return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain) + return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain) ? new DmNvx352C((uint)props.DeviceId, domain, !props.DeviceIsTransmitter()) : new DmNvx352C((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault(), !props.DeviceIsTransmitter()); }; @@ -140,9 +134,8 @@ protected static Func GetDeviceBuildAction(string type, NvxDevic return () => { var xio = GetDirector(props.ParentDeviceKey); - DmXioDirectorBase.DmXioDomain domain; - return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain) + return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain) ? new DmNvx360((uint)props.DeviceId, domain, !props.DeviceIsTransmitter()) : new DmNvx360((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault(), !props.DeviceIsTransmitter()); }; @@ -157,9 +150,8 @@ protected static Func GetDeviceBuildAction(string type, NvxDevic return () => { var xio = GetDirector(props.ParentDeviceKey); - DmXioDirectorBase.DmXioDomain domain; - return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain) + return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain) ? new DmNvx360C((uint)props.DeviceId, domain, !props.DeviceIsTransmitter()) : new DmNvx360C((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault(), !props.DeviceIsTransmitter()); }; @@ -174,9 +166,8 @@ protected static Func GetDeviceBuildAction(string type, NvxDevic return () => { var xio = GetDirector(props.ParentDeviceKey); - DmXioDirectorBase.DmXioDomain domain; - return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain) + return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain) ? new DmNvx363((uint)props.DeviceId, domain, !props.DeviceIsTransmitter()) : new DmNvx363((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault(), !props.DeviceIsTransmitter()); }; @@ -191,9 +182,8 @@ protected static Func GetDeviceBuildAction(string type, NvxDevic return () => { var xio = GetDirector(props.ParentDeviceKey); - DmXioDirectorBase.DmXioDomain domain; - return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain) + return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain) ? new DmNvx363C((uint)props.DeviceId, domain, !props.DeviceIsTransmitter()) : new DmNvx363C((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault(), !props.DeviceIsTransmitter()); }; @@ -208,9 +198,8 @@ protected static Func GetDeviceBuildAction(string type, NvxDevic return () => { var xio = GetDirector(props.ParentDeviceKey); - DmXioDirectorBase.DmXioDomain domain; - return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain) + return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain) ? new DmNvxD30((uint)props.DeviceId, domain) : new DmNvxD30((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault()); }; @@ -225,9 +214,8 @@ protected static Func GetDeviceBuildAction(string type, NvxDevic return () => { var xio = GetDirector(props.ParentDeviceKey); - DmXioDirectorBase.DmXioDomain domain; - return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain) + return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain) ? new DmNvxD30C((uint)props.DeviceId, domain) : new DmNvxD30C((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault()); }; @@ -242,9 +230,8 @@ protected static Func GetDeviceBuildAction(string type, NvxDevic return () => { var xio = GetDirector(props.ParentDeviceKey); - DmXioDirectorBase.DmXioDomain domain; - return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain) + return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain) ? new DmNvxE30((uint)props.DeviceId, domain) : new DmNvxE30((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault()); }; @@ -259,9 +246,8 @@ protected static Func GetDeviceBuildAction(string type, NvxDevic return () => { var xio = GetDirector(props.ParentDeviceKey); - DmXioDirectorBase.DmXioDomain domain; - return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain) + return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain) ? new DmNvxE30C((uint)props.DeviceId, domain) : new DmNvxE30C((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault()); }; @@ -276,9 +262,8 @@ protected static Func GetDeviceBuildAction(string type, NvxDevic return () => { var xio = GetDirector(props.ParentDeviceKey); - DmXioDirectorBase.DmXioDomain domain; - return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain) + return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain) ? new DmNvxE31((uint)props.DeviceId, domain) : new DmNvxE31((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault()); }; @@ -293,9 +278,8 @@ protected static Func GetDeviceBuildAction(string type, NvxDevic return () => { var xio = GetDirector(props.ParentDeviceKey); - DmXioDirectorBase.DmXioDomain domain; - return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain) + return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain) ? new DmNvxE31C((uint)props.DeviceId, domain) : new DmNvxE31C((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault()); }; @@ -310,9 +294,8 @@ protected static Func GetDeviceBuildAction(string type, NvxDevic return () => { var xio = GetDirector(props.ParentDeviceKey); - DmXioDirectorBase.DmXioDomain domain; - return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain) + return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain) ? new DmNvxE760((uint)props.DeviceId, domain) : new DmNvxE760((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault()); }; @@ -327,9 +310,8 @@ protected static Func GetDeviceBuildAction(string type, NvxDevic return () => { var xio = GetDirector(props.ParentDeviceKey); - DmXioDirectorBase.DmXioDomain domain; - return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain) + return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain) ? new DmNvxE760((uint)props.DeviceId, domain) : new DmNvxE760((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault()); }; diff --git a/src/NvxEpi/Factories/NvxD3XDeviceFactory.cs b/src/NvxEpi/Factories/NvxD3XDeviceFactory.cs index 119846f..2c95e13 100644 --- a/src/NvxEpi/Factories/NvxD3XDeviceFactory.cs +++ b/src/NvxEpi/Factories/NvxD3XDeviceFactory.cs @@ -18,14 +18,11 @@ public NvxD3XDeviceFactory() { MinimumEssentialsFrameworkVersion = MinumumEssentialsVersion; - if (_typeNames == null) - { - _typeNames = new List + _typeNames ??= new List { "dmnvxd30", "dmnvxd30c", }; - } TypeNames = _typeNames.ToList(); } diff --git a/src/NvxEpi/Factories/NvxDirectorFactory.cs b/src/NvxEpi/Factories/NvxDirectorFactory.cs index 7920500..2a5dfc0 100644 --- a/src/NvxEpi/Factories/NvxDirectorFactory.cs +++ b/src/NvxEpi/Factories/NvxDirectorFactory.cs @@ -25,21 +25,13 @@ public override EssentialsDevice BuildDevice(DeviceConfig dc) { var config = JsonConvert.DeserializeObject(dc.Properties.ToString()); - DmXioDirectorBase xio; - switch (dc.Type.ToLower()) + DmXioDirectorBase xio = dc.Type.ToLower() switch { - case "xiodirector": - xio = new DmXioDirectorEnterprise(config.Control.IpIdInt, Global.ControlSystem); - break; - case "xiodirector80": - xio = new DmXioDirector80(config.Control.IpIdInt, Global.ControlSystem); - break; - case "xiodirector160": - xio = new DmXioDirector160(config.Control.IpIdInt, Global.ControlSystem); - break; - default: - throw new NotSupportedException(dc.Type); - } + "xiodirector" => new DmXioDirectorEnterprise(config.Control.IpIdInt, Global.ControlSystem), + "xiodirector80" => new DmXioDirector80(config.Control.IpIdInt, Global.ControlSystem), + "xiodirector160" => new DmXioDirector160(config.Control.IpIdInt, Global.ControlSystem), + _ => throw new NotSupportedException(dc.Type), + }; xio.RegisterWithLogging(dc.Key); return new NvxXioDirector(dc.Key, dc.Name, xio); diff --git a/src/NvxEpi/Factories/NvxE3XDeviceFactory.cs b/src/NvxEpi/Factories/NvxE3XDeviceFactory.cs index 361822b..4d33053 100644 --- a/src/NvxEpi/Factories/NvxE3XDeviceFactory.cs +++ b/src/NvxEpi/Factories/NvxE3XDeviceFactory.cs @@ -15,16 +15,13 @@ public NvxE3XDeviceFactory() { MinimumEssentialsFrameworkVersion = MinumumEssentialsVersion; - if (_typeNames == null) - { - _typeNames = new List + _typeNames ??= new List { "dmnvxe30", "dmnvxe30c", "dmnvxe31", "dmnvxe31c", }; - } TypeNames = _typeNames.ToList(); } diff --git a/src/NvxEpi/Features/AutomaticRouting/AutomaticInputRouter.cs b/src/NvxEpi/Features/AutomaticRouting/AutomaticInputRouter.cs index 830093d..86bd5ff 100644 --- a/src/NvxEpi/Features/AutomaticRouting/AutomaticInputRouter.cs +++ b/src/NvxEpi/Features/AutomaticRouting/AutomaticInputRouter.cs @@ -19,8 +19,7 @@ public AutomaticInputRouter(IHdmiInput currentVideoInput) _hdmiInputDetected.Output.OutputChange += OnSyncDetected; - var stream = _currentVideoInput as IStream; - if (stream == null || _currentVideoInput.IsTransmitter) + if (_currentVideoInput is not IStream stream || _currentVideoInput.IsTransmitter) return; stream.IsStreamingVideo.OutputChange += OnSyncDetected; @@ -28,25 +27,21 @@ public AutomaticInputRouter(IHdmiInput currentVideoInput) private void OnSyncDetected(object sender, FeedbackEventArgs feedbackEventArgs) { - var currentVidoInput = _currentVideoInput as ICurrentVideoInput; - if (currentVidoInput == null) + if (_currentVideoInput is not ICurrentVideoInput currentVidoInput) return; - - BoolFeedback hdmi1; - if (_currentVideoInput.SyncDetected.TryGetValue(1, out hdmi1)) + if (_currentVideoInput.SyncDetected.TryGetValue(1, out _)) { currentVidoInput.SetVideoToHdmiInput1(); return; } - BoolFeedback hdmi2; - if (_currentVideoInput.SyncDetected.TryGetValue(2, out hdmi2)) + if (_currentVideoInput.SyncDetected.TryGetValue(2, out _)) { currentVidoInput.SetVideoToHdmiInput2(); return; } - if (!(_currentVideoInput is IStream) || _currentVideoInput.IsTransmitter) + if (_currentVideoInput is not IStream || _currentVideoInput.IsTransmitter) return; currentVidoInput.SetVideoToStream(); diff --git a/src/NvxEpi/Features/Routing/NvxMatrixInput.cs b/src/NvxEpi/Features/Routing/NvxMatrixInput.cs index 35eecb4..75bacac 100644 --- a/src/NvxEpi/Features/Routing/NvxMatrixInput.cs +++ b/src/NvxEpi/Features/Routing/NvxMatrixInput.cs @@ -34,7 +34,7 @@ public NvxMatrixInput(NvxBaseDevice device):base() public BoolFeedback IsOnline => _device.IsOnline; - public bool VideoSyncDetected => _device is IHdmiInput inputDevice ? inputDevice.SyncDetected.Any(fb => fb.Value.BoolValue) : false; + public bool VideoSyncDetected => _device is IHdmiInput inputDevice && inputDevice.SyncDetected.Any(fb => fb.Value.BoolValue); public string Key => $"{_device.Key}"; diff --git a/src/NvxEpi/Features/Streams/Audio/CurrentSecondaryAudioStream.cs b/src/NvxEpi/Features/Streams/Audio/CurrentSecondaryAudioStream.cs index 52e8d90..e8a2bb8 100644 --- a/src/NvxEpi/Features/Streams/Audio/CurrentSecondaryAudioStream.cs +++ b/src/NvxEpi/Features/Streams/Audio/CurrentSecondaryAudioStream.cs @@ -25,7 +25,7 @@ public class CurrentSecondaryAudioStream : SecondaryAudioStream, ICurrentSeconda public CurrentSecondaryAudioStream(INvxDeviceWithHardware device) : base(device) { - _currentSecondaryAudioStreamId = new IntFeedback(RouteValueKey, () => _current != null ? _current.DeviceId : default( int )); + _currentSecondaryAudioStreamId = new IntFeedback(RouteValueKey, () => _current != null ? _current.DeviceId : default); _currentSecondaryAudioStreamName = new StringFeedback(RouteNameKey, () => _current != null ? _current.Name : NvxGlobalRouter.NoSourceText); Feedbacks.Add(CurrentSecondaryAudioStreamId); diff --git a/src/NvxEpi/Features/Streams/Usb/UsbStream.cs b/src/NvxEpi/Features/Streams/Usb/UsbStream.cs index 21a9084..9adb65e 100644 --- a/src/NvxEpi/Features/Streams/Usb/UsbStream.cs +++ b/src/NvxEpi/Features/Streams/Usb/UsbStream.cs @@ -103,8 +103,7 @@ private UsbStream(INvxDeviceWithHardware device, bool isRemote, bool followStrea return; } - var stream = device as ICurrentStream; - if (stream == null) + if (device is not ICurrentStream stream) { return; } @@ -288,8 +287,7 @@ private void SetDefaultStream(bool isRemote, string defaultPair) if (!isRemote || string.IsNullOrEmpty(defaultPair)) return; - var local = DeviceManager.GetDeviceForKey(defaultPair) as IUsbStreamWithHardware; - if (local == null) + if (DeviceManager.GetDeviceForKey(defaultPair) is not IUsbStreamWithHardware local) return; local.AddRemoteUsbStreamToLocal(this); diff --git a/src/NvxEpi/Features/Streams/Video/CurrentVideoStream.cs b/src/NvxEpi/Features/Streams/Video/CurrentVideoStream.cs index 3e8e956..2890952 100644 --- a/src/NvxEpi/Features/Streams/Video/CurrentVideoStream.cs +++ b/src/NvxEpi/Features/Streams/Video/CurrentVideoStream.cs @@ -24,8 +24,8 @@ public class CurrentVideoStream : VideoStream, ICurrentStream public CurrentVideoStream(INvxDeviceWithHardware device) : base(device) { _currentStreamId = IsTransmitter - ? new IntFeedback(() => default( int )) - : new IntFeedback(RouteValueKey, () => _current != null ? _current.DeviceId : default( int )); + ? new IntFeedback(() => default) + : new IntFeedback(RouteValueKey, () => _current != null ? _current.DeviceId : default); _currentStreamName = IsTransmitter ? new StringFeedback(() => string.Empty) diff --git a/src/NvxEpi/McMessengers/EndpointInfoMessenger.cs b/src/NvxEpi/McMessengers/EndpointInfoMessenger.cs index f4e098b..1a1d38a 100644 --- a/src/NvxEpi/McMessengers/EndpointInfoMessenger.cs +++ b/src/NvxEpi/McMessengers/EndpointInfoMessenger.cs @@ -13,14 +13,10 @@ namespace NvxEpi.McMessengers; public class EndpointInfoMessenger:MessengerBase -{ - private readonly NvxBaseDevice device; - +{ private readonly StringFeedback deviceNameFeedback; public EndpointInfoMessenger(string key, string path, NvxBaseDevice device): base(key, path, device) { - this.device = device; - deviceNameFeedback = device.Feedbacks.FirstOrDefault(fb => fb.Key == DeviceNameFeedback.Key) as StringFeedback; if (deviceNameFeedback == null) diff --git a/src/NvxEpi/Services/Bridge/NvxDeviceBridge.cs b/src/NvxEpi/Services/Bridge/NvxDeviceBridge.cs index 1e7df08..6374da0 100644 --- a/src/NvxEpi/Services/Bridge/NvxDeviceBridge.cs +++ b/src/NvxEpi/Services/Bridge/NvxDeviceBridge.cs @@ -137,23 +137,19 @@ private static void LinkFeedback(BasicTriList trilist, IKeyed feedback, uint joi Debug.Console(2, feedback, "Linking to Trilist : {0} | Join : {1}", trilist.ID, join); var stringFeedback = feedback as StringFeedback; - if (stringFeedback != null) - stringFeedback.LinkInputSig(trilist.StringInput[join]); + stringFeedback?.LinkInputSig(trilist.StringInput[join]); var intFeedback = feedback as IntFeedback; - if (intFeedback != null) - intFeedback.LinkInputSig(trilist.UShortInput[join]); + intFeedback?.LinkInputSig(trilist.UShortInput[join]); var boolFeedback = feedback as BoolFeedback; - if (boolFeedback != null) - boolFeedback.LinkInputSig(trilist.BooleanInput[join]); + boolFeedback?.LinkInputSig(trilist.BooleanInput[join]); } public void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge) { var joinMap = new NvxDeviceJoinMap(joinStart); - if (bridge != null) - bridge.AddJoinMap(_device.Key, joinMap); + bridge?.AddJoinMap(_device.Key, joinMap); var customJoins = JoinMapHelper.TryGetJoinMapAdvancedForDevice(joinMapKey); if (customJoins != null) @@ -167,43 +163,38 @@ public void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, E LinkRouting(trilist, joinMap); LinkUsbRouting(trilist, joinMap); - var videoInput = _device as ICurrentVideoInput; - if (videoInput != null) + if (_device is ICurrentVideoInput videoInput) trilist.SetUShortSigAction(joinMap.VideoInput.JoinNumber, videoInput.SetVideoInput); var audioInput = _device as ICurrentAudioInput; if (audioInput != null) trilist.SetUShortSigAction(joinMap.AudioInput.JoinNumber, audioInput.SetAudioInput); - - var naxInput = _device as ICurrentNaxInput; - if (naxInput != null) + + if (_device is ICurrentNaxInput naxInput) trilist.SetUShortSigAction(joinMap.NaxInput.JoinNumber, naxInput.SetNaxInput); var danteInput = _device as ICurrentDanteInput; if (audioInput != null) trilist.SetUShortSigAction(joinMap.DanteInput.JoinNumber, danteInput.SetDanteInput); - var stream = _device as IStreamWithHardware; - if (stream != null) + if (_device is IStreamWithHardware stream) trilist.SetStringSigAction(joinMap.StreamUrl.JoinNumber, stream.SetStreamUrl); - + } private void LinkRouting(BasicTriList trilist, NvxDeviceJoinMap joinMap) { if (!_device.IsTransmitter) { - var stream = _device as IStreamWithHardware; - if (stream != null) + if (_device is IStreamWithHardware stream) { trilist.SetUShortSigAction(joinMap.VideoRoute.JoinNumber, source => PrimaryStreamRouter.Route(source, stream)); trilist.SetStringSigAction(joinMap.VideoRoute.JoinNumber, name => PrimaryStreamRouter.Route(name, stream)); } } - var secondaryAudio = _device as ISecondaryAudioStreamWithHardware; - if (secondaryAudio == null) return; + if (_device is not ISecondaryAudioStreamWithHardware secondaryAudio) return; trilist.SetUShortSigAction(joinMap.AudioRoute.JoinNumber, source => SecondaryAudioRouter.Route(source, secondaryAudio)); trilist.SetStringSigAction(joinMap.AudioRoute.JoinNumber, name => SecondaryAudioRouter.Route(name, secondaryAudio)); @@ -211,8 +202,7 @@ private void LinkRouting(BasicTriList trilist, NvxDeviceJoinMap joinMap) private void LinkUsbRouting(BasicTriList trilist, NvxDeviceJoinMap joinMap) { - var stream = _device as IUsbStreamWithHardware; - if (stream == null) return; + if (_device is not IUsbStreamWithHardware stream) return; trilist.SetUShortSigAction(joinMap.UsbRoute.JoinNumber, source => { if (source == 0) @@ -255,8 +245,7 @@ private void LinkVideowallMode(BasicTriList trilist, NvxDeviceJoinMap joinMap) private void LinkHdmiInputs(BasicTriList trilist, NvxDeviceJoinMap joinMap) { - var hdmiInput = _device as IHdmiInput; - if (hdmiInput == null) + if (_device is not IHdmiInput hdmiInput) return; var hdmi1Fb = new BoolFeedback(() => hdmiInput.SyncDetected.ContainsKey(1)); diff --git a/src/NvxEpi/Services/Feedback/DmHdcpCapabilityValueFeedback.cs b/src/NvxEpi/Services/Feedback/DmHdcpCapabilityValueFeedback.cs index 48bb454..9978c49 100644 --- a/src/NvxEpi/Services/Feedback/DmHdcpCapabilityValueFeedback.cs +++ b/src/NvxEpi/Services/Feedback/DmHdcpCapabilityValueFeedback.cs @@ -7,8 +7,7 @@ public class DmHdcpCapabilityValueFeedback { public static IntFeedback GetFeedback(DmNvxBaseClass device) { - var dmDevice = device as DmNvxE760x; - if (dmDevice == null) + if (device is not DmNvxE760x dmDevice) return new IntFeedback(() => 0); var feedback = new IntFeedback(Hdmi1HdcpCapabilityValueFeedback.Key, @@ -24,8 +23,7 @@ public class DmHdcpCapabilityStateFeedback { public static IntFeedback GetFeedback(DmNvxBaseClass device) { - var dmDevice = device as DmNvxE760x; - if (dmDevice == null) + if (device is not DmNvxE760x dmDevice) return new IntFeedback(() => 0); var feedback = new IntFeedback(Hdmi1HdcpCapabilityValueFeedback.Key, diff --git a/src/NvxEpi/Services/Feedback/DmSyncDetectedFeedback.cs b/src/NvxEpi/Services/Feedback/DmSyncDetectedFeedback.cs index 0b6ed17..9ef5e86 100644 --- a/src/NvxEpi/Services/Feedback/DmSyncDetectedFeedback.cs +++ b/src/NvxEpi/Services/Feedback/DmSyncDetectedFeedback.cs @@ -9,8 +9,7 @@ public class DmSyncDetectedFeedback public static BoolFeedback GetFeedback(DmNvxBaseClass device) { - var dmDevice = device as DmNvxE760x; - if (dmDevice == null) + if (device is not DmNvxE760x dmDevice) return new BoolFeedback(() => false); var feedback = new BoolFeedback(Key, diff --git a/src/NvxEpi/Services/Feedback/MulticastAddressFeedback.cs b/src/NvxEpi/Services/Feedback/MulticastAddressFeedback.cs index e49d0ec..24dad9a 100644 --- a/src/NvxEpi/Services/Feedback/MulticastAddressFeedback.cs +++ b/src/NvxEpi/Services/Feedback/MulticastAddressFeedback.cs @@ -13,8 +13,7 @@ public static StringFeedback GetFeedback(DmNvxBaseClass device) () => device.Control.MulticastAddressFeedback.StringValue); device.BaseEvent += (@base, args) => feedback.FireUpdate(); - var nvx35X = device as DmNvx35x; - if (nvx35X == null) + if (device is not DmNvx35x nvx35X) return feedback; device.SourceReceive.StreamChange += (stream, args) => feedback.FireUpdate(); diff --git a/src/NvxEpi/Services/Feedback/UsbRemoteAddressFeedback.cs b/src/NvxEpi/Services/Feedback/UsbRemoteAddressFeedback.cs index 5325241..7279d3d 100644 --- a/src/NvxEpi/Services/Feedback/UsbRemoteAddressFeedback.cs +++ b/src/NvxEpi/Services/Feedback/UsbRemoteAddressFeedback.cs @@ -31,8 +31,7 @@ public static ReadOnlyDictionary GetFeedbacks(DmNvxBaseCla { for (uint i = 0; i <= device.UsbInput.RemoteDeviceIdFeedbacks.Count; i++) { - StringOutputSig sig; - if (!device.UsbInput.RemoteDeviceIdFeedbacks.TryGetValue(i, out sig)) + if (!device.UsbInput.RemoteDeviceIdFeedbacks.TryGetValue(i, out StringOutputSig sig)) continue; dict.Add(i, new StringFeedback(Key + "-" + i, () => sig.StringValue)); diff --git a/src/NvxEpi/Services/Feedback/VideoAspectRatioModeFeedback.cs b/src/NvxEpi/Services/Feedback/VideoAspectRatioModeFeedback.cs index daf39a2..1de5a48 100644 --- a/src/NvxEpi/Services/Feedback/VideoAspectRatioModeFeedback.cs +++ b/src/NvxEpi/Services/Feedback/VideoAspectRatioModeFeedback.cs @@ -12,7 +12,7 @@ public class VideoAspectRatioModeFeedback public static IntFeedback GetFeedback(DmNvxBaseClass device) { if (device.HdmiOut == null) - return new IntFeedback(() => default (int)); + return new IntFeedback(() => default); var feedback = new IntFeedback(Key, () => (int) device.HdmiOut.VideoAttributes.AspectRatioModeFeedback); device.HdmiOut.VideoAttributes.AttributeChange += (stream, args) => feedback.FireUpdate(); diff --git a/src/NvxEpi/Services/InputSwitching/SwitcherForStreamOutput.cs b/src/NvxEpi/Services/InputSwitching/SwitcherForStreamOutput.cs index 7e6c6df..4003019 100644 --- a/src/NvxEpi/Services/InputSwitching/SwitcherForStreamOutput.cs +++ b/src/NvxEpi/Services/InputSwitching/SwitcherForStreamOutput.cs @@ -34,8 +34,7 @@ public void HandleSwitch(object input, eRoutingSignalType type) SwitchVideo(routingInput); var deviceWithAudioSwitching = _device as ICurrentAudioInput; - if (deviceWithAudioSwitching != null) - deviceWithAudioSwitching.SetAudioToInputAutomatic(); + deviceWithAudioSwitching?.SetAudioToInputAutomatic(); return; } @@ -61,8 +60,7 @@ private void SwitchVideo(Enumeration input) private void SwitchAudio(Enumeration input) { - var deviceWithAudioSwitching = _device as ICurrentAudioInput; - if (deviceWithAudioSwitching == null) return; + if (_device is not ICurrentAudioInput deviceWithAudioSwitching) return; if (input == DeviceInputEnum.PrimaryAudio) deviceWithAudioSwitching.SetAudioToPrimaryStreamAudio();