Beispiel #1
0
        /// <summary>
        /// Creates a flow of the specified name and current subject type (T).
        /// </summary>
        /// <param name="name">Name of the flow.</param>
        /// <param name="id">Id of the node, if not supplied, defaults to the name.</param>
        /// <returns></returns>
        public IFlowBuilder <T> CreateFlow(string name, string id = null)
        {
            RootComponent = new FlowComponent <T> {
                Type = typeof(T), Name = name, Id = (string.IsNullOrEmpty(id) ? name : id), IsFlow = true
            };

            return(new FlowComponentBuilder <T>(RootComponent));
        }
Beispiel #2
0
        /// <summary>
        /// Builds a flow matching the specified flow component.
        /// </summary>
        /// <param name="serializedFlow">Serialized definition of the flow to build.</param>
        /// <returns>Flow matching the requested flow root.</returns>
        public INode <T> BuildFlow <T>(string serializedFlow)
        {
            Guard.AgainstNullOrEmptyArgument("serializedFlow", serializedFlow);

            FlowComponent <T> flowRoot = SerializerProvider.Serializer.Deserialize <T>(serializedFlow);

            return(BuildNode(flowRoot.Children[0], flowRoot.ShouldExecuteFunc, flowRoot.Id));
        }
Beispiel #3
0
        /// <summary>
        /// Returns an instance of FlowComponentBuilder representing the requested parent.
        /// </summary>
        /// <returns>A parent FlowComponentBuilder of this FlowComponentBuilder.</returns>
        public IFlowComponentBuilder <T> ForParent()
        {
            FlowComponent <T> parent = _component.Parent;

            if (parent == null)
            {
                throw new InvalidOperationException("This item has no parent.");
            }

            return(new FlowComponentBuilder <T>(parent));
        }
Beispiel #4
0
        /// <summary>
        /// Returns an instance of FlowComponentBuilder representing the last child of the current builder.
        /// </summary>
        /// <returns>A child FlowComponentBuilder of this FlowComponentBuilder.</returns>
        public IFlowComponentBuilder <T> ForLastChild()
        {
            if (_component.Children == null || _component.Children.Count == 0)
            {
                throw new IndexOutOfRangeException("This item has no children.");
            }

            FlowComponent <T> child = _component.Children.Last();

            return(new FlowComponentBuilder <T>(child));
        }
Beispiel #5
0
        /// <summary>
        /// Adds a child to this FlowComponent.
        /// </summary>
        /// <param name="child">Child to add.</param>
        /// <returns>Updated FlowComponent.</returns>
        protected internal FlowComponent <T> AddChild(FlowComponent <T> child)
        {
            if (IsFlow && _children.Count > 0)
            {
                throw new IndexOutOfRangeException("A flow can only have one root child.");
            }

            _children.Add(child);
            child.Parent = this;

            return(child);
        }
Beispiel #6
0
        /// <summary>
        /// Builds a node from the provided FlowComponent.
        /// </summary>
        /// <param name="component">Flowcomponent providing the node definition.</param>
        /// <param name="shouldExecuteFunc">Allows a ShouldExecuteAsyncFunc to be specified from the parent.</param>
        /// <param name="parentFlowId">ID of the parent flow if it exists.</param>
        /// <returns>A constructed INode.</returns>
        protected INode <T> BuildNode <T>(FlowComponent <T> component,
                                          Func <IExecutionContext <T>, Task <bool> > shouldExecuteFunc = null, string parentFlowId = null)
        {
            INode <T> node;

            //Get the node or flow from the flowComponent
            if (component.IsFlow)
            {
                node = typeof(T) == component.Type ? GetFlow <T>(component.Name) : GetFlow <T>(component.Type, component.Name);
            }
            else
            {
                node        = string.IsNullOrEmpty(component.Name) ? GetNode <T>(component.Type) : GetNode <T>(component.Type, component.Name);
                node.FlowId = parentFlowId;
            }

            if (!string.IsNullOrEmpty(component.Id))
            {
                node.Id = component.Id;
            }

            if (component.ShouldExecuteFunc != null)
            {
                node.AddShouldExecute(component.ShouldExecuteFunc);
            }
            else if (shouldExecuteFunc != null)
            {
                node.AddShouldExecute(shouldExecuteFunc);
            }
            if (component.ShouldExecuteBlockType != null)
            {
                node.AddShouldExecuteBlock(GetShouldExecuteBlock <T>(component.ShouldExecuteBlockType));
            }

            if (component.MetaData != null && component.MetaData.Count > 0)
            {
                ApplyMetaData(node, component.MetaData);
            }

            if (component.Children != null && component.Children.Count > 0)
            {
                var multiNode = (IMultiNode <T>)node;
                foreach (var childComponent in component.Children)
                {
                    multiNode.AddChild(BuildNode(childComponent));
                }
            }

            return(node);
        }
Beispiel #7
0
 /// <summary>
 /// Constructs a new FlowComponentBuilder.
 /// </summary>
 /// <param name="component">FlowComponent to build up.</param>
 public FlowComponentBuilder(FlowComponent <T> component)
 {
     _component = component;
 }
Beispiel #8
0
        /// <summary>
        /// Deserializes and sets the root component using the currently registered serializer.
        /// </summary>
        public FlowComponent <T> DeserializeAndSetRootComponent(string serializedComponent)
        {
            RootComponent = DeserializeRootComponent(serializedComponent);

            return(RootComponent);
        }
Beispiel #9
0
        /// <summary>
        /// Builds a flow matching the specified flow component.
        /// </summary>
        /// <param name="flowRoot">Definition of the flow to build.</param>
        /// <returns>Flow matching the requested flow root.</returns>
        public INode <T> BuildFlow <T>(FlowComponent <T> flowRoot)
        {
            Guard.AgainstNullArgument("flowRoot", flowRoot);

            return(BuildNode(flowRoot.Children[0], flowRoot.ShouldExecuteFunc, flowRoot.Id));
        }