예제 #1
0
        void DispatchMessage(PubsubMessage message)
        {
            Subscription s = null;

            if (this.subscriptions.TryGetValue(message.TopicId, out s))
            {
                if (s.From <= message.MessageId)
                {
                    s.From = message.MessageId + 1;
                }
                try
                {
                    if (s.OnMessageReceived != null)
                    {
                        if (s.SynchronizationContext != null)
                        {
                            s.SynchronizationContext.Post(
                                delegate(object state)
                            {
                                s.OnMessageReceived(s, message);
                            },
                                null);
                        }
                        else
                        {
                            s.OnMessageReceived(s, message);
                        }
                    }
                }
                catch (Exception)
                {
                    // empty
                }
            }
        }
예제 #2
0
        public void PublishAsync(PubsubMessage message, Action <PubsubMessage> onSuccess, Action <PubsubMessage, Exception> onError)
        {
            if (message == null)
            {
                throw new ArgumentException("message");
            }
            if (message.TopicId <= 0)
            {
                throw new InvalidOperationException("TopicId must be a positive integer.");
            }
            if (string.IsNullOrEmpty(message.ContentType))
            {
                throw new InvalidOperationException("ContentType must be specified.");
            }
            if (message.Body == null)
            {
                throw new InvalidOperationException("Body of the message to publish must be specified.");
            }

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
                new Uri(this.BaseAddress, string.Format(CultureInfo.InvariantCulture, "topics/{0}", message.TopicId)));

            request.Method      = "POST";
            request.ContentType = message.ContentType;
            request.BeginGetRequestStream(
                PubsubClient.ContinueHttpRequest,
                new PublishHttpAsyncContext
            {
                SynchronizationContext = SynchronizationContext.Current,
                Message       = message,
                Request       = request,
                Processor     = PubsubClient.ProcessPublishGetRequestStream,
                OnErrorCore   = onError,
                OnSuccessCore = onSuccess
            }
                );
        }
예제 #3
0
 public void PublishByStringTopicAsync(PubsubMessage message)
 {
     this.PublishByStringTopicAsync(message, null, null);
 }
예제 #4
0
 public void PublishAsync(PubsubMessage message)
 {
     this.PublishAsync(message, null, null);
 }