Ejemplo n.º 1
0
 public void StartInformStream(string IP)
 {
     if (!Streaming)
     {
         Streaming = true;
         Task.Run(() =>
         {
             try
             {
                 Client = new TcpClient(IP, 2111);
                 if (Client.Connected)
                 {
                     StreamStart?.Invoke();
                 }
                 using NetworkStream stream = Client.GetStream();
                 RigInform RO;
                 Task.Run(() =>
                 {
                     while (App.Live && Client.Connected && Streaming)
                     {
                         Thread.Sleep(2000);
                         Task.Run(() =>
                         {
                             try
                             {
                                 Client2114?.Close();
                                 Client2114?.Dispose();
                                 Client2114 = new TcpClient(IP, 2114);
                                 using NetworkStream stream = Client2114.GetStream();
                                 byte[] data = new byte[1];
                                 int bytes   = stream.Read(data, 0, data.Length);
                                 OMGAlive    = true;
                             }
                             catch
                             {
                                 Client2114?.Close();
                                 Client2114?.Dispose();
                             }
                         });
                     }
                     Exit();
                 });
                 Task.Run(() =>
                 {
                     Thread.Sleep(5000);
                     asdf:
                     while (App.Live && Client.Connected && Streaming)
                     {
                         if (OMGAlive)
                         {
                             OMGAlive = false;
                             for (int i = 0; i < 6; i++)
                             {
                                 Thread.Sleep(1000);
                                 if (OMGAlive)
                                 {
                                     goto asdf;
                                 }
                             }
                             Exit();
                         }
                     }
                     Exit();
                 });
                 while (App.Live && Client.Connected && Streaming)
                 {
                     RO = ReadRootObject(stream);
                     Task.Run(() => SentInform?.Invoke(RO));
                     Thread.Sleep(50);
                 }
                 Exit();
             }
             catch { Exit(); }
         });
     }
 }
Ejemplo n.º 2
0
        private void SocketOnMessageReceived(object sender, MessageReceivedEventArgs messageReceivedEventArgs)
        {
            PubSubMessageEventArgs msg;
            var type = parser.Parse(messageReceivedEventArgs.Message, out msg);

            // ReSharper disable once BitwiseOperatorOnEnumWithoutFlags (enum is not really using flags)
            if ((type & PubSubMessageType.Unknown) > 0)
            {
                Unknown?.Invoke(this, (UnknownMessageEventArgs)msg);
                return;
            }

            // ReSharper disable once SwitchStatementMissingSomeCases (handled by the if above)
            switch (type)
            {
            case PubSubMessageType.Response:
                Response?.Invoke(this, (ResponseMessageEventArgs)msg);
                break;

            case PubSubMessageType.Pong:
                pongTimeoutTimer.Stop();
                Pong?.Invoke(this, System.EventArgs.Empty);
                break;

            case PubSubMessageType.Reconnect:
                HandleReconnect();
                break;

            case PubSubMessageType.Timeout:
                Timeout?.Invoke(this, (TimeoutMessageEventArgs)msg);
                break;

            case PubSubMessageType.Ban:
                Ban?.Invoke(this, (BanMessageEventArgs)msg);
                break;

            case PubSubMessageType.Unban:
                Unban?.Invoke(this, (UnbanMessageEventArgs)msg);
                break;

            case PubSubMessageType.Host:
                Host?.Invoke(this, (HostMessageEventArgs)msg);
                break;

            case PubSubMessageType.Bits:
                Bits?.Invoke(this, (BitsMessageEventArgs)msg);
                break;

            case PubSubMessageType.StreamStart:
                StreamStart?.Invoke(this, (StreamStartMessageEventArgs)msg);
                break;

            case PubSubMessageType.StreamStop:
                StreamStop?.Invoke(this, (StreamStopMessageEventArgs)msg);
                break;

            case PubSubMessageType.ViewerCount:
                ViewerCount?.Invoke(this, (ViewerCountMessageEventArgs)msg);
                break;

            default:
                Error?.Invoke(this, new ExceptionEventArgs(new ArgumentOutOfRangeException()));
                break;
            }
        }