Ejemplo n.º 1
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());
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }