fix: a few logging updates

This commit is contained in:
Nick Genovese
2025-12-29 15:34:14 -06:00
parent 3878c85a7a
commit 7629921113

View File

@@ -1,7 +1,7 @@
using PepperDash.Core; using System;
using PepperDash.Essentials.Core.Config;
using System;
using System.Linq; using System.Linq;
using PepperDash.Core;
using PepperDash.Essentials.Core.Config;
namespace PepperDash.Essentials.Core.Routing namespace PepperDash.Essentials.Core.Routing
{ {
@@ -9,20 +9,20 @@ namespace PepperDash.Essentials.Core.Routing
/// Manages routing feedback by subscribing to route changes on midpoint and sink devices, /// Manages routing feedback by subscribing to route changes on midpoint and sink devices,
/// tracing the route back to the original source, and updating the CurrentSourceInfo on sink devices. /// tracing the route back to the original source, and updating the CurrentSourceInfo on sink devices.
/// </summary> /// </summary>
public class RoutingFeedbackManager:EssentialsDevice public class RoutingFeedbackManager : EssentialsDevice
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="RoutingFeedbackManager"/> class. /// Initializes a new instance of the <see cref="RoutingFeedbackManager"/> class.
/// </summary> /// </summary>
/// <param name="key">The unique key for this manager device.</param> /// <param name="key">The unique key for this manager device.</param>
/// <param name="name">The name of this manager device.</param> /// <param name="name">The name of this manager device.</param>
public RoutingFeedbackManager(string key, string name): base(key, name) public RoutingFeedbackManager(string key, string name)
{ : base(key, name)
{
AddPreActivationAction(SubscribeForMidpointFeedback); AddPreActivationAction(SubscribeForMidpointFeedback);
AddPreActivationAction(SubscribeForSinkFeedback); AddPreActivationAction(SubscribeForSinkFeedback);
} }
/// <summary> /// <summary>
/// Subscribes to the RouteChanged event on all devices implementing <see cref="IRoutingWithFeedback"/>. /// Subscribes to the RouteChanged event on all devices implementing <see cref="IRoutingWithFeedback"/>.
/// </summary> /// </summary>
@@ -41,12 +41,13 @@ namespace PepperDash.Essentials.Core.Routing
/// </summary> /// </summary>
private void SubscribeForSinkFeedback() private void SubscribeForSinkFeedback()
{ {
var sinkDevices = DeviceManager.AllDevices.OfType<IRoutingSinkWithSwitchingWithInputPort>(); var sinkDevices =
DeviceManager.AllDevices.OfType<IRoutingSinkWithSwitchingWithInputPort>();
foreach (var device in sinkDevices) foreach (var device in sinkDevices)
{ {
device.InputChanged += HandleSinkUpdate; device.InputChanged += HandleSinkUpdate;
} }
} }
/// <summary> /// <summary>
@@ -55,11 +56,15 @@ namespace PepperDash.Essentials.Core.Routing
/// </summary> /// </summary>
/// <param name="midpoint">The midpoint device that reported a route change.</param> /// <param name="midpoint">The midpoint device that reported a route change.</param>
/// <param name="newRoute">The descriptor of the new route.</param> /// <param name="newRoute">The descriptor of the new route.</param>
private void HandleMidpointUpdate(IRoutingWithFeedback midpoint, RouteSwitchDescriptor newRoute) private void HandleMidpointUpdate(
IRoutingWithFeedback midpoint,
RouteSwitchDescriptor newRoute
)
{ {
try try
{ {
var devices = DeviceManager.AllDevices.OfType<IRoutingSinkWithSwitchingWithInputPort>(); var devices =
DeviceManager.AllDevices.OfType<IRoutingSinkWithSwitchingWithInputPort>();
foreach (var device in devices) foreach (var device in devices)
{ {
@@ -68,7 +73,13 @@ namespace PepperDash.Essentials.Core.Routing
} }
catch (Exception ex) catch (Exception ex)
{ {
Debug.LogMessage(ex, "Error handling midpoint update from {midpointKey}:{Exception}", this, midpoint.Key, ex); Debug.LogMessage(
ex,
"Error handling midpoint update from {midpointKey}:{Exception}",
this,
midpoint.Key,
ex
);
} }
} }
@@ -78,7 +89,10 @@ namespace PepperDash.Essentials.Core.Routing
/// </summary> /// </summary>
/// <param name="sender">The sink device that reported an input change.</param> /// <param name="sender">The sink device that reported an input change.</param>
/// <param name="currentInputPort">The new input port selected on the sink device.</param> /// <param name="currentInputPort">The new input port selected on the sink device.</param>
private void HandleSinkUpdate(IRoutingSinkWithSwitching sender, RoutingInputPort currentInputPort) private void HandleSinkUpdate(
IRoutingSinkWithSwitching sender,
RoutingInputPort currentInputPort
)
{ {
try try
{ {
@@ -86,7 +100,13 @@ namespace PepperDash.Essentials.Core.Routing
} }
catch (Exception ex) catch (Exception ex)
{ {
Debug.LogMessage(ex, "Error handling Sink update from {senderKey}:{Exception}", this, sender.Key, ex); Debug.LogMessage(
ex,
"Error handling Sink update from {senderKey}:{Exception}",
this,
sender.Key,
ex
);
} }
} }
@@ -96,13 +116,27 @@ namespace PepperDash.Essentials.Core.Routing
/// </summary> /// </summary>
/// <param name="destination">The destination sink device to update.</param> /// <param name="destination">The destination sink device to update.</param>
/// <param name="inputPort">The currently selected input port on the destination device.</param> /// <param name="inputPort">The currently selected input port on the destination device.</param>
private void UpdateDestination(IRoutingSinkWithSwitching destination, RoutingInputPort inputPort) private void UpdateDestination(
{ IRoutingSinkWithSwitching destination,
Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Updating destination {destination} with inputPort {inputPort}", this, destination?.Key, inputPort?.Key); RoutingInputPort inputPort
)
{
Debug.LogMessage(
Serilog.Events.LogEventLevel.Verbose,
"Updating destination {destination} with inputPort {inputPort}",
this,
destination?.Key,
inputPort?.Key
);
if(inputPort == null) if (inputPort == null)
{ {
Debug.LogMessage(Serilog.Events.LogEventLevel.Warning, "Destination {destination} has not reported an input port yet", this,destination.Key); Debug.LogMessage(
Serilog.Events.LogEventLevel.Debug,
"Destination {destination} has not reported an input port yet",
this,
destination.Key
);
return; return;
} }
@@ -111,11 +145,19 @@ namespace PepperDash.Essentials.Core.Routing
{ {
var tieLines = TieLineCollection.Default; var tieLines = TieLineCollection.Default;
firstTieLine = tieLines.FirstOrDefault(tl => tl.DestinationPort.Key == inputPort.Key && tl.DestinationPort.ParentDevice.Key == inputPort.ParentDevice.Key); firstTieLine = tieLines.FirstOrDefault(tl =>
tl.DestinationPort.Key == inputPort.Key
&& tl.DestinationPort.ParentDevice.Key == inputPort.ParentDevice.Key
);
if (firstTieLine == null) if (firstTieLine == null)
{ {
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "No tieline found for inputPort {inputPort}. Clearing current source", this, inputPort); Debug.LogMessage(
Serilog.Events.LogEventLevel.Debug,
"No tieline found for inputPort {inputPort}. Clearing current source",
this,
inputPort
);
var tempSourceListItem = new SourceListItem var tempSourceListItem = new SourceListItem
{ {
@@ -123,12 +165,13 @@ namespace PepperDash.Essentials.Core.Routing
Name = inputPort.Key, Name = inputPort.Key,
}; };
destination.CurrentSourceInfo = tempSourceListItem;
destination.CurrentSourceInfo = tempSourceListItem; ; ;
destination.CurrentSourceInfoKey = "$transient"; destination.CurrentSourceInfoKey = "$transient";
return; return;
} }
} catch (Exception ex) }
catch (Exception ex)
{ {
Debug.LogMessage(ex, "Error getting first tieline: {Exception}", this, ex); Debug.LogMessage(ex, "Error getting first tieline: {Exception}", this, ex);
return; return;
@@ -143,7 +186,12 @@ namespace PepperDash.Essentials.Core.Routing
if (sourceTieLine == null) if (sourceTieLine == null)
{ {
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "No route found to source for inputPort {inputPort}. Clearing current source", this, inputPort); Debug.LogMessage(
Serilog.Events.LogEventLevel.Debug,
"No route found to source for inputPort {inputPort}. Clearing current source",
this,
inputPort
);
var tempSourceListItem = new SourceListItem var tempSourceListItem = new SourceListItem
{ {
@@ -155,32 +203,45 @@ namespace PepperDash.Essentials.Core.Routing
destination.CurrentSourceInfoKey = string.Empty; destination.CurrentSourceInfoKey = string.Empty;
return; return;
} }
} catch(Exception ex) }
catch (Exception ex)
{ {
Debug.LogMessage(ex, "Error getting sourceTieLine: {Exception}", this, ex); Debug.LogMessage(ex, "Error getting sourceTieLine: {Exception}", this, ex);
return; return;
} }
// Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Found root TieLine {tieLine}", this, sourceTieLine); // Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Found root TieLine {tieLine}", this, sourceTieLine);
// Does not handle combinable scenarios or other scenarios where a display might be part of multiple rooms yet. // Does not handle combinable scenarios or other scenarios where a display might be part of multiple rooms yet.
var room = DeviceManager.AllDevices.OfType<IEssentialsRoom>().FirstOrDefault((r) => { var room = DeviceManager
if(r is IHasMultipleDisplays roomMultipleDisplays) .AllDevices.OfType<IEssentialsRoom>()
{ .FirstOrDefault(
return roomMultipleDisplays.Displays.Any(d => d.Value.Key == destination.Key); (r) =>
} {
if (r is IHasMultipleDisplays roomMultipleDisplays)
{
return roomMultipleDisplays.Displays.Any(d =>
d.Value.Key == destination.Key
);
}
if(r is IHasDefaultDisplay roomDefaultDisplay) if (r is IHasDefaultDisplay roomDefaultDisplay)
{ {
return roomDefaultDisplay.DefaultDisplay.Key == destination.Key; return roomDefaultDisplay.DefaultDisplay.Key == destination.Key;
} }
return false; return false;
}); }
);
if(room == null)
if (room == null)
{ {
Debug.LogMessage(Serilog.Events.LogEventLevel.Warning, "No room found for display {destination}", this, destination.Key); Debug.LogMessage(
Serilog.Events.LogEventLevel.Warning,
"No room found for display {destination}",
this,
destination.Key
);
return; return;
} }
@@ -190,29 +251,45 @@ namespace PepperDash.Essentials.Core.Routing
if (sourceList == null) if (sourceList == null)
{ {
Debug.LogMessage(Serilog.Events.LogEventLevel.Warning, "No source list found for source list key {key}. Unable to find source for tieLine {sourceTieLine}", this, room.SourceListKey, sourceTieLine); Debug.LogMessage(
Serilog.Events.LogEventLevel.Warning,
"No source list found for source list key {key}. Unable to find source for tieLine {sourceTieLine}",
this,
room.SourceListKey,
sourceTieLine
);
return; return;
} }
// Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Found sourceList for room {room}", this, room.Key); // Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Found sourceList for room {room}", this, room.Key);
var sourceListItem = sourceList.FirstOrDefault(sli => { var sourceListItem = sourceList.FirstOrDefault(sli =>
//// Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, {
// "SourceListItem {sourceListItem}:{sourceKey} tieLine sourceport device key {sourcePortDeviceKey}", //// Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose,
// this, // "SourceListItem {sourceListItem}:{sourceKey} tieLine sourceport device key {sourcePortDeviceKey}",
// sli.Key, // this,
// sli.Value.SourceKey, // sli.Key,
// sourceTieLine.SourcePort.ParentDevice.Key); // sli.Value.SourceKey,
// sourceTieLine.SourcePort.ParentDevice.Key);
return sli.Value.SourceKey.Equals(sourceTieLine.SourcePort.ParentDevice.Key,StringComparison.InvariantCultureIgnoreCase); return sli.Value.SourceKey.Equals(
}); sourceTieLine.SourcePort.ParentDevice.Key,
StringComparison.InvariantCultureIgnoreCase
);
});
var source = sourceListItem.Value; var source = sourceListItem.Value;
var sourceKey = sourceListItem.Key; var sourceKey = sourceListItem.Key;
if (source == null) if (source == null)
{ {
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "No source found for device {key}. Creating transient source for {destination}", this, sourceTieLine.SourcePort.ParentDevice.Key, destination); Debug.LogMessage(
Serilog.Events.LogEventLevel.Debug,
"No source found for device {key}. Creating transient source for {destination}",
this,
sourceTieLine.SourcePort.ParentDevice.Key,
destination
);
var tempSourceListItem = new SourceListItem var tempSourceListItem = new SourceListItem
{ {
@@ -221,7 +298,7 @@ namespace PepperDash.Essentials.Core.Routing
}; };
destination.CurrentSourceInfoKey = "$transient"; destination.CurrentSourceInfoKey = "$transient";
destination.CurrentSourceInfo = tempSourceListItem; destination.CurrentSourceInfo = tempSourceListItem;
return; return;
} }
@@ -229,7 +306,6 @@ namespace PepperDash.Essentials.Core.Routing
destination.CurrentSourceInfoKey = sourceKey; destination.CurrentSourceInfoKey = sourceKey;
destination.CurrentSourceInfo = source; destination.CurrentSourceInfo = source;
} }
/// <summary> /// <summary>
@@ -249,29 +325,49 @@ namespace PepperDash.Essentials.Core.Routing
{ {
// Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "TieLine Source device {sourceDevice} is midpoint", this, midpoint); // Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "TieLine Source device {sourceDevice} is midpoint", this, midpoint);
if(midpoint.CurrentRoutes == null || midpoint.CurrentRoutes.Count == 0) if (midpoint.CurrentRoutes == null || midpoint.CurrentRoutes.Count == 0)
{ {
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "Midpoint {midpointKey} has no routes",this, midpoint.Key); Debug.LogMessage(
Serilog.Events.LogEventLevel.Debug,
"Midpoint {midpointKey} has no routes",
this,
midpoint.Key
);
return null; return null;
} }
var currentRoute = midpoint.CurrentRoutes.FirstOrDefault(route => { var currentRoute = midpoint.CurrentRoutes.FirstOrDefault(route =>
{
//Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Checking {route} against {tieLine}", this, route, tieLine); //Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Checking {route} against {tieLine}", this, route, tieLine);
return route.OutputPort != null && route.InputPort != null && 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) if (currentRoute == null)
{ {
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "No route through midpoint {midpoint} for outputPort {outputPort}", this, midpoint.Key, tieLine.SourcePort); Debug.LogMessage(
Serilog.Events.LogEventLevel.Debug,
"No route through midpoint {midpoint} for outputPort {outputPort}",
this,
midpoint.Key,
tieLine.SourcePort
);
return null; return null;
} }
//Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Found currentRoute {currentRoute} through {midpoint}", this, currentRoute, midpoint); //Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Found currentRoute {currentRoute} through {midpoint}", this, currentRoute, midpoint);
nextTieLine = TieLineCollection.Default.FirstOrDefault(tl => { nextTieLine = TieLineCollection.Default.FirstOrDefault(tl =>
{
//Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Checking {route} against {tieLine}", tl.DestinationPort.Key, currentRoute.InputPort.Key); //Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Checking {route} against {tieLine}", tl.DestinationPort.Key, currentRoute.InputPort.Key);
return tl.DestinationPort.Key == currentRoute.InputPort.Key && tl.DestinationPort.ParentDevice.Key == currentRoute.InputPort.ParentDevice.Key; }); return tl.DestinationPort.Key == currentRoute.InputPort.Key
&& tl.DestinationPort.ParentDevice.Key
== currentRoute.InputPort.ParentDevice.Key;
});
if (nextTieLine != null) if (nextTieLine != null)
{ {
@@ -286,19 +382,26 @@ namespace PepperDash.Essentials.Core.Routing
//Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "TieLIne Source Device {sourceDeviceKey} is IRoutingSource: {isIRoutingSource}", this, tieLine.SourcePort.ParentDevice.Key, tieLine.SourcePort.ParentDevice is IRoutingSource); //Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "TieLIne Source Device {sourceDeviceKey} is IRoutingSource: {isIRoutingSource}", this, tieLine.SourcePort.ParentDevice.Key, tieLine.SourcePort.ParentDevice is IRoutingSource);
//Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "TieLine Source Device interfaces: {typeFullName}:{interfaces}", this, tieLine.SourcePort.ParentDevice.GetType().FullName, tieLine.SourcePort.ParentDevice.GetType().GetInterfaces().Select(i => i.Name)); //Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "TieLine Source Device interfaces: {typeFullName}:{interfaces}", this, tieLine.SourcePort.ParentDevice.GetType().FullName, tieLine.SourcePort.ParentDevice.GetType().GetInterfaces().Select(i => i.Name));
if (tieLine.SourcePort.ParentDevice is IRoutingSource || tieLine.SourcePort.ParentDevice is IRoutingOutputs) //end of the chain if (
tieLine.SourcePort.ParentDevice is IRoutingSource
|| tieLine.SourcePort.ParentDevice is IRoutingOutputs
) //end of the chain
{ {
// Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Found root: {tieLine}", this, tieLine); // Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Found root: {tieLine}", this, tieLine);
return tieLine; return tieLine;
} }
nextTieLine = TieLineCollection.Default.FirstOrDefault(tl => tl.DestinationPort.Key == tieLine.SourcePort.Key && tl.DestinationPort.ParentDevice.Key == tieLine.SourcePort.ParentDevice.Key ); nextTieLine = TieLineCollection.Default.FirstOrDefault(tl =>
tl.DestinationPort.Key == tieLine.SourcePort.Key
&& tl.DestinationPort.ParentDevice.Key == tieLine.SourcePort.ParentDevice.Key
);
if (nextTieLine != null) if (nextTieLine != null)
{ {
return GetRootTieLine(nextTieLine); return GetRootTieLine(nextTieLine);
} }
} catch (Exception ex) }
catch (Exception ex)
{ {
Debug.LogMessage(ex, "Error walking tieLines: {Exception}", this, ex); Debug.LogMessage(ex, "Error walking tieLines: {Exception}", this, ex);
return null; return null;