Пример #1
0
        public void runTerminate()
        {
            AutoResetEvent waitForWorkflow = new AutoResetEvent(false);

            CoreWf.Statements.Sequence seq = new CoreWf.Statements.Sequence()
            {
                Activities =
                {
                    new CoreWf.Statements.TerminateWorkflow
                    {
                        Exception = new InArgument <Exception>(context => new TAC.ApplicationException()),
                        Reason    = new InArgument <string>("just because"),
                    },
                    new CoreWf.Statements.WriteLine()
                    {
                        Text = "Hello"
                    },
                }
            };

            try
            {
                WorkflowApplication instance = new WorkflowApplication(seq)
                {
                    Completed = delegate(WorkflowApplicationCompletedEventArgs args)
                    {
                        Console.WriteLine("Completed workflow status: " + args.CompletionState);
                        if (args.CompletionState == ActivityInstanceState.Faulted)
                        {
                            Console.WriteLine("Termination Inner exception: " + args.TerminationException.InnerException.GetType());
                            Console.WriteLine("Termination exception Reason is: " + args.TerminationException.Message);
                            Console.WriteLine("Termination exception: " + args.TerminationException);
                        }
                        waitForWorkflow.Set();
                    }
                };
                Console.WriteLine("Starting");
                instance.Run();
                waitForWorkflow.WaitOne(); // Complete
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception is here!");
                Console.WriteLine("Type = {0} , Message = {1} , RealException is: {2}", e.GetType(), e.Message, e.InnerException.GetType());
            }

            Console.ReadLine();
        }
Пример #2
0
        //  Workflow variable by Linq
        public void VariableByLinq()
        {
            // Linq treats local variable with special syntax.
            // See comment in LeafHelper.GetMemberAccessVariableExpression for more info.
            // The purpose test is to use real compiler generated lambda expression.
            Variable <string> var = new Variable <string>()
            {
                Name    = "var",
                Default = "Linq var test"
            };

            Expression <Func <ActivityContext, string> > expression = (env) => var.Get(env);

            CoreWf.Statements.Sequence expectedSequence = new CoreWf.Statements.Sequence()
            {
                Variables =
                {
                    var
                },
                Activities =
                {
                    new WriteLine()
                    {
                        Text = var
                    }
                }
            };

            CoreWf.Statements.Sequence actualSequence = new CoreWf.Statements.Sequence()
            {
                Variables =
                {
                    var
                },
                Activities =
                {
                    new WriteLine()
                    {
                        Text = ExpressionServices.Convert(expression)
                    }
                }
            };

            ExpressionTestRuntime.ValidateActivity(expectedSequence, actualSequence);
        }
        public void SetDelegateArgument()
        {
            // for using delegate argument

            TheStruct valueType             = new TheStruct();
            int       indiceValue           = 2;
            DelegateInArgument <int> indice = new DelegateInArgument <int>();
            Variable <TheStruct>     var    = VariableHelper.CreateInitialized <TheStruct>("var", valueType);
            TestValueTypeIndexerReference <TheStruct, int> valueTypeIndexerReference = new TestValueTypeIndexerReference <TheStruct, int>()
            {
                OperandLocationVariable = var,
            };

            valueTypeIndexerReference.Indices.Add(new TestArgument <int>(Direction.In, null, (env) => indice.Get(env)));

            int value = 321;
            TestAssign <int> testAssign = new TestAssign <int>()
            {
                ToLocation = valueTypeIndexerReference, Value = value
            };

            TestSequence seq = new TestSequence()
            {
                Activities =
                {
                    testAssign,
                    new TestWriteLine {
                        MessageExpression = ((ctx) => var.Get(ctx)[indiceValue].ToString())
                    }
                }
            };

            CoreWf.Statements.Sequence outerSeq = new CoreWf.Statements.Sequence()
            {
                Variables =
                {
                    var
                },
                Activities =
                {
                    new InvokeAction <int>()
                    {
                        Argument = indiceValue,
                        Action   = new ActivityAction <int>()
                        {
                            Argument = indice,
                            Handler  = seq.ProductActivity
                        }
                    }
                }
            };

            TestCustomActivity testActivity = TestCustomActivity <CoreWf.Statements.Sequence> .CreateFromProduct(outerSeq);

            UnorderedTraces traces = new UnorderedTraces()
            {
                Steps =
                {
                    new UserTrace(value.ToString())
                }
            };

            testActivity.ActivitySpecificTraces.Add(traces);
            ExpectedTrace expectedTrace = testActivity.GetExpectedTrace();

            expectedTrace.AddIgnoreTypes(typeof(ActivityTrace));

            TestRuntime.RunAndValidateWorkflow(testActivity, expectedTrace);
        }