コード例 #1
0
        public void Save(ISession session)
        {
            CommandRequestRepository repCR  = new CommandRequestRepository();
            CommandRequest           crTemp = repCR.GetByCommandID(session, this.CommandID);

            if (crTemp != null)
            {
                // we will always mylist watched state changes
                // this is because the user may be toggling the status in the client, and we need to process
                // them all in the order they were requested
                if (CommandType != (int)CommandRequestType.AniDB_UpdateWatchedUDP)
                {
                    //logger.Trace("Command already in queue with identifier so skipping: {0}", this.CommandID);
                    return;
                }
            }

            CommandRequest cri = this.ToDatabaseObject();

            repCR.Save(session, cri);

            if (CommandType == (int)CommandRequestType.HashFile)
            {
                JMMService.CmdProcessorHasher.NotifyOfNewCommand();
            }
            else if (CommandType == (int)CommandRequestType.ImageDownload)
            {
                JMMService.CmdProcessorImages.NotifyOfNewCommand();
            }
            else
            {
                JMMService.CmdProcessorGeneral.NotifyOfNewCommand();
            }
        }
コード例 #2
0
        public void Save()
        {
            CommandRequest crTemp = RepoFactory.CommandRequest.GetByCommandID(CommandID);

            if (crTemp != null)
            {
                // we will always mylist watched state changes
                // this is because the user may be toggling the status in the client, and we need to process
                // them all in the order they were requested
                if (CommandType == (int)CommandRequestType.AniDB_UpdateWatchedUDP)
                {
                    RepoFactory.CommandRequest.Delete(crTemp);
                }
                else
                {
                    return;
                }
            }

            CommandRequest cri = ToDatabaseObject();

            RepoFactory.CommandRequest.Save(cri);

            switch (CommandRequestRepository.GetQueueIndex(cri))
            {
            case 0:
                ShokoService.CmdProcessorGeneral.NotifyOfNewCommand();
                break;

            case 1:
                ShokoService.CmdProcessorHasher.NotifyOfNewCommand();
                break;

            case 2:
                ShokoService.CmdProcessorImages.NotifyOfNewCommand();
                break;
            }
        }
コード例 #3
0
ファイル: CommandRequest.cs プロジェクト: maxpiva/ShokoServer
        public virtual void Save(ISession session)
        {
            CommandRequest crTemp = RepoFactory.CommandRequest.GetByCommandID(CommandID);

            if (crTemp != null)
            {
                // we will always mylist watched state changes
                // this is because the user may be toggling the status in the client, and we need to process
                // them all in the order they were requested
                if (CommandType == (int)CommandRequestType.AniDB_UpdateWatchedUDP)
                {
                    RepoFactory.CommandRequest.Delete(crTemp);
                }
                else
                {
                    return;
                }
            }

            CommandDetails  = ToXML();
            DateTimeUpdated = DateTime.Now;
            RepoFactory.CommandRequest.SaveWithOpenTransaction(session, this);

            switch (CommandRequestRepository.GetQueueIndex(this))
            {
            case 0:
                ShokoService.CmdProcessorGeneral.NotifyOfNewCommand();
                break;

            case 1:
                ShokoService.CmdProcessorHasher.NotifyOfNewCommand();
                break;

            case 2:
                ShokoService.CmdProcessorImages.NotifyOfNewCommand();
                break;
            }
        }
