private void doWork(string seriesID) { XmlNode banners = OnlineAPI.getBannerList(Int32.Parse(seriesID)); if (banners == null) { return; } if (Helper.getCorrespondingSeries(Int32.Parse(seriesID)) == null) { return; } string SeriesName = Helper.getCorrespondingSeries(Int32.Parse(seriesID)).ToString(); List <WideBannerSeries> widebannerSeriesList = new List <WideBannerSeries>(); List <PosterSeries> posterSeriesList = new List <PosterSeries>(); List <PosterSeason> posterSeasonList = new List <PosterSeason>(); SeriesBannersMap map = new SeriesBannersMap(); map.SeriesID = seriesID; #region Series WideBanners foreach (XmlNode banner in banners.SelectNodes("/Banners/Banner[BannerType='series']")) { WideBannerSeries seriesWideBanners = new WideBannerSeries(); seriesWideBanners.Language = banner.SelectSingleNode("Language").InnerText; seriesWideBanners.OnlinePath = banner.SelectSingleNode("BannerPath").InnerText; seriesWideBanners.SeriesName = SeriesName; try { seriesWideBanners.Style = (ArtworkStyles)Enum.Parse(typeof(ArtworkStyles), banner.SelectSingleNode("BannerType2").InnerText, true); } catch { // maybe a new style introduced seriesWideBanners.Style = ArtworkStyles.unknown; } if (!string.IsNullOrEmpty(banner.SelectSingleNode("Rating").InnerText)) { double rating = double.Parse(banner.SelectSingleNode("Rating").InnerText, NumberStyles.Any, NumberFormatInfo.InvariantInfo); seriesWideBanners.Rating = Math.Round(rating, 1, MidpointRounding.AwayFromZero); } if (!string.IsNullOrEmpty(banner.SelectSingleNode("RatingCount").InnerText)) { seriesWideBanners.RatingCount = int.Parse(banner.SelectSingleNode("RatingCount").InnerText); } seriesWideBanners.SeriesID = seriesID; widebannerSeriesList.Add(seriesWideBanners); } // sort by highest rated widebannerSeriesList.Sort(); // remove banners of no interest if (!DBOption.GetOptions(DBOption.cGetTextBanners)) { widebannerSeriesList.RemoveAll(b => b.Style == ArtworkStyles.text); } if (!DBOption.GetOptions(DBOption.cGetBlankBanners)) { widebannerSeriesList.RemoveAll(b => b.Style == ArtworkStyles.blank); } // Respect User Limits, exception: if higher rated image or localised image is uploaded online int limit = DBOption.GetOptions(DBOption.cArtworkLimitSeriesWideBanners); if (limit < widebannerSeriesList.Count) { widebannerSeriesList.RemoveRange(limit, widebannerSeriesList.Count - limit); } map.SeriesWideBanners = widebannerSeriesList; #endregion #region Series Posters foreach (XmlNode banner in banners.SelectNodes("/Banners/Banner[BannerType='poster']")) { PosterSeries seriesPoster = new PosterSeries(); seriesPoster.Language = banner.SelectSingleNode("Language").InnerText; seriesPoster.OnlinePath = banner.SelectSingleNode("BannerPath").InnerText; seriesPoster.SeriesName = SeriesName; if (!string.IsNullOrEmpty(banner.SelectSingleNode("Rating").InnerText)) { double rating = double.Parse(banner.SelectSingleNode("Rating").InnerText, NumberStyles.Any, NumberFormatInfo.InvariantInfo); seriesPoster.Rating = Math.Round(rating, 1, MidpointRounding.AwayFromZero); } if (!string.IsNullOrEmpty(banner.SelectSingleNode("RatingCount").InnerText)) { seriesPoster.RatingCount = int.Parse(banner.SelectSingleNode("RatingCount").InnerText); } seriesPoster.SeriesID = seriesID; posterSeriesList.Add(seriesPoster); } posterSeasonList.Sort(); limit = DBOption.GetOptions(DBOption.cArtworkLimitSeriesPosters); if (limit < posterSeriesList.Count) { posterSeriesList.RemoveRange(limit, posterSeriesList.Count - limit); } map.SeriesPosters = posterSeriesList; #endregion #region Season Posters List <string> seasons = new List <string>(); foreach (XmlNode banner in banners.SelectNodes("/Banners/Banner[BannerType='season']")) { PosterSeason seasonPoster = new PosterSeason(); seasonPoster.Language = banner.SelectSingleNode("Language").InnerText; seasonPoster.OnlinePath = banner.SelectSingleNode("BannerPath").InnerText; seasonPoster.SeasonIndex = banner.SelectSingleNode("Season").InnerText; seasonPoster.SeriesName = SeriesName; try { seasonPoster.Style = (ArtworkStyles)Enum.Parse(typeof(ArtworkStyles), banner.SelectSingleNode("BannerType2").InnerText, true); } catch { // maybe a new style introduced seasonPoster.Style = ArtworkStyles.unknown; } if (!string.IsNullOrEmpty(banner.SelectSingleNode("Rating").InnerText)) { double rating = double.Parse(banner.SelectSingleNode("Rating").InnerText, NumberStyles.Any, NumberFormatInfo.InvariantInfo); seasonPoster.Rating = Math.Round(rating, 1, MidpointRounding.AwayFromZero); } if (!string.IsNullOrEmpty(banner.SelectSingleNode("RatingCount").InnerText)) { seasonPoster.RatingCount = int.Parse(banner.SelectSingleNode("RatingCount").InnerText); } if (!seasons.Contains(seasonPoster.SeasonIndex)) { seasons.Add(seasonPoster.SeasonIndex); } seasonPoster.SeriesID = seriesID; posterSeasonList.Add(seasonPoster); } posterSeasonList.Sort(); // we dont support season widebanners posterSeasonList.RemoveAll(p => p.Style == ArtworkStyles.seasonwide); limit = DBOption.GetOptions(DBOption.cArtworkLimitSeasonPosters); List <PosterSeason> posterSeasonListTemp = new List <PosterSeason>(posterSeasonList); foreach (string season in seasons) { int count = 0; foreach (PosterSeason pSeason in posterSeasonListTemp) { if (season == pSeason.SeasonIndex) { count++; if (limit < count) { posterSeasonList.Remove(pSeason); } } } } map.SeasonPosters = posterSeasonList; #endregion // series already in? if (SeriesBannersMap.Contains(map)) { SeriesBannersMap seriesMap = SeriesBannersMap[SeriesBannersMap.IndexOf(map)]; seriesMap.SeasonPosters.AddRange(map.SeasonPosters); seriesMap.SeriesWideBanners.AddRange(map.SeriesWideBanners); seriesMap.SeriesPosters.AddRange(map.SeriesPosters); } else { SeriesBannersMap.Add(map); } }
private void doWork(string aSeriesID) { XmlNode lEnglishBanners = null; XmlNode lBanners = OnlineAPI.GetBannerList(Int32.Parse(aSeriesID)); if (lBanners == null) { return; } DBSeries lSeries = Helper.getCorrespondingSeries(Int32.Parse(aSeriesID)); if (lSeries == null) { return; } string lSeriesName = lSeries.ToString(); List <WideBannerSeries> lWidebannerSeriesList = new List <WideBannerSeries>(); List <PosterSeries> lPosterSeriesList = new List <PosterSeries>(); List <PosterSeason> lPosterSeasonList = new List <PosterSeason>(); SeriesBannersMap lMap = new SeriesBannersMap(); lMap.SeriesID = aSeriesID; #region Series WideBanners lWidebannerSeriesList = GetWideSeriesBanners(lBanners, aSeriesID, lSeriesName); // if the banner count is zero, try to get from english language if (lWidebannerSeriesList.Count == 0 && OnlineAPI.GetSeriesLanguage(int.Parse(aSeriesID)) != "en") { lEnglishBanners = OnlineAPI.GetBannerList(Int32.Parse(aSeriesID), "en"); if (lEnglishBanners == null) { return; } lWidebannerSeriesList = GetWideSeriesBanners(lEnglishBanners, aSeriesID, lSeriesName); } // sort by highest rated lWidebannerSeriesList.Sort(); // remove banners of no interest if (!DBOption.GetOptions(DBOption.cGetTextBanners)) { lWidebannerSeriesList.RemoveAll(b => b.Style == ArtworkStyles.text); } if (!DBOption.GetOptions(DBOption.cGetBlankBanners)) { lWidebannerSeriesList.RemoveAll(b => b.Style == ArtworkStyles.blank); } // Respect User Limits, exception: if higher rated image or localised image is uploaded online int limit = DBOption.GetOptions(DBOption.cArtworkLimitSeriesWideBanners); if (limit < lWidebannerSeriesList.Count) { lWidebannerSeriesList.RemoveRange(limit, lWidebannerSeriesList.Count - limit); } lMap.SeriesWideBanners = lWidebannerSeriesList; #endregion #region Series Posters lPosterSeriesList = GetPosterSeries(lBanners, aSeriesID, lSeriesName); // if the poster count is zero, try to get from english language if (lPosterSeriesList.Count == 0 && OnlineAPI.GetSeriesLanguage(int.Parse(aSeriesID)) != "en") { if (lEnglishBanners == null) { lEnglishBanners = OnlineAPI.GetBannerList(Int32.Parse(aSeriesID), "en"); if (lEnglishBanners == null) { return; } } lPosterSeriesList = GetPosterSeries(lEnglishBanners, aSeriesID, lSeriesName); } lPosterSeriesList.Sort(); limit = DBOption.GetOptions(DBOption.cArtworkLimitSeriesPosters); if (limit < lPosterSeriesList.Count) { lPosterSeriesList.RemoveRange(limit, lPosterSeriesList.Count - limit); } lMap.SeriesPosters = lPosterSeriesList; #endregion #region Season Posters List <string> lSeasons = new List <string>(); lPosterSeasonList = GetPosterSeason(lBanners, aSeriesID, lSeriesName, ref lSeasons); // if the poster count is zero try to get from english language if (lPosterSeasonList.Count == 0 && OnlineAPI.GetSeriesLanguage(int.Parse(aSeriesID)) != "en") { if (lEnglishBanners == null) { lEnglishBanners = OnlineAPI.GetBannerList(Int32.Parse(aSeriesID), "en"); if (lEnglishBanners == null) { return; } } lPosterSeasonList = GetPosterSeason(lEnglishBanners, aSeriesID, lSeriesName, ref lSeasons); } lPosterSeasonList.Sort(); // we dont support season widebanners lPosterSeasonList.RemoveAll(p => p.Style == ArtworkStyles.seasonwide); limit = DBOption.GetOptions(DBOption.cArtworkLimitSeasonPosters); List <PosterSeason> posterSeasonListTemp = new List <PosterSeason>(lPosterSeasonList); foreach (string season in lSeasons) { int count = 0; foreach (PosterSeason pSeason in posterSeasonListTemp) { if (season == pSeason.SeasonIndex) { count++; if (limit < count) { lPosterSeasonList.Remove(pSeason); } } } } lMap.SeasonPosters = lPosterSeasonList; #endregion // series already in? if (SeriesBannersMap.Contains(lMap)) { SeriesBannersMap seriesMap = SeriesBannersMap[SeriesBannersMap.IndexOf(lMap)]; seriesMap.SeasonPosters.AddRange(lMap.SeasonPosters); seriesMap.SeriesWideBanners.AddRange(lMap.SeriesWideBanners); seriesMap.SeriesPosters.AddRange(lMap.SeriesPosters); } else { SeriesBannersMap.Add(lMap); } }