当前位置: 首页>>代码示例>>C#>>正文


C# ISession.Wrap方法代码示例

本文整理汇总了C#中ISession.Wrap方法的典型用法代码示例。如果您正苦于以下问题:C# ISession.Wrap方法的具体用法?C# ISession.Wrap怎么用?C# ISession.Wrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISession的用法示例。


在下文中一共展示了ISession.Wrap方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SaveMovieToDatabase

        public static void SaveMovieToDatabase(ISession session, MovieDB_Movie_Result searchResult, bool saveImages,
            bool isTrakt)
        {
            ISessionWrapper sessionWrapper = session.Wrap();

            // save to the DB
            MovieDB_Movie movie = RepoFactory.MovieDb_Movie.GetByOnlineID(searchResult.MovieID);
            if (movie == null) movie = new MovieDB_Movie();
            movie.Populate(searchResult);

            // Only save movie info if source is not trakt, this presents adding tv shows as movies
            // Needs better fix later on

            if (!isTrakt)
            {
                RepoFactory.MovieDb_Movie.Save(movie);
            }

            if (!saveImages) return;

            int numFanartDownloaded = 0;
            int numPostersDownloaded = 0;

            // save data to the DB and determine the number of images we already have
            foreach (MovieDB_Image_Result img in searchResult.Images)
            {
                if (img.ImageType.Equals("poster", StringComparison.InvariantCultureIgnoreCase))
                {
                    MovieDB_Poster poster = RepoFactory.MovieDB_Poster.GetByOnlineID(session, img.URL);
                    if (poster == null) poster = new MovieDB_Poster();
                    poster.Populate(img, movie.MovieId);
                    RepoFactory.MovieDB_Poster.Save(poster);

                    if (!string.IsNullOrEmpty(poster.FullImagePath) && File.Exists(poster.FullImagePath))
                        numPostersDownloaded++;
                }
                else
                {
                    // fanart (backdrop)
                    MovieDB_Fanart fanart = RepoFactory.MovieDB_Fanart.GetByOnlineID(session, img.URL);
                    if (fanart == null) fanart = new MovieDB_Fanart();
                    fanart.Populate(img, movie.MovieId);
                    RepoFactory.MovieDB_Fanart.Save(fanart);

                    if (!string.IsNullOrEmpty(fanart.FullImagePath) && File.Exists(fanart.FullImagePath))
                        numFanartDownloaded++;
                }
            }

            // download the posters
            if (ServerSettings.MovieDB_AutoPosters || isTrakt)
            {
                foreach (MovieDB_Poster poster in RepoFactory.MovieDB_Poster.GetByMovieID(sessionWrapper, movie.MovieId)
                    )
                {
                    if (numPostersDownloaded < ServerSettings.MovieDB_AutoPostersAmount)
                    {
                        // download the image
                        if (!string.IsNullOrEmpty(poster.FullImagePath) && !File.Exists(poster.FullImagePath))
                        {
                            CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(poster.MovieDB_PosterID,
                                JMMImageType.MovieDB_Poster, false);
                            cmd.Save(session);
                            numPostersDownloaded++;
                        }
                    }
                    else
                    {
                        //The MovieDB_AutoPostersAmount should prevent from saving image info without image
                        // we should clean those image that we didn't download because those dont exists in local repo
                        // first we check if file was downloaded
                        if (!File.Exists(poster.FullImagePath))
                        {
                            RepoFactory.MovieDB_Poster.Delete(poster.MovieDB_PosterID);
                        }
                    }
                }
            }

            // download the fanart
            if (ServerSettings.MovieDB_AutoFanart || isTrakt)
            {
                foreach (MovieDB_Fanart fanart in RepoFactory.MovieDB_Fanart.GetByMovieID(sessionWrapper, movie.MovieId)
                    )
                {
                    if (numFanartDownloaded < ServerSettings.MovieDB_AutoFanartAmount)
                    {
                        // download the image
                        if (!string.IsNullOrEmpty(fanart.FullImagePath) && !File.Exists(fanart.FullImagePath))
                        {
                            CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(fanart.MovieDB_FanartID,
                                JMMImageType.MovieDB_FanArt, false);
                            cmd.Save(session);
                            numFanartDownloaded++;
                        }
                    }
                    else
                    {
                        //The MovieDB_AutoFanartAmount should prevent from saving image info without image
                        // we should clean those image that we didn't download because those dont exists in local repo
//.........这里部分代码省略.........
开发者ID:ElementalCrisis,项目名称:jmmserver,代码行数:101,代码来源:MovieDBHelper.cs

示例2: SaveResultsForAnimeXML

        private AniDB_Anime SaveResultsForAnimeXML(ISession session, int animeID, bool downloadRelations,
            AniDBHTTPCommand_GetFullAnime getAnimeCmd)
        {
            AniDB_Anime anime = null;
            ISessionWrapper sessionWrapper = session.Wrap();

            logger.Trace("cmdResult.Anime: {0}", getAnimeCmd.Anime);

            anime = RepoFactory.AniDB_Anime.GetByAnimeID(sessionWrapper, animeID);
            if (anime == null)
                anime = new AniDB_Anime();
            anime.PopulateAndSaveFromHTTP(session, getAnimeCmd.Anime, getAnimeCmd.Episodes, getAnimeCmd.Titles,
                getAnimeCmd.Categories, getAnimeCmd.Tags,
                getAnimeCmd.Characters, getAnimeCmd.Relations, getAnimeCmd.SimilarAnime, getAnimeCmd.Recommendations,
                downloadRelations);

            // Request an image download
            CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(anime.AniDB_AnimeID,
                JMMImageType.AniDB_Cover,
                false);
            cmd.Save(session);
            // create AnimeEpisode records for all episodes in this anime
            // only if we have a series
            AnimeSeries ser = RepoFactory.AnimeSeries.GetByAnimeID(animeID);
            RepoFactory.AniDB_Anime.Save(anime);
            if (ser != null)
            {
                ser.CreateAnimeEpisodes(session);
                RepoFactory.AnimeSeries.Save(ser, true, false);
            }

            // update any files, that may have been linked
            /*CrossRef_File_EpisodeRepository repCrossRefs = new CrossRef_File_EpisodeRepository();
            repCrossRefs.GetByAnimeID(*/

            // update cached stats

            //StatsCache.Instance.UpdateUsingAnime(session, anime.AnimeID);
            //StatsCache.Instance.UpdateAnimeContract(session, anime.AnimeID);

            // download character images
            foreach (AniDB_Anime_Character animeChar in anime.GetAnimeCharacters(session.Wrap()))
            {
                AniDB_Character chr = animeChar.GetCharacter(sessionWrapper);
                if (chr == null) continue;

                if (ServerSettings.AniDB_DownloadCharacters)
                {
                    if (!string.IsNullOrEmpty(chr.PosterPath) && !File.Exists(chr.PosterPath))
                    {
                        logger.Debug("Downloading character image: {0} - {1}({2}) - {3}", anime.MainTitle, chr.CharName,
                            chr.CharID,
                            chr.PosterPath);
                        cmd = new CommandRequest_DownloadImage(chr.AniDB_CharacterID, JMMImageType.AniDB_Character,
                            false);
                        cmd.Save();
                    }
                }

                if (ServerSettings.AniDB_DownloadCreators)
                {
                    AniDB_Seiyuu seiyuu = chr.GetSeiyuu(session);
                    if (seiyuu == null || string.IsNullOrEmpty(seiyuu.PosterPath)) continue;

                    if (!File.Exists(seiyuu.PosterPath))
                    {
                        logger.Debug("Downloading seiyuu image: {0} - {1}({2}) - {3}", anime.MainTitle,
                            seiyuu.SeiyuuName, seiyuu.SeiyuuID,
                            seiyuu.PosterPath);
                        cmd = new CommandRequest_DownloadImage(seiyuu.AniDB_SeiyuuID, JMMImageType.AniDB_Creator, false);
                        cmd.Save();
                    }
                }
            }

            return anime;
        }
开发者ID:japanesemediamanager,项目名称:jmmserver,代码行数:77,代码来源:AniDBHelper.cs

示例3: GetAnimeInfoHTTP

        public AniDB_Anime GetAnimeInfoHTTP(ISession session, int animeID, bool forceRefresh, bool downloadRelations)
        {
            //if (!Login()) return null;

            AniDB_Anime anime = null;
            ISessionWrapper sessionWrapper = session.Wrap();

            bool skip = true;
            if (forceRefresh)
                skip = false;
            else
            {
                anime = RepoFactory.AniDB_Anime.GetByAnimeID(sessionWrapper, animeID);
                if (anime == null) skip = false;
            }

            if (skip)
            {
                if (anime == null)
                    anime = RepoFactory.AniDB_Anime.GetByAnimeID(sessionWrapper, animeID);

                return anime;
            }

            AniDBHTTPCommand_GetFullAnime getAnimeCmd = null;
            lock (lockAniDBConnections)
            {
                getAnimeCmd = new AniDBHTTPCommand_GetFullAnime();
                getAnimeCmd.Init(animeID, false, forceRefresh, false);
                getAnimeCmd.Process();
            }

            if (getAnimeCmd.Anime != null)
            {
                anime = SaveResultsForAnimeXML(session, animeID, downloadRelations, getAnimeCmd);
                //this endpoint is not working, so comenting...
            /*
                if (forceRefresh)
                {
                    CommandRequest_Azure_SendAnimeFull cmdAzure = new CommandRequest_Azure_SendAnimeFull(anime.AnimeID);
                    cmdAzure.Save(session);
                }*/
            }

            return anime;
        }
开发者ID:japanesemediamanager,项目名称:jmmserver,代码行数:46,代码来源:AniDBHelper.cs

示例4: CreateCharacters

        private void CreateCharacters(ISession session, List<Raw_AniDB_Character> chars)
        {
            if (chars == null) return;

            ISessionWrapper sessionWrapper = session.Wrap();

            // delete all the existing cross references just in case one has been removed
            List<AniDB_Anime_Character> animeChars = RepoFactory.AniDB_Anime_Character.GetByAnimeID(sessionWrapper, AnimeID);

            RepoFactory.AniDB_Anime_Character.Delete(animeChars);

            List<AniDB_Character> chrsToSave = new List<AniDB_Character>();
            List<AniDB_Anime_Character> xrefsToSave = new List<AniDB_Anime_Character>();

            Dictionary<int, AniDB_Seiyuu> seiyuuToSave = new Dictionary<int, AniDB_Seiyuu>();
            List<AniDB_Character_Seiyuu> seiyuuXrefToSave = new List<AniDB_Character_Seiyuu>();

            // delete existing relationships to seiyuu's
            List<AniDB_Character_Seiyuu> charSeiyuusToDelete = new List<AniDB_Character_Seiyuu>();
            foreach (Raw_AniDB_Character rawchar in chars)
            {
                // delete existing relationships to seiyuu's
                List<AniDB_Character_Seiyuu> allCharSei = RepoFactory.AniDB_Character_Seiyuu.GetByCharID(session, rawchar.CharID);
                foreach (AniDB_Character_Seiyuu xref in allCharSei)
                    charSeiyuusToDelete.Add(xref);
            }
            RepoFactory.AniDB_Character_Seiyuu.Delete(charSeiyuusToDelete);

            foreach (Raw_AniDB_Character rawchar in chars)
            {
                AniDB_Character chr = RepoFactory.AniDB_Character.GetByCharID(sessionWrapper, rawchar.CharID);
                if (chr == null)
                    chr = new AniDB_Character();

                chr.PopulateFromHTTP(rawchar);
                chrsToSave.Add(chr);

                // create cross ref's between anime and character, but don't actually download anything
                AniDB_Anime_Character anime_char = new AniDB_Anime_Character();
                anime_char.Populate(rawchar);
                xrefsToSave.Add(anime_char);

                foreach (Raw_AniDB_Seiyuu rawSeiyuu in rawchar.Seiyuus)
                {
                    // save the link between character and seiyuu
                    AniDB_Character_Seiyuu acc = RepoFactory.AniDB_Character_Seiyuu.GetByCharIDAndSeiyuuID(session, rawchar.CharID,
                        rawSeiyuu.SeiyuuID);
                    if (acc == null)
                    {
                        acc = new AniDB_Character_Seiyuu();
                        acc.CharID = chr.CharID;
                        acc.SeiyuuID = rawSeiyuu.SeiyuuID;
                        seiyuuXrefToSave.Add(acc);
                    }

                    // save the seiyuu
                    AniDB_Seiyuu seiyuu = RepoFactory.AniDB_Seiyuu.GetBySeiyuuID(session, rawSeiyuu.SeiyuuID);
                    if (seiyuu == null) seiyuu = new AniDB_Seiyuu();
                    seiyuu.PicName = rawSeiyuu.PicName;
                    seiyuu.SeiyuuID = rawSeiyuu.SeiyuuID;
                    seiyuu.SeiyuuName = rawSeiyuu.SeiyuuName;
                    seiyuuToSave[seiyuu.SeiyuuID] = seiyuu;
                }
            }
            RepoFactory.AniDB_Character.Save(chrsToSave);
            RepoFactory.AniDB_Anime_Character.Save(xrefsToSave);
            RepoFactory.AniDB_Seiyuu.Save(seiyuuToSave.Values.ToList());
            RepoFactory.AniDB_Character_Seiyuu.Save(seiyuuXrefToSave);
        }
开发者ID:ElementalCrisis,项目名称:jmmserver,代码行数:69,代码来源:AniDB_Anime.cs


注:本文中的ISession.Wrap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。