Exemple #1
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);
        }
 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;
 }
        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);
        }