fix: modify how current sources dictionary gets updated

This commit is contained in:
Andrew Welker
2025-08-01 09:22:22 -05:00
parent ce886aea63
commit 27bf36c58c
3 changed files with 70 additions and 51 deletions

View File

@@ -217,7 +217,8 @@ namespace PepperDash.Essentials.Core
} }
catch (Exception ex) catch (Exception ex)
{ {
Debug.LogError(ex, "Exception occurred while creating device {0}: {1}", null, dc.Key, ex.Message); Debug.LogError(ex, "Exception occurred while creating device {key}: {message}", dc.Key, ex.Message);
Debug.LogDebug(ex, "Exception details: {stackTrace}", ex.StackTrace);
return null; return null;
} }
} }

View File

@@ -62,18 +62,17 @@ namespace PepperDash.Essentials.Core.Config
/// <returns>null if config data does not match ports, cards or devices</returns> /// <returns>null if config data does not match ports, cards or devices</returns>
public TieLine GetTieLine() public TieLine GetTieLine()
{ {
Debug.LogMessage(LogEventLevel.Information, "Build TieLine: {0}",null, this); Debug.LogInformation("Build TieLine: {config}", ToString());
// Get the source device // Get the source device
var sourceDev = DeviceManager.GetDeviceForKey(SourceKey) as IRoutingOutputs; if (!(DeviceManager.GetDeviceForKey(SourceKey) is IRoutingOutputs sourceDev))
if (sourceDev == null)
{ {
LogError("Routable source not found"); LogError("Routable source not found");
return null; return null;
} }
// Get the destination device // Get the destination device
var destDev = DeviceManager.GetDeviceForKey(DestinationKey) as IRoutingInputs; if (!(DeviceManager.GetDeviceForKey(DestinationKey) is IRoutingInputs destDev))
if (destDev == null)
{ {
LogError("Routable destination not found"); LogError("Routable destination not found");
return null; return null;
@@ -104,9 +103,9 @@ namespace PepperDash.Essentials.Core.Config
/// Logs an error message related to creating this tie line configuration. /// Logs an error message related to creating this tie line configuration.
/// </summary> /// </summary>
/// <param name="msg">The specific error message.</param> /// <param name="msg">The specific error message.</param>
void LogError(string msg) private void LogError(string msg)
{ {
Debug.LogMessage(LogEventLevel.Error, "WARNING: Cannot create tie line: {message}:\r {tieLineConfig}",null, msg, this); Debug.LogError("Cannot create tie line: {message}", msg);
} }
/// <summary> /// <summary>
@@ -115,8 +114,7 @@ namespace PepperDash.Essentials.Core.Config
/// <returns>A string describing the source and destination of the configured tie line.</returns> /// <returns>A string describing the source and destination of the configured tie line.</returns>
public override string ToString() public override string ToString()
{ {
return string.Format("{0}.{1}.{2} --> {3}.{4}.{5}", SourceKey, SourceCard, SourcePort, return $"{SourceKey}.{SourceCard}.{SourcePort} --> {DestinationKey}.{DestinationCard}.{DestinationPort}";
DestinationKey, DestinationCard, DestinationPort);
} }
} }
} }

View File

@@ -1,10 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.DeviceSupport;
using Newtonsoft.Json; using Newtonsoft.Json;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Core.Logging;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Core.DeviceTypeInterfaces; using PepperDash.Essentials.Core.DeviceTypeInterfaces;
@@ -384,7 +386,28 @@ namespace PepperDash.Essentials.Devices.Common.Displays
/// <inheritdoc /> /// <inheritdoc />
public virtual void SetCurrentSource(eRoutingSignalType signalType, string sourceListKey, SourceListItem sourceListItem) public virtual void SetCurrentSource(eRoutingSignalType signalType, string sourceListKey, SourceListItem sourceListItem)
{ {
// Update the current source for the specified signal type foreach (eRoutingSignalType type in Enum.GetValues(typeof(eRoutingSignalType)))
{
var flagValue = Convert.ToInt32(type);
if (flagValue == 0 || (flagValue & (flagValue - 1)) != 0)
{
this.LogDebug("Skipping {type}", type);
continue;
}
this.LogDebug("setting {type}", type);
if (signalType.HasFlag(type))
{
UpdateCurrentSources(type, sourceListKey, sourceListItem);
}
}
// Raise the CurrentSourcesChanged event
CurrentSourcesChanged?.Invoke(this, EventArgs.Empty);
}
private void UpdateCurrentSources(eRoutingSignalType signalType, string sourceListKey, SourceListItem sourceListItem)
{
if (CurrentSources.ContainsKey(signalType)) if (CurrentSources.ContainsKey(signalType))
{ {
CurrentSources[signalType] = sourceListItem; CurrentSources[signalType] = sourceListItem;
@@ -403,9 +426,6 @@ namespace PepperDash.Essentials.Devices.Common.Displays
{ {
CurrentSourceKeys.Add(signalType, sourceListKey); CurrentSourceKeys.Add(signalType, sourceListKey);
} }
// Raise the CurrentSourcesChanged event
CurrentSourcesChanged?.Invoke(this, EventArgs.Empty);
} }
} }