Ejemplo n.º 1
0
        public void UnsubscribeFromVote <T, C>(string queryName, QueryDelegate <Vote <T>, C> answer)
        {
            QueryKey key = new QueryKey(queryName, typeof(T));

            if (!voteListeners.ContainsKey(key))
            {
                voteListeners.Add(key, new Dictionary <int, VoteQueryDelegateWrapper>());
            }

            int answerHash = answer.GetHashCode();

            if (voteListeners[key].ContainsKey(answerHash))
            {
                voteListeners[key].Remove(answerHash);
            }
        }
Ejemplo n.º 2
0
        public void UnsubscribeFromBool <C>(string queryName, QueryDelegate <BoolResult, C> answer)
        {
            QueryKey key = new QueryKey(queryName, typeof(BoolResult));

            if (!boolListeners.ContainsKey(key))
            {
                boolListeners.Add(key, new Dictionary <int, QueryDelegateWrapper>());
            }

            int answerHash = answer.GetHashCode();

            if (boolListeners[key].ContainsKey(answerHash))
            {
                boolListeners[key].Remove(answerHash);
            }
        }
Ejemplo n.º 3
0
        public void UnsubscribeFromSum <T, C>(string queryName, QueryDelegate <T, C> answer) where T : struct
        {
            QueryKey key = new QueryKey(queryName, typeof(T));

            if (!numberListeners.ContainsKey(key))
            {
                numberListeners.Add(key, new Dictionary <int, QueryDelegateWrapper>());
            }

            int answerHash = answer.GetHashCode();

            if (numberListeners[key].ContainsKey(answerHash))
            {
                numberListeners[key].Remove(answerHash);
            }
        }
Ejemplo n.º 4
0
        public void SubscribeToBool <C>(string queryName, QueryDelegate <BoolResult, C> answer)
        {
            QueryKey key = new QueryKey(queryName, typeof(BoolResult));

            if (!boolListeners.ContainsKey(key))
            {
                boolListeners.Add(key, new Dictionary <int, QueryDelegateWrapper>());
            }

            int answerHash = answer.GetHashCode();

            if (!boolListeners[key].ContainsKey(answerHash))
            {
                QueryDelegateWrapper wrappedAnswer = (object context) => { return(answer((C)context)); };
                boolListeners[key].Add(answerHash, wrappedAnswer);
            }
        }
Ejemplo n.º 5
0
        public void SubscribeToSum <T, C>(string queryName, QueryDelegate <T, C> answer) where T : struct
        {
            QueryKey key = new QueryKey(queryName, typeof(T));

            if (!numberListeners.ContainsKey(key))
            {
                numberListeners.Add(key, new Dictionary <int, QueryDelegateWrapper>());
            }

            int answerHash = answer.GetHashCode();

            if (!numberListeners[key].ContainsKey(answerHash))
            {
                QueryDelegateWrapper wrappedAnswer = (object context) => { return(answer((C)context)); };
                numberListeners[key].Add(answerHash, wrappedAnswer);
            }
        }
Ejemplo n.º 6
0
        public void SubscribeToVote <T, C>(string queryName, QueryDelegate <Vote <T>, C> answer)
        {
            QueryKey key = new QueryKey(queryName, typeof(T));

            if (!voteListeners.ContainsKey(key))
            {
                voteListeners.Add(key, new Dictionary <int, VoteQueryDelegateWrapper>());
            }

            int answerHash = answer.GetHashCode();

            if (!voteListeners[key].ContainsKey(answerHash))
            {
                VoteQueryDelegateWrapper wrappedAnswer = (object context) =>
                {
                    Vote <T> answerVote = answer((C)context);
                    return(new Vote <object>(answerVote.isApplicable, answerVote.candidate, answerVote.weight));
                };

                voteListeners[key].Add(answerHash, wrappedAnswer);
            }
        }