public void TestExecutiveUnRequestHash() { string[] eventUserData = new string[] { "Cat", "Dog", "Bat", "Frog", "Mink", "Bee", "Bird", "Worm", "Horse", "Moose", "Bear", "Platypus" }; ArrayList eventsToRemove = new ArrayList(new string[] { "Cat", "Bat", "Bee", "Bird", "Bear", "Platypus" }); //ArrayList eventsThatShouldRemain = new ArrayList(new string[]{"Dog","Frog","Mink","Worm","Horse","Moose"}); IExecutive exec = ExecFactory.Instance.CreateExecutive(); DateTime now = DateTime.Now; DateTime when; double priority; // initialize validation variables m_error = false; m_validateUnRequest = new ArrayList(); Debug.WriteLine(""); Debug.WriteLine("Start test TestExecutiveUnRequestHash"); Debug.WriteLine(""); ArrayList eventIDsForRemoval = new ArrayList(); foreach (string eud in eventUserData) { when = new DateTime(now.Ticks + m_random.Next()); priority = m_random.NextDouble(); Trace.Write("Primary requesting event service with user data \"" + eud + "\", and eventID "); long eventID = exec.RequestEvent(new ExecEventReceiver(ExecEventRecieverUnRequestHash), when, priority, eud, m_execEventType); Debug.WriteLine(eventID + "."); if (eventsToRemove.Contains(eud)) { eventIDsForRemoval.Add(eventID); Debug.WriteLine("\tWe will be requesting the removal of this event."); } } foreach (long eventID in eventIDsForRemoval) { Debug.WriteLine("Unrequesting event # " + eventID); m_validateUnRequest.Add(eventID); exec.UnRequestEvent(eventID); } Debug.WriteLine(""); exec.Start(); Debug.WriteLine(""); // test validation variable Assert.IsTrue(!m_error, "Executive did fire a unrequested event"); Debug.WriteLine(""); }
private void SetFillRate(double fillRate) { double level = Level; // Forces recalc of level. Console.Write("{0} : Setting tank fill rate to {1}, Level is currently {2}. ", m_exec.Now, fillRate, level); m_fillRate = fillRate; if (fillRate > 0.0) { double minutesTilFull = ((m_capacity - m_level) / m_fillRate); m_fullEventID = m_exec.RequestEvent(TankIsFull, m_exec.Now + TimeSpan.FromMinutes(minutesTilFull)); Console.WriteLine("Tank will be full in {0} minutes.", minutesTilFull); } else { if (m_fullEventID != -1) { m_exec.UnRequestEvent(m_fullEventID); // Rescind full event. } Console.WriteLine("Tank level is constant."); } }
private static void RescindIt(IExecutive exec, object userData) { Console.WriteLine("{0} : Rescinding event {1}", exec.Now, userData); exec.UnRequestEvent((long)userData); }