Example #1
0
        private static void ShowTime(MyClock sender)
        {
            MyTime time = sender.CurrentTime;

            Console.WriteLine($"Tick Event: " +
                              $"{time.Hour}:{time.Minute}:{time.Second}");
        }
Example #2
0
        /// /// <summary>
        /// remove alarm time from clock
        /// </summary>
        public void RemoveAlarmTime(int hour, int minute, int second)
        {
            MyTime time = new MyTime(hour, minute, second);

            if (times.ContainsKey(time.Id))
            {
                times.Remove(time.Id);
            }
        }
Example #3
0
 /// <summary>
 /// response function
 /// </summary>
 /// <param name="time">time when the Alarming call</param>
 /// <param name="seconds">how many seconds the alarming continues</param>
 public void Alarming(MyTime time, int seconds)
 {
     Console.WriteLine($"Alarm time -- {time.Hour}:{time.Minute}:{time.Second}");
     Console.WriteLine($"Contiue {seconds} seconds");
     while (seconds-- > 0)
     {
         Console.WriteLine("dingling dingling dingling dingling dingling\a");
         Thread.Sleep(1000);
     }
 }
Example #4
0
        public static void Alarming(MyClock sender)
        {
            MyTime time = sender.CurrentTime;

            Console.WriteLine($"Alarm Event: {time.Hour}:{time.Minute}:{time.Second}");
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("dingling dingling dingling");
                Thread.Sleep(1000);
            }
        }
Example #5
0
 public void Run()
 {
     while (true)
     {
         DateTime now = DateTime.Now;
         CurrentTime = new MyTime(now.Hour, now.Minute, now.Second);
         TickEvent(this);
         if (AlarmTime.Equals(CurrentTime))
         {
             AlarmEvent(this);
         }
         Thread.Sleep(1000);
     }
 }
Example #6
0
 /// <summary>
 /// constuctor
 /// </summary>
 public MyClock()
 {
     currentTime = new MyTime();
     times       = new Dictionary <int, int>();
 }
Example #7
0
 public MyClock()
 {
     CurrentTime = new MyTime();
 }