コード例 #4
0
        void workerCommands_DoWork(object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                if (workerCommands.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                // if paused we will sleep for 5 seconds, and the try again
                // we will remove the pause if it was set more than 6 hours ago
                // the pause is initiated when banned from AniDB or manually by the user
                if (Paused)
                {
                    try
                    {
                        if (workerCommands.CancellationPending)
                        {
                            e.Cancel = true;
                            return;
                        }

                        //logger.Trace("Images Queue is paused: {0}", pauseTime.Value);
                        TimeSpan ts = DateTime.Now - pauseTime.Value;
                        if (ts.TotalHours >= 6)
                        {
                            Paused = false;
                        }
                    }
                    catch
                    {
                    }
                    Thread.Sleep(5000);
                    continue;
                }

                //logger.Trace("Looking for next command request (images)...");

                CommandRequestRepository repCR = new CommandRequestRepository();
                CommandRequest           crdb  = repCR.GetNextDBCommandRequestImages();
                if (crdb == null)
                {
                    return;
                }

                QueueCount = repCR.GetQueuedCommandCountImages();
                //logger.Trace("{0} commands remaining in queue (images)", QueueCount);

                if (workerCommands.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                //logger.Trace("Next command request (images): {0}", crdb.CommandID);

                ICommandRequest icr = CommandHelper.GetCommand(crdb);
                if (icr == null)
                {
                    //logger.Trace("No implementation found for command: {0}-{1}", crdb.CommandType, crdb.CommandID);
                    return;
                }

                if (workerCommands.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                QueueState = icr.PrettyDescription;

                //logger.Trace("Processing command request (images): {0}", crdb.CommandID);
                icr.ProcessCommand();

                //logger.Trace("Deleting command request (images): {0}", crdb.CommandID);
                repCR.Delete(crdb.CommandRequestID);
                QueueCount = repCR.GetQueuedCommandCountImages();
            }
        }
コード例 #5
0
ファイル: TvDBHelper.cs プロジェクト: pmcleish/jmmserver
        public static string LinkAniDBTvDB(int animeID, enEpisodeType aniEpType, int aniEpNumber, int tvDBID,
                                           int tvSeasonNumber, int tvEpNumber, bool excludeFromWebCache)
        {
            using (var session = JMMService.SessionFactory.OpenSession())
            {
                CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository();
                List <CrossRef_AniDB_TvDBV2>    xrefTemps   = repCrossRef.GetByAnimeIDEpTypeEpNumber(session, animeID,
                                                                                                     (int)aniEpType,
                                                                                                     aniEpNumber);
                if (xrefTemps != null && xrefTemps.Count > 0)
                {
                    foreach (CrossRef_AniDB_TvDBV2 xrefTemp in xrefTemps)
                    {
                        // delete the existing one if we are updating
                        TvDBHelper.RemoveLinkAniDBTvDB(xrefTemp.AnimeID, (enEpisodeType)xrefTemp.AniDBStartEpisodeType,
                                                       xrefTemp.AniDBStartEpisodeNumber,
                                                       xrefTemp.TvDBID, xrefTemp.TvDBSeasonNumber, xrefTemp.TvDBStartEpisodeNumber);
                    }
                }

                // check if we have this information locally
                // if not download it now
                TvDB_SeriesRepository repSeries = new TvDB_SeriesRepository();
                TvDB_Series           tvSeries  = repSeries.GetByTvDBID(tvDBID);
                if (tvSeries == null)
                {
                    // we download the series info here just so that we have the basic info in the
                    // database before the queued task runs later
                    tvSeries = GetSeriesInfoOnline(tvDBID);
                }

                // download and update series info, episode info and episode images
                // will also download fanart, posters and wide banners
                CommandRequest_TvDBUpdateSeriesAndEpisodes cmdSeriesEps =
                    new CommandRequest_TvDBUpdateSeriesAndEpisodes(tvDBID,
                                                                   false);
                //Optimize for batch updates, if there are a lot of LinkAniDBTvDB commands queued
                //this will cause only one updateSeriesAndEpisodes command to be created
                CommandRequestRepository repCR = new CommandRequestRepository();
                if (repCR.GetByCommandID(cmdSeriesEps.CommandID) == null)
                {
                    cmdSeriesEps.Save();
                }

                CrossRef_AniDB_TvDBV2 xref = repCrossRef.GetByTvDBID(session, tvDBID, tvSeasonNumber, tvEpNumber,
                                                                     animeID,
                                                                     (int)aniEpType, aniEpNumber);
                if (xref == null)
                {
                    xref = new CrossRef_AniDB_TvDBV2();
                }

                xref.AnimeID = animeID;
                xref.AniDBStartEpisodeType   = (int)aniEpType;
                xref.AniDBStartEpisodeNumber = aniEpNumber;

                xref.TvDBID                 = tvDBID;
                xref.TvDBSeasonNumber       = tvSeasonNumber;
                xref.TvDBStartEpisodeNumber = tvEpNumber;
                if (tvSeries != null)
                {
                    xref.TvDBTitle = tvSeries.SeriesName;
                }

                if (excludeFromWebCache)
                {
                    xref.CrossRefSource = (int)CrossRefSource.WebCache;
                }
                else
                {
                    xref.CrossRefSource = (int)CrossRefSource.User;
                }

                repCrossRef.Save(xref);

                AniDB_Anime.UpdateStatsByAnimeID(animeID);

                logger.Trace("Changed tvdb association: {0}", animeID);

                if (!excludeFromWebCache)
                {
                    CommandRequest_WebCacheSendXRefAniDBTvDB req =
                        new CommandRequest_WebCacheSendXRefAniDBTvDB(xref.CrossRef_AniDB_TvDBV2ID);
                    req.Save();
                }

                if (ServerSettings.Trakt_IsEnabled && !string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken))
                {
                    CrossRef_AniDB_TraktV2Repository repTraktXrefs = new CrossRef_AniDB_TraktV2Repository();
                    if (repTraktXrefs.GetByAnimeID(animeID).Count == 0)
                    {
                        // check for Trakt associations
                        CommandRequest_TraktSearchAnime cmd2 = new CommandRequest_TraktSearchAnime(animeID, false);
                        cmd2.Save(session);
                    }
                }
            }

            return("");
        }