/// <summary> /// Loads the time tracker data from our data file. /// </summary> private void InitializeTimeTracker() { String csvData = AtomicFileManager.ReadAtomicFile(GetDataFile()); _timeTracker.LoadCsv(csvData); // Load it into the displayed list and sort foreach (ProcessEntry entry in _timeTracker.GetDictionary().Values) { _processList.Add(entry); } // Sort it SortByColumnHeader(_currentSortedColumnName, _sortedColumnIsAscending); }
private void OnCheckProcessesTimerElapsed(object sender, ElapsedEventArgs e) { // Take the opportunity to save our label state App.Current.Dispatcher.Invoke(() => { String xml = _labelManager.ToXml(); File.WriteAllText(GetLabelMapFile(), xml); }); Process[] processes = Process.GetProcesses(); bool needsSort = false; _timeTrackerLock.WaitOne(); foreach (Process process in processes) { bool wasNew = _timeTracker.AddTime(process.ProcessName, _timePeriod); if (wasNew) { _processList.Add(_timeTracker.GetEntry(process.ProcessName)); needsSort = true; } } // Persist the tracker to disk. This could be more efficient // but this will work for now. String csvString = _timeTracker.ToCsv(); _timeTrackerLock.ReleaseMutex(); String dataFile = GetDataFile(); AtomicFileManager.WriteAtomicFile(dataFile, csvString); App.Current.Dispatcher.Invoke(() => { if (needsSort) { SortByColumnHeader(_currentSortedColumnName, _sortedColumnIsAscending); } ApplyFilters(); }); }