/// <summary> /// Broadcasts a <paramref name="value"/> to all receivers. /// </summary> public SimEvent Put(TItem value) { if (_pipes.Count == 0) { throw new InvalidOperationException("There are no output pipes."); } var events = _pipes.Select(p => p.Put(value)).ToArray(); switch (events.Length) { case 1: return(_env.AllOf(events[0])); case 2: return(_env.AllOf(events[0], events[1])); case 3: return(_env.AllOf(events[0], events[1], events[2])); case 4: return(_env.AllOf(events[0], events[1], events[2], events[3])); case 5: return(_env.AllOf(events[0], events[1], events[2], events[3], events[4])); } throw new Exception("Too many pipes!"); }
static IEnumerable <SimEvent> CondTester(SimEnvironment env) { var aProc = env.Process(AProcess(env)); var cond = env.AllOf(env.Timeout(5, "VAL_T"), aProc); yield return(cond); Console.WriteLine("ALL: {0}", cond.Value.Select(x => x.Value).Aggregate((s1, s2) => s1 + ", " + s2)); aProc = env.Process(AProcess(env)); cond = env.AnyOf(env.Timeout(5, "VAL_T"), aProc); yield return(cond); Console.WriteLine("ANY: {0}", cond.Value.Select(x => x.Value).Aggregate((s1, s2) => s1 + ", " + s2)); aProc = env.Process(AProcess(env)); var aTime = env.Timeout(5, "VAL_T"); ConditionEval <Timeout <string>, SimProcess> pred = c => c.Ev1.Succeeded && c.Ev2.Succeeded && c.Ev1.Value.Equals("VAL_T") && c.Ev2.Value.Equals("VAL_P"); cond = env.Condition(aTime, aProc, pred); yield return(cond); Console.WriteLine("CUSTOM: {0}", cond.Value.Select(x => x.Value).Aggregate((s1, s2) => s1 + ", " + s2)); }
static IEnumerable <SimEvent> Process(SimEnvironment env) { var t1 = env.Timeout(3); var t2 = env.Timeout(7); var c1 = env.AllOf(t1, t2); yield return(c1); Console.WriteLine(env.Now); // 7 Console.WriteLine(c1.Value.Contains(t1)); // True Console.WriteLine(c1.Value.Contains(t2)); // True t1 = env.Timeout(3); t2 = env.Timeout(7); var c2 = env.Condition(t1, t2, c => c.Ev1.Succeeded || c.Ev2.Succeeded); yield return(c2); Console.WriteLine(env.Now); // 10 Console.WriteLine(c2.Value.Contains(t1)); // True Console.WriteLine(c2.Value.Contains(t2)); // False }