Пример #1
0
            resultAction = new ResultActionConfig()
            {
                Name  = Constants.Events.ExpiredEventName,
                Label = "Expiration",
                Delay = delay,
                Kind  = Constants.PushActionName
            };

            rule = new ResultRuleConfig()
            {
            };
            rule.Actions.Add(resultAction);
            resultActions.Add(("in", rule));

            #endregion

            #region action to add to 'On Exit State' (remove expiration event)

            resultAction = new ResultActionConfig()
            {
                Name  = Constants.Events.CancelReminderAction,
                Label = "Cancel Expiration",
                Kind  = Constants.PushActionName,
            };

            rule = new ResultRuleConfig()
            {
                WhenRuleText = $"@IncomingEvent.Name != '{Constants.Events.ExpiredEventName}'",
                WhenRule     = (ctx) => ctx.IncomingEvent.Name != Constants.Events.ExpiredEventName,
            };
            rule.Actions.Add(resultAction);
            resultActions.Add(("out", rule));

            #endregion
        }
Пример #2
0
        public void AvaluateArgumentConstant()
        {
            var        value  = Guid.NewGuid().ToString();
            RunContext ctx    = CreateContextForEvaluateArgument();
            var        result = new ResultActionConfig()
            {
                Name = "act_on_state_in_1"
            }
            .AddArgument("v1", "toto")
            .Map(ctx);
            var v1 = result.Arguments.FirstOrDefault();

            Assert.AreEqual(v1.Value.GetValue(ctx), "toto");
        }
Пример #3
0
        /// <summary>
        /// execute3 :
        ///      (EXECUTE | key) action+
        ///    | STORE matchings+
        ///     ;
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override object VisitExecute3([NotNull] WorkflowParser.Execute3Context context)
        {
            List <ResultActionConfig> _actions = new List <ResultActionConfig>();

            if (context.STORE() != null)
            {
                var matchings = context.matchings();
                foreach (var item_matching in matchings)
                {
                    var _stores = (List <(string, string)>)VisitMatchings(item_matching);

                    foreach (var item in _stores)
                    {
                        var act = new ResultActionConfig()
                        {
                            Name  = "update " + item.Item1,
                            Label = $"update {item.Item1} to {item.Item2}",
                            Kind  = Constants.SetValueActionName,
                        }
                        .AddArgument("key", item.Item1)
                        .AddArgument("value", item.Item2)
                        ;

                        _actions.Add(act);
                    }
                }
            }
            else
            {
                string kind = context.EXECUTE() != null
                    ? Constants.PushActionName
                    : (string)VisitKey(context.key())
                ;

                var actions = context.action();
                foreach (var action in actions)
                {
                    var act = (ResultActionConfig)VisitAction(action);
                    act.Kind = kind;
                    _actions.Add(act);
                }
            }

            return(_actions);
        }
Пример #4
0
        /// <summary>
        /// action :
        ///     key LEFT_PAREN arguments? RIGHT_PAREN
        ///     ;
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override object VisitAction([NotNull] WorkflowParser.ActionContext context)
        {
            var act = new ResultActionConfig()
            {
                Name = (string)VisitKey(context.key()),
            };

            if (!this._actions.TryGetValue(act.Name, out MethodReference method))
            {
                throw new InvalidMethodReferenceException(act.Name);
            }

            Dictionary <string, Type> o = method.Arguments.ToList().ToDictionary(c => c.Key, c => c.Value);

            var args = context.arguments();

            if (args != null)
            {
                var a = (List <(string, string)>)VisitArguments(args);
                foreach ((string, string)item in a)
                {
                    var type = ResolveTypeOfArgument(item.Item1, method);
                    var func = GetLambda(item.Item1, item.Item2, type);

                    act.Arguments.Add(item.Item1, func);
                    if (!o.ContainsKey(item.Item1))
                    {
                        if (!method.Arguments.ContainsKey(item.Item1))
                        {
                            throw new DuplicatedArgumentNameMethodReferenceException(item.Item1);
                        }
                    }
                    o.Remove(item.Item1);
                }

                if (o.Count > 0)
                {
                    throw new MissingArgumentNameMethodReferenceException(string.Join(", ", o));
                }
            }

            return(act);
        }
Пример #5
0
        public static IncomingEventConfig AddAction(this IncomingEventConfig self, Func <RunContext, bool> func, ResultActionConfig act)
        {
            var r = self.Rules.FirstOrDefault(c => c.WhenRule == func);

            if (r == null)
            {
                r = new ResultRuleConfig()
                {
                    WhenRule = func,
                };
                self.Rules.Add(r);
            }
            r.Actions.Add(act);
            return(self);
        }
Пример #6
0
 public static ResultActionConfig AddArgument(this ResultActionConfig self, string key, string value)
 {
     if (value is string s && s.StartsWith("@"))
     {
         self.Arguments.Add(key, Expresssions.ExpressionDynobjectExtension.GetAccessors <RunContext>(s.Substring(1)));
     }