Пример #1
0
        /// <summary>
        /// Event handler for when the timer elapses.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            AlarmClockEventArgs alarmEventArgs = new AlarmClockEventArgs();

            alarmEventArgs.TotalTime = this.duration;

            TimeSpan elapsedTime = e.SignalTime - this.startTime;

            alarmEventArgs.TimeRemaining = this.duration - Convert.ToInt32(elapsedTime.TotalMilliseconds);

            //------------------------------------------------------------------
            //  Check to see if we need to trigger the alarm.
            //------------------------------------------------------------------
            if (alarmEventArgs.TimeRemaining <= 0)
            {
                this.ActivateAlarm(alarmEventArgs);
            }

            //------------------------------------------------------------------
            //  Always invoke the tick event.
            //------------------------------------------------------------------
            if (this.OnTick != null)
            {
                this.OnTick(this, alarmEventArgs);
            }
        }
Пример #2
0
 /// <summary>
 /// Event handler for when the alarm clock triggers an alarm event.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void alarm_OnAlarm(object sender, AlarmClockEventArgs e)
 {
     if (this.promptedAdWarning)
     {
         this.engine.View.HideAboutToTakeAdBreakMessage();
         this.promptedAdWarning = false;
     }
     this.engine.View.ShowAdBreakMessage();
     this.engine.RunAdBreak();
 }
Пример #3
0
        /// <summary>
        /// Event handler for when the alarm clock's timer ticks.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void alarm_OnTick(object sender, AlarmClockEventArgs e)
        {
            AdTimeRemaining adTime = new AdTimeRemaining();

            adTime.TimeRemaining = new TimeSpan(0, 0, 0, 0, e.TimeRemaining);
            double progress = ((double)e.TimeRemaining / (double)e.TotalTime * 100.0);

            adTime.Percent = Convert.ToInt32(progress);
            this.engine.View.UpdateAdTimeRemaining(adTime);

            if (!this.promptedAdWarning && this.engine.Settings.Ads.WarningTimeDuration > 0 && e.TimeRemaining > 0 && e.TimeRemaining < (int)this.engine.Settings.Ads.WarningTimeDuration * 1000)
            {
                this.promptedAdWarning = true;
                this.engine.View.ShowAboutToTakeAdBreakMessage();
            }
        }
Пример #4
0
        //======================================================================
        //  Private Methods
        //======================================================================
        /// <summary>
        /// Activates the alarm using the specified event arguments
        /// </summary>
        /// <param name="e">The event arguments to use when activating the alarm.</param>
        private void ActivateAlarm(AlarmClockEventArgs e)
        {
            this.startTime  = DateTime.Now;
            e.TimeRemaining = 0;
            e.Snooze        = true;

            if (this.OnAlarm != null)
            {
                this.OnAlarm(this, e);

                //--------------------------------------------------------------
                //  If the caller has chosen not to snooze, then stop the alarm.
                //--------------------------------------------------------------
                if (!e.Snooze)
                {
                    this.Stop();
                }
            }
        }