Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private bool ReadEpisodeInfos()
- {
- cfgReader = new XmlTextReader("episodeInfos.xml");
- cfgReader.WhitespaceHandling = WhitespaceHandling.None;
- try
- {
- while (cfgReader.Read())
- {
- if (cfgReader.NodeType == XmlNodeType.EndElement || cfgReader.Name == "")
- {
- continue;
- }
- else if (cfgReader.NodeType == XmlNodeType.Element)
- {
- if (cfgReader.Name.Equals("Season1"))
- {
- HandleEpisode();
- }
- }
- }
- }
- catch (FileNotFoundException)
- {
- MessageBox.Show("Couldn't open \"episodeInfos.xml\"! Please download again!", "Error opening \"episodeInfos.xml\"", MessageBoxButton.OK);
- this.Close();
- }
- catch (Exception)
- {
- MessageBox.Show("Couldn't load \"episodeInfos.xml\"! Make sure it's not opened. You might also check the syntax.", "Error loading \"episodeInfos.xml\"", MessageBoxButton.OK);
- this.Close();
- }
- cfgReader.Close();
- return true;
- }
- private void HandleEpisode()
- {
- int seasonNr;
- int episodeNr;
- try
- {
- DateTime tmp;
- for (seasonNr = 0; seasonNr < season.Length; seasonNr++)
- {
- cfgReader.Read();
- for (episodeNr = 0; episodeNr < season[seasonNr].episode.Length; episodeNr++)
- {
- cfgReader.MoveToFirstAttribute();
- season[seasonNr].episode[episodeNr].id = cfgReader.ReadContentAsInt();
- cfgReader.MoveToNextAttribute();
- season[seasonNr].episode[episodeNr].title = cfgReader.ReadContentAsString();
- cfgReader.MoveToNextAttribute();
- DateTime.TryParse(cfgReader.Value, out tmp);
- season[seasonNr].episode[episodeNr].airDate = tmp;
- cfgReader.MoveToNextAttribute();
- season[seasonNr].episode[episodeNr].views = cfgReader.ReadContentAsDouble();
- cfgReader.MoveToContent();
- season[seasonNr].episode[episodeNr].description = cfgReader.ReadElementContentAsString();
- }
- cfgReader.Read();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("An error occured while loading episode information.\nError message:\n" + ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement