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 } } }
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 } ); }
public void PublishByStringTopicAsync(PubsubMessage message) { this.PublishByStringTopicAsync(message, null, null); }
public void PublishAsync(PubsubMessage message) { this.PublishAsync(message, null, null); }