/// <summary> /// save the data to the xml file, please catch InvalidOperationException to /// identify the existing file is broken. /// </summary> /// <param name="data">format data</param> public void save(PressureLossReportData data) { try { XmlSerializer serializer = new XmlSerializer(typeof(PressureLossReportFormats)); PressureLossReportFormats formats = new PressureLossReportFormats(); if (File.Exists(formatFileName)) { formats = getAllFormats(false); //formats can't been null, it may throw exception. //this format exists if (formats != null && formats.Contains(data)) { formats.Remove(data); } } formats.Add(data); using (TextWriter writer = new StreamWriter(formatFileName)) { serializer.Serialize(writer, formats); } } catch { //do nothing } }
/// <summary> /// /// </summary> /// <param name="path"></param> /// <param name="formatName"></param> public void remove(string formatName) { PressureLossReportFormats formats = getAllFormats(false); if (formats != null) { PressureLossReportHelper helper = PressureLossReportHelper.instance; foreach (PressureLossReportData data in formats) { if (0 == string.Compare(data.Name, formatName) && helper.Domain == data.Domain) { formats.Remove(data); break; } } clear(); save(formats); } }