public void WriteFile() { StringBuilder stringBuilder = null; string messageText = ""; Exception exceptionDetails = null; StreamWriter writer = null; string line = ""; char delim = '|'; try { GetFormattedFileName(); if (File.Exists(this.FilePathName) == true) { File.Delete(this.FilePathName); } writer = new StreamWriter(this.FilePathName); if (this.personallyIdentifiableInformation != null) { line = ConvertLogic.ConvertPersonallyIdentifiableInformationToString(this.personallyIdentifiableInformation, delim); writer.WriteLine(line); } foreach (BloodGlucose bloodGlucose in this.listBloodGlucose) { line = ConvertLogic.ConvertBloodGlucoseToString(bloodGlucose, delim); writer.WriteLine(line); } foreach (PulseAndOxygen pulseAndOxygen in this.listPulseAndOxygen) { line = ConvertLogic.ConvertPulseAndOxygenToString(pulseAndOxygen, delim); writer.WriteLine(line); } } catch (Exception exception) { stringBuilder = new StringBuilder(); exceptionDetails = exception; while (exceptionDetails != null) { messageText = "\r\nMessage: " + exceptionDetails.Message + "\r\nSource: " + exceptionDetails.Source + "\r\nStack Trace: " + exceptionDetails.StackTrace + "\r\n----------\r\n"; stringBuilder.Append(messageText); exceptionDetails = exceptionDetails.InnerException; } messageText = stringBuilder.ToString(); throw new Exception(messageText); } finally { if (writer != null) { writer.Flush(); writer.Close(); writer = null; } } }
public void ReadFile() { StringBuilder stringBuilder = null; string messageText = ""; Exception exceptionDetails = null; StreamReader streamReader = null; string line = ""; BloodGlucose bloodGlucose = null; PulseAndOxygen pulseAndOxygen = null; try { SetupLists(); GetFormattedFileName(); if (File.Exists(FilePathName) == true) { streamReader = new StreamReader(FilePathName, Encoding.ASCII); while (streamReader.EndOfStream == false) { line = streamReader.ReadLine(); if (string.IsNullOrEmpty(line) == false) { if (line.StartsWith("PII") == true) { this.personallyIdentifiableInformation = ConvertLogic.ConvertPersonallyIdentifiableInformation(line, '|'); } if (line.StartsWith("PO") == true) { pulseAndOxygen = ConvertLogic.ConvertPulseAndOxygen(line, '|'); if (pulseAndOxygen != null) { this.listPulseAndOxygen.Add(pulseAndOxygen); } } if (line.StartsWith("BG") == true) { bloodGlucose = ConvertLogic.ConvertBloodGlucose(line, '|'); if (bloodGlucose != null) { this.listBloodGlucose.Add(bloodGlucose); } } } } } } catch (Exception exception) { stringBuilder = new StringBuilder(); exceptionDetails = exception; while (exceptionDetails != null) { messageText = "\r\nMessage: " + exceptionDetails.Message + "\r\nSource: " + exceptionDetails.Source + "\r\nStack Trace: " + exceptionDetails.StackTrace + "\r\n----------\r\n"; stringBuilder.Append(messageText); exceptionDetails = exceptionDetails.InnerException; } messageText = stringBuilder.ToString(); throw new Exception(messageText); } finally { if (streamReader != null) { streamReader.Close(); streamReader = null; } } }