コード例 #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;
            }
        }
コード例 #2
0
        public bool VoteAnime(int animeID, decimal voteValue, enAniDBVoteType voteType)
        {
            if (!Login())
            {
                return(false);
            }

            enHelperActivityType ev      = enHelperActivityType.NoSuchVote;
            AniDBCommand_Vote    cmdVote = null;

            AniDB_VoteRepository repVotes = new AniDB_VoteRepository();

            lock (lockAniDBConnections)
            {
                Pause();

                cmdVote = new AniDBCommand_Vote();
                cmdVote.Init(animeID, voteValue, voteType);
                SetWaitingOnResponse(true);
                ev = cmdVote.Process(ref soUdp, ref remoteIpEndPoint, curSessionID, new UnicodeEncoding(true, false));
                SetWaitingOnResponse(false);
                if (ev == enHelperActivityType.Voted || ev == enHelperActivityType.VoteUpdated)
                {
                    List <AniDB_Vote> dbVotes  = repVotes.GetByEntity(cmdVote.EntityID);
                    AniDB_Vote        thisVote = null;
                    foreach (AniDB_Vote dbVote in dbVotes)
                    {
                        // we can only have anime permanent or anime temp but not both
                        if (cmdVote.VoteType == enAniDBVoteType.Anime || cmdVote.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 = cmdVote.EntityID;
                    }
                    thisVote.VoteType  = (int)cmdVote.VoteType;
                    thisVote.VoteValue = cmdVote.VoteValue;
                    repVotes.Save(thisVote);
                }
            }

            return(false);
        }
コード例 #3
0
        public System.IO.Stream VoteAnime(string userid, string objectid, string votevalue, string votetype)
        {
            Respond rsp = new Respond();

            rsp.code = 500;

            int    objid  = 0;
            int    usid   = 0;
            int    vt     = 0;
            double vvalue = 0;

            if (!int.TryParse(objectid, out objid))
            {
                return(KodiHelper.GetStreamFromXmlObject(rsp));
            }
            if (!int.TryParse(userid, out usid))
            {
                return(KodiHelper.GetStreamFromXmlObject(rsp));
            }
            if (!int.TryParse(votetype, out vt))
            {
                return(KodiHelper.GetStreamFromXmlObject(rsp));
            }
            if (!double.TryParse(votevalue, NumberStyles.Any, CultureInfo.InvariantCulture, out vvalue))
            {
                return(KodiHelper.GetStreamFromXmlObject(rsp));
            }
            using (var session = JMMService.SessionFactory.OpenSession())
            {
                if (vt == (int)enAniDBVoteType.Episode)
                {
                    AnimeEpisodeRepository repEpisodes = new AnimeEpisodeRepository();
                    AnimeEpisode           ep          = repEpisodes.GetByID(session, objid);
                    AniDB_Anime            anime       = ep.GetAnimeSeries().GetAnime();
                    if (anime == null)
                    {
                        rsp.code = 404;
                        return(KodiHelper.GetStreamFromXmlObject(rsp));
                    }
                    string msg = string.Format("Voting for anime episode: {0} - Value: {1}", ep.AnimeEpisodeID, vvalue);
                    logger.Info(msg);

                    // lets save to the database and assume it will work
                    AniDB_VoteRepository repVotes = new AniDB_VoteRepository();
                    List <AniDB_Vote>    dbVotes  = repVotes.GetByEntity(ep.AnimeEpisodeID);
                    AniDB_Vote           thisVote = null;
                    foreach (AniDB_Vote dbVote in dbVotes)
                    {
                        if (dbVote.VoteType == (int)enAniDBVoteType.Episode)
                        {
                            thisVote = dbVote;
                        }
                    }

                    if (thisVote == null)
                    {
                        thisVote          = new AniDB_Vote();
                        thisVote.EntityID = ep.AnimeEpisodeID;
                    }
                    thisVote.VoteType = vt;

                    int iVoteValue = 0;
                    if (vvalue > 0)
                    {
                        iVoteValue = (int)(vvalue * 100);
                    }
                    else
                    {
                        iVoteValue = (int)vvalue;
                    }

                    msg = string.Format("Voting for anime episode Formatted: {0} - Value: {1}", ep.AnimeEpisodeID, iVoteValue);
                    logger.Info(msg);
                    thisVote.VoteValue = iVoteValue;
                    repVotes.Save(thisVote);
                    CommandRequest_VoteAnime cmdVote = new CommandRequest_VoteAnime(anime.AnimeID, vt, Convert.ToDecimal(vvalue));
                    cmdVote.Save();
                }

                if (vt == (int)enAniDBVoteType.Anime)
                {
                    AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                    AnimeSeries           ser       = repSeries.GetByID(session, objid);
                    AniDB_Anime           anime     = ser.GetAnime();
                    if (anime == null)
                    {
                        rsp.code = 404;
                        return(KodiHelper.GetStreamFromXmlObject(rsp));
                    }
                    string msg = string.Format("Voting for anime: {0} - Value: {1}", anime.AnimeID, vvalue);
                    logger.Info(msg);

                    // lets save to the database and assume it will work
                    AniDB_VoteRepository repVotes = new AniDB_VoteRepository();
                    List <AniDB_Vote>    dbVotes  = repVotes.GetByEntity(anime.AnimeID);
                    AniDB_Vote           thisVote = null;
                    foreach (AniDB_Vote dbVote in dbVotes)
                    {
                        // we can only have anime permanent or anime temp but not both
                        if (vt == (int)enAniDBVoteType.Anime || vt == (int)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 = anime.AnimeID;
                    }
                    thisVote.VoteType = vt;

                    int iVoteValue = 0;
                    if (vvalue > 0)
                    {
                        iVoteValue = (int)(vvalue * 100);
                    }
                    else
                    {
                        iVoteValue = (int)vvalue;
                    }

                    msg = string.Format("Voting for anime Formatted: {0} - Value: {1}", anime.AnimeID, iVoteValue);
                    logger.Info(msg);
                    thisVote.VoteValue = iVoteValue;
                    repVotes.Save(thisVote);
                    CommandRequest_VoteAnime cmdVote = new CommandRequest_VoteAnime(anime.AnimeID, vt, Convert.ToDecimal(vvalue));
                    cmdVote.Save();
                }
                rsp.code = 200;
                return(KodiHelper.GetStreamFromXmlObject(rsp));
            }
        }