Пример #1
0
        /// <summary>
        /// Load the default SectionDatabase.
        /// </summary>
        /// <remarks>Create</remarks>
        /// <returns></returns>
        public static SectionDatabase GetDefault()
        {
            SectionDatabase sectionDatabase = SectionDatabase.DeserializeFromResource();

            sectionDatabase.End = "";
            return(sectionDatabase);
        }
Пример #2
0
        /// <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?");
        }
Пример #3
0
        /// <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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
 public static Section GetSectionByName(SectionDatabase sectionDatabase, string sectionName)
 {
     return(sectionDatabase.SectionByName(sectionName));
 }