public SrcPadViewModel(ISrcPad model, ElementViewModel element, int padIndex) : base(element, padIndex) { this.Model = model; this.Type = "double"; this.Info = string.Empty; }
/// <inheritdoc/> public bool Equals(ISrcPad other) { if (other == null) { return(false); } return(this.Parent.Equals(other.Parent) && this.Name.Equals(other.Name, StringComparison.Ordinal)); }
/// <inheritdoc/> public Option <ISrcPad <TValue>, string> Link(ISrcPad <TValue> peer) { if (peer == this.Peer) { return(Option.Some <ISrcPad <TValue>, string>(peer)); } this.Peer = peer; this.Peer.Link(this); return(Option.Some <ISrcPad <TValue>, string>(peer)); }
/// <summary> /// Tries to Connect two pads if you don't have strongly typed pads. /// </summary> /// <param name="src">The src pad sending data.</param> /// <param name="sink">The sink pad receiving the data.</param> /// <returns>True if the elements were linked. False otherwise.</returns> /// <exception cref="ArgumentNullException">If either parameters were null.</exception> public bool TryConnect(ISrcPad src, ISinkPad sink) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (sink == null) { throw new ArgumentNullException(nameof(sink)); } var srcType = src.GetType(); var sinkType = sink.GetType(); var srcBaseType = srcType.GetGenericInterfaceImplementation(typeof(ISrcPad <>)); var sinkBaseType = sinkType.GetGenericInterfaceImplementation(typeof(ISinkPad <>)); if (srcBaseType == null) { return(false); } if (sinkBaseType == null) { return(false); } if (!srcBaseType.GenericTypeArguments.SequenceEqual(sinkBaseType.GenericTypeArguments)) { return(false); } MethodInfo?genericConnect = typeof(PipeLine).GetMethod(nameof(this.Connect)); if (genericConnect == null) { return(false); } var specificConnect = genericConnect.MakeGenericMethod(srcBaseType.GenericTypeArguments); this.Unlink(sink); this.Unlink(src); specificConnect.Invoke(this, new object[] { src, sink }); return(true); }
/// <summary> /// Connect two element pads, letting them send data from the src to the sink. /// </summary> /// <typeparam name="TValue">The type of data that can be sent.</typeparam> /// <param name="src">The src ot the data.</param> /// <param name="sink">The destination of the data.</param> public void Connect <TValue>(ISrcPad <TValue> src, ISinkPad <TValue> sink) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (sink == null) { throw new ArgumentNullException(nameof(sink)); } src.Link(sink); this.OnElementsLinked(src, sink); }
/// <inheritdoc/> public Option <ISrcPad, string> Link(ISrcPad peer) { if (peer == this.Peer) { return(Option.Some <ISrcPad, string>(peer)); } if (peer is ISrcPad <TValue> truePeer) { this.Peer = truePeer; return(Option.Some <ISrcPad, string>(peer)); } else { return(Option.None <ISrcPad, string>("Could not link Pads be casue the types didn't match")); } }
/// <summary> /// Initializes a new instance of the <see cref="ElementsLinkedEventArgs"/> class. /// </summary> /// <param name="src">The src pad that was linked.</param> /// <param name="sink">The sink pad that was linked.</param> public ElementsLinkedEventArgs(ISrcPad src, ISinkPad sink) { this.Src = src; this.Sink = sink; }