Exemplo n.º 1
0
        public void LoadXml(XmlReader r)
        {
            //<Data>
            // <Series>
            //  <id>...</id>
            //  etc.
            // </Series>
            // <Episode>
            //  <id>...</id>
            //  blah blah
            // </Episode>
            // <Episode>
            //  <id>...</id>
            //  blah blah
            // </Episode>
            // ...
            //</Data>

            try
            {
                r.Read();
                if (r.Name != "Series")
                {
                    return;
                }

                r.Read();
                while (!r.EOF)
                {
                    if ((r.Name == "Series") && (!r.IsStartElement()))
                    {
                        break;
                    }
                    if (r.Name == "id")
                    {
                        this.TVDBCode = r.ReadElementContentAsInt();
                    }
                    else if (r.Name == "SeriesName")
                    {
                        this.Name = Helpers.ReadStringFixQuotesAndSpaces(r);
                    }
                    else if (r.Name == "lastupdated")
                    {
                        this.Srv_LastUpdated = r.ReadElementContentAsLong();
                    }
                    else if ((r.Name == "Language") || (r.Name == "language"))
                    {
                        this.Language = r.ReadElementContentAsString();
                    }
                    else if (r.Name == "TimeZone")
                    {
                        this.ShowTimeZone = r.ReadElementContentAsString();
                    }
                    else if (r.Name == "Airs_Time")
                    {
                        this.AirsTime = DateTime.Parse("20:00");

                        try
                        {
                            string theTime = r.ReadElementContentAsString();
                            if (!string.IsNullOrEmpty(theTime))
                            {
                                this.Items["Airs_Time"] = theTime;
                                DateTime airsTime;
                                if (DateTime.TryParse(theTime, out airsTime) |
                                    DateTime.TryParse(theTime.Replace('.', ':'), out airsTime))
                                {
                                    this.AirsTime = airsTime;
                                }
                                else
                                {
                                    this.AirsTime = null;
                                }
                            }
                        }
                        catch (FormatException)
                        {
                        }
                    }
                    else if (r.Name == "FirstAired")
                    {
                        string theDate = r.ReadElementContentAsString();

                        try
                        {
                            this.FirstAired          = DateTime.ParseExact(theDate, "yyyy-MM-dd", new System.Globalization.CultureInfo(""));
                            this.Items["FirstAired"] = this.FirstAired.Value.ToString("yyyy-MM-dd");
                            this.Items["Year"]       = this.FirstAired.Value.ToString("yyyy");
                        }
                        catch
                        {
                            this.FirstAired          = null;
                            this.Items["FirstAired"] = "";
                            this.Items["Year"]       = "";
                        }
                    }
                    else
                    {
                        string name = r.Name;
                        this.Items[name] = r.ReadElementContentAsString();
                    }
                    //   r->ReadOuterXml(); // skip
                } // while
            }     // try
            catch (XmlException e)
            {
                string message = "Error processing data from TheTVDB for a show.";
                if (this.TVDBCode != -1)
                {
                    message += "\r\nTheTVDB Code: " + this.TVDBCode;
                }
                if (!string.IsNullOrEmpty(this.Name))
                {
                    message += "\r\nName: " + this.Name;
                }
                if (!string.IsNullOrEmpty(this.Language))
                {
                    message += "\r\nLanguage: \"" + this.Language + "\"";
                }

                message += "\r\n" + e.Message;

                MessageBox.Show(message, "TVRename", MessageBoxButtons.OK, MessageBoxIcon.Error);

                throw new TVDBException(e.Message);
            }
        }
Exemplo n.º 2
0
        public Episode(SeriesInfo ser, Season seas, XmlReader r, CommandLineArgs args)
        {
            // <Episode>
            //  <id>...</id>
            //  blah blah
            // </Episode>

            try
            {
                this.SetDefaults(ser, seas);

                r.Read();
                if (r.Name != "Episode")
                {
                    return;
                }

                r.Read();
                while (!r.EOF)
                {
                    if ((r.Name == "Episode") && (!r.IsStartElement()))
                    {
                        break;
                    }
                    if (r.Name == "id")
                    {
                        this.EpisodeID = r.ReadElementContentAsInt();
                    }
                    else if (r.Name == "seriesid")
                    {
                        this.SeriesID = r.ReadElementContentAsInt(); // thetvdb series id
                    }
                    else if (r.Name == "seasonid")
                    {
                        this.SeasonID = r.ReadElementContentAsInt();
                    }
                    else if (r.Name == "EpisodeNumber")
                    {
                        this.EpNum = r.ReadElementContentAsInt();
                    }
                    else if (r.Name == "SeasonNumber")
                    {
                        String sn = r.ReadElementContentAsString();
                        int.TryParse(sn, out this.ReadSeasonNum);
                    }
                    else if (r.Name == "lastupdated")
                    {
                        this.Srv_LastUpdated = r.ReadElementContentAsInt();
                    }
                    else if (r.Name == "Overview")
                    {
                        this.Overview = Helpers.ReadStringFixQuotesAndSpaces(r);
                    }
                    else if (r.Name == "Rating")
                    {
                        this.EpisodeRating = Helpers.ReadStringFixQuotesAndSpaces(r);
                    }
                    else if (r.Name == "GuestStars")
                    {
                        this.EpisodeGuestStars = Helpers.ReadStringFixQuotesAndSpaces(r);
                    }
                    else if (r.Name == "Director")
                    {
                        this.EpisodeDirector = Helpers.ReadStringFixQuotesAndSpaces(r);
                    }
                    else if (r.Name == "Writer")
                    {
                        this.Writer = Helpers.ReadStringFixQuotesAndSpaces(r);
                    }
                    else if (r.Name == "EpisodeName")
                    {
                        this.Name = Helpers.ReadStringFixQuotesAndSpaces(r);
                    }
                    else if (r.Name == "FirstAired")
                    {
                        try
                        {
                            this.FirstAired = DateTime.ParseExact(r.ReadElementContentAsString(), "yyyy-MM-dd", new System.Globalization.CultureInfo(""));
                        }
                        catch
                        {
                            this.FirstAired = null;
                        }
                    }
                    else
                    {
                        if ((r.IsEmptyElement) || !r.IsStartElement())
                        {
                            r.ReadOuterXml();
                        }
                        else
                        {
                            XmlReader r2 = r.ReadSubtree();
                            r2.Read();
                            string name = r2.Name;
                            this.Items[name] = r2.ReadElementContentAsString();
                            r.Read();
                        }
                    }
                }
            }
            catch (XmlException e)
            {
                string message = "Error processing data from TheTVDB for an episode.";
                if (this.SeriesID != -1)
                {
                    message += "\r\nSeries ID: " + this.SeriesID;
                }
                if (this.EpisodeID != -1)
                {
                    message += "\r\nEpisode ID: " + this.EpisodeID;
                }
                if (this.EpNum != -1)
                {
                    message += "\r\nEpisode Number: " + this.EpNum;
                }
                if (!string.IsNullOrEmpty(this.Name))
                {
                    message += "\r\nName: " + this.Name;
                }

                message += "\r\n" + e.Message;

                if (!args.Unattended)
                {
                    MessageBox.Show(message, "TVRename", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                throw new TVDBException(e.Message);
            }
        }