Esempio n. 1
0
        public void IncDecHourIntervalTest()
        {
            CommandIncDec  com  = new CommandIncDec();
            ClockEventArgs args = new ClockEventArgs(int.MinValue, 0, 0);

            // com.Clock = MockClock.Instance;
            com.Clock.Set(12, 0, 0);

            com.Execute(args);
            Assert.AreEqual(11, com.Clock.Hour);

            args = new ClockEventArgs(-1, 0, 0);
            com.Execute(args);
            Assert.AreEqual(10, com.Clock.Hour);

            args = new ClockEventArgs(0, 0, 0);
            com.Execute(args);
            Assert.AreEqual(10, com.Clock.Hour);

            args = new ClockEventArgs(1, 0, 0);
            com.Execute(args);
            Assert.AreEqual(11, com.Clock.Hour);

            args = new ClockEventArgs(int.MaxValue, 0, 0);
            com.Execute(args);
            Assert.AreEqual(12, com.Clock.Hour);
        }
Esempio n. 2
0
        public void IncDecSecondIntervalTest()
        {
            CommandIncDec  com  = new CommandIncDec();
            ClockEventArgs args = new ClockEventArgs(0, 0, int.MinValue);

            // com.Clock = MockClock.Instance;
            com.Clock.Set(0, 0, 30);

            com.Execute(args);
            Assert.AreEqual(29, com.Clock.Second);

            args = new ClockEventArgs(0, 0, -1);
            com.Execute(args);
            Assert.AreEqual(28, com.Clock.Second);

            args = new ClockEventArgs(0, 0, 0);
            com.Execute(args);
            Assert.AreEqual(28, com.Clock.Second);

            args = new ClockEventArgs(0, 0, 1);
            com.Execute(args);
            Assert.AreEqual(29, com.Clock.Second);

            args = new ClockEventArgs(0, 0, int.MaxValue);
            com.Execute(args);
            Assert.AreEqual(30, com.Clock.Second);
        }
Esempio n. 3
0
 public void AlarmMode(ClockEventArgs e)
 {
     if (AlarmEvent != null)
     {
         AlarmEvent(this, e);  // 响铃事件
     }
 }
Esempio n. 4
0
 public void TickMode(ClockEventArgs e)
 {
     if (TickEvent != null)
     {
         TickEvent(this, e);  // 显示时间事件
     }
 }
Esempio n. 5
0
            public void ShowTime(DateTime alarmColck)
            {
                ClockEventArgs args = new ClockEventArgs();

                args.AlarmTime = alarmColck;
                while (true)
                {
                    args.CurrentTime = System.DateTime.Now;
                    if (DateTime.Compare(args.CurrentTime, args.AlarmTime) >= 0 && isPause)
                    {
                        Console.WriteLine("Dou Dou Dou Dou!!!!!!");
                        Console.WriteLine("Get up now!!!!!!");
                        Console.WriteLine("Press any key to ditch the alarm");

                        if (Alarm != null)
                        {
                            Alarm(args);
                        }

                        if (Console.ReadLine() != null)
                        {
                            isPause = false;
                        }
                    }
                    else
                    {
                        Console.WriteLine($"The current time is {DateTime.Now}");
                        if (Tick != null)
                        {
                            Tick(args);
                        }
                    }
                    Thread.Sleep(1000);
                }
            }
