예제 #1
0
        public void TestThreadSepFunctionality()
        {
            IExecutive exec = ExecFactory.Instance.CreateExecutive();
            DateTime   now  = DateTime.Now;
            DateTime   when;
            double     priority;

            for (int i = 0; i < NUM_EVENTS; i++)
            {
                when     = new DateTime(now.Ticks + m_random.Next());
                priority = m_random.NextDouble();
                Debug.WriteLine("Primary requesting detachable event service for " + when + ", at priority " + priority);
                exec.RequestEvent(new ExecEventReceiver(TimeSeparatedTask), when, priority, "Task " + i, ExecEventType.Detachable);
            }

            exec.Start();

            Debug.WriteLine("\r\n\r\n\r\nNow going to do it again after a 1.5 second pause.\r\n\r\n\r\n");
            System.Threading.Thread.Sleep(1500);

            exec = ExecFactory.Instance.CreateExecutive();
            now  = DateTime.Now;

            for (int i = 0; i < NUM_EVENTS; i++)
            {
                when     = new DateTime(now.Ticks + m_random.Next());
                priority = m_random.NextDouble();
                Debug.WriteLine("Primary requesting detachable event service for " + when + ", at priority " + priority);
                exec.RequestEvent(new ExecEventReceiver(TimeSeparatedTask), when, priority, "Task " + i, ExecEventType.Detachable);
            }

            exec.Start();
        }
예제 #2
0
            public static void Run()
            {
                IExecutive exec = ExecFactory.Instance.CreateExecutive();

                DateTime when = DateTime.Parse("Fri, 15 Jul 2016 03:51:21");

                Domain.Sample1.Dog rastro = new Domain.Sample1.Dog("Rastro");

                for (int i = 0; i < 5; i++)
                {
                    // Schedule 15 speaking events.

                    Domain.Sample1.Cat aCat = new Domain.Sample1.Cat("Cat_" + i);
                    Domain.Sample1.Dog aDog = new Domain.Sample1.Dog("Dog_" + i);

                    exec.RequestEvent(rastro.Speak, when, 0.0, null, ExecEventType.Detachable);
                    exec.RequestEvent(aDog.Speak, when, 0.0, null, ExecEventType.Detachable);
                    exec.RequestEvent(aCat.Speak, when, 0.0, null, ExecEventType.Detachable);

                    when += TimeSpan.FromMinutes(10.0);
                }

                exec.RequestEvent(RescindIndividual, when - TimeSpan.FromMinutes(35), rastro);
                exec.RequestEvent(RescindCats, when - TimeSpan.FromMinutes(25));

                exec.Start();
            }
예제 #3
0
 private static void ExecStarted(IExecutive exec)
 {
     Console.WriteLine("Setting up the simulation. Executive is in state {0}.", exec.State);
     exec.RequestEvent(ReportIt, DateTime.Now);
     exec.RequestEvent(ReportIt, DateTime.Now + TimeSpan.FromMinutes(10));
     exec.RequestEvent(ReportIt, DateTime.Now + TimeSpan.FromMinutes(20));
 }
예제 #4
0
        public void TestExecutiveUnRequestTarget()
        {
            IExecutive  exec = ExecFactory.Instance.CreateExecutive();
            DateTime    now  = DateTime.Now;
            DateTime    when;
            double      priority;
            OtherTarget ot = null;

            // initialize validation variables
            m_error             = false;
            m_validateUnRequest = new ArrayList();
            Debug.WriteLine("");
            Debug.WriteLine("Start test TestExecutiveUnRequestTarget");
            Debug.WriteLine("");

            for (int i = 0; i < NUM_EVENTS; i++)
            {
                when     = new DateTime(now.Ticks + m_random.Next());
                priority = m_random.NextDouble();
                Debug.WriteLine("Primary requesting event service " + i);
                switch (i)
                {
                case 1:
                case 2:
                case 3:
                case 5:
                case 7:
                case 11:
                    m_validateUnRequest.Add(i);
                    ot = new OtherTarget(m_validateUnRequest, m_error);
                    ExecEventReceiver eer = new ExecEventReceiver(ot.ExecEventRecieverUnRequestEventReceiver);
                    exec.RequestEvent(eer, when, priority, i, m_execEventType);
                    exec.UnRequestEvents(ot);
                    break;

                default:
                    exec.RequestEvent(new ExecEventReceiver(this.ExecEventRecieverUnRequestEventReceiver), when, priority, i, m_execEventType);
                    break;
                }
                ;
            }


            Debug.WriteLine("");

// AEL			exec.UnRequestEvents(new OtherTarget(m_validateUnRequest, m_error));

            exec.Start();

            Debug.WriteLine("");

            // test validation variable
            Assert.IsTrue(!m_error, "Executive did fire a unrequested event");

            Debug.WriteLine("");
        }
