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);
        }
Example #2
0
        /// <summary>
        /// on_event_statement :
        ///    (ON EVENT key | EXPIRE AFTER delay) switch_state+
        ///     ;
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override object VisitOn_event_statement([NotNull] WorkflowParser.On_event_statementContext context)
        {
            List <(string, ResultRuleConfig)> resultActions = new List <(string, ResultRuleConfig)>();
            Func <RunContext, bool>           whenRule      = null;
            string whenRuleText = string.Empty;
            var    key          = context.key();

            IncomingEventConfig incomingEvent = new IncomingEventConfig();

            if (key != null)
            {
                incomingEvent.Name = (string)VisitKey(key);
            }

            if (context.EXPIRE() != null)
            {
                incomingEvent.Name = Constants.Events.ExpiredEventName;
                int delay = (int)VisitDelay(context.delay());
                whenRule = (ctx) =>
                {
                    var i = ctx.IncomingEvent.ExtendedDatas()["CurrentState"];
                    if (i.GetValue == null)
                    {
                        return(false);
                    }
                    var j = i.GetValue(ctx)?.ToString();
                    return(ctx.Workflow.CurrentState == j);
                };
                whenRuleText = $"@IncomingEvent.CurrentState == @Workflow.CurrentState";

                AddExpirationActions(resultActions, delay);
            }

            InsertTransitions(context, whenRule, incomingEvent, whenRuleText);

            return(incomingEvent, resultActions);
        }
Example #3
0
        private void InsertTransitions(WorkflowParser.On_event_statementContext context, Func <RunContext, bool> whenRule, IncomingEventConfig incomingEvent, string ruleText)
        {
            var switchs = context.switch_state();

            foreach (var item in switchs)
            {
                var s = (TransitionConfig)VisitSwitch_state(item);
                if (whenRule != null)
                {
                    if (s.WhenRule == null)
                    {
                        s.WhenRule     = whenRule;
                        s.WhenRuleText = ruleText;
                    }
                    else
                    {
                        var r = s.WhenRule;
                        s.WhenRule      = (ctx) => whenRule(ctx) && r(ctx);
                        s.WhenRuleText += " && " + ruleText;
                    }
                }
                incomingEvent.AddTransition(s);
            }
        }
 public static IncomingEventConfig AddTransition(this IncomingEventConfig self, TransitionConfig t)
 {
     self.Transitions.Add(t);
     return(self);
 }
 public static StateConfig AddEvent(this StateConfig self, IncomingEventConfig e)
 {
     self.Events.Add(e.Name, e);
     return(self);
 }