Exemple #1
0
        public static ActivityFunc <TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TResult> Delegate <TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TResult>(Func <DelegateInArgument <TArg1>, DelegateInArgument <TArg2>, DelegateInArgument <TArg3>, DelegateInArgument <TArg4>, DelegateInArgument <TArg5>, DelegateInArgument <TArg6>, DelegateInArgument <TArg7>, DelegateInArgument <TArg8>, Activity <TResult> > create)
        {
            if (create == null)
            {
                throw new ArgumentNullException(nameof(create));
            }

            var arg1   = new DelegateInArgument <TArg1>();
            var arg2   = new DelegateInArgument <TArg2>();
            var arg3   = new DelegateInArgument <TArg3>();
            var arg4   = new DelegateInArgument <TArg4>();
            var arg5   = new DelegateInArgument <TArg5>();
            var arg6   = new DelegateInArgument <TArg6>();
            var arg7   = new DelegateInArgument <TArg7>();
            var arg8   = new DelegateInArgument <TArg8>();
            var result = new DelegateOutArgument <TResult>();
            var action = create(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);

            action.Result = result;

            return(new ActivityFunc <TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TResult>()
            {
                Argument1 = arg1,
                Argument2 = arg2,
                Argument3 = arg3,
                Argument4 = arg4,
                Argument5 = arg5,
                Argument6 = arg6,
                Argument7 = arg7,
                Argument8 = arg8,
                Result = result,
                Handler = action,
            });
        }
Exemple #2
0
        public static ActivityFunc <TArg1, TArg2, TArg3, TArg4, TArg5, TResult> Delegate <TArg1, TArg2, TArg3, TArg4, TArg5, TResult>(Func <DelegateInArgument <TArg1>, DelegateInArgument <TArg2>, DelegateInArgument <TArg3>, DelegateInArgument <TArg4>, DelegateInArgument <TArg5>, DelegateOutArgument <TResult>, Activity <TResult> > create)
        {
            if (create == null)
            {
                throw new ArgumentNullException(nameof(create));
            }

            var arg1   = new DelegateInArgument <TArg1>();
            var arg2   = new DelegateInArgument <TArg2>();
            var arg3   = new DelegateInArgument <TArg3>();
            var arg4   = new DelegateInArgument <TArg4>();
            var arg5   = new DelegateInArgument <TArg5>();
            var result = new DelegateOutArgument <TResult>();

            return(new ActivityFunc <TArg1, TArg2, TArg3, TArg4, TArg5, TResult>()
            {
                Argument1 = arg1,
                Argument2 = arg2,
                Argument3 = arg3,
                Argument4 = arg4,
                Argument5 = arg5,
                Result = result,
                Handler = create(arg1, arg2, arg3, arg4, arg5, result),
            });
        }
Exemple #3
0
        public void BaseDelegateOutArgumentLValueGet()
        {
            DelegateOutArgument delArg = new DelegateOutArgument <string>();

            Expression <Func <ActivityContext, object> > expression       = (env) => delArg.Get(env);
            DelegateArgumentReference <object>           expectedActivity = new DelegateArgumentReference <object>(delArg);

            ConvertReferenceAndValidate(expression, expectedActivity, null);
        }
