Example #1
0
 private static Sequence CompileActions(Rule rule, Dictionary<string, Type> inputs)
 {
     var sequence = new Sequence();
     foreach (var action in rule.Actions)
     {
         Activity activity;
         switch (action.GetType().Name)
         {
             case "AssignAction":
                 activity = new Assign<string>
                     {
                         To = new OutArgument<string>(new VisualBasicReference<string>(action.LeftHandSide)),
                         Value = new InArgument<string>(action.Value)
                     };
                 break;
             default:
                 throw new Exception("The action type '" + action.GetType().Name + "' has not been implemented");
         }
         sequence.Activities.Add(activity);
     }
     return sequence;
 }
Example #2
0
        void CreateImplementation()
        {
            this.bodyClone = Activator.CreateInstance(this.Body.GetType()) as Activity;

            foreach (PropertyInfo pi in this.Body.GetType().GetProperties())
            {
                if (pi.CanWrite)
                {
                    pi.SetValue(this.bodyClone, pi.GetValue(this.Body, null), null);
                }

                if (pi.PropertyType.IsGenericType)
                {
                    Type argType = pi.PropertyType.GetGenericArguments()[0];
                    Type exprRefType = typeof(VisualBasicReference<>).MakeGenericType(argType);
                    Type exprValueType = typeof(VisualBasicValue<>).MakeGenericType(argType);

                    if (pi.PropertyType.GetGenericTypeDefinition() == typeof(InArgument<>))
                    {
                        // only expose InArguments that haven't already been bound
                        if (pi.GetValue(this.Body, null) == null)
                        {
                            // create the Variable and add it internally
                            string variableName = pi.Name;
                            Variable var = Variable.Create(variableName, argType, VariableModifiers.None);
                            this.variables.Add(var);

                            // create the OutArgument by calling the VisualBasicReference<>(string expressionText) constructor and set it on the Receive
                            OutArgument outArg = Argument.Create(argType, ArgumentDirection.Out) as OutArgument;
                            outArg.Expression = (ActivityWithResult)Activator.CreateInstance(exprRefType, variableName);
                            ((ReceiveParametersContent)receive.Content).Parameters.Add(pi.Name, outArg);

                            // create the InArgument by calling the VisualBasicReference<>(string expressionText) constructor and set it to the Variable
                            InArgument inArg = Argument.Create(argType, ArgumentDirection.In) as InArgument;
                            inArg.Expression = (ActivityWithResult)Activator.CreateInstance(exprValueType, variableName);
                            pi.SetValue(this.bodyClone, inArg, null);
                        }

                    }
                    else if (pi.PropertyType.GetGenericTypeDefinition() == typeof(OutArgument<>))
                    {
                        // create the Variable and add it internally
                        string variableName = pi.Name;
                        Variable var = Variable.Create(variableName, argType, VariableModifiers.None);
                        this.variables.Add(var);

                        if (pi.GetValue(this.Body, null) != null)
                        {
                            // copy the OutArgument
                            OutArgument refOutArg = ((OutArgument)pi.GetValue(this.Body, null));

                            string temp = refOutArg.Expression.ResultType.ToString();
                            InArgument assignInArg = Argument.Create(argType, ArgumentDirection.In) as InArgument;
                            assignInArg.Expression = (ActivityWithResult)Activator.CreateInstance(exprValueType, variableName);

                            Assign a = new Assign
                            {
                                To = refOutArg,
                                //To = OutArgument.CreateReference(varRef, pi.Name),
                                Value = assignInArg
                            };

                            assigns.Add(a);
                        }

                        // create an OutArgument by calling the VisualBasicReference<>(string expressionText) constructor and set it to the Variable
                        OutArgument outArg = Argument.Create(argType, ArgumentDirection.Out) as OutArgument;
                        outArg.Expression = (ActivityWithResult)Activator.CreateInstance(exprRefType, variableName);
                        pi.SetValue(this.bodyClone, outArg, null);

                        // create the InArgument by calling the VisualBasicReference<>(string expressionText) constructor and set it on the SendReply
                        InArgument inArg = Argument.Create(argType, ArgumentDirection.In) as InArgument;
                        inArg.Expression = (ActivityWithResult)Activator.CreateInstance(exprValueType, variableName);
                        ((SendParametersContent)reply.Content).Parameters.Add(variableName, inArg);

                    }
                }
            }

            // create internal Sequence and add the variables
            impl = new Sequence();
            foreach (Variable v in this.variables)
            {
                impl.Variables.Add(v);
            }

            // add the Receive
            receive.CanCreateInstance = this.CanCreateInstance;
            receive.OperationName = (this.DisplayName != "OperationScope" ? this.DisplayName : this.Body.DisplayName);
            impl.Activities.Add(receive);

            // add the activity which represents the operation body
            impl.Activities.Add(this.bodyClone);

            // add the Reply
            impl.Activities.Add(reply);

            // add any other Assigns to OutArguments
            foreach (Assign assignToOutArg in this.assigns)
            {
                impl.Activities.Add(assignToOutArg);
            }
        }
 private static Constraint ConfirmWithNoTarget()
 {
     DelegateInArgument<Confirm> element = new DelegateInArgument<Confirm> {
         Name = "element"
     };
     DelegateInArgument<ValidationContext> argument = new DelegateInArgument<ValidationContext> {
         Name = "validationContext"
     };
     Variable<bool> assertFlag = new Variable<bool> {
         Name = "assertFlag"
     };
     Variable<IEnumerable<Activity>> elements = new Variable<IEnumerable<Activity>> {
         Name = "elements"
     };
     Variable<int> index = new Variable<int> {
         Name = "index"
     };
     Constraint<Confirm> constraint = new Constraint<Confirm>();
     ActivityAction<Confirm, ValidationContext> action = new ActivityAction<Confirm, ValidationContext> {
         Argument1 = element,
         Argument2 = argument
     };
     Sequence sequence = new Sequence {
         Variables = { assertFlag, elements, index }
     };
     If item = new If {
         Condition = new InArgument<bool>(env => element.Get(env).Target != null)
     };
     Assign<bool> assign = new Assign<bool> {
         To = assertFlag,
         Value = 1
     };
     item.Then = assign;
     Sequence sequence2 = new Sequence();
     Assign<IEnumerable<Activity>> assign2 = new Assign<IEnumerable<Activity>> {
         To = elements
     };
     GetParentChain chain = new GetParentChain {
         ValidationContext = argument
     };
     assign2.Value = chain;
     sequence2.Activities.Add(assign2);
     While @while = new While(env => !assertFlag.Get(env) && (index.Get(env) < elements.Get(env).Count<Activity>()));
     Sequence sequence3 = new Sequence();
     If if2 = new If(env => elements.Get(env).ElementAt<Activity>(index.Get(env)).GetType() == typeof(CompensationParticipant));
     Assign<bool> assign3 = new Assign<bool> {
         To = assertFlag,
         Value = 1
     };
     if2.Then = assign3;
     sequence3.Activities.Add(if2);
     Assign<int> assign4 = new Assign<int> {
         To = index,
         Value = new InArgument<int>(env => index.Get(env) + 1)
     };
     sequence3.Activities.Add(assign4);
     @while.Body = sequence3;
     sequence2.Activities.Add(@while);
     item.Else = sequence2;
     sequence.Activities.Add(item);
     AssertValidation validation = new AssertValidation {
         Assertion = new InArgument<bool>(assertFlag),
         Message = new InArgument<string>(System.Activities.SR.ConfirmWithNoTargetConstraint)
     };
     sequence.Activities.Add(validation);
     action.Handler = sequence;
     constraint.Body = action;
     return constraint;
 }
