コード例 #1
0
 private void OnSubscribed(string topic)
 {
     Subscribed?.Invoke(this, new SubscriptionEventArgs()
     {
         Topic = topic
     });
 }
コード例 #2
0
        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();
                }
            }
        }
コード例 #3
0
        internal virtual void SubscriptionSucceeded(string data)
        {
            if (IsSubscribed)
            {
                return;
            }

            IsSubscribed = true;

            Subscribed?.Invoke(this);
        }
コード例 #4
0
        private void EnsureConnected(TcpClientWrapper client)
        {
            Subscribers.Add(client);
            Subscribed?.Invoke(client);

            Task.Factory.StartNew(() =>
            {
                while (client.State != TcpState.Closed)
                {
                    ;
                }
                Subscribers.Remove(client);
            });
        }
コード例 #5
0
 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));
             }
         }
     }
 }
コード例 #6
0
ファイル: AimpObserver.cs プロジェクト: SKKbySSK/Legato
        /// <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();
        }
コード例 #7
0
ファイル: NatsService.cs プロジェクト: fremag/nats-ui
        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);
        }
コード例 #8
0
 /// <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));
 }
コード例 #9
0
 protected virtual void OnSubscribed(Subscribe subscribe)
 {
     Subscribed?.Invoke(this, new SubscriptionEventArgs(subscribe));
 }
コード例 #10
0
 public virtual void Subscribe <TParameter>(Action <TParameter> callback)
 {
     Subscribed?.Invoke(this, callback);
 }
コード例 #11
0
 public virtual void Subscribe(Action callback)
 {
     Subscribed?.Invoke(this, callback);
 }
コード例 #12
0
        private void RaiseOnReSubscribe()
        {
            OnSubscribed();

            Subscribed?.Invoke(this, new EventArgs());
        }
コード例 #13
0
        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);
            }
        }