Esempio n. 6
0
 /// <summary>
 /// Event handler for the current games time notifier.
 /// </summary>
 /// <param name="sender">Sender of the event</param>
 /// <param name="e">Event arguments</param>
 private void BlackClockEventHandler(object sender, ClockEventArgs e)
 {
     if (BlackClockNotifier != null)
     {
         BlackClockNotifier(this, e);
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Event handler for the current games time notifier.
 /// </summary>
 /// <param name="sender">Sender of the event</param>
 /// <param name="e">Event arguments</param>
 private void WhiteClockEventHandler(object sender, ClockEventArgs e)
 {
     if (WhiteClockNotifier != null)
     {
         WhiteClockNotifier(this, e);
     }
 }
Esempio n. 8
0
 public event ClockEventHandle Clocking;//声明事件
 public void Response()
 {
     if (Clocking != null)
     {
         ClockEventArgs args = new ClockEventArgs();
         Clocking(this, args);//每触发一次事件,通知一次外界
     }
 }
 public void Start(TimeSpan time)
 {
     Task.Run(() =>
     {
         Thread.Sleep(time);
         var e = new ClockEventArgs(DateTime.Now);
         OnAlarm(e);
     });
 }
Esempio n. 10
0
        public void ClockEventArgsAttributesAreMinSetable()
        {
            ClockEventArgs args = new ClockEventArgs();

            args.Hour = int.MinValue;
            Assert.AreEqual(int.MinValue, args.Hour);
            args.Minute = int.MinValue;
            Assert.AreEqual(int.MinValue, args.Minute);
            args.Second = int.MinValue;
            Assert.AreEqual(int.MinValue, args.Second);
        }
Esempio n. 11
0
        public void ClockEventArgsContructorCreatesCorrectValues()
        {
            ClockEventArgs args = new ClockEventArgs();

            Assert.AreEqual(0, args.Hour);
            Assert.AreEqual(0, args.Minute);
            Assert.AreEqual(0, args.Second);

            args = new ClockEventArgs(1, 2, 3);
            Assert.AreEqual(1, args.Hour);
            Assert.AreEqual(2, args.Minute);
            Assert.AreEqual(3, args.Second);
        }
Esempio n. 12
0
        public void CommandIncDecExecutesCorrectly()
        {
            CommandIncDec  incdec = new CommandIncDec();
            ClockEventArgs args   = new ClockEventArgs(9, 9, 9);

            incdec.Clock = MockClock.Instance;

            incdec.Execute(args);
            Assert.AreEqual(true, MockClock.Instance.IncDecExecuted);
            Assert.AreEqual(-9, args.Hour);
            Assert.AreEqual(-9, args.Minute);
            Assert.AreEqual(-9, args.Second);
            MockClock.Instance.ResetMock();
        }
Esempio n. 13
0
 public void SomeClock(int setTime)
 {
     for (int i = 0; i <= 1000; i++)
     {
         Thread.Sleep(500);
         clockTime = i % 24;
         ClockEventArgs e = new ClockEventArgs(clockTime);
         TickMode(e);
         if (clockTime == setTime)
         {
             AlarmMode(e);
         }
     }
 }
Esempio n. 14
0
            public event ClockHandler Ring; //闹钟响铃

            public void Clock(DateTime clockring)
            {
                ClockEventArgs args = new ClockEventArgs();

                args.Time    = System.DateTime.Now;
                args.SetTime = clockring;
                if (DateTime.Compare(args.Time, args.SetTime) == 0) //当时间到设定时间时
                {
                    Ring(this, args);                               //开始响铃
                }
                else
                {
                    Run(this, args);
                }
            }
Esempio n. 15
0
        public void CommandSetExecutesCorrectly()
        {
            CommandSet     set  = new CommandSet();
            ClockEventArgs args = new ClockEventArgs(9, 9, 9);

            Clock.Instance.Set(0, 0, 0);
            set.Clock = MockClock.Instance;

            set.Execute(args);
            Assert.AreEqual(true, MockClock.Instance.SetExecuted);
            Assert.AreEqual(0, args.Hour);
            Assert.AreEqual(0, args.Minute);
            Assert.AreEqual(0, args.Second);
            MockClock.Instance.ResetMock();
        }
Esempio n. 16
0
    public void InterpolateChange(Clock clock, ClockEventArgs args)
    {
        if (currentMonth != args.month)
        {
            currentMonth = args.month;

            ConnectionManager cManager = GameObject.Find("MainObject").GetComponent <ConnectionManager>();

            if (cManager)
            {
                cManager.Send(new RequestPrediction());
            }
        }

        if (currentDay != args.day)
        {
            currentDay = args.day;

            if (results.Count > 0)
            {
                foreach (KeyValuePair <int, int> entry in results)
                {
                    int group_id = entry.Key, biomass = entry.Value;

                    Species speciesGroup = gameObject.GetComponent <GameState>().GetSpeciesGroup(group_id);

                    if (speciesGroup != null)
                    {
                        int nextBiomass = speciesGroup.size + biomass / 30;
                        gameObject.GetComponent <GameState>().UpdateSpecies(group_id, nextBiomass);

                        if (nextBiomass < 0)
                        {
                            //gameObject.GetComponent<Chat>().SetMessage(speciesGroup.name + " decreased by " + -nextBiomass);
                        }
                        else
                        {
                            //gameObject.GetComponent<Chat>().SetMessage(speciesGroup.name + " increased by " + nextBiomass);
                        }
                    }
                    else
                    {
                        Debug.Log("Missing Species");
                    }
                }
            }
        }
    }
Esempio n. 17
0
    public void DoClock()
    {
        DateTime now   = DateTime.Now;
        int      year  = now.Year;
        int      month = now.Month;
        int      day   = now.Day;
        DateTime set   = new DateTime(year, month, day, Hour, Minute, Second);

        while (now < set)
        {
            now = DateTime.Now;
        }
        ClockEventArgs args = new ClockEventArgs();

        Clocking(this, args);
    }
Esempio n. 18
0
    public void InterpolateChange(Clock clock, ClockEventArgs args)
    {
        if (currentMonth != args.month)
        {
            currentMonth = args.month;

            NetworkManager.Send(
                PredictionProtocol.Prepare(),
                ProcessPrediction
                );
        }

        if (currentDay != args.day)
        {
            currentDay = args.day;

            if (results.Count > 0)
            {
                foreach (KeyValuePair <int, int> entry in results)
                {
                    int group_id = entry.Key, biomass = entry.Value;

                    Species speciesGroup = gameObject.GetComponent <GameState>().GetSpeciesGroup(group_id);

                    if (speciesGroup != null)
                    {
                        int nextBiomass = speciesGroup.size + biomass / 30;
                        gameObject.GetComponent <GameState>().UpdateSpecies(group_id, nextBiomass);

                        if (nextBiomass < 0)
                        {
                            gameObject.GetComponent <Chat>().SetMessage(speciesGroup.name + " decreased by " + -nextBiomass);
                        }
                        else
                        {
                            gameObject.GetComponent <Chat>().SetMessage(speciesGroup.name + " increased by " + nextBiomass);
                        }
                    }
                    else
                    {
                        Debug.Log("Missing Species");
                    }
                }
            }
        }
    }
Esempio n. 19
0
        public void RunClock()
        {
            ClockEventArgs clockEventArgs = new ClockEventArgs(DateTime.Now);

            while (true)
            {
                clockEventArgs.CurrentTime = DateTime.Now;
                Thread.Sleep(1000);
                Console.Clear();
                ClockRunningEventHandler?.Invoke(this, clockEventArgs);

                if (clockEventArgs.CancelCounting)
                {
                    Console.WriteLine("Stopped clock");
                    break;
                }
            }
        }
Esempio n. 20
0
        public void CommandSetHourIntervalMiddleTest()
        {
            CommandSet     com  = new CommandSet();
            ClockEventArgs args = new ClockEventArgs(11, 0, 0);

            // com.Clock = MockClock.Instance;

            com.Execute(args);
            Assert.AreEqual(11, com.Clock.Hour);

            args = new ClockEventArgs(12, 0, 0);
            com.Execute(args);
            Assert.AreEqual(12, com.Clock.Hour);

            args = new ClockEventArgs(13, 0, 0);
            com.Execute(args);
            Assert.AreEqual(13, com.Clock.Hour);
        }
Esempio n. 21
0
        public void CommandSetSecondIntervalMiddleTest()
        {
            CommandSet     com  = new CommandSet();
            ClockEventArgs args = new ClockEventArgs(0, 0, 29);

            // com.Clock = MockClock.Instance;

            com.Execute(args);
            Assert.AreEqual(29, com.Clock.Second);

            args = new ClockEventArgs(0, 0, 30);
            com.Execute(args);
            Assert.AreEqual(30, com.Clock.Second);

            args = new ClockEventArgs(0, 0, 31);
            com.Execute(args);
            Assert.AreEqual(31, com.Clock.Second);
        }
Esempio n. 22
0
            public void SetTime()//用户设定时间
            {
                Console.WriteLine(NowTime);
                Console.WriteLine("Please input the hour");
                String hour = Console.ReadLine();

                Console.WriteLine("Please input the minute");
                String minute = Console.ReadLine();

                Console.WriteLine("Please input the second");
                String second = Console.ReadLine();

                Time = hour + ":" + minute + ":" + second;

                if (NowTime == Time)
                {
                    ClockEventArgs args = new ClockEventArgs();
                    args.Clock = String.Equals(Time, NowTime);
                    Setting(this, args);
                }
            }
Esempio n. 23
0
        public void CommandSetHourIntervalBeginTest()
        {
            CommandSet     com  = new CommandSet();
            ClockEventArgs args = new ClockEventArgs(int.MinValue, 0, 0);

            // com.Clock = MockClock.Instance;

            com.Execute(args);
            Assert.AreNotEqual(int.MinValue, com.Clock.Hour);

            args = new ClockEventArgs(-1, 0, 0);
            com.Execute(args);
            Assert.AreNotEqual(-1, com.Clock.Hour);

            args = new ClockEventArgs(0, 0, 0);
            com.Execute(args);
            Assert.AreEqual(0, com.Clock.Hour);

            args = new ClockEventArgs(1, 0, 0);
            com.Execute(args);
            Assert.AreEqual(1, com.Clock.Hour);
        }
Esempio n. 24
0
        private void HandleWhiteTimeEvent(object sender, ClockEventArgs e)
        {
            string time;

            if (e.Time.Milliseconds <= 0 || e.ClockType == ClockType.None)
            {
                time = e.Time.ToString();
            }
            else
            {
                TimeSpan timeSpan = new TimeSpan(e.Time.Hours, e.Time.Minutes, e.Time.Seconds + 1);
                time = timeSpan.ToString();
            }

            if (time.Contains("."))
            {
                time = time.Substring(0, time.IndexOf('.'));
            }

            m_whiteTimeGraphic.Clear(Color.White);
            m_whiteTimeGraphic.DrawString(time, m_panelFont, m_blackBrush, (time[0] == '-') ? -3 : 4, 1);
            pictureWhiteTime.Refresh();
        }
Esempio n. 25
0
        public void CommandSetSecondIntervalEndTest()
        {
            CommandSet     com  = new CommandSet();
            ClockEventArgs args = new ClockEventArgs(0, 0, 59);

            // com.Clock = MockClock.Instance;

            com.Execute(args);
            Assert.AreEqual(59, com.Clock.Second);

            args = new ClockEventArgs(0, 0, 60);
            com.Execute(args);
            Assert.AreNotEqual(60, com.Clock.Second);
            Assert.AreEqual(0, com.Clock.Second);

            args = new ClockEventArgs(0, 0, 61);
            com.Execute(args);
            Assert.AreNotEqual(61, com.Clock.Second);

            args = new ClockEventArgs(0, 0, int.MaxValue);
            com.Execute(args);
            Assert.AreNotEqual(int.MaxValue, com.Clock.Second);
        }
Esempio n. 26
0
        public void CommandSetHourIntervalEndTest()
        {
            CommandSet     com  = new CommandSet();
            ClockEventArgs args = new ClockEventArgs(23, 0, 0);

            // com.Clock = MockClock.Instance;

            com.Execute(args);
            Assert.AreEqual(23, com.Clock.Hour);

            args = new ClockEventArgs(24, 0, 0);
            com.Execute(args);
            Assert.AreNotEqual(24, com.Clock.Hour);
            Assert.AreEqual(0, com.Clock.Hour);

            args = new ClockEventArgs(25, 0, 0);
            com.Execute(args);
            Assert.AreNotEqual(25, com.Clock.Hour);

            args = new ClockEventArgs(int.MaxValue, 0, 0);
            com.Execute(args);
            Assert.AreNotEqual(int.MaxValue, com.Clock.Hour);
        }
Esempio n. 27
0
    public void InterpolateChange(Clock clock, ClockEventArgs args)
    {
        if (currentMonth != args.month) {
            currentMonth = args.month;

            ConnectionManager cManager = GameObject.Find("MainObject").GetComponent<ConnectionManager>();

            if (cManager) {
                cManager.Send(new RequestPrediction());
            }
        }

        if (currentDay != args.day) {
            currentDay = args.day;

            if (results.Count > 0) {
                foreach (KeyValuePair<int, int> entry in results) {
                    int group_id = entry.Key, biomass = entry.Value;

                    Species speciesGroup = gameObject.GetComponent<GameState>().GetSpeciesGroup(group_id);

                    if (speciesGroup != null) {
                        int nextBiomass = speciesGroup.size + biomass / 30;
                        gameObject.GetComponent<GameState>().UpdateSpecies(group_id, nextBiomass);

                        if (nextBiomass < 0) {
                            //gameObject.GetComponent<Chat>().SetMessage(speciesGroup.name + " decreased by " + -nextBiomass);
                        } else {
                            //gameObject.GetComponent<Chat>().SetMessage(speciesGroup.name + " increased by " + nextBiomass);
                        }
                    } else {
                        Debug.Log("Missing Species");
                    }
                }
            }
        }
    }
Esempio n. 28
0
    public void InterpolateChange(Clock clock, ClockEventArgs args)
    {
        if (currentMonth != args.month) {
            currentMonth = args.month;

            NetworkManager.Send(
                PredictionProtocol.Prepare(),
                ProcessPrediction
            );
        }

        if (currentDay != args.day) {
            currentDay = args.day;

            if (results.Count > 0) {
                foreach (KeyValuePair<int, int> entry in results) {
                    int group_id = entry.Key, biomass = entry.Value;

                    Species speciesGroup = gameObject.GetComponent<GameState>().GetSpeciesGroup(group_id);

                    if (speciesGroup != null) {
                        int nextBiomass = speciesGroup.size + biomass / 30;
                        gameObject.GetComponent<GameState>().UpdateSpecies(group_id, nextBiomass);

                        if (nextBiomass < 0) {
                            gameObject.GetComponent<Chat>().SetMessage(speciesGroup.name + " decreased by " + -nextBiomass);
                        } else {
                            gameObject.GetComponent<Chat>().SetMessage(speciesGroup.name + " increased by " + nextBiomass);
                        }
                    } else {
                        Debug.Log("Missing Species");
                    }
                }
            }
        }
    }
Esempio n. 29
0
 static void ShowProgress(object sender, ClockEventArgs e)
 {
     Console.WriteLine("Time is Now!");
 }
Esempio n. 30
0
 /// <summary>
 /// Event handler for the current games time notifier.
 /// </summary>
 /// <param name="sender">Sender of the event</param>
 /// <param name="e">Event arguments</param>
 private void WhiteClockEventHandler(object sender, ClockEventArgs e)
 {
     if (WhiteClockNotifier != null)
     WhiteClockNotifier(this, e);
 }
Esempio n. 31
0
 private void SubscriberTwoMsg(object sender, ClockEventArgs eventArgs)
 {
     Console.WriteLine("SubscriberOne:");
     Console.WriteLine("Timer value = {0}, Subscribers number = {1}", eventArgs.Seconds, eventArgs.SubNumber);
 }
Esempio n. 32
0
 public void Message(object sender, ClockEventArgs e)
 {
     Console.WriteLine("Time is over!\nDate: {0}\nNumber of milliseconds: {1}", e.Date, e.IntervalInMilliseconds);
 }
 protected virtual void OnAlarm(ClockEventArgs e)
 {
     e.Raise(this, ref Alarm);
 }
Esempio n. 34
0
 /// <summary>
 /// Event handler for the current games time notifier.
 /// </summary>
 /// <param name="sender">Sender of the event</param>
 /// <param name="e">Event arguments</param>
 private void BlackClockEventHandler(object sender, ClockEventArgs e)
 {
     if (BlackClockNotifier != null)
     BlackClockNotifier(this, e);
 }
Esempio n. 35
0
 private static void ShowNotification(object sender, ClockEventArgs e) =>
 Console.WriteLine($"Notification from: {sender.GetType().FullName}. Args: {e.NotificationData} | {e.NotificationInterval}");
 private void Do(object sender,ClockEventArgs e)
 {
     Console.WriteLine(Name + " " + e.DateTime.ToShortTimeString());
 }
Esempio n. 37
0
 static void Ring(object sender, ClockEventArgs e)
 {
     Console.WriteLine("~~~时间到啦~~~");
 }