예제 #5
0
            public static void Run()
            {
                IExecutive exec = ExecFactory.Instance.CreateExecutive();

                DateTime when = DateTime.Parse("Fri, 15 Jul 2016 03:51:21");

                exec.RequestEvent(WriteIt, when, 0.0, "World");
                exec.RequestEvent(WriteIt, when, 1.0, "Hello");

                exec.Start();
            }
예제 #6
0
 private void ScheduleNext(IExecutive exec)
 {
     if (UseDaemonEvents)
     {
         Exec.RequestDaemonEvent(Eer, NextOccurrence, Priority, null);
     }
     else
     {
         Exec.RequestEvent(Eer, NextOccurrence, Priority, null);
     }
     AdvanceNextOccurrenceDate();
 }
예제 #7
0
            public static void CookDinner(IExecutive exec, object userData)
            {
                Console.WriteLine(" {0} : Starting to cook dinner...", exec.Now);

                long code1 = exec.RequestEvent(MakeTurkey, exec.Now, 0.0, null, ExecEventType.Detachable);
                long code2 = exec.RequestEvent(MakeGravy, exec.Now, 0.0, null, ExecEventType.Detachable);
                long code3 = exec.RequestEvent(MakeStuffing, exec.Now, 0.0, null, ExecEventType.Detachable);

                Console.WriteLine(" {0} : We'll wait 'til everything is done before we serve dinner!", exec.Now);
                exec.Join(code1, code2, code3);

                Console.WriteLine(" {0} : Serving dinner!", exec.Now);
            }
예제 #8
0
            public static void Run()
            {
                IExecutive exec = ExecFactory.Instance.CreateExecutive();

                DateTime when = DateTime.Parse("Fri, 15 Jul 2016 03:51:21");

                long eventKey =
                    exec.RequestEvent(WriteIt, when + TimeSpan.FromMinutes(5.0), "Hello.");

                exec.RequestEvent(RescindIt, when, eventKey);

                exec.Start();
            }
예제 #9
0
            public static void Run()
            {
                IExecutive exec = ExecFactory.Instance.CreateExecutive();

                DateTime when1 = DateTime.Parse("Fri, 15 Jul 2016 03:51:21");

                exec.RequestEvent(SayHello, when1);

                DateTime when2 = DateTime.Parse("Mon, 18 Jul 2016 05:15:08");

                exec.RequestEvent(SayWorld, when2);

                exec.Start();
            }
예제 #10
0
            public static void Run()
            {
                IExecutive exec = ExecFactory.Instance.CreateExecutive();

                DateTime when = DateTime.Parse("Fri, 15 Jul 2016 03:51:21");

                exec.RequestEvent(WriteIt, when + TimeSpan.FromMinutes(5), "Reporting.");

                double   priority          = 0.0;
                TimeSpan userData_duration = TimeSpan.FromMinutes(10.0);

                exec.RequestEvent(DoSomething, when, priority, userData_duration, ExecEventType.Detachable);

                exec.Start();
            }
예제 #11
0
        public void TestEventTimeHistorian()
        {
            IRandomChannel     irc         = m_rs.GetRandomChannel();
            IExecutive         exec        = ExecFactory.Instance.CreateExecutive();
            EventTimeHistorian myHistorian = new EventTimeHistorian(exec, 256);
            DateTime           when        = m_startDate;

            // We set up NUM_SAMPLES events with random (0->50) minute intervals.
            TimeSpan totalTimeSpan = TimeSpan.Zero;

            for (int i = 0; i < NUM_SAMPLES; i++)
            {
                exec.RequestEvent(DoEvent, when, 0.0, myHistorian, ExecEventType.Synchronous);
                double   d     = irc.NextDouble();
                TimeSpan delta = TimeSpan.FromMinutes(d * 50.0);
                totalTimeSpan += delta;
                if (i < 30)
                {
                    Console.WriteLine("Delta #" + i + ", " + delta.ToString());
                }
                when += delta;
            }

            m_actualAverage = TimeSpan.FromTicks(totalTimeSpan.Ticks / NUM_SAMPLES);
            Console.WriteLine("Average timeSpan was " + m_actualAverage + ".");

            exec.Start();

            Console.WriteLine("After {0} events, the average interval was {1}.", myHistorian.PastEventsReceived, myHistorian.GetAverageIntraEventDuration());
        }
