Esempio n. 1
0
        public void TestDiscreteModel()
        {
            Model model = new Model();

            Metronome_Simple sm = Metronome_Simple.CreateMetronome(model.Executive, DateTime.Now, DateTime.Now + TimeSpan.FromHours(5), _timedifference);

            sm.TickEvent += new ExecEventReceiver(sm_TickEvent);

            model.Start();

            _Debug.Assert(_dotick == 0, "Tick event did not fire 30 times");
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a metronome with the specified parameters. It uses a static factory method
        /// because if there is already an existing metronome with the same parameters, that
        /// metronome is returned, rather than creating another one - after all, the whole
        /// point is to avoid a large number of tick events on the executive's event list.
        /// </summary>
        /// <param name="exec">The executive that will issue the ticks.</param>
        /// <param name="period">The period of the ticking.</param>
        /// <returns>Metronome_Simple.</returns>
        public static Metronome_Simple CreateMetronome(IExecutive exec, TimeSpan period)
        {
            Metronome_Simple retval = null;

            foreach (Metronome_Simple ms in m_channels)
            {
                if (ms.Period.Equals(period) && ms.StartAt == DateTime.MinValue && ms.FinishAt == DateTime.MaxValue)
                {
                    retval = ms;
                    break;
                }
            }
            if (retval == null)
            {
                retval = new Metronome_Simple(exec, period);
                m_channels.Add(exec, retval);
            }
            return(retval);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a metronome with the specified parameters. It uses a static factory method
        /// because if there is already an existing metronome with the same parameters, that
        /// metronome is returned, rather than creating another one - after all, the whole
        /// point is to avoid a large number of tick events on the executive's event list.
        /// </summary>
        /// <param name="exec">The executive that will issue the ticks.</param>
        /// <param name="startAt">The time at which the metronome's ticks are to start.</param>
        /// <param name="finishAfter">The time at which the metronome's ticks are to stop.</param>
        /// <param name="period">The period of the ticking.</param>
        /// <returns>A metronome that meets the criteria.</returns>
        public static Metronome_Simple CreateMetronome(IExecutive exec, DateTime startAt, DateTime finishAfter, TimeSpan period)
        {
            Metronome_Simple retval = null;

            foreach (Metronome_Simple ms in m_channels)
            {
                if (ms.Executive.Equals(exec) && ms.StartAt.Equals(startAt) && ms.FinishAt.Equals(finishAfter) && ms.Period.Equals(period))
                {
                    retval = ms;
                    break;
                }
            }
            if (retval == null)
            {
                retval = new Metronome_Simple(exec, startAt, finishAfter, period);
                m_channels.Add(exec, retval);
                exec.ExecutiveFinished += exec_ExecutiveFinished;
            }
            return(retval);
        }