private void OnSubscribed(string topic) { Subscribed?.Invoke(this, new SubscriptionEventArgs() { Topic = topic }); }
void IPusher.SubscriptionSuceeded(string channelName, string data) { if (Channels.TryGetValue(channelName, out Channel channel)) { channel.SubscriptionSucceeded(data); if (Subscribed != null) { Task.Run(() => { try { Subscribed.Invoke(this, channel); } catch (Exception error) { InvokeErrorHandler(new SubscribedEventHandlerException(channel, error, data)); } }); } if (channel._subscribeCompleted != null) { channel._subscribeCompleted.Release(); } } }
internal virtual void SubscriptionSucceeded(string data) { if (IsSubscribed) { return; } IsSubscribed = true; Subscribed?.Invoke(this); }
private void EnsureConnected(TcpClientWrapper client) { Subscribers.Add(client); Subscribed?.Invoke(client); Task.Factory.StartNew(() => { while (client.State != TcpState.Closed) { ; } Subscribers.Remove(client); }); }
internal virtual void SubscriptionSucceeded(string data) { if (!IsSubscribed) { IsSubscribed = true; if (Subscribed != null) { try { Subscribed.Invoke(this); } catch (Exception error) { _pusher.RaiseChannelError(new SubscribedEventHandlerException(this, error, data)); } } } }
/// <summary> /// AIMP のイベント通知を購読します /// </summary> /// <exception cref="ApplicationException" /> public void Subscribe() { if (IsSubscribed) { throw new ApplicationException("既に通知を購読しています"); } IsSubscribed = true; var isRunning = Helper.AimpRemoteWindowHandle != IntPtr.Zero; if (!isRunning) { throw new ApplicationException("AIMPが起動していないため、購読に失敗しました"); } Helper.RegisterNotify(_Receiver); Subscribed?.Invoke(); }
public void Subscribe(NatsSubscription natsSubscription) { if (Subscriptions.ContainsKey(natsSubscription)) { return; } Logger.Info($"{nameof(Subscribe)}: {natsSubscription.Subject}"); List <IAsyncSubscription> subs = new List <IAsyncSubscription>(); foreach (var conn in ConnectionsByName.Values) { IAsyncSubscription sub = conn.SubscribeAsync(natsSubscription.Subject, OnMessage); subs.Add(sub); } Subscriptions[natsSubscription] = subs; natsSubscription.Subscribed = subs.Any(); Subscribed?.Invoke(natsSubscription); }
/// <summary> /// Called when an observer is subscribed. /// </summary> /// <param name="observer">The newly subscribed observer.</param> protected virtual void OnSubscribed(IObserver <T> observer) { Subscribed?.Invoke(this, new ObserverEventArgs <T>(observer)); }
protected virtual void OnSubscribed(Subscribe subscribe) { Subscribed?.Invoke(this, new SubscriptionEventArgs(subscribe)); }
public virtual void Subscribe <TParameter>(Action <TParameter> callback) { Subscribed?.Invoke(this, callback); }
public virtual void Subscribe(Action callback) { Subscribed?.Invoke(this, callback); }
private void RaiseOnReSubscribe() { OnSubscribed(); Subscribed?.Invoke(this, new EventArgs()); }
private async void _wsclient_OnMessage(object sender, MessageEventArgs e) { // Ignore if its not text if (!e.IsText) { return; } // Try to parse else ignore message TwitchPubSubPayload received; try { received = JsonConvert.DeserializeObject <TwitchPubSubPayload>(e.Data); } catch { // TODO: remove console debugging output Console.WriteLine("PUBSUB Deserialize Failure..."); return; } // PONG received if (received.Type == "PONG") { // Stop PONG timer _pongtimer.Stop(); // TODO: remove console debugging output #if DEBUG Console.WriteLine("PUBSUB PONG RECEIVED"); #endif } // RECONNECT received else if (received.Type == "RECONNECT") { // Silently reconnect await Reconnect(); } // RESONSE received else if (received.Type == "RESPONSE") { switch (received.Type) { // Server error case "ERR_SERVER": break; // Bad message error case "ERR_BADMESSAGE": break; // Bad oauth error case "ERR_BADAUTH": break; // Bad topic error case "ERR_BADTOPIC": break; // All OK default: Messenger.Default.Send <bool>(true, "PubSubConnectionChanged"); Subscribed?.Invoke(this, null); break; } } // PubSub message on event registered for else if (received.Type == "MESSAGE") { Message?.Invoke(this, new EventArgs()); Console.WriteLine("PUBSUB MESSAGE: " + received.Data.Message); } }