Exemple #4
0
        // Retrieve all roles from the database. Uses an ActivityFunc<DataReader, Role> to map the results
        // Performance decreases (since the mapping is done in multiple pulses) but mapping can be serialized
        // to Xaml and authored declaratively in the the designer.
        static void GetAllRolesUsingActivityFuncMapping()
        {
            DelegateInArgument <DbDataReader> reader = new DelegateInArgument <DbDataReader>()
            {
                Name = "readerInArgument"
            };
            DelegateOutArgument <Role> roleOutArg = new DelegateOutArgument <Role>()
            {
                Name = "roleOutArgument"
            };

            Activity dbQuery = new DbQuery <Role>()
            {
                ConfigName = "DbActivitiesSample",
                Sql        = "SELECT * FROM Roles",
                MapperFunc = new ActivityFunc <System.Data.Common.DbDataReader, Role>
                {
                    Argument = reader,
                    Handler  = new Sequence
                    {
                        Activities =
                        {
                            new Assign <Role> {
                                To = roleOutArg, Value = new InArgument <Role>(c => new Role())
                            },
                            new Assign <string>
                            {
                                To    = new OutArgument <string>(c => roleOutArg.Get(c).Code),
                                Value = new InArgument <string>(c => reader.Get(c)["code"].ToString())
                            },
                            new Assign <string>
                            {
                                To    = new OutArgument <string>(c => roleOutArg.Get(c).Name),
                                Value = new InArgument <string>(c => reader.Get(c)["name"].ToString())
                            }
                        }
                    },
                    Result = roleOutArg
                }
            };

            IDictionary <string, object> results = WorkflowInvoker.Invoke(dbQuery);
            IList <Role> roles = (IList <Role>)results["Result"];

            foreach (Role role in roles)
            {
                Console.WriteLine(role.ToString());
            }
        }
Exemple #5
0
        public static ActivityFunc <TResult> Delegate <TResult>(Func <DelegateOutArgument <TResult>, Activity <TResult> > create)
        {
            if (create == null)
            {
                throw new ArgumentNullException(nameof(create));
            }

            var result = new DelegateOutArgument <TResult>();

            return(new ActivityFunc <TResult>()
            {
                Result = result,
                Handler = create(result),
            });
        }
Exemple #6
0
        public static ActivityFunc <Task <Func <Task> >, Func <Task> > CreateActivityDelegate()
        {
            var resultTaskFuncTask = new DelegateInArgument <Task <Func <Task> > >();
            var result             = new DelegateOutArgument <Func <Task> >();

            return(new ActivityFunc <Task <Func <Task> >, Func <Task> >()
            {
                Argument = resultTaskFuncTask,
                Result = result,
                Handler = new TaskFuncTaskWaiter()
                {
                    ResultTaskFuncTask = resultTaskFuncTask,
                    Result = result,
                },
            });
        }
        /// <summary>
        /// Assigns <paramref name="value"/> to <paramref name="to"/>.
        /// </summary>
        /// <param name="to"></param>
        /// <param name="value"></param>
        /// <param name="displayName"></param>
        /// <returns></returns>
        public static Assign <T> Assign <T>(DelegateOutArgument <T> to, InArgument <T> value, string displayName = null)
        {
            if (to == null)
            {
                throw new ArgumentNullException(nameof(to));
            }
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            return(new Assign <T>()
            {
                DisplayName = displayName,
                To = to,
                Value = value,
            });
        }
Exemple #8
0
        private static Activity CreateRequestReplyService()
        {
            var request    = new DelegateInArgument <HttpRequestMessage>();
            var response   = new DelegateOutArgument <object>();
            var parameters = new DelegateInArgument <IDictionary <string, string> > {
                Name = "parameters"
            };

            return(new Sequence
            {
                Activities =
                {
                    new HttpReceive
                    {
                        Method = "GET",
                        UriTemplate = "/{arg1}/{arg2}?q1={q1}&q2={q2}",
                        CanCreateInstance = true,
                        Body =
                            new ActivityFunc <HttpRequestMessage, IDictionary <string, string>, object>
                        {
                            Argument1 = request,
                            Argument2 = parameters,
                            Result = response,
                            Handler =
                                new Sequence
                            {
                                Activities =
                                {
                                    new Assign
                                    {
                                        DisplayName = "Assign response content",
                                        To = new OutArgument <object>(response),
                                        Value =
                                            new InArgument <string>(
                                                new VisualBasicValue <string>(
                                                    "string.Format(\"Arg1 = {0}, Arg2 = {1}, Q1 = {2}, Q2 = {3}\", parameters(\"ARG1\"), parameters(\"ARG2\"), parameters(\"Q1\"), parameters(\"Q2\"))"))
                                    }
                                }
                            }
                        }
                    },
                }
            });
        }
