/// <summary> /// Load the default SectionDatabase. /// </summary> /// <remarks>Create</remarks> /// <returns></returns> public static SectionDatabase GetDefault() { SectionDatabase sectionDatabase = SectionDatabase.DeserializeFromResource(); sectionDatabase.End = ""; return(sectionDatabase); }
/// <summary> /// Deserialize section database from embedded resource. /// </summary> private static SectionDatabase DeserializeFromResource() { XmlSerializer deserializer = new XmlSerializer(typeof(SectionDatabase)); Assembly assembly = Assembly.GetExecutingAssembly(); foreach (string resourceName in assembly.GetManifestResourceNames()) { if (resourceName.EndsWith("sections.struxml")) { using (Stream stream = assembly.GetManifestResourceStream(resourceName)) { TextReader reader = new StreamReader(stream); object obj = deserializer.Deserialize(reader); SectionDatabase sectionDatabase = (SectionDatabase)obj; reader.Close(); if (sectionDatabase.Sections.Section.Count == 0) { throw new System.ArgumentException("The project was compiled without any sections. Add sections to your project and re-compile or use another method to construct the section database (i.e DeserializeStruxml)."); } return(sectionDatabase); } } } throw new System.ArgumentException("Section library resource not in assembly! Was project compiled without embedded resource?"); }
/// <summary> /// Load a custom SectionDatabase from a .struxml file. /// </summary> /// <remarks>Create</remarks> /// <param name="filePath">File path to .struxml file.</param> /// <returns></returns> public static SectionDatabase DeserializeStruxml(string filePath) { SectionDatabase sectionDatabase = SectionDatabase.DeserializeFromFilePath(filePath); sectionDatabase.End = ""; return(sectionDatabase); }
private static SectionDatabase DeserializeFromFilePath(string filePath) { XmlSerializer deserializer = new XmlSerializer(typeof(SectionDatabase)); TextReader reader = new StreamReader(filePath); object obj = deserializer.Deserialize(reader); SectionDatabase sectionDatabase = (SectionDatabase)obj; reader.Close(); return(sectionDatabase); }
public SectionDatabase AddSection(Section section) { // check if section is null if (section == null) { throw new System.ArgumentException("Section is null."); } // clone section db SectionDatabase obj = this.DeepClone(); // add section obj.AddNewSection(section); // return return(obj); }
public static Section GetSectionByName(SectionDatabase sectionDatabase, string sectionName) { return(sectionDatabase.SectionByName(sectionName)); }