Example #4
0
        private static Constraint ConfirmWithNoTarget()
        {
            DelegateInArgument <Confirm> element = new DelegateInArgument <Confirm> {
                Name = "element"
            };
            DelegateInArgument <ValidationContext> argument = new DelegateInArgument <ValidationContext> {
                Name = "validationContext"
            };
            Variable <bool> assertFlag = new Variable <bool> {
                Name = "assertFlag"
            };
            Variable <IEnumerable <Activity> > elements = new Variable <IEnumerable <Activity> > {
                Name = "elements"
            };
            Variable <int> index = new Variable <int> {
                Name = "index"
            };
            Constraint <Confirm> constraint = new Constraint <Confirm>();
            ActivityAction <Confirm, ValidationContext> action = new ActivityAction <Confirm, ValidationContext> {
                Argument1 = element,
                Argument2 = argument
            };
            Sequence sequence = new Sequence {
                Variables = { assertFlag, elements, index }
            };
            If item = new If {
                Condition = new InArgument <bool>(env => element.Get(env).Target != null)
            };
            Assign <bool> assign = new Assign <bool> {
                To    = assertFlag,
                Value = 1
            };

            item.Then = assign;
            Sequence sequence2 = new Sequence();
            Assign <IEnumerable <Activity> > assign2 = new Assign <IEnumerable <Activity> > {
                To = elements
            };
            GetParentChain chain = new GetParentChain {
                ValidationContext = argument
            };

            assign2.Value = chain;
            sequence2.Activities.Add(assign2);
            While         @while    = new While(env => !assertFlag.Get(env) && (index.Get(env) < elements.Get(env).Count <Activity>()));
            Sequence      sequence3 = new Sequence();
            If            if2       = new If(env => elements.Get(env).ElementAt <Activity>(index.Get(env)).GetType() == typeof(CompensationParticipant));
            Assign <bool> assign3   = new Assign <bool> {
                To    = assertFlag,
                Value = 1
            };

            if2.Then = assign3;
            sequence3.Activities.Add(if2);
            Assign <int> assign4 = new Assign <int> {
                To    = index,
                Value = new InArgument <int>(env => index.Get(env) + 1)
            };

            sequence3.Activities.Add(assign4);
            @while.Body = sequence3;
            sequence2.Activities.Add(@while);
            item.Else = sequence2;
            sequence.Activities.Add(item);
            AssertValidation validation = new AssertValidation {
                Assertion = new InArgument <bool>(assertFlag),
                Message   = new InArgument <string>(System.Activities.SR.ConfirmWithNoTargetConstraint)
            };

            sequence.Activities.Add(validation);
            action.Handler  = sequence;
            constraint.Body = action;
            return(constraint);
        }