예제 #12
0
        private void EvaluateCondition(IExecutive exec, object userData)
        {
            PfcExecutionContext pfcec   = (PfcExecutionContext)userData;
            TsmData             tsmData = GetTsmData(pfcec);

            tsmData.NextExpressionEvaluation = 0L;
            if (tsmData.State == TransitionState.Active && ExecutableCondition(pfcec, this))
            {
                PredecessorStateMachines.ForEach(delegate(StepStateMachine ssm) {
                    if (ssm.GetState(pfcec) != StepState.Complete)
                    {
                        ssm.Stop(pfcec);
                    }
                    ssm.Reset(pfcec);
                });
                // When the last predecessor goes to Idle, I will go to Inactive.
                Debug.Assert(AllPredsAreIdle(pfcec));
                Debug.Assert(tsmData.State == TransitionState.Inactive);
                if (s_diagnostics)
                {
                    Console.WriteLine("Done condition-scanning on transition " + m_myTransition.Name + " in EC " + pfcec.Name + ".");
                }
                SuccessorStateMachines.ForEach(delegate(StepStateMachine ssm) { RunSuccessor(ssm, pfcec); });
            }
            else
            {
                // Either I'm NotBeingEvaluated, or the evaluation came out false.
                // NOTE: Must halt event stream when "NotBeingEvaluated".
                tsmData.NextExpressionEvaluation = exec.RequestEvent(new ExecEventReceiver(EvaluateCondition), exec.Now + m_scanningPeriod, 0.0, pfcec, ExecEventType.Synchronous);
            }
        }
예제 #13
0
        public void TestExecutiveWhen()
        {
            IExecutive exec = ExecFactory.Instance.CreateExecutive();
            DateTime   now  = DateTime.Now;
            DateTime   when;

            // initialize validation variables
            m_error        = false;
            m_validateWhen = new DateTime(now.Ticks);
            Debug.WriteLine("");
            Debug.WriteLine("Start test TestExecutiveWhen");
            Debug.WriteLine("");

            for (int i = 0; i < NUM_EVENTS; i++)
            {
                when = new DateTime(now.Ticks + m_random.Next());
                Debug.WriteLine("Primary requesting event service for " + when);
                //if (m_validateWhen.Ticks < when.Ticks) {m_validateWhen = when;}
                exec.RequestEvent(new ExecEventReceiver(ExecEventRecieverWhen), when, 0, when, m_execEventType);
            }

            Debug.WriteLine("");

            exec.Start();

            Debug.WriteLine("");

            // test validation variable
            Assert.IsTrue(!m_error, "Executive did not submit events in correct date/time order");

            Debug.WriteLine("");
        }
예제 #14
0
 private void OnExecEvent(IExecutive exec, object userData)
 {
     if (!m_abortRequested)
     {
         Debug.Assert(exec == m_executive, "Executive Mismatch"
                      , "A metronome was called by an executive that is not the one it was initially created for.");
         FireEvents(exec, userData);
         if (!m_abortRequested)
         {
             TickIndex++;
             DateTime nextEventTime = exec.Now + m_period;
             if (nextEventTime <= m_finishAfter)
             {
                 if (m_autoFinish)
                 {
                     exec.RequestDaemonEvent(m_execEvent, nextEventTime, 0.0, null);
                 }
                 else
                 {
                     exec.RequestEvent(m_execEvent, nextEventTime, 0.0, null);
                 }
             }
         }
     }
 }
예제 #15
0
        public void TestExecutivePriority()
        {
            IExecutive exec = ExecFactory.Instance.CreateExecutive();
            DateTime   now  = DateTime.Now;
            int        priority;

            // initialize validation variables
            m_error            = false;
            m_validatePriority = 0;
            Debug.WriteLine("");
            Debug.WriteLine("Start test TestExecutivePriority");
            Debug.WriteLine("");

            for (int i = 0; i < NUM_EVENTS; i++)
            {
                priority = (int)(m_random.NextDouble() * 100);
                if (m_validatePriority < priority)
                {
                    m_validatePriority = priority;
                }
                Debug.WriteLine("Primary requesting event service for " + now + ", at priority " + priority);
                exec.RequestEvent(new ExecEventReceiver(ExecEventRecieverPriority), now, priority, priority, m_execEventType);
            }

            Debug.WriteLine("");

            exec.Start();

            Debug.WriteLine("");

            // test validate variable
            Assert.IsTrue(!m_error, "Executive did not submit events in the order of the correct priority");

            Debug.WriteLine("");
        }
