public void PlayPause() { Session s = SavedState.Data.CurrentSession; DateTime now = DateTime.Now; if (s.Paused) { if (s.StartTime == DateTime.MinValue) { s.StartTime = now; } s.Paused = false; dispatcherTimer.Start(); stopwatch.Reset(); s.PauseTime = now; stopwatch.Start(); } else { stopwatch.Stop(); dispatcherTimer.Stop(); s.Paused = true; s.TimeElapsed += stopwatch.Elapsed; s.PauseTime = now; UpdateControls(); SavedState.Save(); } }
private void Workspace_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == nameof(SkipExtractNextRestart) && _savedstate != null) { _savedstate.SkipExtractNextRestart = SkipExtractNextRestart; _savedstate.Save(); } }
private void DialogHost_DialogClosing(object sender, DialogClosingEventArgs eventArgs) { if (eventArgs.Parameter == null) { return; } if ((bool)eventArgs.Parameter) { Session s = SavedState.Data.CurrentSession; SavedState.Data.CurrentSession = null; SavedState.Save(); SessionEnd?.Invoke(this, s); } }
private void btnStart_Click(object sender, RoutedEventArgs e) { SessionType type = listSessionType.SelectedItem as SessionType; if (type == null) { return; } SavedState.Data.CurrentSession = new Session() { TypeId = type.Id }; SavedState.Save(); SessionStart?.Invoke(this, type.Id); }
private void btnSaveSession_Click(object sender, RoutedEventArgs e) { Session s = SavedState.Data.CurrentSession; DateTime now = DateTime.Now; if (!s.Paused) { PlayPause(); } s.EndTime = s.PauseTime; SavedState.Data.SessionRecords.Add(s); SavedState.Data.CurrentSession = null; SavedState.Save(); SessionEnd?.Invoke(this, s); }
private void btnDelete_Click(object sender, RoutedEventArgs e) { SessionType type = listSessionType.SelectedItem as SessionType; if (type == null) { return; } if (SavedState.Data.SessionRecords.Select(x => x.TypeId).Contains(type.Id)) { snackbar.MessageQueue.Enqueue("Cannot delete a session type that is in use"); return; } SavedState.Data.SessionTypes.Remove(type); SavedState.Save(); snackbar.MessageQueue.Enqueue("Session type deleted"); }
private void btnNewSession_Click(object sender, RoutedEventArgs e) { NewSessionNameValidationRule.CheckDuplicate = EditSession == null; if (!NewSessionNameValidationRule.StaticValidate(newSessionName, CultureInfo.InvariantCulture).IsValid) { txtNewSessionName.Focus(); txtNewSessionName.SelectAll(); Keyboard.Focus(txtNewSessionName); return; } if (timeNewSession.SelectedTime == null && !checkCountUp.IsChecked.GetValueOrDefault()) { timeNewSession.Focus(); Keyboard.Focus(timeNewSession); return; } if (EditSession == null) { string id; do { id = Helper.RandomString(10); } while (SavedState.Data.SessionTypes.Select(x => x.Id).Contains(id)); if (checkCountUp.IsChecked.GetValueOrDefault()) { SavedState.Data.SessionTypes.Add(new SessionType(id, txtNewSessionName.Text, TimeSpan.Zero, true)); } else { SavedState.Data.SessionTypes.Add(new SessionType(id, txtNewSessionName.Text, timeNewSession.SelectedTime.Value - DateTime.Today, false)); } SavedState.Save(); expanderNewSession.IsExpanded = false; snackbar.MessageQueue.Enqueue("New session type created"); } else { EditSession.Name = txtNewSessionName.Text; EditSession.CountUp = checkCountUp.IsChecked.GetValueOrDefault(); if (EditSession.CountUp) { EditSession.Time = TimeSpan.Zero; } else { EditSession.Time = timeNewSession.SelectedTime.Value - DateTime.Today; } SavedState.Save(); foreach (DaySummary daySummary in SavedState.Data.DaySummaries) { if (daySummary.Records.Select(x => x.TypeId).Contains(EditSession.Id)) { daySummary.NotifyStatsChanged(); } } expanderNewSession.IsExpanded = false; expanderNewSession.Header = "New Session Type"; snackbar.MessageQueue.Enqueue("Session type saved"); EditSession = null; } }