public LoggerController(LoggerGui loggerGui) { this.loggerGui = loggerGui; secTicker = new Services.Ticker(1000); modeSecTicker = new Services.Ticker(1000); measurementSecTicker = new Services.Ticker(1000); clock = new Services.Clock(); // Listen to ButtonClick Events in GUI. loggerGui.modeButtonClick += OnModeButtonClick; loggerGui.startStopEvent += OnStartStopEvent; // Listen to Tick Events of Ticker. secTicker.tick += OnTick; modeSecTicker.tick += OnTick; measurementSecTicker.tick += OnTick; // Create new mode manager and listen to its Events. modeManager = new Services.ModeManager(); modeManager.newActiveModeEvent += OnNewActiveModeEvent; // Initialize all modes in gui. loggerGui.InitializeModes(modeManager); // Disable all mode buttons at start of software. loggerGui.EnableModeButtons(false); loggerGui.EnableStartStopButtons(true); loggerGui.ResetModeCounters(); loggerGui.ResetTimeInMode(); loggerGui.ResetLog(); // Start the ticker to get current time secTicker.StartTicker(); }
private void OnStartStopEvent(object sender, StartStopEventArgs e) { Button button = e.startStopButton; bool start = e.start; if (!start) { // Create stopLogLine before showing messageBox to get proper time stamp. string stopLogLine = CreateLogLineString("STOP"); if (MessageBox.Show("Do you really want to finish measurement? Timers will be reset!", "End Measurement", MessageBoxButtons.OKCancel) == DialogResult.OK) { // Code for stop routine. logFile.AddLine(stopLogLine); loggerGui.AddLogLine(stopLogLine); modeSecTicker.StopTicker(); measurementSecTicker.StopTicker(); loggerGui.ResetTimeInMode(); modeManager.SetNoModeActive(); loggerGui.EnableModeButtons(start); loggerGui.EnableStartStopButtons(!start); loggerGui.ResetModeCounters(); loggerGui.SetTimeInMeasurement("00:00:00"); loggerGui.SetRecordingStatus(start); } } else { // Check if a valid file path was selected before. if (loggerGui.FilePathOk()) { // Code for start routine. measurementStartTime = clock.GetDateTime(); InitializeLogFile(); string startLogLine = CreateLogLineString("START"); measurementSecTicker.StartTicker(); modeManager.SetNoModeActive(); loggerGui.EnableModeButtons(start); loggerGui.EnableStartStopButtons(!start); loggerGui.SetRecordingStatus(start); logFile.AddLine(startLogLine); loggerGui.ResetLog(); loggerGui.AddLogLine(startLogLine); } else { MessageBox.Show("Select a valid folder for the log file first!", "Folder missing", MessageBoxButtons.OK); } } }