public Timer() { if (System.Diagnostics.Debugger.IsAttached) { m_SprintDuration = TimeSpan.FromSeconds(10); m_HomeStraightDuration = TimeSpan.FromSeconds(1); m_BreakDuration = TimeSpan.FromSeconds(5); m_MaxBreakDuration = TimeSpan.FromSeconds(10); } else { m_SprintDuration = TimeSpan.FromMinutes(25); m_HomeStraightDuration = TimeSpan.FromMinutes(1); m_BreakDuration = TimeSpan.FromMinutes(5); m_MaxBreakDuration = TimeSpan.FromMinutes(60); } m_InternalStates = new Dictionary<TimerState, ITimerState>(); m_InternalStates.Add(TimerState.Ready, new ReadyTimerState(this)); m_InternalStates.Add(TimerState.Sprint, new SprintTimerState(this)); m_InternalStates.Add(TimerState.HomeStraight, new HomeStraightTimerState(this)); m_InternalStates.Add(TimerState.Break, new BreakTimerState(this)); m_InternalStates.Add(TimerState.BreakOverrun, new BreakOverrunTimerState(this)); m_Timer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(1) }; m_Timer.Tick += (s, e) => m_InternalState.HandleSecondElapsed(); _State = TimerState.Ready; m_InternalState = m_InternalStates[_State]; m_InternalState.OnEnter(); }
public Timer() { if (System.Diagnostics.Debugger.IsAttached) { m_SprintDuration = TimeSpan.FromSeconds(10); m_HomeStraightDuration = TimeSpan.FromSeconds(1); m_BreakDuration = TimeSpan.FromSeconds(5); m_MaxBreakDuration = TimeSpan.FromSeconds(10); } else { m_SprintDuration = TimeSpan.FromMinutes(25); m_HomeStraightDuration = TimeSpan.FromMinutes(1); m_BreakDuration = TimeSpan.FromMinutes(5); m_MaxBreakDuration = TimeSpan.FromMinutes(60); } m_InternalStates = new Dictionary <TimerState, ITimerState>(); m_InternalStates.Add(TimerState.Ready, new ReadyTimerState(this)); m_InternalStates.Add(TimerState.Sprint, new SprintTimerState(this)); m_InternalStates.Add(TimerState.HomeStraight, new HomeStraightTimerState(this)); m_InternalStates.Add(TimerState.Break, new BreakTimerState(this)); m_InternalStates.Add(TimerState.BreakOverrun, new BreakOverrunTimerState(this)); m_Timer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(1) }; m_Timer.Tick += (s, e) => m_InternalState.HandleSecondElapsed(); _State = TimerState.Ready; m_InternalState = m_InternalStates[_State]; m_InternalState.OnEnter(); }
private void OnNewStateGenerated(ITimerState newState) { m_TimerState.NewStateGenerated -= OnNewStateGenerated; m_TimerState.Dispose(); newState.NewStateGenerated += OnNewStateGenerated; m_TimerState = newState; }
public Timer() { m_TimerState = new WorkState(Properties.Settings.Default.WorkTime); m_TimerState.NewStateGenerated += OnNewStateGenerated; m_Timer = new DispatcherTimer(); m_Timer.Interval = TimeSpan.FromSeconds(1); m_Timer.Tick += OnEachSecond; m_Timer.Start(); }
protected virtual void OnNewStateGenerated(ITimerState newState) { var handler = NewStateGenerated; if (handler == null) { return; } foreach (Action <ITimerState> dlgt in handler.GetInvocationList()) { try { dlgt(newState); } catch { } } }
public IntervalHandler(ITimerState ts, SmartThreadPool ReaderThreadPool) { s = ts; ReaderThreads = ReaderThreadPool; }
public void OnClickPauseButton() { ITimerState state = timerState.Value.OnPauseCommand(); timerState.Value = state ?? timerState.Value; }
public void OnClickStopButton() { ITimerState state = timerState.Value.OnStopCommand(); timerState.Value = state ?? timerState.Value; }
public void OnClickResetButton() { ITimerState state = timerState.Value.OnResetCommand(); timerState.Value = state ?? timerState.Value; }
/// <summary> /// Перейти к состоянию /// </summary> /// <param name="_state">Состояние к которому требуется перейти</param> internal void GoToState(ITimerState _state) { if (_state is PlayState) // Если переходим в плей { if (state is StopState) // Если перешли из Stop CurrentTime = CurrentPreriodTime; timer.Start(); // То запустить таймер } else if (_state is StopState) // Если нет { timer.Stop(); // То остановить CurrentTime = CurrentPreriodTime; } else if (_state is PauseState) { timer.Stop(); // То остановить } state = _state; OnUpdate(); // Обновить }
public void SwitchToForeground() { currentState?.Dispose(); currentState = new ForegroundTimerState(); currentState.AddListener(OnTick); }