public MainViewModel() { this.Settings = SettingsViewModel.ReadSettingsFile(); this.Settings.PropertyChanged += Settings_PropertyChanged; this.LastKnownDate = DateTime.Now.Date; this.DateChangeTimer = new Timer(HandleDateChangeTimerChange, null, 1000, 1000); this.GenerateLogSummaryForCurrentLogCommand = new RelayCommand <LogViewModel>(GenerateLogSummaryForCurrentLogCommand_Execute); this.LogListing = new LogListingViewModel(this.Settings); this.Summary = new TimeSummaryViewModel(); this.IdleCounter = new IdleCounter(); this.IdleCounter.PropertyChanged += IdleCounter_PropertyChanged; if (!IsInDesignMode) { this.CurrentLog = LogViewModel.LoadByDate(DateTime.Now.Date, this.Settings); } else { this.CurrentLog = new LogViewModel(DateTime.Now, this.Settings); } this.MessengerInstance.Register <LoadLogMessage>(this, HandleLoadLogMessage); }
private void HandleDateChangeTimerChange(object state) { if (DateTime.Now.Date != this.LastKnownDate) { this.LastKnownDate = DateTime.Now.Date; if (this.CurrentLog != null) { this.CurrentLog.WriteToFileAsync(); } // Create the file for the next day and save it synchronously, so that it shows up in the log listing var log = LogViewModel.LoadByDate(this.LastKnownDate, this.Settings); log.WriteToFile(); this.LogListing.LoadAllLogs(); RaiseEvent(this.QueryUserToChangeToCurrentLog); } }
internal void GoToLogForToday() { this.CurrentLog = LogViewModel.LoadByDate(this.LastKnownDate, this.Settings); }