mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-16 13:15:03 +00:00
fix: modify how current sources dictionary gets updated
This commit is contained in:
@@ -135,7 +135,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
{
|
{
|
||||||
if (FactoryMethods.ContainsKey(typeName))
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,38 +22,38 @@ namespace PepperDash.Essentials.Core.Config
|
|||||||
/// The key of the source device.
|
/// The key of the source device.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string SourceKey { get; set; }
|
public string SourceKey { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 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).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string SourceCard { get; set; }
|
public string SourceCard { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The key of the source output port, used for routing configurations.
|
/// The key of the source output port, used for routing configurations.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string SourcePort { get; set; }
|
public string SourcePort { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the DestinationKey
|
/// Gets or sets the DestinationKey
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string DestinationKey { get; set; }
|
public string DestinationKey { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the DestinationCard
|
/// Gets or sets the DestinationCard
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string DestinationCard { get; set; }
|
public string DestinationCard { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the DestinationPort
|
/// Gets or sets the DestinationPort
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string DestinationPort { get; set; }
|
public string DestinationPort { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Optional override for the signal type of the tie line. If set, this overrides the destination port's type for routing calculations.
|
/// Optional override for the signal type of the tie line. If set, this overrides the destination port's type for routing calculations.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)]
|
[JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
[JsonConverter(typeof(StringEnumConverter))]
|
[JsonConverter(typeof(StringEnumConverter))]
|
||||||
public eRoutingSignalType? OverrideType { get; set; }
|
public eRoutingSignalType? OverrideType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the appropriate tie line for either a card-based device or
|
/// Returns the appropriate tie line for either a card-based device or
|
||||||
@@ -62,40 +62,39 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get the source port
|
//Get the source port
|
||||||
var sourceOutputPort = sourceDev.OutputPorts[SourcePort];
|
var sourceOutputPort = sourceDev.OutputPorts[SourcePort];
|
||||||
|
|
||||||
if (sourceOutputPort == null)
|
if (sourceOutputPort == null)
|
||||||
{
|
{
|
||||||
LogError("Source does not contain port");
|
LogError("Source does not contain port");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get the Destination port
|
//Get the Destination port
|
||||||
var destinationInputPort = destDev.InputPorts[DestinationPort];
|
var destinationInputPort = destDev.InputPorts[DestinationPort];
|
||||||
|
|
||||||
if (destinationInputPort == null)
|
if (destinationInputPort == null)
|
||||||
{
|
{
|
||||||
LogError("Destination does not contain port");
|
LogError("Destination does not contain port");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TieLine(sourceOutputPort, destinationInputPort, OverrideType);
|
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.
|
/// 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user