Beispiel #1
0
        private Task ExecuteNextNode([NotNull] IActivityNode node, [NotNull] Task task)
        {
            if (task.IsCanceled)
            {
                Log.Info("At node: {0}. Cancelled", node);

                IFlowNode handlerNode = node.CancellationHandler;
                Debug.Assert(handlerNode != null);

                return(handlerNode.Accept(this));
            }

            if (task.IsFaulted)
            {
                string message = $"At node: {node}. Faulted";
                Log.Exception(message, task.Exception);

                IFaultHandlerNode handlerNode = node.FaultHandler;
                Debug.Assert(handlerNode != null);

                return(handlerNode.Accept(this));
            }

            Log.Info("At node: {0}. Completed", node);

            if (node.PointsTo != null)
            {
                return(node.PointsTo.Accept(this));
            }

            return(TaskHelper.CompletedTask);
        }
Beispiel #2
0
        /// <summary>
        /// Registers a child activity node.
        /// </summary>
        /// <param name="Node">Activity node.</param>
        public void Register(IActivityNode Node)
        {
            if (this.activityNodes is null)
            {
                this.activityNodes = new LinkedList <IActivityNode>();
            }

            this.Model.Register(this.activityNodes.AddLast(Node));
        }
Beispiel #3
0
        public static TActivityNode ConnectCancellationTo <TActivityNode>(
            [NotNull] this TActivityNode from, [NotNull] IActivityNode to)
            where TActivityNode : ActivityNode
        {
            from.AssertNotNull("from != null");
            to.AssertNotNull("to != null");
            from.CancellationHandler.AssertIsNull("Cancellation handler is already set");

            from.CancellationHandler = to;
            return(from);
        }
        public FlowBuilder WithDefaultCancellationHandler <TCancellationHandler>(
            [NotNull] ActivityNode <TCancellationHandler> handler)
            where TCancellationHandler : class, IActivity
        {
            handler.AssertNotNull("handler != null");
            myDefaultCancellationHandler.AssertIsNull("Default cancellation handler is already set");
            handler.AssertIsItemOf(myNodes, "Handler must be part of the flow");
            myIsFreezed.AssertFalse("Builder is freezed");

            myDefaultCancellationHandler = handler;
            return(this);
        }
Beispiel #5
0
 internal FlowDescription(
     [CanBeNull] IFlowNode initialNode,
     [CanBeNull] IFaultHandlerNode defaultFaultHandler, [CanBeNull] IActivityNode defaultCancellationHandler,
     [NotNull] ReadOnlyCollection <IFlowNode> nodes,
     [NotNull] ReadOnlyCollection <IVariable> globalVariables)
 {
     InitialNode                = initialNode;
     DefaultFaultHandler        = defaultFaultHandler;
     DefaultCancellationHandler = defaultCancellationHandler;
     Nodes           = nodes;
     GlobalVariables = globalVariables;
 }
        public void Clear()
        {
            myDefaultCancellationHandler = null;
            myDefaultFaultHandler        = null;

            foreach (IFlowNode node in myNodes)
            {
                node.RemoveConnections();
            }

            myNodes.Clear();
            myGlobalVariables.Clear();
        }
Beispiel #7
0
        private void CheckActivityNode(IActivityNode node)
        {
            CheckSelfReference(node, node.PointsTo);
            CheckSelfReference(node, node.FaultHandler);
            CheckSelfReference(node, node.CancellationHandler);

            if (node.FaultHandler == null && Flow.DefaultFaultHandler == null)
            {
                Result.AddError(node, "Neither node nor the flow has a fault handler");
            }

            if (node.CancellationHandler == null && Flow.DefaultCancellationHandler == null)
            {
                Result.AddError(node, "Neither node nor the flow has a cancellation handler");
            }
        }
        public void ToExceptionOf([NotNull] IActivityNode activity)
        {
            activity.AssertNotNull("activity != null");

            var bindingInfo = new FaultBinding(myPropertyName, activity);

            myActivityDescriptor.AddBindingInfo(bindingInfo);

            ActivityTaskHandler handler = task =>
            {
                if (task.Status == TaskStatus.Faulted)
                {
                    myActivityDescriptor.AddInitializer(a => SetProperty(a, task.Exception));
                }
            };

            activity.RegisterActivityTaskHandler(handler);
        }
Beispiel #9
0
 public void SubscribeToExceptionsOf(IActivityNode node)
 {
     node.AssertNotNull("node != null");
     Bind(x => x.Exception).ToExceptionOf(node);
 }
Beispiel #10
0
 public DefaultHandlersSetter([NotNull] FlowDescription flowDescription)
 {
     myFlowDescription     = flowDescription.NotNull();
     myFaultHandler        = flowDescription.DefaultFaultHandler;
     myCancellationHandler = flowDescription.DefaultCancellationHandler;
 }
 public FaultBinding(string propertyName, IActivityNode node)
 {
     PropertyName = propertyName.NotNullOrEmpty("propertyName");
     Node         = node.NotNull();
 }
Beispiel #12
0
 private void VisitActivityNode(IActivityNode node)
 {
     AddReachable(node.PointsTo);
     AddReachable(node.FaultHandler);
     AddReachable(node.CancellationHandler);
 }