Exemple #1
0
        /// <summary>
        /// Streamingを再接続します。
        /// </summary>
        public void RestartStreaming()
        {
            StopStreaming();

            Streaming = Token.Streaming
                        .StartObservableStream(
                StreamingType.User,
                new StreamingParameters(include_entities => "true", include_followings_activity => "true"))
                        .Publish();

            StreamManager.Add(Streaming.Subscribe(
                                  (p) =>
            {
                Task.Run(() =>
                {
                    if (p is StatusMessage)
                    {
                        OnStatus((StatusMessage)p);
                    }
                    if (p is EventMessage)
                    {
                        OnEvent((EventMessage)p);
                    }
                    if (p is IdMessage)
                    {
                        OnIdEvent((IdMessage)p);
                    }
                    if (p is DirectMessageMessage)
                    {
                        OnDirectMessage((DirectMessageMessage)p);
                    }
                });
            },
                                  (Action <Exception>)((ex) =>
            {
                //throw ex;
            }),
                                  (Action)(() =>
            {
                Console.WriteLine("Completed!?");
                throw new InvalidOperationException("何故かUserStreamが切れました");
            })
                                  ));

            StreamManager.Add(Streaming.Connect());
        }