Exemple #9
0
        protected override void GatherOutputs(ActivityInstance completedInstance)
        {
            int resultId = -1;

            if (completedInstance.Activity.HandlerOf != null)
            {
                DelegateOutArgument resultArgument = completedInstance.Activity.HandlerOf.GetResultArgument();
                if (resultArgument != null)
                {
                    resultId = resultArgument.Id;
                }
                else
                {
                    ActivityWithResult activity = completedInstance.Activity as ActivityWithResult;
                    // for auto-generated results, we should bind the value from the Handler if available
                    if (activity != null && TypeHelper.AreTypesCompatible(activity.ResultType, typeof(T)))
                    {
                        resultId = GetResultId(activity);
                    }
                }
            }
            else
            {
                Fx.Assert(completedInstance.Activity is ActivityWithResult, "should only be using FuncCompletionCallbackWrapper with ActivityFunc and ActivityWithResult");
                resultId = GetResultId((ActivityWithResult)completedInstance.Activity);
            }

            if (resultId >= 0)
            {
                Location     location      = completedInstance.Environment.GetSpecificLocation(resultId);
                Location <T> typedLocation = location as Location <T>;

                if (typedLocation != null)
                {
                    _resultValue = typedLocation.Value;
                }
                else if (location != null)
                {
                    _resultValue = TypeHelper.Convert <T>(location.Value);
                }
            }
        }
Exemple #10
0
        public static ActivityFunc <TArg, TResult> Delegate <TArg, TResult>(Func <DelegateInArgument <TArg>, Activity <TResult> > create)
        {
            if (create == null)
            {
                throw new ArgumentNullException(nameof(create));
            }

            var arg    = new DelegateInArgument <TArg>();
            var result = new DelegateOutArgument <TResult>();
            var action = create(arg);

            action.Result = result;

            return(new ActivityFunc <TArg, TResult>()
            {
                Argument = arg,
                Result = result,
                Handler = action,
            });
        }
