예제 #1
0
 private void OnUpdateOrderTotal(NativeActivityContext context,
                                 Bookmark bookmark, object value)
 {
     if (value is Decimal)
     {
         OrderTotal.Set(context,
                        OrderTotal.Get(context) + (Decimal)value);
         Console.WriteLine(
             "OrderScope.OnUpdateOrderTotal Value: {0}, Total: {1}",
             (Decimal)value, OrderTotal.Get(context));
     }
 }
예제 #2
0
        private Activity GetImplementation()
        {
            Variable <string> atBatResult = new Variable <string>
            {
                Name    = "outerAtBatResult",
                Default = "default at bat result"
            };
            Variable <int> pitchCount = new Variable <int>
            {
                Name    = "outerPitchCount",
                Default = 0
            };

            Activity stateMachine = CreateStateMachine(atBatResult, pitchCount);

            return(new Sequence
            {
                DisplayName = "OuterImplementation",
                Variables = { atBatResult, pitchCount },
                Activities =
                {
                    stateMachine,
                    new Assign <string>
                    {
                        To = new OutArgument <string>(ctx => AtBatResult.Get(ctx)),
                        Value = new InArgument <string>(ctx => atBatResult.Get(ctx))
                    },
                    new Assign <int>
                    {
                        To = new OutArgument <int>(ctx => PitchCount.Get(ctx)),
                        Value = new InArgument <int>(ctx => pitchCount.Get(ctx))
                    }
                }
            });
        }
예제 #3
0
        private Activity GetImplementation()
        {
            var target = new Variable <int>();
            var guess  = new Variable <int>();

            return(new Sequence
            {
                Variables = { target, guess },
                Activities =
                {
                    new Assign <int>             {
                        To = new OutArgument <int>(target),
                        Value = new InArgument <int>(ctx => GuessNumber.Get(ctx))
                    },
                    new DoWhile                  {
                        Body = new Sequence      {
                            Activities =
                            {
                                new Prompt       {
                                    BookmarkName = "EnterGuess",
                                    Text = new InArgument <string>(ctx =>
                                                                   "Please enter your guess"),
                                    Result = new OutArgument <int>(guess)
                                },
                                new Assign <int> {
                                    To = new OutArgument <int>(ctx => Turns.Get(ctx)),
                                    Value = new InArgument <int>(ctx => Turns.Get(ctx) + 1)
                                },
                                new If           {
                                    Condition = new InArgument <bool>(ctx => guess.Get(ctx) != target.Get(ctx)),
                                    Then = new If{
                                        Condition = new InArgument <bool>(ctx => guess.Get(ctx) < target.Get(ctx)),
                                        Then = new WriteLine{
                                            Text = "Your guess is too low."
                                        },
                                        Else = new WriteLine{
                                            Text = "Your guess is too high."
                                        }
                                    }
                                }
                            }
                        },
                        Condition = new LambdaValue <bool>(ctx => guess.Get(ctx) != target.Get(ctx))
                    }
                }
            });
        }
예제 #4
0
        // Updates and returns the version of the specified attribute.
        private string UpdateVersion(string attributeName, string format, OutArgument <Version> maxVersion)
        {
            var oldValue = this.file[attributeName];

            if (oldValue == null || string.IsNullOrWhiteSpace(format))
            {
                // do nothing
                return(oldValue);
            }

            // parse old version (handle * character)
            bool   containsWildcard = oldValue.Contains('*');
            string versionPattern   = "{0}.{1}.{2}.{3}";

            if (containsWildcard)
            {
                if (oldValue.Split('.').Length == 3)
                {
                    oldValue       = oldValue.Replace("*", "0.0");
                    versionPattern = "{0}.{1}.*";
                }
                else
                {
                    oldValue       = oldValue.Replace("*", "0");
                    versionPattern = "{0}.{1}.{2}.*";
                }
            }

            if (!versionParser.IsMatch(oldValue))
            {
                throw new FormatException("Current value for attribute '" + attributeName + "' is not in a correct version format.");
            }

            var version = new Version(oldValue);

            // update version
            var tokens = format.Split('.');

            if (tokens.Length != 4)
            {
                throw new FormatException("Specified value for attribute '" + attributeName + "'  is not a correct version format.");
            }

            version = new Version(
                Convert.ToInt32(this.ReplaceTokens(tokens[0], version.Major)),
                Convert.ToInt32(this.ReplaceTokens(tokens[1], version.Minor)),
                Convert.ToInt32(this.ReplaceTokens(tokens[2], version.Build)),
                Convert.ToInt32(this.ReplaceTokens(tokens[3], version.Revision)));

            this.file[attributeName] = string.Format(versionPattern, version.Major, version.Minor, version.Build, version.Revision);

            if (version > maxVersion.Get(this.ActivityContext))
            {
                maxVersion.Set(this.ActivityContext, version);
            }

            return(version.ToString());
        }
