コード例 #1
0
        public AniDB_Vote GetByEntityAndType(int entID, AniDBVoteType voteType)
        {
            using (var session = DatabaseFactory.SessionFactory.OpenSession())
            {
                IList <AniDB_Vote> cr = session
                                        .CreateCriteria(typeof(AniDB_Vote))
                                        .Add(Restrictions.Eq("EntityID", entID))
                                        .Add(Restrictions.Eq("VoteType", (int)voteType))
                                        .List <AniDB_Vote>();

                if (cr.Count > 1)
                {
                    bool first = true;
                    foreach (AniDB_Vote dbVote in cr)
                    {
                        if (first)
                        {
                            first = false;
                            continue;
                        }
                        using (var transact = session.BeginTransaction())
                        {
                            RepoFactory.AniDB_Vote.DeleteWithOpenTransaction(session, dbVote);
                            transact.Commit();
                        }
                    }
                }

                return(cr.FirstOrDefault());
            }
        }
コード例 #2
0
        public void InitEpisode(int entityid, int epno, decimal votevalue, EpisodeType epType)
        {
            // allow the user to enter a vote value between 1 and 10
            // can be 9.5 etc
            // then multiple by 100 to get anidb value

            // type: 1=anime, 2=anime tmpvote, 3=group
            // entity: anime, episode, or group
            // for episode voting add epno on type=1
            // value: negative number means revoke, 0 means retrieve (default), 100-1000 are valid vote values, rest is illegal
            // votes will be updated automatically (no questions asked)
            // tmpvoting when there exist a perm vote is not possible

            this.entityID      = entityid;
            this.episodeNumber = epno;
            if (votevalue > 0)
            {
                this.voteValue = (int)(votevalue * 100);
            }
            else
            {
                this.voteValue = (int)votevalue;
            }
            this.voteType    = AniDBVoteType.Episode;
            this.episodeType = epType;

            commandID = entityID.ToString();

            int iVoteType = 1;

            string epNumberFormatted = episodeNumber.ToString();

            switch (epType)
            {
            case EpisodeType.Credits:
                epNumberFormatted = "C" + epno.ToString();
                break;

            case EpisodeType.Special:
                epNumberFormatted = "S" + epno.ToString();
                break;

            case EpisodeType.Other:
                epNumberFormatted = "0" + epno.ToString();
                break;

            case EpisodeType.Trailer:
                epNumberFormatted = "T" + epno.ToString();
                break;

            case EpisodeType.Parody:
                epNumberFormatted = "P" + epno.ToString();
                break;
            }

            commandText  = "VOTE type=" + iVoteType.ToString();
            commandText += "&id=" + entityID.ToString();
            commandText += "&value=" + voteValue.ToString();
            commandText += "&epno=" + epNumberFormatted;
        }
コード例 #3
0
        public AniDB_Vote GetByEntityAndType(int entID, AniDBVoteType voteType)
        {
            lock (Cache)
            {
                List <AniDB_Vote> cr = EntityIDs.GetMultiple(entID)?.Where(a => a.VoteType == (int)voteType).ToList();

                if (cr == null)
                {
                    return(null);
                }
                if (cr.Count <= 1)
                {
                    return(cr.FirstOrDefault());
                }

                {
                    bool first = true;
                    foreach (AniDB_Vote dbVote in cr)
                    {
                        if (first)
                        {
                            first = false;
                            continue;
                        }
                        Repo.Instance.AniDB_Vote.Delete(dbVote);
                    }

                    return(cr.FirstOrDefault());
                }
            }
        }
コード例 #4
0
        public void ProcessEpisode(XmlNode node)
        {
            NumberStyles style   = NumberStyles.Number;
            CultureInfo  culture = CultureInfo.CreateSpecificCulture("en-GB");

            this.VoteType = AniDBVoteType.Episode;
            this.EntityID = int.Parse(node.Attributes["eid"].Value);
            double.TryParse(node.InnerText.Trim(), style, culture, out double val);
            int.TryParse((val * 100).ToString(), out int ival);
            VoteValue = ival;
        }