예제 #16
0
 private void ScheduleProcessingOfGetters()
 {
     if (m_getFlushEventId == -1)
     {
         m_getFlushEventId = m_executive.RequestEvent(ProcessGetters, m_executive.Now, 0.0, null, ExecEventType.Detachable);
     }
 }
예제 #17
0
            private void WaitAndRun(IModel theModel)
            {
                IExecutive exec         = theModel.Executive;
                DateTime   whenToStart  = exec.Now + TimeSpan.FromHours(m_rc.NextDouble() * 2);
                TimeSpan   howLongToRun = TimeSpan.FromHours(m_rc.NextDouble() * 4);

                exec.RequestEvent((executive, data) => StartRunning(howLongToRun), whenToStart);
            }
예제 #18
0
        public void TestEventJoinDetachable()
        {
            IExecutive    exec1     = ExecFactory.Instance.CreateExecutive("Highpoint.Sage.SimCore.Executive", Guid.NewGuid());
            DateTime      setupTime = new DateTime(2008, 11, 24, 12, 15, 44);
            ExecEventType eet       = ExecEventType.Detachable; // Don't change this one. Join must be done on a detachable event.

            exec1.RequestEvent(new ExecEventReceiver(JoinDetachableSetup), setupTime, 0.0, null, eet);
            exec1.Start();
        }
예제 #19
0
        public void TestExecutiveUnRequestSelector()
        {
            IExecutive exec = ExecFactory.Instance.CreateExecutive();
            DateTime   now  = DateTime.Now;
            DateTime   when;
            double     priority;

//			IExecEventSelector ees = null;

            // initialize validation variables
            m_error             = false;
            m_validateUnRequest = new ArrayList();
            _Debug.WriteLine("");
            _Debug.WriteLine("Start test TestExecutiveUnRequestSelector");
            _Debug.WriteLine("");

            for (int i = 0; i < NUM_EVENTS; i++)
            {
                when     = new DateTime(now.Ticks + m_random.Next());
                priority = m_random.NextDouble();
                _Debug.WriteLine("Primary requesting event service " + i);
                switch (i)
                {
                case 1:
                case 2:
                case 3:
                case 5:
                case 7:
                case 11:
//						m_validateUnRequest.Add(i);
//						ees = new ExecEventSelectorByTargetType(this.GetType());
//						ExecEventReceiver eer = new ExecEventReceiver(ees.SelectThisEvent(eer,when,priority,i,m_execEventType));
//						exec.RequestEvent(eer,when,priority,i,m_execEventType);
//						exec.UnRequestEvents(ees);
                    break;

                default:
                    exec.RequestEvent(new ExecEventReceiver(this.ExecEventRecieverUnRequestEventReceiver), when, priority, i, m_execEventType);
                    break;
                }
                ;
            }


            _Debug.WriteLine("");

            // AEL			exec.UnRequestEvents(new ExecEventSelectorByTargetType(this));

            exec.Start();

            _Debug.WriteLine("");

            // test validation variable
            _Debug.Assert(!m_error, "Executive fired a unrequested event");

            _Debug.WriteLine("");
        }
예제 #20
0
        public static void Run()
        {
            DateTime when = DateTime.Parse("Fri, 15 Jul 2016 00:00:00");

            IExecutive exec = ExecFactory.Instance.CreateExecutive();

            exec.RequestEvent(StartProcessToken, when, 0.0, null, ExecEventType.Detachable);

            exec.Start();
        }
예제 #21
0
        private static void StartProcessToken(IExecutive exec, object userData)
        {
            // UserData is a State object.
            State state = (State)userData;

            Console.WriteLine("{0} : Commence processing {1}.", exec.Now, state.Who);
            DateTime completeWhen = exec.Now + state.Duration;

            exec.RequestEvent(FinishProcessToken, completeWhen, state.Who);
        }
