Пример #1
0
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_SyncMyVotes");

            try
            {
                AniDB_VoteRepository repVotes = new AniDB_VoteRepository();

                AniDBHTTPCommand_GetVotes cmd = new AniDBHTTPCommand_GetVotes();
                cmd.Init(ServerSettings.AniDB_Username, ServerSettings.AniDB_Password);
                enHelperActivityType ev = cmd.Process();
                if (ev == enHelperActivityType.GotVotesHTTP)
                {
                    foreach (Raw_AniDB_Vote_HTTP myVote in cmd.MyVotes)
                    {
                        List <AniDB_Vote> dbVotes  = repVotes.GetByEntity(myVote.EntityID);
                        AniDB_Vote        thisVote = null;
                        foreach (AniDB_Vote dbVote in dbVotes)
                        {
                            // we can only have anime permanent or anime temp but not both
                            if (myVote.VoteType == enAniDBVoteType.Anime || myVote.VoteType == enAniDBVoteType.AnimeTemp)
                            {
                                if (dbVote.VoteType == (int)enAniDBVoteType.Anime || dbVote.VoteType == (int)enAniDBVoteType.AnimeTemp)
                                {
                                    thisVote = dbVote;
                                }
                            }
                            else
                            {
                                thisVote = dbVote;
                            }
                        }

                        if (thisVote == null)
                        {
                            thisVote          = new AniDB_Vote();
                            thisVote.EntityID = myVote.EntityID;
                        }
                        thisVote.VoteType  = (int)myVote.VoteType;
                        thisVote.VoteValue = myVote.VoteValue;

                        repVotes.Save(thisVote);

                        if (myVote.VoteType == enAniDBVoteType.Anime || myVote.VoteType == enAniDBVoteType.AnimeTemp)
                        {
                            // download the anime info if the user doesn't already have it
                            CommandRequest_GetAnimeHTTP cmdAnime = new CommandRequest_GetAnimeHTTP(thisVote.EntityID, false, false);
                            cmdAnime.Save();
                        }
                    }

                    logger.Info("Processed Votes: {0} Items", cmd.MyVotes.Count);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_SyncMyVotes: {0} ", ex.ToString());
                return;
            }
        }
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_SyncMyVotes");

            try
            {
                AniDBHTTPCommand_GetVotes cmd = new AniDBHTTPCommand_GetVotes();
                cmd.Init(ServerSettings.Instance.AniDb.Username, ServerSettings.Instance.AniDb.Password);
                enHelperActivityType ev = cmd.Process();
                if (ev == enHelperActivityType.GotVotesHTTP)
                {
                    foreach (Raw_AniDB_Vote_HTTP myVote in cmd.MyVotes)
                    {
                        List <AniDB_Vote> dbVotes  = Repo.Instance.AniDB_Vote.GetByEntity(myVote.EntityID);
                        AniDB_Vote        thisVote = null;
                        foreach (AniDB_Vote dbVote in dbVotes)
                        {
                            // we can only have anime permanent or anime temp but not both
                            if (myVote.VoteType == AniDBVoteType.Anime || myVote.VoteType == AniDBVoteType.AnimeTemp)
                            {
                                if (dbVote.VoteType == (int)AniDBVoteType.Anime || dbVote.VoteType == (int)AniDBVoteType.AnimeTemp)
                                {
                                    thisVote = dbVote;
                                }
                            }
                            else
                            {
                                thisVote = dbVote;
                            }
                        }

                        using (var upd = Repo.Instance.AniDB_Vote.BeginAddOrUpdate(
                                   () => thisVote,
                                   () => new AniDB_Vote {
                            EntityID = myVote.EntityID
                        }
                                   ))
                        {
                            upd.Entity.VoteType  = (int)myVote.VoteType;
                            upd.Entity.VoteValue = myVote.VoteValue;

                            upd.Commit();
                        }

                        if (myVote.VoteType == AniDBVoteType.Anime || myVote.VoteType == AniDBVoteType.AnimeTemp)
                        {
                            // download the anime info if the user doesn't already have it
                            CommandRequest_GetAnimeHTTP cmdAnime = new CommandRequest_GetAnimeHTTP(thisVote.EntityID,
                                                                                                   false, false);
                            cmdAnime.Save();
                        }
                    }

                    logger.Info("Processed Votes: {0} Items", cmd.MyVotes.Count);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_SyncMyVotes: {0} ", ex);
            }
        }
Пример #3
0
        public override void Run(IProgress <ICommand> progress = null)
        {
            logger.Info("Processing CommandRequest_SyncMyVotes");
            try
            {
                ReportInit(progress);
                AniDBHTTPCommand_GetVotes cmd = new AniDBHTTPCommand_GetVotes();
                cmd.Init(ServerSettings.Instance.AniDb.Username, ServerSettings.Instance.AniDb.Password);
                ReportUpdate(progress, 30);
                enHelperActivityType ev = cmd.Process();
                ReportUpdate(progress, 60);
                if (ev == enHelperActivityType.GotVotesHTTP)
                {
                    List <ICommand> cmdstoAdd = new List <ICommand>();
                    foreach (Raw_AniDB_Vote_HTTP myVote in cmd.MyVotes)
                    {
                        List <AniDB_Vote> dbVotes  = Repo.Instance.AniDB_Vote.GetByEntity(myVote.EntityID);
                        AniDB_Vote        thisVote = null;
                        foreach (AniDB_Vote dbVote in dbVotes)
                        {
                            // we can only have anime permanent or anime temp but not both
                            if (myVote.VoteType == AniDBVoteType.Anime || myVote.VoteType == AniDBVoteType.AnimeTemp)
                            {
                                if (dbVote.VoteType == (int)AniDBVoteType.Anime || dbVote.VoteType == (int)AniDBVoteType.AnimeTemp)
                                {
                                    thisVote = dbVote;
                                }
                            }
                            else
                            {
                                thisVote = dbVote;
                            }
                        }

                        using (var upd = Repo.Instance.AniDB_Vote.BeginAddOrUpdate(thisVote, () => new AniDB_Vote {
                            EntityID = myVote.EntityID
                        }))
                        {
                            upd.Entity.VoteType  = (int)myVote.VoteType;
                            upd.Entity.VoteValue = myVote.VoteValue;

                            upd.Commit();
                        }

                        if ((myVote.VoteType == AniDBVoteType.Anime || myVote.VoteType == AniDBVoteType.AnimeTemp) && (thisVote != null))
                        {
                            cmdstoAdd.Add(new CmdAniDBGetAnimeHTTP(thisVote.EntityID, false, false));
                        }
                    }
                    if (cmdstoAdd.Count > 0)
                    {
                        Queue.Instance.AddRange(cmdstoAdd);
                    }
                    ReportUpdate(progress, 90);
                    logger.Info("Processed Votes: {0} Items", cmd.MyVotes.Count);
                }
                ReportFinish(progress);
            }
            catch (Exception ex)
            {
                ReportError(progress, $"Error processing AniDb.SyncMyVotes: {ex}", ex);
            }
        }