public void Save(TvDB_ImageFanart obj) { using (var session = JMMService.SessionFactory.OpenSession()) { // populate the database using (var transaction = session.BeginTransaction()) { session.SaveOrUpdate(obj); transaction.Commit(); } } }
private List<object> ParseBanners(int seriesID, XmlDocument xmlDoc) { List<object> banners = new List<object>(); try { XmlNodeList bannerItems = xmlDoc["Banners"].GetElementsByTagName("Banner"); //BaseConfig.MyAnimeLog.Write("Found {0} banner nodes", bannerItems.Count); if (bannerItems.Count <= 0) return banners; // banner types // series = wide banner // fanart = fanart // poster = filmstrip poster/dvd cover TvDB_ImageFanartRepository repFanart = new TvDB_ImageFanartRepository(); TvDB_ImagePosterRepository repPosters = new TvDB_ImagePosterRepository(); TvDB_ImageWideBannerRepository repWideBanners = new TvDB_ImageWideBannerRepository(); List<int> validFanartIDs = new List<int>(); List<int> validPosterIDs = new List<int>(); List<int> validBannerIDs = new List<int>(); foreach (XmlNode node in bannerItems) { JMMImageType imageType = JMMImageType.TvDB_Cover; string bannerType = node["BannerType"].InnerText.Trim().ToUpper(); string bannerType2 = node["BannerType2"].InnerText.Trim().ToUpper(); if (bannerType == "FANART") imageType = JMMImageType.TvDB_FanArt; else if (bannerType == "POSTER") imageType = JMMImageType.TvDB_Cover; else if (bannerType == "SEASON") { if (bannerType2 == "SEASON") imageType = JMMImageType.TvDB_Cover; else imageType = JMMImageType.TvDB_Banner; } else if (bannerType == "SERIES") { if (bannerType2 == "SEASONWIDE" || bannerType2 == "GRAPHICAL" || bannerType2 == "TEXT" || bannerType2 == "BLANK") imageType = JMMImageType.TvDB_Banner; else imageType = JMMImageType.TvDB_Cover; } if (imageType == JMMImageType.TvDB_FanArt) { int id = int.Parse(node["id"].InnerText); TvDB_ImageFanart img = repFanart.GetByTvDBID(id); if (img == null) { img = new TvDB_ImageFanart(); img.Enabled = 1; } img.Populate(seriesID, node); repFanart.Save(img); banners.Add(img); validFanartIDs.Add(id); } if (imageType == JMMImageType.TvDB_Banner) { int id = int.Parse(node["id"].InnerText); TvDB_ImageWideBanner img = repWideBanners.GetByTvDBID(id); if (img == null) { img = new TvDB_ImageWideBanner(); img.Enabled = 1; } img.Populate(seriesID, node, TvDBImageNodeType.Series); repWideBanners.Save(img); banners.Add(img); validBannerIDs.Add(id); } if (imageType == JMMImageType.TvDB_Cover) { int id = int.Parse(node["id"].InnerText); TvDB_ImagePoster img = repPosters.GetByTvDBID(id); if (img == null) { img = new TvDB_ImagePoster(); img.Enabled = 1; } TvDBImageNodeType nodeType = TvDBImageNodeType.Series; if (bannerType == "SEASON") nodeType = TvDBImageNodeType.Season; img.Populate(seriesID, node, nodeType); repPosters.Save(img); banners.Add(img); validPosterIDs.Add(id); } } // delete any banners from the database which are no longer valid foreach (TvDB_ImageFanart img in repFanart.GetBySeriesID(seriesID)) { if (!validFanartIDs.Contains(img.Id)) repFanart.Delete(img.TvDB_ImageFanartID); } foreach (TvDB_ImagePoster img in repPosters.GetBySeriesID(seriesID)) { if (!validPosterIDs.Contains(img.Id)) repPosters.Delete(img.TvDB_ImagePosterID); } foreach (TvDB_ImageWideBanner img in repWideBanners.GetBySeriesID(seriesID)) { if (!validBannerIDs.Contains(img.Id)) repWideBanners.Delete(img.TvDB_ImageWideBannerID); } } catch (Exception ex) { logger.ErrorException("Error in ParseBanners: " + ex.ToString(), ex); } return banners; }
public Contract_AniDB_Anime_DefaultImage ToContract(ISession session) { Contract_AniDB_Anime_DefaultImage contract = new Contract_AniDB_Anime_DefaultImage(); contract.AniDB_Anime_DefaultImageID = this.AniDB_Anime_DefaultImageID; contract.AnimeID = this.AnimeID; contract.ImageParentID = this.ImageParentID; contract.ImageParentType = this.ImageParentType; contract.ImageType = this.ImageType; contract.MovieFanart = null; contract.MoviePoster = null; contract.TVPoster = null; contract.TVFanart = null; contract.TVWideBanner = null; contract.TraktFanart = null; contract.TraktPoster = null; JMMImageType imgType = (JMMImageType)ImageParentType; switch (imgType) { case JMMImageType.TvDB_Banner: TvDB_ImageWideBannerRepository repBanners = new TvDB_ImageWideBannerRepository(); TvDB_ImageWideBanner banner = repBanners.GetByID(session, ImageParentID); if (banner != null) { contract.TVWideBanner = banner.ToContract(); } break; case JMMImageType.TvDB_Cover: TvDB_ImagePosterRepository repPosters = new TvDB_ImagePosterRepository(); TvDB_ImagePoster poster = repPosters.GetByID(session, ImageParentID); if (poster != null) { contract.TVPoster = poster.ToContract(); } break; case JMMImageType.TvDB_FanArt: TvDB_ImageFanartRepository repFanart = new TvDB_ImageFanartRepository(); TvDB_ImageFanart fanart = repFanart.GetByID(session, ImageParentID); if (fanart != null) { contract.TVFanart = fanart.ToContract(); } break; case JMMImageType.MovieDB_Poster: MovieDB_PosterRepository repMoviePosters = new MovieDB_PosterRepository(); MovieDB_Poster moviePoster = repMoviePosters.GetByID(session, ImageParentID); if (moviePoster != null) { contract.MoviePoster = moviePoster.ToContract(); } break; case JMMImageType.MovieDB_FanArt: MovieDB_FanartRepository repMovieFanart = new MovieDB_FanartRepository(); MovieDB_Fanart movieFanart = repMovieFanart.GetByID(session, ImageParentID); if (movieFanart != null) { contract.MovieFanart = movieFanart.ToContract(); } break; case JMMImageType.Trakt_Fanart: Trakt_ImageFanartRepository repTraktFanart = new Trakt_ImageFanartRepository(); Trakt_ImageFanart traktFanart = repTraktFanart.GetByID(session, ImageParentID); if (traktFanart != null) { contract.TraktFanart = traktFanart.ToContract(); } break; case JMMImageType.Trakt_Poster: Trakt_ImagePosterRepository repTraktPoster = new Trakt_ImagePosterRepository(); Trakt_ImagePoster traktPoster = repTraktPoster.GetByID(session, ImageParentID); if (traktPoster != null) { contract.TraktPoster = traktPoster.ToContract(); } break; } return(contract); }