Example #5
0
        /// <summary>
        ///  获取并发状态
        /// </summary>
        /// <param name="wfslElements"></param>
        /// <param name="currentXmlNode"></param>
        /// <param name="currentFlowNode"></param>
        /// <param name="resultListNodes"></param>
        /// <param name="templateId"></param>
        /// <returns></returns>
        public static int GetNextNodeofActivityWithParallel(IEnumerable<XElement> wfslElements, XElement currentXmlNode, FlowNode currentFlowNode, Dictionary<string, FlowNode> resultListNodes, Guid templateId)
        {
            try
            {
                var num = 0;
                var para = new Parallel();
                var flowNode = new FlowStep();
                var endParallelNodeId = "";

                var nextNodes = GetXElementAttribute(currentXmlNode, "NextNodes");
                if (!string.IsNullOrEmpty(nextNodes))
                {
                    var nextNodeIds = nextNodes.Split(',');
                    if (nextNodeIds.Length > 0)
                    {
                        var varable = new Variable<int>("branchesNum");
                        para.Variables.Add(varable);
                        para.CompletionCondition = new VisualBasicValue<bool>() { ExpressionText = "branchesNum=ParallelBranchesCount" };

                        foreach (var nextNodeId in nextNodeIds)
                        {
                            num++;
                            if (!resultListNodes.ContainsKey(nextNodeId))  //避免有回路,已经添加过的节点不用再添加,否则会死循环
                            {
                                var nextXmlNode = GetXmlNode(wfslElements, "UniqueID", nextNodeId);
                                var nextNodeType = GetXElementAttribute(nextXmlNode, "WFSLElementType");
                                endParallelNodeId = GetXElementAttribute(nextXmlNode, "NextNodeID");
                                if (nextNodeType == "WFSLActivity")
                                {
                                    //   var nextFlowNode = GetFlowStep(nextXmlNode);
                                    var nextAcitivity = GetAcitivityForParallel(nextXmlNode);
                                    var seq = new Sequence();
                                    seq.DisplayName = "seq" + num;

                                    seq.Activities.Add(nextAcitivity);

                                    var assgin = new Assign();
                                    assgin.DisplayName = "assgin" + num;
                                    assgin.Value = new InArgument<int>() { Expression = new VisualBasicValue<int> { ExpressionText = "branchesNum+1" } };
                                    assgin.To = new OutArgument<int>() { Expression = new VisualBasicReference<int> { ExpressionText = "branchesNum" } };
                                    seq.Activities.Add(assgin);

                                    para.Branches.Add(seq);

                                    //  resultListNodes.Add(GetXElementAttribute(nextXmlNode, "UniqueID"), nextFlowNode);
                                    SaveStateInfo(nextXmlNode, templateId, false);
                                }
                            }
                            //else  //该节点已经包含在内,只需要画上连线即可,即表明关系即可
                            //{
                            //   //((FlowStep)currentFlowNode).Next = resultListNodes[nextNodeId];
                            //}
                        }
                    }
                }

                var afterParalleXmlNode = GetXmlNode(wfslElements, "UniqueID", endParallelNodeId);
                var afterParalleWfNode = GetFlowStep(afterParalleXmlNode);
                flowNode.Action = para;
                flowNode.Next = afterParalleWfNode;
                ((FlowStep)currentFlowNode).Next = flowNode;
                resultListNodes.Add(Guid.Empty.ToString(), flowNode);
                GetNextNode(wfslElements, afterParalleXmlNode, afterParalleWfNode, ref resultListNodes, templateId);
                return num;
            }
            catch (Exception ex)
            {
                LogWritter.WriteSystemExceptionLog(ex);
                throw ex;
            }
        }
        private static Constraint NoCompensableActivityInSecondaryRoot()
        {
            DelegateInArgument <ValidationContext> argument = new DelegateInArgument <ValidationContext> {
                Name = "validationContext"
            };
            DelegateInArgument <CompensableActivity> argument2 = new DelegateInArgument <CompensableActivity> {
                Name = "element"
            };
            Variable <bool> assertFlag = new Variable <bool> {
                Name    = "assertFlag",
                Default = 1
            };
            Variable <IEnumerable <Activity> > elements = new Variable <IEnumerable <Activity> > {
                Name = "elements"
            };
            Variable <int> index = new Variable <int> {
                Name = "index"
            };
            Constraint <CompensableActivity> constraint = new Constraint <CompensableActivity>();
            ActivityAction <CompensableActivity, ValidationContext> action = new ActivityAction <CompensableActivity, ValidationContext> {
                Argument1 = argument2,
                Argument2 = argument
            };
            Sequence sequence = new Sequence {
                Variables = { assertFlag, elements, index }
            };
            Assign <IEnumerable <Activity> > item = new Assign <IEnumerable <Activity> > {
                To = elements
            };
            GetParentChain chain = new GetParentChain {
                ValidationContext = argument
            };

            item.Value = chain;
            sequence.Activities.Add(item);
            While         @while    = new While(env => assertFlag.Get(env) && (index.Get(env) < elements.Get(env).Count <Activity>()));
            Sequence      sequence2 = new Sequence();
            If            @if       = new If(env => elements.Get(env).ElementAt <Activity>(index.Get(env)).GetType() == typeof(System.Activities.Statements.CompensationParticipant));
            Assign <bool> assign2   = new Assign <bool> {
                To    = assertFlag,
                Value = 0
            };

            @if.Then = assign2;
            sequence2.Activities.Add(@if);
            Assign <int> assign3 = new Assign <int> {
                To    = index,
                Value = new InArgument <int>(env => index.Get(env) + 1)
            };

            sequence2.Activities.Add(assign3);
            @while.Body = sequence2;
            sequence.Activities.Add(@while);
            AssertValidation validation = new AssertValidation {
                Assertion = new InArgument <bool>(assertFlag),
                Message   = new InArgument <string>(System.Activities.SR.NoCAInSecondaryRoot)
            };

            sequence.Activities.Add(validation);
            action.Handler  = sequence;
            constraint.Body = action;
            return(constraint);
        }