Exemple #11
0
        /// <summary>
        /// Waits for the given bookmark, and then executes <paramref name="func"/>.
        /// </summary>
        /// <typeparam name="TWait"></typeparam>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="bookmarkName"></param>
        /// <param name="func"></param>
        /// <returns></returns>
        public static Activity <TResult> WaitThen <TWait, TResult>(InArgument <string> bookmarkName, ActivityFunc <TWait, TResult> func)
        {
            if (bookmarkName == null)
            {
                throw new ArgumentNullException(nameof(bookmarkName));
            }
            if (func == null)
            {
                throw new ArgumentNullException(nameof(func));
            }

            var waitVar = new Variable <TWait>();
            var rsltArg = new DelegateOutArgument <TResult>();

            return(new InvokeFunc <TResult>()
            {
                Func = new ActivityFunc <TResult>()
                {
                    Handler = new Sequence()
                    {
                        Variables = { waitVar },
                        Activities =
                        {
                            new Wait <TWait>()
                            {
                                BookmarkName = bookmarkName,
                                Result = waitVar,
                            },
                            new InvokeFunc <TWait, TResult>()
                            {
                                Func = func,
                                Argument = waitVar,
                                Result = rsltArg,
                            }
                        }
                    },
                    Result = rsltArg,
                },
            });
        }
        public static object ActivityFuncMorphHelper(ModelItem originalValue, ModelProperty newModelProperty)
        {
            Fx.Assert(newModelProperty.PropertyType.GetGenericArguments().Count() == 2, "This should only be applied for ActivityFunc<TArgument, TResult>");
            Type      activityFuncArgumentType = newModelProperty.PropertyType.GetGenericArguments()[0];
            Type      activityFuncResultType   = newModelProperty.PropertyType.GetGenericArguments()[1];
            Type      activityFuncType         = typeof(ActivityFunc <,>).MakeGenericType(activityFuncArgumentType, activityFuncResultType);
            object    activityFunc             = Activator.CreateInstance(activityFuncType);
            ModelItem morphed = ModelFactory.CreateItem(originalValue.GetEditingContext(), activityFunc);

            ModelItem originalActivityFuncArgument = originalValue.Properties[PropertyNames.ActionArgument].Value;

            if (originalActivityFuncArgument != null)
            {
                Type argumentType = typeof(DelegateInArgument <>).MakeGenericType(activityFuncArgumentType);
                DelegateInArgument newActivityActionArgument = (DelegateInArgument)Activator.CreateInstance(argumentType);
                newActivityActionArgument.Name = (string)originalActivityFuncArgument.Properties[PropertyNames.NameProperty].Value.GetCurrentValue();
                morphed.Properties[PropertyNames.ActionArgument].SetValue(newActivityActionArgument);
            }

            ModelItem originalActivityFuncResult = originalValue.Properties[PropertyNames.ResultProperty].Value;

            if (originalActivityFuncResult != null)
            {
                Type resultType = typeof(DelegateOutArgument <>).MakeGenericType(activityFuncResultType);
                DelegateOutArgument newActivityActionResult = (DelegateOutArgument)Activator.CreateInstance(resultType);
                newActivityActionResult.Name = (string)originalActivityFuncResult.Properties[PropertyNames.NameProperty].Value.GetCurrentValue();
                morphed.Properties[PropertyNames.ResultProperty].SetValue(newActivityActionResult);
            }

            ModelItem originalActivityActionHandler = originalValue.Properties[PropertyNames.ActionHandler].Value;

            if (originalActivityActionHandler != null)
            {
                morphed.Properties[PropertyNames.ActionHandler].SetValue(originalActivityActionHandler);
                originalValue.Properties[PropertyNames.ActionHandler].SetValue(null);
            }

            return(morphed);
        }
        protected override void GatherOutputs(System.Activities.ActivityInstance completedInstance)
        {
            int id = -1;

            if (completedInstance.Activity.HandlerOf != null)
            {
                DelegateOutArgument resultArgument = completedInstance.Activity.HandlerOf.GetResultArgument();
                if (resultArgument != null)
                {
                    id = resultArgument.Id;
                }
                else
                {
                    ActivityWithResult activity = completedInstance.Activity as ActivityWithResult;
                    if ((activity != null) && TypeHelper.AreTypesCompatible(activity.ResultType, typeof(T)))
                    {
                        id = this.GetResultId(activity);
                    }
                }
            }
            else
            {
                id = this.GetResultId((ActivityWithResult)completedInstance.Activity);
            }
            if (id >= 0)
            {
                System.Activities.Location specificLocation = completedInstance.Environment.GetSpecificLocation(id);
                Location <T> location2 = specificLocation as Location <T>;
                if (location2 != null)
                {
                    this.resultValue = location2.Value;
                }
                else if (specificLocation != null)
                {
                    this.resultValue = TypeHelper.Convert <T>(specificLocation.Value);
                }
            }
        }