예제 #22
0
            public static void Run()
            {
                IExecutive exec = ExecFactory.Instance.CreateExecutive();

                DateTime when = DateTime.Parse("Fri, 15 Jul 2016 03:51:21");

                exec.RequestEvent(CookDinner, when, 0.0, null, ExecEventType.Detachable);

                exec.Start();
            }
예제 #23
0
            public static void Run()
            {
                IExecutive exec = ExecFactory.Instance.CreateExecutive();

                DateTime when = DateTime.Parse("Fri, 15 Jul 2016 03:51:21");

                exec.RequestEvent(SayHello, when);

                exec.Start();
            }
예제 #24
0
        private void StartExec(object obj)
        {
            IExecutive exec = (IExecutive)obj;

            Debug.WriteLine("\r\n" + "Starting exec..." + "\r\n");
            DateTime startTime = new DateTime(2006, 5, 16);

            exec.RequestEvent(new ExecEventReceiver(SteadyStateEventStream), startTime, 1, 400);
            exec.Start();
        }
예제 #25
0
            public static void Run()
            {
                IExecutive exec = ExecFactory.Instance.CreateExecutive();

                DateTime when = DateTime.Parse("Fri, 15 Jul 2016 03:51:21");

                exec.RequestEvent(new Plumber("Paul").FixTheSink, when, 0.0, null, ExecEventType.Detachable);

                exec.Start();
            }
예제 #26
0
            private static void WriteIt(IExecutive exec, object _userData)
            {
                Queue <string> userData = (Queue <string>)_userData;

                if (userData.Count > 0)
                {
                    Console.WriteLine("{0} : {1}", exec.Now, userData.Dequeue());
                    exec.RequestEvent(WriteIt, exec.Now + TimeSpan.FromMinutes(10), userData);
                }
            }
예제 #27
0
            private static void WriteIt(IExecutive exec, object _userData)
            {
                // We want to generate an exception in an event handler.
                Stack <string> userData = (Stack <string>)_userData; // <-- Miscast. It's a queue.

                if (userData.Count > 0)
                {
                    Console.WriteLine("{0} : {1}", exec.Now, userData.Pop());
                    exec.RequestEvent(WriteIt, exec.Now + TimeSpan.FromMinutes(10), userData);
                }
            }
예제 #28
0
        public static void Run()
        {
            IExecutive exec = ExecFactory.Instance.CreateExecutive();

            _tank = new Tank(exec, 1000.0, 100.0);

            DateTime when = DateTime.Parse("Fri, 15 Jul 2016 00:00:00");

            exec.SetStartTime(when); // Must do this, or the initial level is computed at time zero, rather than Fri, 15 Jul 2016 00:00:00.
            exec.RequestEvent(delegate { _tank.OpenFillValve(); }, when, 1.0);
            exec.RequestEvent(delegate { _tank.CloseFillValve(); }, when + TimeSpan.FromMinutes(15.0));
            exec.RequestEvent(delegate { _tank.OpenFillValve(40); }, when + TimeSpan.FromMinutes(30.0));
            for (int i = 0; i < 8; i++)
            {
                exec.RequestEvent(ReportTankLevel, when, 0.0);
                when += TimeSpan.FromMinutes(6.0);
            }

            exec.Start();
        }
예제 #29
0
 private void PerfTestExecute(IExecutive exec, object userData)
 {
     Randoms.IRandomChannel rch = (Randoms.IRandomChannel)userData;
     if (rch.NextDouble() < 0.405 && exec.EventCount < eventCountCeil)
     {
         int nNewEvents = rch.Next(1, 5);
         for (int i = 0; i < nNewEvents; i++)
         {
             DateTime when = exec.Now + TimeSpan.FromMinutes(rch.NextDouble() * 100);
             if (rch.NextDouble() < pctSynchronous)
             {
                 exec.RequestEvent(new ExecEventReceiver(PerfTestExecute), when, 0.0, rch);
             }
             else
             {
                 exec.RequestEvent(new ExecEventReceiver(PerfTestExecute), when, 0.0, rch, ExecEventType.Detachable);
             }
         }
     }
 }
예제 #30
0
            public static void Run()
            {
                DateTime when = DateTime.Parse("Fri, 15 Jul 2016 00:00:00");

                IExecutive exec = ExecFactory.Instance.CreateExecutive();

                exec.RequestDaemonEvent(CheckIfStillRunning, when, 0.0, null);
                exec.RequestEvent(Finish, when + TimeSpan.FromMinutes(100));

                exec.Start();
            }