Specifies a set of values used to start a timer.
Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Timer"/> class.
        /// </summary>
        /// <param name="timerInfo">A <see cref="TimerInfo"/> representing the state of the <see
        /// cref="Timer"/>.</param>
        public Timer(TimerInfo timerInfo)
            : base(timerInfo)
        {
            this.timerStart = TimerStart.FromTimerStartInfo(timerInfo.TimerStart);
            this.options    = TimerOptions.FromTimerOptionsInfo(timerInfo.Options) ?? new TimerOptions();

            this.UpdateHourglassTimer();
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a <see cref="TimerStartInfo"/> for a <see cref="TimerStart"/>.
        /// </summary>
        /// <param name="timerStart">A <see cref="TimerStart"/>.</param>
        /// <returns>The <see cref="TimerStartInfo"/> for the <see cref="TimerStart"/>.</returns>
        public static TimerStartInfo FromTimerStart(TimerStart timerStart)
        {
            if (timerStart == null)
            {
                return null;
            }

            return timerStart.ToTimerStartInfo();
        }
Esempio n. 3
0
        /// <summary>
        /// Updates the <see cref="Timer"/> state.
        /// </summary>
        private void UpdateHourglassTimer()
        {
            this.timerStart              = this.State != TimerState.Stopped ? this.timerStart : null;
            this.timeLeftAsPercentage    = this.GetTimeLeftAsPercentage();
            this.timeElapsedAsPercentage = this.GetTimeElapsedAsPercentage();
            this.timeLeftAsString        = this.GetTimeLeftAsString();
            this.timeElapsedAsString     = this.GetTimeElapsedAsString();
            this.timeExpiredAsString     = this.GetTimeExpiredAsString();

            this.OnPropertyChanged("TimerStart", "TimeLeftAsPercentage", "TimeElapsedAsPercentage", "TimeLeftAsString", "TimeElapsedAsString", "TimeExpiredAsString");
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Timer"/> class.
        /// </summary>
        /// <param name="options">Configuration data for this timer.</param>
        public Timer(TimerOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            this.timerStart = null;
            this.options    = TimerOptions.FromTimerOptions(options);

            this.UpdateHourglassTimer();
        }
        /// <summary>
        /// Adds a <see cref="TimerStart"/> to the list of recent <see cref="TimerStart"/> objects.
        /// </summary>
        /// <param name="timerStart">A <see cref="TimerStart"/>.</param>
        public void Add(TimerStart timerStart)
        {
            // Remove all equivalent objects
            this.timerStarts.RemoveAll(e => e.ToString() == timerStart.ToString());

            // Add the object to the top of the list
            this.timerStarts.Insert(0, timerStart);

            // Limit the number of objects in the list
            while (this.timerStarts.Count > Capacity)
            {
                this.timerStarts.RemoveAt(this.timerStarts.Count - 1);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Starts the timer.
        /// </summary>
        /// <param name="newTimerStart">A <see cref="TimerStart"/>.</param>
        /// <returns>A value indicating whether the timer was started successfully.</returns>
        /// <exception cref="ObjectDisposedException">If the timer has been disposed.</exception>
        public bool Start(TimerStart newTimerStart)
        {
            this.ThrowIfDisposed();

            DateTime start = DateTime.Now;
            DateTime end;

            if (newTimerStart != null && newTimerStart.TryGetEndTime(start, out end))
            {
                this.timerStart = newTimerStart;
                this.OnPropertyChanged("TimerStart");

                this.Start(start, end);
                return(true);
            }

            return(false);
        }
Esempio n. 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Timer"/> class.
        /// </summary>
        /// <param name="options">Configuration data for this timer.</param>
        public Timer(TimerOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            this.timerStart = null;
            this.options = TimerOptions.FromTimerOptions(options);

            this.UpdateHourglassTimer();
        }
Esempio n. 8
0
        /// <summary>
        /// Updates the <see cref="Timer"/> state.
        /// </summary>
        private void UpdateHourglassTimer()
        {
            this.timerStart = this.State != TimerState.Stopped ? this.timerStart : null;
            this.timeLeftAsPercentage = this.GetTimeLeftAsPercentage();
            this.timeElapsedAsPercentage = this.GetTimeElapsedAsPercentage();
            this.timeLeftAsString = this.GetTimeLeftAsString();
            this.timeElapsedAsString = this.GetTimeElapsedAsString();
            this.timeExpiredAsString = this.GetTimeExpiredAsString();

            this.OnPropertyChanged("TimerStart", "TimeLeftAsPercentage", "TimeElapsedAsPercentage", "TimeLeftAsString", "TimeElapsedAsString", "TimeExpiredAsString");
        }
Esempio n. 9
0
        /// <summary>
        /// Starts the timer.
        /// </summary>
        /// <param name="newTimerStart">A <see cref="TimerStart"/>.</param>
        /// <returns>A value indicating whether the timer was started successfully.</returns>
        /// <exception cref="ObjectDisposedException">If the timer has been disposed.</exception>
        public bool Start(TimerStart newTimerStart)
        {
            this.ThrowIfDisposed();

            DateTime start = DateTime.Now;
            DateTime end;
            if (newTimerStart != null && newTimerStart.TryGetEndTime(start, out end))
            {
                this.timerStart = newTimerStart;
                this.OnPropertyChanged("TimerStart");

                this.Start(start, end);
                return true;
            }

            return false;
        }
Esempio n. 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Timer"/> class.
        /// </summary>
        /// <param name="timerInfo">A <see cref="TimerInfo"/> representing the state of the <see
        /// cref="Timer"/>.</param>
        public Timer(TimerInfo timerInfo)
            : base(timerInfo)
        {
            this.timerStart = TimerStart.FromTimerStartInfo(timerInfo.TimerStart);
            this.options = TimerOptions.FromTimerOptionsInfo(timerInfo.Options) ?? new TimerOptions();

            this.UpdateHourglassTimer();
        }
Esempio n. 11
0
        /// <summary>
        /// Opens the <see cref="TimerWindow"/> if it is not already open and displays a new timer started with the
        /// specified <see cref="TimerStart"/>.
        /// </summary>
        /// <param name="timerStart">A <see cref="TimerStart"/>.</param>
        public void Show(TimerStart timerStart)
        {
            // Keep track of the input
            this.LastTimerStart = timerStart;

            // Start a new timer
            Timer newTimer = new Timer(this.Options);
            if (!newTimer.Start(timerStart))
            {
                this.Show();
                this.SwitchToInputMode();
                this.BeginValidationErrorAnimation();
                return;
            }

            TimerManager.Instance.Add(newTimer);
            TimerStartManager.Instance.Add(timerStart);

            // Show the window
            this.Show(newTimer);
        }
Esempio n. 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TimerWindow"/> class.
 /// </summary>
 /// <param name="timerStart">The <see cref="TimerStart"/> to start when the window loads, or <c>null</c> if no
 /// <see cref="TimerStart"/> is to be started.</param>
 public TimerWindow(TimerStart timerStart)
     : this()
 {
     this.timerStartToStartOnLoad = timerStart;
 }
Esempio n. 13
0
        /// <summary>
        /// Invoked when the <see cref="TimerWindow"/> is laid out, rendered, and ready for interaction.
        /// </summary>
        /// <param name="sender">The <see cref="TimerWindow"/>.</param>
        /// <param name="e">The event data.</param>
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            // Deal with any input or timer set in the constructor
            if (this.timerStartToStartOnLoad != null)
            {
                this.Show(this.timerStartToStartOnLoad);
                this.timerStartToStartOnLoad = null;
                this.timerToResumeOnLoad = null;
            }
            else if (this.timerToResumeOnLoad != null)
            {
                this.Show(this.timerToResumeOnLoad);
                this.timerStartToStartOnLoad = null;
                this.timerToResumeOnLoad = null;
            }

            // Minimize to notification area if required
            if (this.WindowState == WindowState.Minimized && Settings.Default.ShowInNotificationArea)
            {
                this.MinimizeToNotificationArea();
            }
        }