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;
			}
		}
Esempio n. 2
0
		public void Save(AniDB_Vote obj)
		{
			using (var session = JMMService.SessionFactory.OpenSession())
			{
				// populate the database
				using (var transaction = session.BeginTransaction())
				{
					session.SaveOrUpdate(obj);
					transaction.Commit();
				}
			}
			if (obj.VoteType == (int)AniDBVoteType.Anime || obj.VoteType == (int)AniDBVoteType.AnimeTemp)
			{
				StatsCache.Instance.UpdateUsingAnime(obj.EntityID);
				StatsCache.Instance.UpdateAnimeContract(obj.EntityID);
			}
		}
        public Response VoteAnime(IProvider prov, string userid, string objectid, string votevalue,
            string votetype)
        {
            Response rsp = new Response();
            rsp.Code = "400";
            rsp.Message = "Bad Request";
            try
            {
                int objid = 0;
                int usid = 0;
                int vt = 0;
                double vvalue = 0;
                if (!int.TryParse(objectid, out objid))
                    return rsp;
                if (!int.TryParse(userid, out usid))
                    return rsp;
                if (!int.TryParse(votetype, out vt))
                    return rsp;
                if (!double.TryParse(votevalue, NumberStyles.Any, CultureInfo.InvariantCulture, out vvalue))
                    return rsp;
                using (var session = DatabaseFactory.SessionFactory.OpenSession())
                {
                    ISessionWrapper sessionWrapper = session.Wrap();

                    if (vt == (int) enAniDBVoteType.Episode)
                    {
                        AnimeEpisode ep = RepoFactory.AnimeEpisode.GetByID(objid);
                        if (ep == null)
                        {
                            rsp.Code = "404";
                            rsp.Message = "Episode Not Found";
                            return rsp;
                        }
                        AniDB_Anime anime = ep.GetAnimeSeries().GetAnime();
                        if (anime == null)
                        {
                            rsp.Code = "404";
                            rsp.Message = "Anime Not Found";
                            return 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
                        List<AniDB_Vote> dbVotes = RepoFactory.AniDB_Vote.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;
                        RepoFactory.AniDB_Vote.Save(thisVote);
                        CommandRequest_VoteAnime cmdVote = new CommandRequest_VoteAnime(anime.AnimeID, vt,
                            Convert.ToDecimal(vvalue));
                        cmdVote.Save();
                    }

                    if (vt == (int)enAniDBVoteType.Anime)
                    {
                        AnimeSeries ser = RepoFactory.AnimeSeries.GetByID(objid);
                        AniDB_Anime anime = ser.GetAnime();
                        if (anime == null)
                        {
                            rsp.Code = "404";
                            rsp.Message = "Anime Not Found";
                            return 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
                        List<AniDB_Vote> dbVotes = RepoFactory.AniDB_Vote.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;
                        RepoFactory.AniDB_Vote.Save(thisVote);
                        CommandRequest_VoteAnime cmdVote = new CommandRequest_VoteAnime(anime.AnimeID, vt,
                            Convert.ToDecimal(vvalue));
                        cmdVote.Save();
                    }
                    rsp.Code = "200";
                    rsp.Message = null;
                }
            }
            catch (Exception ex)
            {
                rsp.Code = "500";
                rsp.Message = "Internal Error : " + ex;
                logger.Error( ex,ex.ToString());
            }
            return rsp;
        }
Esempio n. 4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="animeID"></param>
        /// <param name="voteValue">Must be 1 or 2 (Anime or Anime Temp(</param>
        /// <param name="voteType"></param>
        public void VoteAnime(int animeID, decimal voteValue, int voteType)
        {
            string msg = string.Format("Voting for anime: {0} - Value: {1}", animeID, voteValue);
            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(animeID);
            AniDB_Vote thisVote = null;
            foreach (AniDB_Vote dbVote in dbVotes)
            {
                // we can only have anime permanent or anime temp but not both
                if (voteType == (int)enAniDBVoteType.Anime || voteType == (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 = animeID;
            }
            thisVote.VoteType = voteType;

            int iVoteValue = 0;
            if (voteValue > 0)
                iVoteValue = (int)(voteValue * 100);
            else
                iVoteValue = (int)voteValue;

            msg = string.Format("Voting for anime Formatted: {0} - Value: {1}", animeID, iVoteValue);
            logger.Info(msg);

            thisVote.VoteValue = iVoteValue;
            repVotes.Save(thisVote);

            CommandRequest_VoteAnime cmdVote = new CommandRequest_VoteAnime(animeID, voteType, voteValue);
            cmdVote.Save();
        }
Esempio n. 5
0
        /// <summary>
        /// Internal function for saving vote on given serie
        /// </summary>
        /// <param name="id">serie id</param>
        /// <param name="score">rating score as 1-10 or 100-1000</param>
        /// <param name="uid"></param>
        /// <returns>APIStatus</returns>
        internal object SerieVote(int id, int score, int uid)
        {
            if (id > 0)
            {
                if (score > 0 && score <= 1000)
                {
                    List<AniDB_Vote> dbVotes = RepoFactory.AniDB_Vote.GetByEntity(id);
                    AniDB_Vote thisVote = null;
                    foreach (AniDB_Vote dbVote in dbVotes)
                    {
                        if (dbVote.VoteType == (int)enAniDBVoteType.Anime)
                        {
                            thisVote = dbVote;
                        }
                    }

                    if (thisVote == null)
                    {
                        thisVote = new AniDB_Vote();
                        thisVote.VoteType = (int)enAniDBVoteType.Anime;
                        thisVote.EntityID = id;
                    }

                    if (score <= 10)
                    {
                        score = (int)(score * 100);
                    }

                    thisVote.VoteValue = score;
                    RepoFactory.AniDB_Vote.Save(thisVote);
                    //Commands.CommandRequest_VoteAnime cmdVote = new Commands.CommandRequest_VoteAnime(para.id, (int)enAniDBVoteType.Anime, Convert.ToDecimal(para.score));
                    //cmdVote.Save();
                    return APIStatus.statusOK();
                }
                else
                {
                    return APIStatus.badRequest("'score' value is wrong");
                }
            }
            else
            {
                return APIStatus.badRequest("'id' value is wrong");
            }
        }
Esempio n. 6
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);
            }
        }
Esempio n. 7
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;
		}
        public void VoteAnime(string userid, string seriesid, string votevalue, string votetype)
        {
            int serid = 0;
            int usid = 0;
            int vt = 0;
            double vvalue = 0;
            if (!int.TryParse(seriesid, out serid))
                return;
            if (!int.TryParse(userid, out usid))
                return;
            if (!int.TryParse(votetype, out vt))
                return;
            if (!double.TryParse(votevalue, NumberStyles.Any, CultureInfo.InvariantCulture, out vvalue))
                return;
            using (var session = JMMService.SessionFactory.OpenSession())
            {
                
                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                AnimeSeries ser = repSeries.GetByID(session, serid);
                AniDB_Anime anime = ser?.GetAnime();
                if (anime == null)
                    return;
                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();
            }
        }