Exemple #14
0
        public void DifferentArguments()
        {
            //Testing Different argument types for Switch.Expression
            // DelegateInArgument
            // DelegateOutArgument
            // Activity<T>
            // Variable<T> , Activity<T> and Expression is already implemented.

            DelegateInArgument <string>  delegateInArgument  = new DelegateInArgument <string>("Input");
            DelegateOutArgument <string> delegateOutArgument = new DelegateOutArgument <string>("Output");

            TestCustomActivity <InvokeFunc <string, string> > invokeFunc = TestCustomActivity <InvokeFunc <string, string> > .CreateFromProduct(
                new InvokeFunc <string, string>
            {
                Argument = "PassedInValue",
                Func     = new ActivityFunc <string, string>
                {
                    Argument = delegateInArgument,
                    Result   = delegateOutArgument,
                    Handler  = new CoreWf.Statements.Sequence
                    {
                        DisplayName = "Sequence1",
                        Activities  =
                        {
                            new CoreWf.Statements.Switch <string>
                            {
                                DisplayName = "Switch1",
                                Expression  = delegateInArgument,
                                Cases       =
                                {
                                    {
                                        "PassedInValue",
                                        new CoreWf.Statements.Assign <string>
                                        {
                                            DisplayName = "Assign1",
                                            To          = delegateOutArgument,
                                            Value       = "OutValue",
                                        }
                                    },
                                },
                                Default = new Test.Common.TestObjects.CustomActivities.WriteLine{
                                    DisplayName = "W1", Message = "This should not be printed"
                                },
                            },
                            new CoreWf.Statements.Switch <string>
                            {
                                DisplayName = "Switch2",
                                Expression  = delegateOutArgument,
                                Cases       =
                                {
                                    {
                                        "OutValue",
                                        new Test.Common.TestObjects.CustomActivities.WriteLine {
                                            DisplayName = "W2", Message = delegateOutArgument
                                        }
                                    }
                                },
                                Default = new Test.Common.TestObjects.CustomActivities.WriteLine{
                                    DisplayName = "W3", Message = "This should not be printed"
                                },
                            }
                        }
                    }
                }
            }
                );

            TestSwitch <string> switch1 = new TestSwitch <string>
            {
                DisplayName = "Switch1",
                Hints       = { 0 }
            };

            switch1.AddCase("PassedInValue", new TestAssign <string> {
                DisplayName = "Assign1"
            });
            switch1.Default = new TestWriteLine {
                DisplayName = "W1"
            };

            TestSwitch <string> switch2 = new TestSwitch <string>
            {
                DisplayName = "Switch2",
                Hints       = { 0 }
            };

            switch2.AddCase("OutValue", new TestWriteLine {
                DisplayName = "W2", HintMessage = "OutValue"
            });
            switch2.Default = new TestWriteLine {
                DisplayName = "W3"
            };

            TestSequence sequenceForTracing = new TestSequence
            {
                DisplayName = "Sequence1",
                Activities  =
                {
                    switch1,
                    switch2,
                }
            };

            invokeFunc.CustomActivityTraces.Add(sequenceForTracing.GetExpectedTrace().Trace);

            TestRuntime.RunAndValidateWorkflow(invokeFunc);
        }
Exemple #15
0
        public void DifferentArguments()
        {
            //Testing Different argument types for If.Condition
            // DelegateInArgument
            // DelegateOutArgument
            // Activity<T>
            // Variable<T> , Activity<T> and Expression is already implemented.

            DelegateInArgument <bool>  delegateInArgument  = new DelegateInArgument <bool>("Condition");
            DelegateOutArgument <bool> delegateOutArgument = new DelegateOutArgument <bool>("Output");

            TestCustomActivity <InvokeFunc <bool, bool> > invokeFunc = TestCustomActivity <InvokeFunc <bool, bool> > .CreateFromProduct(
                new InvokeFunc <bool, bool>
            {
                Argument = true,
                Func     = new ActivityFunc <bool, bool>
                {
                    Argument = delegateInArgument,
                    Result   = delegateOutArgument,
                    Handler  = new System.Activities.Statements.Sequence
                    {
                        DisplayName = "Sequence1",
                        Activities  =
                        {
                            new System.Activities.Statements.If
                            {
                                DisplayName = "If1",
                                Condition   = delegateInArgument,
                                Then        = new System.Activities.Statements.Sequence
                                {
                                    DisplayName = "Sequence2",
                                    Activities  =
                                    {
                                        new System.Activities.Statements.Assign <bool>
                                        {
                                            DisplayName = "Assign1",
                                            Value       = delegateInArgument,
                                            To          = delegateOutArgument,
                                        },
                                        new System.Activities.Statements.If
                                        {
                                            DisplayName = "If2",
                                            Condition   = delegateOutArgument,
                                            Then        = new System.Activities.Statements.WriteLine
                                            {
                                                DisplayName = "W1",
                                                Text        = "Tested DelegateIn and DelegateOut arguments in If condition"
                                            },
                                        }
                                    }
                                }
                            }
                        },
                    }
                }
            }
                );

            TestSequence sequenceForTracing = new TestSequence
            {
                DisplayName = "Sequence1",
                Activities  =
                {
                    new TestIf(HintThenOrElse.Then)
                    {
                        DisplayName  = "If1",
                        ThenActivity = new TestSequence
                        {
                            DisplayName = "Sequence2",
                            Activities  =
                            {
                                new TestAssign <bool> {
                                    DisplayName = "Assign1"
                                },
                                new TestIf(HintThenOrElse.Then)
                                {
                                    DisplayName  = "If2",
                                    ThenActivity = new TestSequence("W1"),
                                }
                            }
                        }
                    }
                }
            };

            invokeFunc.CustomActivityTraces.Add(sequenceForTracing.GetExpectedTrace().Trace);


            TestIf root = new TestIf(HintThenOrElse.Then)
            {
                ConditionActivity = invokeFunc,
                ThenActivity      = new TestWriteLine {
                    Message = "True", HintMessage = "True"
                },
                ElseActivity = new TestWriteLine {
                    Message = "False", HintMessage = "This is not expected"
                },
            };

            TestRuntime.RunAndValidateWorkflow(root);
        }