예제 #5
0
        public void ParameterAssign()
        {
            //Define the input argument for the activity
            var inputValue  = new InArgument <int>();
            var outputValue = new OutArgument <int>();
            //Create the activity, property, and implementation
            Activity dynamicWorkflow = new DynamicActivity()
            {
                Properties =
                {
                    new DynamicActivityProperty
                    {
                        Name  = "InputInteger",
                        Type  = typeof(InArgument <int>),
                        Value = inputValue
                    },
                    new DynamicActivityProperty
                    {
                        Name  = "OutputInteger",
                        Type  = typeof(OutArgument <int>),
                        Value = outputValue
                    },
                },
                Implementation = () => new Sequence()
                {
                    Activities =
                    {
                        new Assign()
                        {
                            To    = new OutArgument <int>(env => outputValue.Get(env)),
                            Value = new InArgument <int>(env => inputValue.Get(env))
                        },
                        new WriteLine()
                        {
                            Text = new InArgument <string>("Assign was successful")
                        }
                    }
                }
            };
            //Execute the activity with a parameter dictionary
            var o = WorkflowInvoker.Invoke(dynamicWorkflow, new Dictionary <string, object> {
                { "InputInteger", 42 }
            });

            foreach (var kvp in o)
            {
                Console.WriteLine(kvp.Key + " : " + kvp.Value.ToString());
            }

            if (o.TryGetValue("OutputInteger", out object value))
            {
                int returnedInt = (int)value;
                Assert.Equal(42, returnedInt);
            }
        }
        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);
        }
        // Updates and returns the version of the specified attribute.
        private string UpdateVersion(string attributeName, string format, OutArgument <Version> maxVersion)
        {
            var oldValue = this.file[attributeName];

            if (oldValue == null || string.IsNullOrWhiteSpace(format))
            {
                // do nothing
                return(string.Empty);
            }

            // parse old version
            if (!versionParser.IsMatch(oldValue))
            {
                throw new FormatException("Current value for attribute '" + attributeName + "' is not in a correct version format.");
            }

            var version = new Version(oldValue);

            // update version
            var tokens = format.Split('.');

            if (tokens.Length != 4)
            {
                throw new FormatException("Specified value for attribute '" + attributeName + "'  is not a correct version format.");
            }

            version = new Version(
                Convert.ToInt32(this.ReplaceTokens(tokens[0], version.Major)),
                Convert.ToInt32(this.ReplaceTokens(tokens[1], version.Minor)),
                Convert.ToInt32(this.ReplaceTokens(tokens[2], version.Build)),
                Convert.ToInt32(this.ReplaceTokens(tokens[3], version.Revision)));

            this.file[attributeName] = version.ToString();

            if (version > maxVersion.Get(this.ActivityContext))
            {
                maxVersion.Set(this.ActivityContext, version);
            }

            return(version.ToString());
        }
예제 #8
0
        void BookmarkCallback(NativeActivityContext context, Bookmark bookmark, object bookmarkData)
        {
            int localGuess = (int)bookmarkData, localTarget = Target.Get(context);

            Guess.Set(context, localGuess);
            Turns.Set(context, Turns.Get(context) + 1);

            if (localGuess != localTarget)
            {
                if (localGuess < localTarget)
                {
                    Console.WriteLine("Your guess is too low.");
                }
                else
                {
                    Console.WriteLine("Your guess is too high.");
                }
            }
            else
            {
                context.RemoveBookmark(bookmark.Name);
            }
        }
예제 #9
0
 /// <summary>
 /// Получение значения выходного параметра.
 /// </summary>
 /// <typeparam name="T">Тип параметра.</typeparam>
 /// <param name="argument">Экземпляр класса <see cref="InArgument{T}"/>.</param>
 /// <param name="context">Контекст выполенения.</param>
 /// <returns>Метод возвращает значение указанного входного параметра.</returns>
 public static T Get <T>(this OutArgument <T> argument, Context context)
 {
     return(argument.Get <T>(context.SourceActivityContext));
 }
