コード例 #1
0
        private void Update()
        {
            Timer.Stop();

            var nextTimerLength = state.Func(
                pomStateInactive => TaskDuration,
                pomStateActive => PomodoroCounter == SetLength
                    ? LongBreakDuration
                    : ShortBreakDuration,
                pomStateBreak => TaskDuration
                );

            PomodoroCounter = state.Func(
                pomStateInactive => PomodoroCounter,
                pomStateActive => PomodoroCounter,
                pomStateBreak => PomodoroCounter == SetLength
                    ? 1
                    : PomodoroCounter + 1
                );
            state = state.Transition(
                pomStateInactive => pomStateInactive,
                pomStateActive => pomStateActive.Continue(),
                pomStateBreak => pomStateBreak.Continue()
                );
            CurrentDuration = GetCurrentDuration();
            Timer           = new Timer(nextTimerLength.TotalMilliseconds);
            Timer.Elapsed  += TimerElapsed;
            SecondsElapsed  = 0;

            Timer.Start();
        }
コード例 #2
0
        public void Stop()
        {
            Timer?.Stop();
            Metronome?.Stop();


            state = state.Transition(
                pomStateInactive => pomStateInactive,
                pomStateActive => pomStateActive.Stop(),
                pomStateBreak => pomStateBreak.Stop()
                );
        }
コード例 #3
0
        private PomodoroTimer(Task Task,
                              IPomodoroState State,
                              TimeSpan TaskDuration,
                              TimeSpan ShortBreakDuration,
                              TimeSpan LongBreakDuration,
                              int SetLength = 4)
        {
            this.Task               = Task;
            state                   = State;
            this.TaskDuration       = TaskDuration;
            this.ShortBreakDuration = ShortBreakDuration;
            this.LongBreakDuration  = LongBreakDuration;
            this.SetLength          = SetLength;

            Metronome          = new Timer(1000);
            Metronome.Elapsed += (o, e) => SecondsElapsed++;
        }
コード例 #4
0
        public void Start()
        {
            state = state.Transition(
                pomStateInactive => pomStateInactive.Start(),
                pomStateActive => pomStateActive,
                pomStateBreak => pomStateBreak
                );
            CurrentDuration = GetCurrentDuration();
            PomodoroCounter = 1;
            SecondsElapsed  = 0;
            Timer           = new Timer(TaskDuration.TotalMilliseconds);
            Timer.Elapsed  += TimerElapsed;

            Timer.Start();
            Metronome.Start();
            OnStateChanged();
        }