private void ProcessEvent(Response message) { int subscriptionId = message.ContextSpecificResultId; PublishHandler publishEvent = null; if (!subscriptions.TryGetValue((uint)subscriptionId, out publishEvent)) { throw new ErrorException("UNSUBSCRIBE: unknown subscription id."); } publishEvent(message.Json); }
private async void PacketArrival(object sender, Packet packet) { using (var pHandler = new PublishHandler(Environment.MachineName)) { await pHandler.SubmitPacketAsync(new PacketRequestItem { Packets = new List <Packet> { packet }, DeviceToken = _deviceToken }); Console.WriteLine(packet); } }
/// <summary> /// Subscribe to a topic. Refer to WAAPI reference documentation to obtain the list of topics available. /// </summary> /// <param name="topic">Topic to subscribe</param> /// <param name="options">Option for the subscrition.</param> /// <param name="publishHandler">Delegate that will be executed when the topic is pusblished.</param> /// <param name="timeout">The maximum timeout in milliseconds for the function to execute. Will raise Waapi.TimeoutException when timeout is reached.</param> /// <returns></returns> public async System.Threading.Tasks.Task <int> Subscribe( string topic, object options, PublishHandler publishHandler, int timeout = TimeoutMilliSec) { if (options == null) { options = new { } } ; return(await Subscribe(topic, Newtonsoft.Json.Linq.JObject.FromObject(options), publishHandler, timeout).ConfigureAwait(false)); }
/// <summary> /// Subscribe to a topic. Refer to WAAPI reference documentation to obtain the list of topics available. /// </summary> /// <param name="topic">Topic to subscribe</param> /// <param name="options">Option for the subscrition.</param> /// <param name="publishHandler">Delegate that will be executed when the topic is pusblished.</param> /// <param name="timeout">The maximum timeout in milliseconds for the function to execute. Will raise Waapi.TimeoutException when timeout is reached.</param> /// <returns>The subscription id assigned to the subscription. Store the id to call Unsubscribe.</returns> public async System.Threading.Tasks.Task <int> Subscribe( string topic, Newtonsoft.Json.Linq.JObject options, PublishHandler publishHandler, int timeout = TimeoutMilliSec) { if (options == null) { options = new Newtonsoft.Json.Linq.JObject(); } return(await client.Subscribe( topic, options.ToString(), (string json) => { publishHandler(Newtonsoft.Json.Linq.JObject.Parse(json)); }, timeout).ConfigureAwait(false)); }
public void RemoveEvent(Action callback) { Ph -= new PublishHandler(callback); }
public void AddEvent(Action callback) { Ph += new PublishHandler(callback); }
public SubPubComponet() { PublishEvent += new PublishHandler(Notify); }
private void EndUpdateContent(IAsyncResult result) { UpdateContentHander uch = result.AsyncState as UpdateContentHander; Guid[] webresourceIds = uch.EndInvoke(result); // once the content has been updated on all selected web resources then we can publish in bulk rather than 1 by 1 PublishHandler ph = new PublishHandler(BeginPublish); AsyncCallback callback = new AsyncCallback(EndPublish); ph.BeginInvoke(webresourceIds, callback, ph); }
/// <summary> /// Subscribe to a WAMP topic. /// </summary> /// <param name="topic">The topic to which subscribe.</param> /// <param name="options">The options the subscription.</param> /// <param name="publishEvent">The delegate function to call when the topic is published.</param> /// <param name="timeout">The maximum timeout in milliseconds for the function to execute. Will raise Waapi.TimeoutException when timeout is reached.</param> /// <returns>Subscription id, that you can use to unsubscribe.</returns> internal async System.Threading.Tasks.Task <uint> Subscribe(string topic, string options, PublishHandler publishEvent, int timeout) { int requestId = ++currentRequestId; // [SUBSCRIBE, Request|id, Options|dict, Topic|uri] await Send($"[{(int)Messages.SUBSCRIBE},{requestId},{options},\"{topic}\"]", timeout); // Should receive the SUBSCRIBED or ERROR Response response = await ReceiveExpect(Messages.SUBSCRIBED, requestId, timeout); subscriptions.TryAdd(response.SubscriptionId, publishEvent); return(response.SubscriptionId); }