public void WriteSettings(LimsSimulatorSettings limsSimulatorSettings) { try { var settingsFile = _GetSettingsFilePath(); LogWriter.WriteDebugMessage( string.Format("Writing settings file. SampleFile: '{0}' DestinationPath: '{1}' DueTime: '{2}'", limsSimulatorSettings.SampleFile, limsSimulatorSettings.DestinationPath, limsSimulatorSettings.DueTime)); var fileStream = new FileStream(settingsFile, FileMode.Create, FileAccess.Write, FileShare.None); var settingsWriter = new StreamWriter(fileStream); settingsWriter.WriteLine(limsSimulatorSettings.SampleFile); settingsWriter.WriteLine(limsSimulatorSettings.DestinationPath); settingsWriter.WriteLine(limsSimulatorSettings.DueTime.TotalSeconds); settingsWriter.Close(); LogWriter.WriteDebugMessage("Settings file was successfully written."); } catch (Exception exception) { LogWriter.WriteFailureMessage("Writing settings file failed!"); LogWriter.WriteException(exception); throw; } }
public void GetSettings(out LimsSimulatorSettings limsSimulatorSettings) { try { limsSimulatorSettings = new LimsSimulatorSettings(); var settingsFile = _GetSettingsFilePath(); LogWriter.WriteDebugMessage(string.Format("Reading settings. File: '{0}'", settingsFile)); if (!File.Exists(settingsFile)) { limsSimulatorSettings.SampleFile = string.Empty; limsSimulatorSettings.DestinationPath = Environment.GetEnvironmentVariable("SYSTEMDRIVE") + @"\Anton Paar\Davis 5\Data Monitoring\"; limsSimulatorSettings.DueTime = new TimeSpan(0, 0, 0, 1); LogWriter.WriteDebugMessage("Settings file not found, using default settings."); return; } var fileStream = new FileStream(settingsFile, FileMode.Open, FileAccess.Read, FileShare.None); var settingsReader = new StreamReader(fileStream); limsSimulatorSettings.SampleFile = settingsReader.ReadLine(); limsSimulatorSettings.DestinationPath = settingsReader.ReadLine(); limsSimulatorSettings.DueTime = new TimeSpan(0, 0, Convert.ToInt16(settingsReader.ReadLine())); settingsReader.Close(); LogWriter.WriteDebugMessage(string.Format("Settings file found. SampleFile: '{0}' DestinationPath: '{1}' DueTime: '{2}'", limsSimulatorSettings.SampleFile, limsSimulatorSettings.DestinationPath, limsSimulatorSettings.DueTime)); } catch (Exception exception) { LogWriter.WriteFailureMessage("Reading settings file failed!"); LogWriter.WriteException(exception); throw; } }