Example #7
0
        private Constraint ProcessChildSubtreeConstraints()
        {
            DelegateInArgument <System.Activities.Statements.TransactionScope> argument = new DelegateInArgument <System.Activities.Statements.TransactionScope> {
                Name = "element"
            };
            DelegateInArgument <ValidationContext> argument2 = new DelegateInArgument <ValidationContext> {
                Name = "validationContext"
            };
            DelegateInArgument <Activity> delegateArgument = new DelegateInArgument <Activity> {
                Name = "child"
            };
            Variable <bool> variable = new Variable <bool>();
            Constraint <System.Activities.Statements.TransactionScope> constraint = new Constraint <System.Activities.Statements.TransactionScope>();
            ActivityAction <System.Activities.Statements.TransactionScope, ValidationContext> action = new ActivityAction <System.Activities.Statements.TransactionScope, ValidationContext> {
                Argument1 = argument,
                Argument2 = argument2
            };
            Sequence sequence = new Sequence {
                Variables = { variable }
            };
            ForEach <Activity> item    = new ForEach <Activity>();
            GetChildSubtree    subtree = new GetChildSubtree {
                ValidationContext = argument2
            };

            item.Values = subtree;
            ActivityAction <Activity> action2 = new ActivityAction <Activity> {
                Argument = delegateArgument
            };
            Sequence sequence2             = new Sequence();
            If       @if                   = new If();
            Equal <Type, Type, bool> equal = new Equal <Type, Type, bool>();
            ObtainType type                = new ObtainType {
                Input = new InArgument <Activity>(delegateArgument)
            };

            equal.Left    = type;
            equal.Right   = new InArgument <Type>(context => typeof(CompensableActivity));
            @if.Condition = equal;
            Assign <bool> assign = new Assign <bool> {
                To    = new OutArgument <bool>(variable),
                Value = new InArgument <bool>(true)
            };

            @if.Then = assign;
            sequence2.Activities.Add(@if);
            action2.Handler = sequence2;
            item.Body       = action2;
            sequence.Activities.Add(item);
            AssertValidation     validation = new AssertValidation();
            Not <bool, bool>     expression = new Not <bool, bool>();
            VariableValue <bool> value2     = new VariableValue <bool> {
                Variable = variable
            };

            expression.Operand      = value2;
            validation.Assertion    = new InArgument <bool>(expression);
            validation.Message      = new InArgument <string>(System.Activities.SR.CompensableActivityInsideTransactionScopeActivity);
            validation.PropertyName = "Body";
            sequence.Activities.Add(validation);
            action.Handler  = sequence;
            constraint.Body = action;
            return(constraint);
        }