public void StartStopwatch(StopwatchSettings settings)
 {
     InitializeStopwatch(settings);
     if (settings.ResetOnStart)
     {
         ResetStopwatch(settings);
     }
     dicCounters[settings.StopwatchId].IsEnabled = true;
 }
 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}");
 }
        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, "");
            }
        }
        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;
        }
        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;
        }