Exemple #16
0
        private static Activity CreateWf()
        {
            // variables.
            var pipeline = new DelegateInArgument <PSObject>()
            {
                Name = "Pipeline"
            };
            var processName = new DelegateOutArgument <string>()
            {
                Name = "Process Name"
            };
            var processes1 = new Variable <Collection <Process> > {
                Name = "Processes 1"
            };
            var processes2 = new Variable <Collection <Process> > {
                Name = "Processes 2"
            };
            var processes3 = new Variable <Collection <Process> > {
                Name = "Processes 3"
            };
            var processNames = new Variable <Collection <string> > {
                Name = "Process Names"
            };
            var errors = new Variable <Collection <ErrorRecord> > {
                Name = "Errors"
            };
            var error = new DelegateInArgument <ErrorRecord> {
                Name = "Error"
            };

            Sequence body = new Sequence()
            {
                Variables  = { processes1, processes2, processes3, processNames, errors },
                Activities =
                {
                    // Simple PowerShell invocation.
                    new WriteLine()
                    {
                        Text = "Simple PowerShell invocation. Launching notepad."
                    },

                    new InvokePowerShell()
                    {
                        CommandText = "notepad"
                    },
                    new WriteLine(),

                    // Using PowerShell<T> to capture output.
                    new WriteLine()
                    {
                        Text = "Getting process and then pass the output to a Collection."
                    },

                    new InvokePowerShell <Process>()
                    {
                        CommandText = "Get-Process",
                        Output      = processes1,
                    },

                    CreatePrintProcessActivity(processes1),

                    // Do some post-processing after invocation.
                    new WriteLine()
                    {
                        Text = "Getting the names of the processes."
                    },

                    new InvokePowerShell <string>()
                    {
                        CommandText          = "Get-Process",
                        Output               = processNames,
                        InitializationAction = new ActivityFunc <PSObject, string>
                        {
                            Argument = pipeline,
                            Result   = processName,
                            Handler  = new Assign <string>
                            {
                                To    = processName,
                                Value = new LambdaValue <string>(ctx => ((Process)pipeline.Get(ctx).BaseObject).ToString())
                            }
                        },
                    },

                    new WriteLine()
                    {
                        Text = new InArgument <string>(ctx => "The first process returned is: " + processNames.Get(ctx)[0]),
                    },
                    new WriteLine(),

                    // Passing data using an input pipeline.
                    new WriteLine()
                    {
                        Text = "Passing data using an input pipeline and then extracting unique process names."
                    },

                    new InvokePowerShell <Process>()
                    {
                        CommandText = "Get-Unique",
                        Input       = processes1,
                        Output      = processes2,
                    },

                    CreatePrintProcessActivity(processes2),

                    // Passing in a parameter to the command.
                    new WriteLine()
                    {
                        Text = "Reverse sorting."
                    },

                    new InvokePowerShell <Process>()
                    {
                        CommandText = "Sort-Object",
                        Input       = processes2,
                        Output      = processes3,
                        Parameters  =
                        {
                            { "descending", new InArgument <Boolean>(true)                   }
                        }
                    },

                    CreatePrintProcessActivity(processes3),

                    // Run a command that results in errors.
                    new WriteLine()
                    {
                        Text = "Returning errors."
                    },

                    new InvokePowerShell <string>()
                    {
                        CommandText = "Write-Error",
                        Errors      = errors,
                        Parameters  =
                        {
                            { "message", new InArgument <string>("a short error message")    }
                        }
                    },

                    new ForEach <ErrorRecord>()
                    {
                        Values = errors,
                        Body   = new ActivityAction <ErrorRecord>
                        {
                            Argument = error,
                            Handler  = new WriteLine()
                            {
                                Text = new InArgument <string>(ctx => "Error returned: " + error.Get(ctx).ToString()),
                            },
                        }
                    }
                }
            };

            return(body);
        }