예제 #10
0
        private Activity GetImplementation()
        {
            Variable <double> discount     = new Variable <double>();
            Variable <string> discountCode = new Variable <string>();
            Variable <bool>   isStudent    = new Variable <bool>()
            {
                Default = _isStudent
            };
            Variable <bool> isMarried = new Variable <bool> {
                Default = _isMarried
            };
            Variable <bool> haveChild = new Variable <bool> {
                Default = _haveChild
            };

            FlowStep returnDiscountCode = new FlowStep
            {
                Action = new Assign <string>
                {
                    DisplayName = "Return Discount Code",
                    To          = new OutArgument <string>((ctx) => DiscountCode.Get(ctx)),
                    Value       = new InArgument <string>(discountCode)
                },
                Next = null
            };

            FlowStep printDiscount = new FlowStep
            {
                Action = new WriteLine
                {
                    DisplayName = "WriteLine: Discount Applied",
                    Text        = discountCode
                },
                Next = returnDiscountCode
            };

            FlowStep applyDefaultDiscount = new FlowStep
            {
                Action = new Assign <double>
                {
                    DisplayName = "Default Discount is 0%",
                    To          = discount,
                    Value       = new InArgument <double>(0)
                },
                Next = printDiscount
            };

            FlowStep applyBaseDiscount = new FlowStep
            {
                Action = new Assign <double>
                {
                    DisplayName = "Base Discount is 5%",
                    To          = discount,
                    Value       = new InArgument <double>(5)
                },
                Next = printDiscount
            };

            FlowStep applyStandardDiscount = new FlowStep
            {
                Action = new Assign <double>
                {
                    DisplayName = "Standard Discount is 10%",
                    To          = discount,
                    Value       = new InArgument <double>(10)
                },
                Next = printDiscount
            };

            FlowStep applyPremiumDiscount = new FlowStep
            {
                Action = new Assign <double>
                {
                    DisplayName = "Standard Discount is 15%",
                    To          = discount,
                    Value       = new InArgument <double>(15)
                },
                Next = printDiscount
            };

            FlowSwitch <string> discountCodeSwitch = new FlowSwitch <string>
            {
                Expression = discountCode,
                Cases      =
                {
                    { "STD", applyBaseDiscount     },
                    { "MNC", applyStandardDiscount },
                    { "MWC", applyPremiumDiscount  },
                },
                Default = applyDefaultDiscount
            };

            FlowStep noDiscount = new FlowStep
            {
                Action = new Assign <string>
                {
                    DisplayName = "No Discount",
                    To          = discountCode,
                    Value       = new InArgument <string>("NONE")
                },
                Next = discountCodeSwitch
            };

            FlowStep studentDiscount = new FlowStep
            {
                Action = new Assign <string>
                {
                    DisplayName = "Student Discount is appplied",
                    To          = discountCode,
                    Value       = new InArgument <string>("STD")
                },
                Next = discountCodeSwitch
            };

            FlowStep marriedWithNoChildDiscount = new FlowStep
            {
                Action = new Assign <string>
                {
                    DisplayName = "Married with no child Discount is applied",
                    To          = discountCode,
                    Value       = new InArgument <string>("MNC")
                },
                Next = discountCodeSwitch
            };

            FlowStep marriedWithChildDiscount = new FlowStep
            {
                Action = new Assign <string>
                {
                    DisplayName = "Married with child Discount is 15%",
                    To          = discountCode,
                    Value       = new InArgument <string>("MWC")
                },
                Next = discountCodeSwitch
            };


            FlowDecision singleFlowDecision = new FlowDecision
            {
                Condition = ExpressionServices.Convert <bool>((ctx) => isStudent.Get(ctx)),
                True      = studentDiscount,
                False     = noDiscount,
            };

            FlowDecision marriedFlowDecision = new FlowDecision
            {
                Condition = ExpressionServices.Convert <bool>((ctx) => haveChild.Get(ctx)),
                True      = marriedWithChildDiscount,
                False     = marriedWithNoChildDiscount,
            };

            FlowDecision startNode = new FlowDecision
            {
                Condition = ExpressionServices.Convert <bool>((ctx) => isMarried.Get(ctx)),
                True      = marriedFlowDecision,
                False     = singleFlowDecision
            };

            return(new Flowchart()
            {
                DisplayName = "Auto insurance discount calculation",
                Variables = { discount, isMarried, isStudent, haveChild, discountCode },

                StartNode = startNode,
                Nodes =
                {
                    startNode,
                    marriedFlowDecision,
                    singleFlowDecision,
                    marriedWithChildDiscount,
                    marriedWithNoChildDiscount,
                    studentDiscount,
                    noDiscount,
                    discountCodeSwitch,
                    applyBaseDiscount,
                    applyDefaultDiscount,
                    applyPremiumDiscount,
                    applyStandardDiscount,
                    printDiscount,
                    returnDiscountCode
                }
            });
        }
예제 #11
0
 public static InArgument <T> In <T>(this OutArgument <T> self)
 {
     return(new InArgument <T>(context => self.Get(context)));
 }
예제 #12
0
 public static OutArgument <T> Out <T>(this OutArgument <T> self)
 {
     return(new OutArgument <T>(context => self.Get(context)));
 }