/// <summary> /// Deserializes an existing chapter file and returns it as a new Chapters instance. /// </summary> /// <param name="chapterFile">The full path of the chapter file to process.</param> /// <returns>A shining, brand new Chapters instance.</returns> public static ChaptersObject LoadChapterFile(string chapterFile) { XmlSerializer xmlRead = new XmlSerializer(typeof(ChaptersObject)); var chapters = new ChaptersObject(); using (FileStream fileStream = new FileStream(chapterFile, FileMode.Open)) { chapters = (ChaptersObject)xmlRead.Deserialize(fileStream); } return chapters; }
/// <summary> /// Deserializes an existing chapter file and returns it as a new Chapters instance. /// </summary> /// <param name="chapterFile">The full path of the chapter file to process.</param> /// <returns>A shining, brand new Chapters instance.</returns> public static ChaptersObject LoadChapterFile(string chapterFile) { XmlSerializer xmlRead = new XmlSerializer(typeof(ChaptersObject)); var chapters = new ChaptersObject(); using (FileStream fileStream = new FileStream(chapterFile, FileMode.Open)) { chapters = (ChaptersObject)xmlRead.Deserialize(fileStream); } return(chapters); }
/// <summary> /// Diagnostic. Demo method for chapter file parsing. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void parseXmlButton_Click(object sender, EventArgs e) { DialogResult result = openFileDialog3.ShowDialog(); if (result == DialogResult.OK) { try { ChaptersObject chapter = ChaptersObject.LoadChapterFile(openFileDialog3.FileName); MessageBox.Show(chapter.InterpretChapterFile()); chapter.SaveChapterFile(Path.Combine(Program.defaultPath, Path.GetFileNameWithoutExtension(openFileDialog3.FileName) + "_parsed" + Path.GetExtension(openFileDialog3.FileName))); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }