Skip to content

Commit

Permalink
chore: remove unnecessary compiler directives
Browse files Browse the repository at this point in the history
Update to use newer C# features, now that 3-sereis support is no longer required.
  • Loading branch information
andrew-welker committed May 8, 2024
1 parent c84a24c commit 4393182
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 74 deletions.
19 changes: 4 additions & 15 deletions src/NvxEpi/Application/Entities/NvxApplicationVideoReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
using NvxEpi.Services.InputSwitching;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Routing;


#if SERIES4
using MockDisplay = PepperDash.Essentials.Devices.Common.Displays.MockDisplay;
#endif

namespace NvxEpi.Application.Entities
{
Expand Down Expand Up @@ -48,10 +44,7 @@ public NvxApplicationVideoReceiver(string key, NvxApplicationDeviceVideoConfig c

AddPostActivationAction(() =>
{
var port = Device.OutputPorts[SwitcherForHdmiOutput.Key];
if (port == null)
throw new NullReferenceException("hdmi output routing port");
var port = Device.OutputPorts[SwitcherForHdmiOutput.Key] ?? throw new NullReferenceException("hdmi output routing port");
TieLineCollection.Default.Add(new TieLine(port, sink.InputPorts[RoutingPortNames.HdmiIn1]));
});

Expand All @@ -66,9 +59,7 @@ public NvxApplicationVideoReceiver(string key, NvxApplicationDeviceVideoConfig c

AddPostActivationAction(() =>
{
var feedback = Device.Feedbacks[CurrentVideoStream.RouteNameKey] as StringFeedback;
if (feedback == null)
throw new NullReferenceException(CurrentVideoStream.RouteNameKey);
var feedback = Device.Feedbacks[CurrentVideoStream.RouteNameKey] as StringFeedback ?? throw new NullReferenceException(CurrentVideoStream.RouteNameKey);
var currentRouteFb = new IntFeedback(() =>
{
Expand Down Expand Up @@ -107,16 +98,14 @@ public NvxApplicationVideoReceiver(string key, NvxApplicationDeviceVideoConfig c
AspectRatioMode = new IntFeedback(() => 0);
EdidManufacturer = new StringFeedback(() => string.Empty);
var hdmiOut = Device as IHdmiOutput;
if (hdmiOut == null)
if (!(Device is IHdmiOutput hdmiOut))
return;
DisabledByHdcp = hdmiOut.DisabledByHdcp;
HorizontalResolution = hdmiOut.HorizontalResolution;
EdidManufacturer = hdmiOut.EdidManufacturer;
var aspect = Device as IVideowallMode;
if(aspect == null)
if (!(Device is IVideowallMode aspect))
return;
AspectRatioMode = aspect.VideoAspectRatioMode;
Expand Down
11 changes: 1 addition & 10 deletions src/NvxEpi/Application/Services/ApplicationTieLineConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
using PepperDash.Essentials;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Routing;

#if SERIES4
using MockDisplay = PepperDash.Essentials.Devices.Common.Displays.MockDisplay;
#endif

namespace NvxEpi.Application.Services
{
Expand All @@ -25,14 +22,8 @@ public static void AddTieLineForAmp(Amplifier amp, INvxDevice rx)

public static void AddTieLineForMockDisplay(MockDisplay dest, INvxDevice rx)
{
var outputPort = rx.OutputPorts[SwitcherForHdmiOutput.Key];
if (outputPort == null)
throw new ArgumentNullException("outputPort");
#if SERIES4
var outputPort = rx.OutputPorts[SwitcherForHdmiOutput.Key] ?? throw new ArgumentNullException("outputPort");
TieLineCollection.Default.Add(new TieLine(outputPort, dest.InputPorts[RoutingPortNames.HdmiIn1], eRoutingSignalType.AudioVideo));
#else
TieLineCollection.Default.Add(new TieLine(outputPort, dest.HdmiIn1, eRoutingSignalType.AudioVideo));
#endif
}
}
}
10 changes: 3 additions & 7 deletions src/NvxEpi/Devices/Nvx36X.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@

using HdmiInput = NvxEpi.Features.Hdmi.Input.HdmiInput;

#if SERIES4
using NvxEpi.McMessengers;
#endif


namespace NvxEpi.Devices
{
Expand Down Expand Up @@ -93,8 +92,7 @@ public void ClearCurrentUsbRoute()
public void MakeUsbRoute(IUsbStreamWithHardware hardware)
{
Debug.Console(0, this, "Try Make USB Route for mac : {0}", hardware.UsbLocalId.StringValue);
var usbStream = _usbStream as UsbStream;
if (usbStream == null)
if (!(_usbStream is UsbStream usbStream))
{
Debug.Console(0, this, "cannot Make USB Route for url : {0} - UsbStream is null", hardware.UsbLocalId.StringValue);
return;
Expand Down Expand Up @@ -194,9 +192,7 @@ public void ExecuteSwitch(object inputSelector, object outputSelector, eRoutingS
{
try
{
var switcher = outputSelector as IHandleInputSwitch;
if (switcher == null)
throw new NullReferenceException("outputSelector");
var switcher = outputSelector as IHandleInputSwitch ?? throw new NullReferenceException("outputSelector");

Debug.Console(1,
this,
Expand Down
7 changes: 0 additions & 7 deletions src/NvxEpi/Devices/NvxBaseDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
using PepperDash.Core;
using NvxEpi.Abstractions.HdmiOutput;


#if SERIES4
using NvxEpi.McMessengers;
#endif


namespace NvxEpi.Devices
{
Expand Down Expand Up @@ -146,7 +141,6 @@ public override bool CustomActivate()

protected void AddMcMessengers()
{
#if SERIES4
var mc = DeviceManager.AllDevices.OfType<IMobileControl>().FirstOrDefault();

if (mc == null)
Expand Down Expand Up @@ -189,7 +183,6 @@ protected void AddMcMessengers()
var hdmiOutputMessenger = new IHdmiOutputMessenger($"{Key}-hdmiOutputMessenger", $"/device/{Key}", hdmiOutputDevice);

mc.AddDeviceMessenger(hdmiOutputMessenger);
#endif
}

public StringFeedback CurrentAudioInput
Expand Down
9 changes: 2 additions & 7 deletions src/NvxEpi/Devices/NvxD3X.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ public NvxD3X(DeviceConfig config, Func<DmNvxBaseClass> getHardware)

public override bool CustomActivate()
{
var hardware = base.Hardware as DmNvxD3x;
if (hardware == null)
throw new Exception("hardware built doesn't match");

var hardware = base.Hardware as DmNvxD3x ?? throw new Exception("hardware built doesn't match");
Hardware = hardware;
_hdmiOutput = new HdmiOutput(this);

Expand Down Expand Up @@ -97,9 +94,7 @@ public void ExecuteSwitch(object inputSelector, object outputSelector, eRoutingS
{
try
{
var switcher = outputSelector as IHandleInputSwitch;
if (switcher == null)
throw new NullReferenceException("outputSelector");
var switcher = outputSelector as IHandleInputSwitch ?? throw new NullReferenceException("outputSelector");

Debug.Console(1,
this,
Expand Down
30 changes: 2 additions & 28 deletions src/NvxEpi/Features/Routing/NvxGlobalRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,13 @@
using PepperDash.Essentials.Core.Routing;
using NvxEpi.Abstractions.SecondaryAudio;
using NvxEpi.Devices;

#if SERIES4
using PepperDash.Essentials.AppServer.Messengers;
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
#endif

namespace NvxEpi.Features.Routing
{
#if SERIES4
public class NvxGlobalRouter : EssentialsDevice, IRoutingNumeric, IMatrixRouting
#else
public class NvxGlobalRouter : EssentialsDevice, IRoutingNumeric
#endif

{
private static readonly NvxGlobalRouter _instance = new NvxGlobalRouter();

Expand All @@ -46,15 +40,11 @@ private NvxGlobalRouter()

AddPostActivationAction(BuildTieLines);

#if SERIES4
AddPostActivationAction(BuildMatrixRouting);


InputSlots = new Dictionary<string, IRoutingInputSlot>();
OutputSlots = new Dictionary<string, IRoutingOutputSlot>();

//AddPostActivationAction(BuildMobileControlMessenger);
#endif
OutputSlots = new Dictionary<string, IRoutingOutputSlot>();
}

public static NvxGlobalRouter Instance { get { return _instance; } }
Expand Down Expand Up @@ -109,7 +99,6 @@ public void ExecuteNumericSwitch(ushort input, ushort output, eRoutingSignalType
throw new NotImplementedException("Execute Numeric Switch");
}

#if SERIES4
public Dictionary<string, IRoutingInputSlot> InputSlots { get; private set; }

public Dictionary<string, IRoutingOutputSlot> OutputSlots { get; private set; }
Expand Down Expand Up @@ -155,20 +144,6 @@ private void BuildMatrixRouting()
}
}

private void BuildMobileControlMessenger()
{
var mc = DeviceManager.AllDevices.OfType<IMobileControl>().FirstOrDefault();

if(mc == null)
{
Debug.Console(0, this, "Unable to find mobile control device");
return;
}

var routingMessenger = new IMatrixRoutingMessenger($"{Key}-matrixRoutingMessenger", $"/device/{Key}", this);
mc.AddDeviceMessenger(routingMessenger);
}

public void Route(string inputSlotKey, string outputSlotKey, eRoutingSignalType type)
{
if(!InputSlots.TryGetValue(inputSlotKey, out var inputSlot))
Expand Down Expand Up @@ -211,6 +186,5 @@ public void Route(string inputSlotKey, string outputSlotKey, eRoutingSignalType
Routing.SecondaryAudioRouter.Route(inputSlot.SlotNumber, audioOutput);
}
}
#endif
}
}

0 comments on commit 4393182

Please sign in to comment.