Ejemplo n.º 1
0
 public SrcPadViewModel(ISrcPad model, ElementViewModel element, int padIndex)
     : base(element, padIndex)
 {
     this.Model = model;
     this.Type  = "double";
     this.Info  = string.Empty;
 }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public bool Equals(ISrcPad other)
        {
            if (other == null)
            {
                return(false);
            }

            return(this.Parent.Equals(other.Parent) && this.Name.Equals(other.Name, StringComparison.Ordinal));
        }
Ejemplo n.º 3
0
        /// <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));
        }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
        /// <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"));
            }
        }
Ejemplo n.º 7
0
 /// <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;
 }