static IPipeLine CreatePipeInstance(PipeLineDefinition pipeDefinition)
        {
            var       assemly = Assembly.Load(pipeDefinition.AssemblyName);
            var       type    = assemly.GetTypes().FirstOrDefault(x => x.Name == pipeDefinition.Name);
            IPipeLine pipe    = Activator.CreateInstance(type) as IPipeLine;

            pipe.Name     = pipeDefinition.Name;
            pipe.PipeType = Enum.Parse <PipeType>(pipeDefinition.Type);
            return(pipe);
        }
Exemple #2
0
        /// <summary>
        /// Gets a description of the current pipeline including all off the pipelines elements, element properties and links.
        /// Used for serializing the pipeline.
        /// </summary>
        /// <returns>The pipelines desciption.</returns>
        public PipeLineDefinition GetDefinition()
        {
            var pipeline = new PipeLineDefinition();

            foreach (var element in this.elements)
            {
                pipeline.Elements.Add(new ElementDefinition(element.GetElementName(), element.Name, element.GetPropertyValues().ToList()));

                foreach (var srcPad in element.GetSrcPads())
                {
                    if (srcPad.Peer != null)
                    {
                        pipeline.Links.Add(new LinkDefinition(srcPad.Parent.Name, srcPad.Name, srcPad.Peer.Parent.Name, srcPad.Peer.Name));
                    }
                }
            }

            return(pipeline);
        }
Exemple #3
0
        /// <summary>
        /// Clears the pipeline and recreates itself using the given description.
        /// USed for deserializing the pipeline.
        /// </summary>
        /// <param name="definition">the pipelinee definition.</param>
        /// <returns>A list of errors that occured turing the builing of the pipeline.</returns>
        public IList <string> FromDefinition(PipeLineDefinition definition)
        {
            if (definition == null)
            {
                throw new ArgumentNullException(nameof(definition));
            }

            IList <string> errors = new List <string>();

            this.Clear();
            Dictionary <string, IElement> elementCache = new Dictionary <string, IElement>();

            foreach (var element in definition.Elements)
            {
                IElement?pipeElement = PipeElementFactory.Make(element.TypeFactory, element.Name);
                if (pipeElement != null)
                {
                    this.Add(pipeElement);

                    foreach (var propvalue in element.Properties)
                    {
                        pipeElement
                        .SetPropertyValue(propvalue)
                        .MatchNone((error) => errors.Add(error));
                    }

                    elementCache.Add(element.Name, pipeElement);
                }
            }

            foreach (var link in definition.Links)
            {
                IElement?fromElement = elementCache[link.FromElement];
                IElement?toElement   = elementCache[link.ToElement];

                if (fromElement == null)
                {
                    errors.Add($"Could not Link from {link.FromElement}:{link.FromPad} because the Element doesn't exist");
                    continue;
                }

                if (fromElement == null)
                {
                    errors.Add($"Could not Link to {link.ToElement}:{link.ToPad} because the Element doesn't exist");
                    continue;
                }

                Option <ISrcPad>  srcPad  = fromElement.GetSrcPad(link.FromPad);
                Option <ISinkPad> sinkPad = toElement.GetSinkPad(link.ToPad);

                srcPad.Match(
                    (srcPad) =>
                {
                    sinkPad.Match(
                        (sinkPad) =>
                    {
                        if (!this.TryConnect(srcPad, sinkPad))
                        {
                            errors.Add($"Could not Link to {link.ToElement}:{link.ToPad} because the types don't match");
                        }
                    },
                        () =>
                    {
                        errors.Add($"Could not Link to {link.ToElement}:{link.ToPad} because the Pad doesn't exist");
                    });
                },
                    () =>
                {
                    errors.Add($"Could not Link from {link.FromElement}:{link.FromPad} because the Pad doesn't exist");
                });
            }

            return(errors);
        }
Exemple #4
0
 public GraphicalPipeLineDefinition(PipeLineDefinition definition, Dictionary <string, Point> positions)
 {
     this.Definition = definition;
     this.Positions  = positions;
 }