Esempio n. 1
0
 public void Start()
 {
     if (Running)
     {
         throw new Exception("Trying to start timer while it is already running.");
     }
     StartTime  = DateTime.Now;
     FinishTime = null;
     TimerStarted?.Invoke(this, EventArgs.Empty);
 }
 private void OnTimerStarted(TimerStarted @event)
 {
     menu.Update(mutator =>
     {
         mutator.UpdateRemainingTime(@event.RemainingTime.ToTimeString());
         mutator.EnableStartPomodoroItem(@event.IntervalType != IntervalType.Pomodoro);
         mutator.EnableStartShortBreakItem(@event.IntervalType != IntervalType.ShortBreak);
         mutator.EnableStartLongBreakItem(@event.IntervalType != IntervalType.LongBreak);
         mutator.EnableStopTimerItem(true);
     });
 }
Esempio n. 3
0
    IEnumerator TimerCoroutine()
    {
        TimerStarted?.Invoke(TimeLeft);
        while (_timeLeft > 0)
        {
            yield return(new WaitForSeconds(TimerStep));

            TimeLeft -= TimerStep;
        }
        EndGame();
    }
Esempio n. 4
0
        protected async void Hibernate_Click(object sender, RoutedEventArgs e)
        {
            DialogWindow dialog = new DialogWindow();
            bool?        result = dialog.ShowDialog();

            if (dialog.DialogResult == true)
            {
                TimerStarted?.Invoke(this, dialog.DWTimer);
                Action action = new Action(HibernateComputer);
                this.DataContext = dialog.DWTimer;
                await dialog.DWTimer.Start(action);
            }
        }
Esempio n. 5
0
 public static void StartTimer() //Метод, который должен вызываться в FixUpdate
 {
     if (_timer >= 0)
     {
         _timer -= Time.deltaTime;
         TimerStarted?.Invoke($"Время осталось: {Mathf.Round(_timer).ToString()}"); //Событие при старте таймера.
     }
     else
     {
         TimerStatus();
         TimerEnded?.Invoke(String.Empty); //Событие при остановке таймера.
     }
 }
Esempio n. 6
0
        protected async void Restart_Click(object sender, RoutedEventArgs e)
        {
            DialogWindow dialog = new DialogWindow();
            bool?        result = dialog.ShowDialog();

            if (dialog.DialogResult == true)
            {
                TimerStarted?.Invoke(this, dialog.DWTimer);
                Action action = new Action(RestartComputer);
                this.DataContext = dialog.DWTimer;
                await dialog.DWTimer.Start(action);
            }

            //Action action = new Action(() => MessageBox.Show("Timer just went off", "Restart"));
            //dialog.DWTimer.Start(action);
        }
Esempio n. 7
0
        /// <summary>
        ///     Start the <see langword="timer" />
        /// </summary>
        public void Start()
        {
            if (IsBusy)
            {
                throw new InvalidOperationException("Unable to start timer: it is already running");
            }
            IsBusy           = true;
            RemainingSeconds = Seconds;
            TimerStarted?.Invoke(this);
            for (var i = 0; i < Seconds; i++)
            {
                RemainingSeconds = Seconds - i - 1;
                Thread.Sleep(1000);
                TimerTick?.Invoke(this);
            }

            TimerFinished?.Invoke(this);
            IsBusy = false;
        }
Esempio n. 8
0
        private async void ExecuteTimer()
        {
            TimerStarted         timerStarted  = (name, seconds) => OutputWriteLine($"'{name}' started for {seconds} seconds.");
            Action <string, int> timerFinished = (name, seconds) => OutputWriteLine($"'{name}' finished.");

            ICutDownNotifier[] notifiers =
            {
                new NotifierByDelegate(timerStarted, timerFinished),
                new NotifierByLambda(timerStarted,   timerFinished),
                new NotifierByMethod(timerStarted,   timerFinished)
            };

            notifiers[0].Init(new MyTimer.MyTimer("Чтение задания", TimerSeconds));
            notifiers[1].Init(new MyTimer.MyTimer("Выполнение задания", TimerSeconds));
            notifiers[2].Init(new MyTimer.MyTimer("Проверка задания перед отправкой", TimerSeconds));

            foreach (var notifier in notifiers)
            {
                await Task.Run(() => notifier.Run());
            }
        }
