From 631dd2b00dc89f03964747b88177b1dda0549e5c Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Fri, 18 Oct 2024 11:09:15 -0500 Subject: [PATCH] fix: check for nulls in SwitchingDevice property --- .../Routing/RouteSwitchDescriptor.cs | 6 +++--- .../Routing/RoutingFeedbackManager.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Routing/RouteSwitchDescriptor.cs b/src/PepperDash.Essentials.Core/Routing/RouteSwitchDescriptor.cs index 9e4aaca1..c425d0a4 100644 --- a/src/PepperDash.Essentials.Core/Routing/RouteSwitchDescriptor.cs +++ b/src/PepperDash.Essentials.Core/Routing/RouteSwitchDescriptor.cs @@ -5,7 +5,7 @@ /// public class RouteSwitchDescriptor { - public IRoutingInputs SwitchingDevice { get { return InputPort.ParentDevice; } } + public IRoutingInputs SwitchingDevice { get { return InputPort?.ParentDevice; } } public RoutingOutputPort OutputPort { get; set; } public RoutingInputPort InputPort { get; set; } @@ -23,9 +23,9 @@ public override string ToString() { if (SwitchingDevice is IRouting) - return $"{SwitchingDevice?.Key} switches output {OutputPort?.Key} to input {InputPort?.Key}"; + return $"{(SwitchingDevice != null ? SwitchingDevice.Key : "No Device")} switches output {(OutputPort != null ? OutputPort.Key : "No output port")} to input {(InputPort != null ? InputPort.Key : "No input port")}"; else - return $"{SwitchingDevice?.Key} switches to input {InputPort?.Key}"; + return $"{(SwitchingDevice != null ? SwitchingDevice.Key : "No Device")} switches to input {(InputPort != null ? InputPort.Key : "No input port")}"; } } diff --git a/src/PepperDash.Essentials.Core/Routing/RoutingFeedbackManager.cs b/src/PepperDash.Essentials.Core/Routing/RoutingFeedbackManager.cs index e8809191..802088df 100644 --- a/src/PepperDash.Essentials.Core/Routing/RoutingFeedbackManager.cs +++ b/src/PepperDash.Essentials.Core/Routing/RoutingFeedbackManager.cs @@ -217,7 +217,7 @@ namespace PepperDash.Essentials.Core.Routing var currentRoute = midpoint.CurrentRoutes.FirstOrDefault(route => { Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Checking {route} against {tieLine}", this, route, tieLine); - return route.OutputPort?.Key == tieLine.SourcePort.Key && route.OutputPort?.ParentDevice.Key == tieLine.SourcePort.ParentDevice.Key; + return route.OutputPort != null && route.InputPort != null && route.OutputPort?.Key == tieLine.SourcePort.Key && route.OutputPort?.ParentDevice.Key == tieLine.SourcePort.ParentDevice.Key; }); if (currentRoute == null)