Пример #1
0
 public virtual Case ElseIf(Condition condition, object result)
 {
     if (condition == null)
     {
         throw new System.ArgumentNullException("condition");
     }
     Whens.Add(new Case(condition, result));
     return(this);
 }
Пример #2
0
        internal void Step()
        {
            if (Next())
            {
                Whens.ForEach(x => x.Eval(this));

                When_ when = Whens.FirstOrDefault(x => x.IsTrue);

                if (when != null)
                {
                    when.Actions.ForEach(x => x(this));
                }
            }
        }
Пример #3
0
 private void UpdateWhensList()
 {
     Whens.Clear();
     foreach (When when in Rule.Whens)
     {
         Type          whenModelType = typeof(WhenViewModel <>).MakeGenericType(when.GetType());
         WhenViewModel whenViewModel = Container.GetExports(typeof(WhenViewModel <>).MakeGenericType(when.GetType()), null, null).FirstOrDefault()?.Value as WhenViewModel;
         if (whenViewModel != null)
         {
             whenModelType.GetMethod("SetModels").Invoke(whenViewModel, new object[] { this, when });
             Whens.Add(whenViewModel);
         }
     }
 }
Пример #4
0
        public void When(When when, Act action, Unless unless = null)
        {
            foreach (var cw in Whens)
            {
                if (cw.When == when && cw.Action == action && cw.Unless == unless)
                {
                    return;
                }
            }
            WhenInfo wi = new WhenInfo();

            wi.When   = when;
            wi.Action = action;
            wi.Unless = unless;
            Whens.Add(wi);
        }
Пример #5
0
 public void AddWhen(string text, when method)
 {
     Whens.Add(method, text);
 }
Пример #6
0
        public void InternalUpdate()
        {
            upmut.WaitOne();
            var iil = new List <IfInfo>();

            foreach (var ci in Ifs)
            {
                if (ci.If())
                {
                    ci.Action();
                }
                else
                {
                    if (ci.Else != null)
                    {
                        ci.Else();
                    }
                }
                if (ci.Until != null)
                {
                    if (ci.Until())
                    {
                        iil.Add(ci);
                    }
                }
            }
            foreach (var ci in iil)
            {
                Ifs.Remove(ci);
            }
            var rd = new List <DoInfo>();
            var dt = new List <DoInfo>();

            foreach (var Do in Dos)
            {
                Do.Do();
                if (Do.Until != null)
                {
                    if (Do.Until())
                    {
                        if (Do.Then != null)
                        {
                            dt.Add(Do);
                        }
                        rd.Add(Do);
                    }
                }
            }
            foreach (var dd in dt)
            {
                dd.Then();
            }
            foreach (var Do in rd)
            {
                Dos.Remove(Do);
            }
            var rw = new List <WhenInfo>();

            foreach (var w in Whens)
            {
                if (w.When())
                {
                    if (w.Unless != null)
                    {
                        if (w.Unless())
                        {
                            //rw.Add(w);
                        }
                        else
                        {
                            w.Action();
                            rw.Add(w);
                        }
                    }
                    else
                    {
                        w.Action();
                        rw.Add(w);
                    }
                }
            }
            foreach (var w in rw)
            {
                Whens.Remove(w);
            }
            if (Flows.Count > 0)
            {
                var ff = Flows[0];
                if (ff.Begun == false)
                {
                    if (ff.Init != null)
                    {
                        ff.Init();
                    }
                    ff.Begun = true;
                }
                if (ff.Logic())
                {
                    if (ff.EndLogic != null)
                    {
                        ff.EndLogic();
                    }
                    Flows.Remove(ff);
                }
            }
            List <ActInfo> rem = new List <ActInfo>();
            int            ms  = Environment.TickCount;

            foreach (var a in Acts)
            {
                if (a.NoTime)
                {
                    a.Action();
                    if (a.Until())
                    {
                        rem.Add(a);
                        continue;
                    }
                }
                if (a.Until != null)
                {
                    if (ms > (a.When))
                    {
                        a.Action();
                        if (a.Until())
                        {
                            rem.Add(a);
                            continue;
                        }
                    }
                }
                if (a.Running)
                {
                    if (ms > (a.When + a.For))
                    {
                        Console.WriteLine("Done");
                        rem.Add(a);
                        continue;
                    }
                }
                else
                {
                    if (ms > a.When)
                    {
                        a.Action();
                        if (a.Once)
                        {
                            rem.Add(a);
                        }
                        else
                        {
                            a.Running = true;
                        }
                    }
                }
            }
            foreach (var a in rem)
            {
                Acts.Remove(a);
            }
            upmut.ReleaseMutex();
        }
Пример #7
0
 /// <summary>
 /// Invoke the given function, failing the scenario if it throws an exception
 /// </summary>
 /// <returns>the next step</returns>
 public WhenStep When <T>(Func <T> function)
 {
     return(Whens.When(Scenario, function));
 }
Пример #8
0
 /// <summary>
 /// Invoke the given action, failing the scenario if it throws an exception
 /// </summary>
 /// <param name="action">the action to invoke</param>
 /// <returns>the next step</returns>
 public WhenStep When(Action action)
 {
     return(Whens.When(Scenario, action));
 }
Пример #9
0
 public WhenStep When(IInvokable invokable)
 {
     return(Whens.When(Scenario, invokable));
 }
Пример #10
0
 /// <summary>
 /// Pass the given instance to the next step.
 /// </summary>
 /// <param name="actual">the instance to pass to the nest step</param>
 /// <returns>the next step containing the given instance</returns>
 public WhenStep When(Object actual)
 {
     return(Whens.When(Scenario, actual));
 }