Ejemplo n.º 1
0
        private Activity GetContentWf(NativeActivity implementation)
        {
            var queueMessage = new InArgument <IoQueueIn>();
            var mandantCode  = new InArgument <string>();

            return(new DynamicActivity
            {
                Name = "Default",
                Properties =
                {
                    new DynamicActivityProperty
                    {
                        Name = "QueueMessage",
                        Type = queueMessage.GetType(),
                        Value = queueMessage
                    },
                    new DynamicActivityProperty
                    {
                        Name = "MandantCode",
                        Type = mandantCode.GetType(),
                        Value = mandantCode
                    }
                },
                Implementation = () => implementation
            });
        }
        public static TOutput Invoke <TActivity, TOutput>(this TActivity activity, Action <TActivity, OutArgument <TOutput> > setOutput)
            where TActivity : Activity
        {
            var inToken   = new InArgument <string>("inToken");
            var inBaseUrl = new InArgument <string>("inBaseUrl");

            var indicoScope = new IndicoScope
            {
                Host  = new InArgument <string>(ctx => inBaseUrl.Get(ctx)),
                Token = new InArgument <string>(ctx => inToken.Get(ctx)),
                Body  = { Handler = activity },
            };

            OutArgument <TOutput> outArg = new OutArgument <TOutput>();

            var root = new DynamicActivity
            {
                Properties =
                {
                    new DynamicActivityProperty
                    {
                        Name  = nameof(IndicoScope.Token),
                        Value = inToken,
                        Type  = inToken.GetType(),
                    },
                    new DynamicActivityProperty
                    {
                        Name  = nameof(IndicoScope.Host),
                        Value = inBaseUrl,
                        Type  = inBaseUrl.GetType(),
                    },
                    new DynamicActivityProperty
                    {
                        Name  = "OutArg",
                        Type  = typeof(OutArgument <TOutput>),
                        Value = outArg,
                    }
                },
                Implementation = () => indicoScope
            };

            setOutput(activity, new OutArgument <TOutput>(ctx => outArg.Get(ctx)));

            var resultDictionary = WorkflowInvoker.Invoke(root, GetScopeParams());

            var result = (TOutput)resultDictionary.Single().Value;

            return(result);
        }
Ejemplo n.º 3
0
        public static Activity workflow_dynamic1()
        {
            //https://docs.microsoft.com/it-it/dotnet/api/system.activities.dynamicactivity?view=netframework-4.8

            //var numbers = new InArgument<List<int>>();
            //var average = new OutArgument<double>();
            var actual    = new InArgument <decimal>(0);
            var number    = new InArgument <decimal>(0);
            var operation = new InArgument <string>();
            var result    = new InArgument <decimal>(0);

            var v_number = new Variable <decimal>();


            return(new DynamicActivity()
            {
                Properties =
                {
                    // Input argument
                    new DynamicActivityProperty
                    {
                        Name = "Actual",
                        Type = actual.GetType(),
                        Value = actual,
                    },
                    new DynamicActivityProperty
                    {
                        Name = "Number",
                        Type = number.GetType(),
                        Value = number,
                    },
                    new DynamicActivityProperty
                    {
                        Name = "Operation",
                        Type = operation.GetType(),
                        Value = operation,
                    },

                    // Output argument
                    new DynamicActivityProperty
                    {
                        Name = "Result",
                        Type = result.GetType(),
                        Value = result
                    }
                },
                Implementation = () =>
                                 new Sequence()
                {
                    Activities =
                    {
                        new Switch <string>()
                        {
                            Expression = new System.Activities.Expressions.ArgumentValue <string>{
                                ArgumentName = "Operation"
                            },
                            Cases =
                            {
                                {
                                    "+", new Assign <decimal>()
                                    {
                                        To = new System.Activities.Expressions.ArgumentReference <decimal>{
                                            ArgumentName = "Result"
                                        },
                                        Value = new InArgument <decimal>(env => actual.Get(env) + number.Get(env))
                                    }
                                }
                            }
                        }
                    }
                }
            });
        }