Пример #1
0
        private void btnSet_Click(object sender, EventArgs e)
        {
            //When we click btnSet it means that we
            //1) want to set our alarm
            //2) Made a mistake and changed options and pressed set again

            //If there was an alarm set, and timenarration is on, we need to turn it off
            if (_narrationTask != null)
            {
                _tokenSource.Cancel();
            }

            //Just to be sure, delete the media player too
            if (_mediaPlayer != null)
            {
                _mediaPlayer.close();
            }

            //If there is a timer running stop it
            if (_alarmObject != null)
            {
                _alarmObject.Exit();
            }

            //Use the factorymethod to create a timerobject and start it
            _alarmObject = CreateAlarmTimer(_alarmTime);
            _alarmObject.Start();
        }
Пример #2
0
        private AlarmTimer CreateAlarmTimer(DateTime alarmtime)
        {
            //Factory method for creating a timer object
            //We instantiate a new AlarmTimer object
            //This will raise an event when the alarm time is hit (time to wake up ;-))
            //We hook a procedure to the AlarmHit event so we can do some work when the alarm is hit
            //Return the object
            var t = new AlarmTimer(alarmtime);

            t.AlarmHit += AlarmHit;
            return(t);
        }
Пример #3
0
        private void btnSet_Click(object sender, EventArgs e)
        {
            if (_alarmObject != null)
            {
                //When we click btnSet it means that we
                //1) want to set our alarm
                //2) Made a mistake and changed options and pressed set again

                //If there was an alarm set, and timenarration is on, we need to turn it off
                if (_narrationTask != null)
                    _tokenSource.Cancel();

                //Just to be sure, delete the media player too
                if (_mediaPlayer != null)
                    _mediaPlayer.close();

                //If there is a timer running stop it
                if (_alarmObject != null)
                    _alarmObject.Exit();

                btnSnooze.Enabled = false;
                btnSet.Text = "Start Alarm";
            }
            else
            {
                //When we click btnSet it means that we
                //1) want to set our alarm
                //2) Made a mistake and changed options and pressed set again

                //If there was an alarm set, and timenarration is on, we need to turn it off
                if (_narrationTask != null)
                    _tokenSource.Cancel();

                //Just to be sure, delete the media player too
                if (_mediaPlayer != null)
                    _mediaPlayer.close();

                //If there is a timer running stop it
                if (_alarmObject != null)
                    _alarmObject.Exit();

                //Use the factorymethod to create a timerobject and start it
                _alarmObject = CreateAlarmTimer(_alarmTime);
                _alarmObject.Start();

                btnSnooze.Enabled = true;
                btnSet.Text = "Stop Alarm";
            }
        }
Пример #4
0
 private AlarmTimer CreateAlarmTimer(DateTime alarmtime)
 {
     //Factory method for creating a timer object
     //We instantiate a new AlarmTimer object
     //This will raise an event when the alarm time is hit (time to wake up ;-))
     //We hook a procedure to the AlarmHit event so we can do some work when the alarm is hit
     //Return the object
     var t = new AlarmTimer(alarmtime);
     t.AlarmHit += AlarmHit;
     return t;
 }
Пример #5
0
        private void btnSnooze_Click(object sender, EventArgs e)
        {
            //If there was an alarm set, and timenarration is on, we need to turn it off
            if (_narrationTask != null)
                _tokenSource.Cancel();

            //Just to be sure, delete the media player too
            if (_mediaPlayer != null)
                _mediaPlayer.close();

            //If there is a timer running stop it
            if (_alarmObject != null)
                _alarmObject.Exit();

            //Use the factorymethod to create a timerobject and start it
            _alarmObject = CreateAlarmTimer(DateTime.Now.AddMinutes(5));
            _alarmObject.Start();
        }