コード例 #5
0
        public void Init(int entityid, decimal votevalue, AniDBVoteType votetype)
        {
            // allow the user to enter a vote value between 1 and 10
            // can be 9.5 etc
            // then multiple by 100 to get anidb value

            // type: 1=anime, 2=anime tmpvote, 3=group
            // entity: anime, episode, or group
            // for episode voting add epno on type=1
            // value: negative number means revoke, 0 means retrieve (default), 100-1000 are valid vote values, rest is illegal
            // votes will be updated automatically (no questions asked)
            // tmpvoting when there exist a perm vote is not possible

            this.entityID      = entityid;
            this.episodeNumber = -1;
            if (votevalue > 0)
            {
                this.voteValue = (int)(votevalue * 100);
            }
            else
            {
                this.voteValue = (int)votevalue;
            }
            this.voteType    = votetype;
            this.episodeType = EpisodeType.Episode;

            commandID = entityID.ToString();

            int iVoteType = 1;

            switch (voteType)
            {
            case AniDBVoteType.Anime:
                iVoteType = 1;
                break;

            case AniDBVoteType.AnimeTemp:
                iVoteType = 2;
                break;

            case AniDBVoteType.Group:
                iVoteType = 3;
                break;

            case AniDBVoteType.Episode:
                iVoteType = 1;
                break;
            }

            commandText  = "VOTE type=" + iVoteType.ToString();
            commandText += "&id=" + entityID.ToString();
            commandText += "&value=" + voteValue.ToString();
        }
コード例 #6
0
        public AniDB_Vote GetByEntityAndType(int entID, AniDBVoteType voteType)
        {
            using (var session = JMMService.SessionFactory.OpenSession())
            {
                AniDB_Vote cr = session
                                .CreateCriteria(typeof(AniDB_Vote))
                                .Add(Restrictions.Eq("EntityID", entID))
                                .Add(Restrictions.Eq("VoteType", (int)voteType))
                                .UniqueResult <AniDB_Vote>();

                return(cr);
            }
        }
コード例 #7
0
ファイル: AniDB_VoteRepository.cs プロジェクト: dizzydezz/jmm
		public AniDB_Vote GetByEntityAndType(int entID, AniDBVoteType voteType)
		{
			using (var session = JMMService.SessionFactory.OpenSession())
			{
				AniDB_Vote cr = session
					.CreateCriteria(typeof(AniDB_Vote))
					.Add(Restrictions.Eq("EntityID", entID))
					.Add(Restrictions.Eq("VoteType", (int)voteType))
					.UniqueResult<AniDB_Vote>();

				return cr;
			}
		}
コード例 #8
0
        // constructor
        // sRecMessage is the message received from ANIDB file info command


        public void ProcessVoteFoundAnime(string sRecMessage, int animeID, AniDBVoteType vtype)
        {
            // remove the header info
            string[] sDetails = sRecMessage.Substring(15).Split('|');

            // 261 VOTE FOUNDCode Geass Hangyaku no Lelouch|900|1|4521


            // 261 VOTE FOUND
            // 0. Code Geass Hangyaku no Lelouch
            // 1. 900 ** vote value
            // 2. 1 ** vote type
            // 3. 4521 ** animeid

            this.EntityID      = animeID;
            this.EpisodeNumber = -1;
            this.VoteValue     = int.Parse(sDetails[1].Trim());
            this.VoteType      = (int)vtype;
            this.EpisodeType   = (int)enEpisodeType.Episode;
        }
コード例 #9
0
        public AniDB_Vote GetByEntityAndType(int entID, AniDBVoteType voteType)
        {
            List <AniDB_Vote> cr;

            using (RepoLock.ReaderLock())
            {
                cr = IsCached
                    ? EntityIDs.GetMultiple(entID)?.Where(a => a.VoteType == (int)voteType).ToList()
                    : Table.Where(a => a.EntityID == entID && a.VoteType == (int)voteType).ToList();
            }

            if (cr == null || cr.Count == 0)
            {
                return(null);
            }
            if (cr.Count > 1)
            {
                Delete(cr.GetRange(1, cr.Count - 1));
            }
            return(cr[0]);
        }
コード例 #10
0
        public AniDB_Vote GetByEntityAndType(int entID, AniDBVoteType voteType)
        {
            lock (Cache)
            {
                List <AniDB_Vote> cr = EntityIDs.GetMultiple(entID)?.Where(a => a.VoteType == (int)voteType).ToList();

                if (cr == null)
                {
                    return(null);
                }
                if (cr.Count <= 1)
                {
                    return(cr.FirstOrDefault());
                }

                lock (globalDBLock)
                {
                    using (var session = DatabaseFactory.SessionFactory.OpenSession())
                    {
                        bool first = true;
                        foreach (AniDB_Vote dbVote in cr)
                        {
                            if (first)
                            {
                                first = false;
                                continue;
                            }
                            using (var transact = session.BeginTransaction())
                            {
                                RepoFactory.AniDB_Vote.DeleteWithOpenTransaction(session, dbVote);
                                transact.Commit();
                            }
                        }

                        return(cr.FirstOrDefault());
                    }
                }
            }
        }
コード例 #11
0
 public Raw_AniDB_Vote_HTTP()
 {
     EntityID  = -1;
     VoteValue = -1;
     VoteType  = AniDBVoteType.Anime;
 }