Exemple #17
0
        public void DifferentArguments()
        {
            //Testing Different argument types for DoWhile.Condition
            // DelegateInArgument
            // DelegateOutArgument
            // Variable<T> , Activity<T> and Expression is already implemented.

            DelegateInArgument <bool>  delegateInArgument  = new DelegateInArgument <bool>("Condition");
            DelegateOutArgument <bool> delegateOutArgument = new DelegateOutArgument <bool>("Output");

            TestCustomActivity <InvokeFunc <bool, bool> > invokeFunc = TestCustomActivity <InvokeFunc <bool, bool> > .CreateFromProduct(
                new InvokeFunc <bool, bool>
            {
                Argument = true,
                Func     = new ActivityFunc <bool, bool>
                {
                    Argument = delegateInArgument,
                    Result   = delegateOutArgument,
                    Handler  = new Microsoft.CoreWf.Statements.Sequence
                    {
                        DisplayName = "sequence1",
                        Activities  =
                        {
                            new Microsoft.CoreWf.Statements.DoWhile
                            {
                                DisplayName = "DoWhile1",
                                Condition   = ExpressionServices.Convert <bool>(ctx => delegateInArgument.Get(ctx)),
                                Body        = new Microsoft.CoreWf.Statements.Assign <bool>
                                {
                                    DisplayName = "Assign1",
                                    To          = delegateInArgument,
                                    Value       = new Not <bool, bool> {
                                        DisplayName = "Not1", Operand = delegateInArgument
                                    }
                                },
                            },
                            new Microsoft.CoreWf.Statements.Assign <bool>
                            {
                                DisplayName = "Assign2",
                                To          = delegateOutArgument,
                                Value       = new Not <bool, bool> {
                                    DisplayName = "Not2", Operand = delegateInArgument
                                },
                            },
                            new Microsoft.CoreWf.Statements.DoWhile
                            {
                                DisplayName = "DoWhile2",
                                Condition   = ExpressionServices.Convert <bool>(ctx => !delegateOutArgument.Get(ctx)),
                                Body        = new Microsoft.CoreWf.Statements.Assign <bool>
                                {
                                    DisplayName = "Assign3",
                                    To          = delegateOutArgument,
                                    Value       = new Not <bool, bool> {
                                        DisplayName = "Not3", Operand = delegateInArgument
                                    }
                                },
                            },
                        },
                    }
                }
            }
                );

            TestSequence sequenceForTracing = new TestSequence
            {
                DisplayName = "sequence1",
                Activities  =
                {
                    new TestDoWhile
                    {
                        DisplayName            = "DoWhile1",
                        ActivitySpecificTraces =
                        {
                            new OrderedTraces()
                            {
                                Steps =
                                {
                                    new ActivityTrace("Assign1",                        ActivityInstanceState.Executing),
                                    new ActivityTrace("Not1",                           ActivityInstanceState.Executing),
                                    new ActivityTrace("Not1",                           ActivityInstanceState.Closed),
                                    new ActivityTrace("Assign1",                        ActivityInstanceState.Closed),
                                    new ActivityTrace("DelegateArgumentValue<Boolean>", ActivityInstanceState.Executing),
                                    new ActivityTrace("DelegateArgumentValue<Boolean>", ActivityInstanceState.Closed),
                                }
                            },
                        }
                    },
                    new TestAssign <bool>
                    {
                        DisplayName   = "Assign2",
                        ValueActivity = new Test.Common.TestObjects.Activities.Expressions.TestNot <bool, bool>{
                            DisplayName = "Not2"
                        }
                    },
                    new TestDoWhile
                    {
                        DisplayName            = "DoWhile2",
                        ActivitySpecificTraces =
                        {
                            new OrderedTraces()
                            {
                                Steps =
                                {
                                    new ActivityTrace("Assign3",              ActivityInstanceState.Executing),
                                    new ActivityTrace("Not3",                 ActivityInstanceState.Executing),
                                    new ActivityTrace("Not3",                 ActivityInstanceState.Closed),
                                    new ActivityTrace("Assign3",              ActivityInstanceState.Closed),
                                    new ActivityTrace("Not<Boolean,Boolean>", ActivityInstanceState.Executing),
                                    new ActivityTrace("Not<Boolean,Boolean>", ActivityInstanceState.Closed),
                                }
                            },
                        }
                    },
                }
            };

            invokeFunc.CustomActivityTraces.Add(sequenceForTracing.GetExpectedTrace().Trace);


            TestIf root = new TestIf(HintThenOrElse.Then)
            {
                ConditionActivity = invokeFunc,
                ThenActivity      = new TestWriteLine {
                    Message = "True", HintMessage = "True"
                },
                ElseActivity = new TestWriteLine {
                    Message = "False", HintMessage = "This is not expected"
                },
            };

            TestRuntime.RunAndValidateWorkflow(root);
        }
