diff --git a/src/PepperDash.Essentials.Core/Factory/DeviceFactory.cs b/src/PepperDash.Essentials.Core/Factory/DeviceFactory.cs index b723f6c9..ae18d9fb 100644 --- a/src/PepperDash.Essentials.Core/Factory/DeviceFactory.cs +++ b/src/PepperDash.Essentials.Core/Factory/DeviceFactory.cs @@ -135,7 +135,7 @@ namespace PepperDash.Essentials.Core { if (FactoryMethods.ContainsKey(typeName)) { - Debug.LogInformation("Unable to add type: '{typeName}'. Already exists in DeviceFactory", typeName); + Debug.LogInformation("Unable to add type: '{typeName}'. Already exists in DeviceFactory", typeName); return; } @@ -217,7 +217,8 @@ namespace PepperDash.Essentials.Core } 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; } } diff --git a/src/PepperDash.Essentials.Core/Routing/TieLineConfig.cs b/src/PepperDash.Essentials.Core/Routing/TieLineConfig.cs index 8143c1f5..156b39b1 100644 --- a/src/PepperDash.Essentials.Core/Routing/TieLineConfig.cs +++ b/src/PepperDash.Essentials.Core/Routing/TieLineConfig.cs @@ -22,38 +22,38 @@ namespace PepperDash.Essentials.Core.Config /// The key of the source device. /// public string SourceKey { get; set; } - - /// - /// The key of the source card (if applicable, e.g., in a modular chassis). - /// + + /// + /// The key of the source card (if applicable, e.g., in a modular chassis). + /// public string SourceCard { get; set; } - - /// - /// The key of the source output port, used for routing configurations. - /// + + /// + /// The key of the source output port, used for routing configurations. + /// public string SourcePort { get; set; } - - /// - /// Gets or sets the DestinationKey - /// + + /// + /// Gets or sets the DestinationKey + /// public string DestinationKey { get; set; } - - /// - /// Gets or sets the DestinationCard - /// + + /// + /// Gets or sets the DestinationCard + /// public string DestinationCard { get; set; } - - /// - /// Gets or sets the DestinationPort - /// + + /// + /// Gets or sets the DestinationPort + /// public string DestinationPort { get; set; } - /// - /// Optional override for the signal type of the tie line. If set, this overrides the destination port's type for routing calculations. - /// - [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)] - [JsonConverter(typeof(StringEnumConverter))] - public eRoutingSignalType? OverrideType { get; set; } + /// + /// Optional override for the signal type of the tie line. If set, this overrides the destination port's type for routing calculations. + /// + [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)] + [JsonConverter(typeof(StringEnumConverter))] + public eRoutingSignalType? OverrideType { get; set; } /// /// Returns the appropriate tie line for either a card-based device or @@ -62,40 +62,39 @@ namespace PepperDash.Essentials.Core.Config /// null if config data does not match ports, cards or devices public TieLine GetTieLine() { - Debug.LogMessage(LogEventLevel.Information, "Build TieLine: {0}",null, this); + Debug.LogInformation("Build TieLine: {config}", ToString()); + // Get the source device - var sourceDev = DeviceManager.GetDeviceForKey(SourceKey) as IRoutingOutputs; - if (sourceDev == null) + if (!(DeviceManager.GetDeviceForKey(SourceKey) is IRoutingOutputs sourceDev)) { LogError("Routable source not found"); return null; } // Get the destination device - var destDev = DeviceManager.GetDeviceForKey(DestinationKey) as IRoutingInputs; - if (destDev == null) + if (!(DeviceManager.GetDeviceForKey(DestinationKey) is IRoutingInputs destDev)) { LogError("Routable destination not found"); return null; } - //Get the source port - var sourceOutputPort = sourceDev.OutputPorts[SourcePort]; + //Get the source port + var sourceOutputPort = sourceDev.OutputPorts[SourcePort]; - if (sourceOutputPort == null) + if (sourceOutputPort == null) { LogError("Source does not contain port"); return null; } - //Get the Destination port - var destinationInputPort = destDev.InputPorts[DestinationPort]; + //Get the Destination port + var destinationInputPort = destDev.InputPorts[DestinationPort]; - if (destinationInputPort == null) - { - LogError("Destination does not contain port"); - return null; - } + if (destinationInputPort == null) + { + LogError("Destination does not contain port"); + return null; + } return new TieLine(sourceOutputPort, destinationInputPort, OverrideType); } @@ -104,9 +103,9 @@ namespace PepperDash.Essentials.Core.Config /// Logs an error message related to creating this tie line configuration. /// /// The specific error message. - 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); } /// @@ -115,8 +114,7 @@ namespace PepperDash.Essentials.Core.Config /// A string describing the source and destination of the configured tie line. public override string ToString() { - return string.Format("{0}.{1}.{2} --> {3}.{4}.{5}", SourceKey, SourceCard, SourcePort, - DestinationKey, DestinationCard, DestinationPort); + return $"{SourceKey}.{SourceCard}.{SourcePort} --> {DestinationKey}.{DestinationCard}.{DestinationPort}"; } } } \ No newline at end of file diff --git a/src/PepperDash.Essentials.Devices.Common/Displays/DisplayBase.cs b/src/PepperDash.Essentials.Devices.Common/Displays/DisplayBase.cs index 27a3e0e0..7a6fa874 100644 --- a/src/PepperDash.Essentials.Devices.Common/Displays/DisplayBase.cs +++ b/src/PepperDash.Essentials.Devices.Common/Displays/DisplayBase.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.InteropServices; using Crestron.SimplSharp; using Crestron.SimplSharpPro.DeviceSupport; using Newtonsoft.Json; using PepperDash.Core; +using PepperDash.Core.Logging; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.DeviceTypeInterfaces; @@ -384,7 +386,28 @@ namespace PepperDash.Essentials.Devices.Common.Displays /// 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)) { CurrentSources[signalType] = sourceListItem; @@ -403,9 +426,6 @@ namespace PepperDash.Essentials.Devices.Common.Displays { CurrentSourceKeys.Add(signalType, sourceListKey); } - - // Raise the CurrentSourcesChanged event - CurrentSourcesChanged?.Invoke(this, EventArgs.Empty); } }