Ejemplo n.º 1
0
        public object Push(NotificationRequest noteRequest)
        {
            string appId = (string)this.Request.Properties["AppId"];

            if (noteRequest == null)
            {
                throw new ArgumentNullException("noteRequest");
            }
            noteRequest.Validate();

            int count = 0;

            // enqueue individual tokens
            string[] goodTokens = new string[0];
            if (noteRequest.Tokens != null)
            {
                var store = new MongoTokenStore();
                goodTokens = store.FilterExisting(appId, noteRequest.Platform, noteRequest.Tokens).Select(r => r.Token).Distinct().ToArray();
                foreach (var tok in goodTokens)
                {
                    count++;
                    _queue.Enqueue(appId, noteRequest.Platform, tok, noteRequest.Expiry, noteRequest.Payload);
                }
            }

            // enqueue segment groups, except tokens already specified
            if (noteRequest.Segments != null)
            {
                foreach (var seg in noteRequest.Segments)
                {
                    foreach (var tok in _store.GetTokens(appId, noteRequest.Platform, seg).Except(goodTokens))
                    {
                        count++;
                        _queue.Enqueue(appId, noteRequest.Platform, tok, noteRequest.Expiry, noteRequest.Payload);
                    }
                }
            }

            return(new { success = true, count = count, badTokens = noteRequest.Tokens.Except(goodTokens).ToArray() });
        }