Esempio n. 9
0
        protected async void Shutdown_Click(object sender, RoutedEventArgs e)
        {
            DialogWindow dialog = new DialogWindow();
            bool?        result = dialog.ShowDialog();

            if (dialog.DialogResult == true)
            {
                TimerStarted?.Invoke(this, dialog.DWTimer);
                Action action = new Action(ShutdownComputer);

                // Now once the dialog returns successfully.
                // We are going to pass it DWTimer object to this control's DataContext.
                // This will make it possible to bind to the properties of be DataContext as required.
                // Can you set the DataContext to the DWTimer Object?...

                // No.. I have forgotten most of what I read in Data Binding
                //
                // That's too bad, It's quite straight forward actually.
                // Now, I won't forget again

                this.DataContext = dialog.DWTimer;
                // And that does that.
                // Replicate it around the other methods.
                // Done.
                // Awesome.
                // Wait a second...
                // Binding it in MainView doesn't seem really useful...
                // MainView only contains buttons...
                // I have a small idea.

                // We create an event here, and then invoke it once we
                // Okay.. I am following your lead
                await dialog.DWTimer.Start(action);
            }

            //Action action = new Action(() => MessageBox.Show("Timer just went off", "Shutdown"));
            //dialog.DWTimer.Start(action);
        }
Esempio n. 10
0
 private void OnTimerStartedEvent()
 {
     TimerStarted?.Invoke(this, new TimerEventArgs(_timerHasEnded));
 }
Esempio n. 11
0
 internal void EmitTimerStarted(IEntry <TeaTimerDefinition> entry)
 {
     TimerStarted?.Invoke(this, new TeaTimerEventArgs(entry));
 }
Esempio n. 12
0
 public async void Start(string setedTime)
 {
     TimerStarted?.Invoke();
     await Worker(setedTime);
 }
Esempio n. 13
0
 private void OnTimerStarted(TimerStarted @event)
 {
     notifyIcon.Icon = GetIcon(@event.IntervalType);
 }
Esempio n. 14
0
 /// <summary>
 ///     Creates an event handler with the specified <see langword="delegates" />
 /// </summary>
 /// <param name="timerStarted">A delegate representing a method to be executed when timer will start.</param>
 /// <param name="timerFinished">A delegate representing a method to be executed when timer will be finished.</param>
 public NotifierByDelegate(TimerStarted timerStarted, Action <string, int> timerFinished) : base(timerStarted,
                                                                                                 timerFinished)
 {
 }
Esempio n. 15
0
 protected Notifier(TimerStarted timerStarted, Action <string, int> timerFinished)
 {
     timerStartedDelegate  = timerStarted;
     timerFinishedDelegate = timerFinished;
 }
Esempio n. 16
0
        /// <summary>
        /// Starts a new timer with the passed name and the given duration.
        /// Queues a <see cref="TimerStarted"/> incident and sets
        /// <see cref="SystemVariables.StartedTimer"/>.
        /// </summary>
        /// <param name="name">Name of the timer to start.</param>
        /// <param name="duration">Duration of the timer.</param>
        private void StartTimer(string name, float duration)
        {
            if (timers.ContainsKey(name))
            {
                string errorMessage = string.Format("A timer named '{0}' already exists.", name);
                throw new ArgumentException(errorMessage);
            }

            if (duration < 0f)
            {
                duration = 0f;
            }

            Timer timer = new Timer();
            timer.Name = name;
            timer.Duration = duration;
            timer.ElapsedTime = 0f;
            timer.IsRunning = true;

            timers.Add(name, timer);

            // ToDo: Set SystemVariable StartedTimer
            //SystemVariables.StartedTimer = name;

            TimerStarted e = new TimerStarted();
            e.Name = name;
            e.Duration = duration;

            QueueEvent(e);
        }
Esempio n. 17
0
 private void OnTimerStarted(TimerStarted @event)
 {
     EnterState(GetRunningTimerStateFor(@event.IntervalType), @event.RemainingTime);
 }
Esempio n. 18
0
 /// <summary>
 ///     Creates an event handler with the specified <see langword="delegates" />
 /// </summary>
 /// <param name="timerStarted">A delegate representing a method to be executed when timer will start.</param>
 /// <param name="timerFinished">A delegate representing a method to be executed when timer will be finished.</param>
 public NotifierByLambda(TimerStarted timerStarted, Action <string, int> timerFinished) : base(timerStarted,
                                                                                               timerFinished)
 {
 }