using Newtonsoft.Json;
using System;
using System.Collections.Generic;
namespace PepperDash.Essentials.Core
{
///
/// Represents a TieLine
///
public class TieLine
{
///
/// The source output port of the tie line.
///
public RoutingOutputPort SourcePort { get; private set; }
///
/// The destination input port of the tie line.
///
public RoutingInputPort DestinationPort { get; private set; }
//public int InUseCount { get { return DestinationUsingThis.Count; } }
///
/// Gets the type of this tie line. Will either be the type of the destination port
/// or the type of OverrideType when it is set.
///
public eRoutingSignalType Type
{
get
{
if (OverrideType.HasValue) return OverrideType.Value;
return DestinationPort.Type;
}
}
///
/// Use this to override the Type property for the destination port. For example,
/// when the tie line is type AudioVideo, and the signal flow should be limited to
/// Audio-only or Video only, changing this type will alter the signal paths
/// available to the routing algorithm without affecting the actual Type
/// of the destination port.
///
public eRoutingSignalType? OverrideType { get; set; }
//List DestinationUsingThis = new List();
///
/// Gets a value indicating whether this tie line represents an internal connection within a device (both source and destination ports are internal).
///
public bool IsInternal { get { return SourcePort.IsInternal && DestinationPort.IsInternal; } }
///
/// Gets a value indicating whether the signal types of the source and destination ports differ.
///
public bool TypeMismatch { get { return SourcePort.Type != DestinationPort.Type; } }
///
/// Gets a value indicating whether the connection types of the source and destination ports differ.
///
public bool ConnectionTypeMismatch { get { return SourcePort.ConnectionType != DestinationPort.ConnectionType; } }
///
/// A descriptive note about any type mismatch, if applicable.
///
public string TypeMismatchNote { get; set; }
///
/// Initializes a new instance of the class.
///
/// The source output port.
/// The destination input port.
public TieLine(RoutingOutputPort sourcePort, RoutingInputPort destinationPort)
{
if (sourcePort == null || destinationPort == null)
throw new ArgumentNullException("source or destination port");
SourcePort = sourcePort;
DestinationPort = destinationPort;
}
///
/// Creates a tie line with an overriding Type. See help for OverrideType property for info.
///
/// The source output port.
/// The destination input port.
/// The signal type to limit the link to. Overrides DestinationPort.Type for routing calculations.
public TieLine(RoutingOutputPort sourcePort, RoutingInputPort destinationPort, eRoutingSignalType? overrideType) :
this(sourcePort, destinationPort)
{
OverrideType = overrideType;
}
///
/// Creates a tie line with an overriding Type. See help for OverrideType property for info.
///
/// The source output port.
/// The destination input port.
/// The signal type to limit the link to. Overrides DestinationPort.Type for routing calculations.
public TieLine(RoutingOutputPort sourcePort, RoutingInputPort destinationPort, eRoutingSignalType overrideType) :
this(sourcePort, destinationPort)
{
OverrideType = overrideType;
}
///
/// Will link up video status from supporting inputs to connected outputs.
///
public void Activate()
{
// Now does nothing
}
///
/// Deactivates the tie line.
///
public void Deactivate()
{
// Now does nothing
}
///
/// Returns a string representation of the tie line.
///
/// A string describing the source, destination, and type of the tie line.
public override string ToString()
{
return string.Format("Tie line: {0}:{1} --> {2}:{3} {4}", SourcePort.ParentDevice.Key, SourcePort.Key,
DestinationPort.ParentDevice.Key, DestinationPort.Key, Type.ToString());
}
}
//********************************************************************************
///
/// Represents a TieLineCollection
///
public class TieLineCollection : List
{
///
/// Gets the default singleton instance of the .
///
public static TieLineCollection Default
{
get
{
if (_Default == null)
_Default = new TieLineCollection();
return _Default;
}
}
///
/// Backing field for the singleton instance.
///
[JsonIgnore]
private static TieLineCollection _Default;
}
}