Esempio n. 1
0
        public void LoadJSON(JObject r)
        {
            //r should be a series of name/value pairs (ie a JArray of JPropertes)
            //save them all into the Items array for safe keeping
            foreach (JProperty seriesItems in r.Children <JProperty>())
            {
                if (seriesItems.Name == "aliases")
                {
                    this.Items[seriesItems.Name] = JSONHelper.flatten((JToken)seriesItems.Value, "|");
                }
                else if (seriesItems.Name == "genre")
                {
                    this.Items[seriesItems.Name] = JSONHelper.flatten((JToken)seriesItems.Value, "|");
                }
                else
                {
                    try
                    {
                        if (seriesItems.Value != null)
                        {
                            this.Items[seriesItems.Name] = (string)seriesItems.Value;
                        }
                    }
                    catch (ArgumentException ae) {
                        logger.Warn("Could not parse Json for " + seriesItems.Name + " :" + ae.Message);
                    }
                }
            }

            this.TVDBCode = (int)r["id"];
            if ((string)r["seriesName"] != null)
            {
                this.Name = (string)r["seriesName"];
            }

            long updateTime;

            if (long.TryParse((string)r["lastUpdated"], out updateTime))
            {
                this.Srv_LastUpdated = updateTime;
            }
            else
            {
                this.Srv_LastUpdated = 0;
            }

            string theDate = (string)r["firstAired"];

            try
            {
                if (!String.IsNullOrEmpty(theDate))
                {
                    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");
                }
                else
                {
                    this.FirstAired          = null;
                    this.Items["firstAired"] = "";
                    this.Items["Year"]       = "";
                }
            }
            catch
            {
                this.FirstAired          = null;
                this.Items["firstAired"] = "";
                this.Items["Year"]       = "";
            }

            this.AirsTime = DateTime.Parse("20:00");
            string theAirsTime = (string)r["airsTime"];

            try
            {
                if (!string.IsNullOrEmpty(theAirsTime))
                {
                    this.Items["airsTime"] = theAirsTime;
                    DateTime airsTime;
                    if (DateTime.TryParse(theAirsTime, out airsTime) |
                        DateTime.TryParse(theAirsTime.Replace('.', ':'), out airsTime))
                    {
                        this.AirsTime = airsTime;
                    }
                    else
                    {
                        this.AirsTime = null;
                    }
                }
            }
            catch (FormatException)
            {
            }
        }