コード例 #1
0
 public void StartStopwatch(StopwatchSettings settings)
 {
     InitializeStopwatch(settings);
     if (settings.ResetOnStart)
     {
         ResetStopwatch(settings);
     }
     dicCounters[settings.StopwatchId].IsEnabled = true;
 }
コード例 #2
0
 public void ResetStopwatchAndRecreateFile(StopwatchSettings settings)
 {
     File.Delete(settings.SpineFileName);
     InitializeStopwatch(settings);
     if (settings.ResetOnStart)
     {
         ResetStopwatch(settings);
     }
     dicCounters[settings.StopwatchId].IsEnabled = true;
     File.WriteAllText(settings.SpineFileName, $"{DateTime.Now:dd-MM-yyyy-HH-mm-ss}");
 }
コード例 #3
0
        public void ResetStopwatch(StopwatchSettings settings)
        {
            InitializeStopwatch(settings);
            dicCounters[settings.StopwatchId].Counter = 0;
            dicCounters[settings.StopwatchId].Laps.Clear();

            // Clear file contents
            if (settings.ClearFileOnReset)
            {
                SaveTimerToFile(settings.FileName, "");
            }
        }
コード例 #4
0
        private void InitializeStopwatch(StopwatchSettings settings)
        {
            string stopwatchId = settings.StopwatchId;

            if (!dicCounters.ContainsKey(stopwatchId))
            {
                dicCounters[stopwatchId] = new StopwatchStatus();
            }

            dicCounters[stopwatchId].Filename         = settings.FileName;
            dicCounters[stopwatchId].ClearFileOnReset = settings.ClearFileOnReset;
            dicCounters[stopwatchId].LapMode          = settings.LapMode;
        }
コード例 #5
0
        public void LoadStopwatchAndRun(StopwatchSettings settings)
        {
            InitializeStopwatch(settings);
            if (settings.ResetOnStart)
            {
                ResetStopwatch(settings);
            }

            if (File.Exists(settings.SpineFileName))
            {
                var dt = DateTime.ParseExact(File.ReadAllText(settings.SpineFileName), "dd-MM-yyyy-HH-mm-ss", CultureInfo.InvariantCulture);
                dicCounters[settings.StopwatchId].Counter = Convert.ToInt64((DateTime.Now - dt).TotalSeconds);
            }
            dicCounters[settings.StopwatchId].IsEnabled = true;
        }