public void runTerminate()
        {
            AutoResetEvent waitForWorkflow = new AutoResetEvent(false);

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

            try
            {
                WorkflowApplication instance = new WorkflowApplication(seq);
                instance.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();
        }
Example #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);

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

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

            ExpressionTestRuntime.ValidateActivity(expectedSequence, actualSequence);
        }
Example #3
0
        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())
                    }
                }
            };

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

            TestCustomActivity testActivity = TestCustomActivity <Microsoft.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);
        }