public virtual Case ElseIf(Condition condition, object result) { if (condition == null) { throw new System.ArgumentNullException("condition"); } Whens.Add(new Case(condition, result)); return(this); }
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)); } } }
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); } } }
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); }
public void AddWhen(string text, when method) { Whens.Add(method, text); }
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(); }
/// <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)); }
/// <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)); }
public WhenStep When(IInvokable invokable) { return(Whens.When(Scenario, invokable)); }
/// <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)); }