Exemple #18
0
        private static Activity CreateIntResourceService()
        {
            var request1 = new DelegateInArgument <HttpRequestMessage>()
            {
                Name = "Request1"
            };
            var response1 = new DelegateOutArgument <object>()
            {
                Name = "Response1"
            };
            var parameters1 = new DelegateInArgument <IDictionary <string, string> > {
                Name = "Parameters1"
            };
            var request2 = new DelegateInArgument <HttpRequestMessage>()
            {
                Name = "Request2"
            };
            var response2 = new DelegateOutArgument <object>()
            {
                Name = "Response2"
            };
            var parameters2 = new DelegateInArgument <IDictionary <string, string> > {
                Name = "Parameters2"
            };
            var num = new Variable <int>()
            {
                Name = "Num"
            };

            return(new Sequence
            {
                Variables = { num },
                Activities =
                {
                    new HttpReceive
                    {
                        Method = "POST",
                        UriTemplate = "/{Num}",
                        CanCreateInstance = true,
                        Body =
                            new ActivityFunc <HttpRequestMessage, IDictionary <string, string>, object>
                        {
                            Argument1 = request1,
                            Argument2 = parameters1,
                            Result = response1,
                            Handler =
                                new Sequence
                            {
                                Activities =
                                {
                                    new Assign
                                    {
                                        DisplayName = "Store arg in variable",
                                        To = new OutArgument <object>(num),
                                        Value =
                                            new InArgument <int>(
                                                // new VisualBasicValue<int>("Request.Content.ReadAs(Of Int32)()"))
                                                new VisualBasicValue <int>("CType(Parameters1(\"Num\"), Int32)"))
                                    }
                                }
                            }
                        }
                    },
                    new HttpReceive
                    {
                        Method = "GET",
                        UriTemplate = "/{Num}",
                        CanCreateInstance = true,
                        Body =
                            new ActivityFunc <HttpRequestMessage, IDictionary <string, string>, object>
                        {
                            Argument1 = request2,
                            Argument2 = parameters2,
                            Result = response2,
                            Handler =
                                new Sequence
                            {
                                Activities =
                                {
                                    new Assign
                                    {
                                        DisplayName = "Assign response message",
                                        To = new OutArgument <object>(response1),
                                        Value =
                                            new InArgument <int>(num)
                                    }
                                }
                            }
                        }
                    },
                }
            });
        }