示例#1
0
 private void BiliLiveListener_ConnectionFailed(string message)
 {
     AppendMessage(message, (Color)ColorConverter.ConvertFromString("#FFE61919"));
     if (ConfigManager.CurrentStatus.IsConnected)
     {
         PingReply pingReply = null;
         try
         {
             if (ConfigManager.CurrentConfig.Timeout > 0)
             {
                 pingReply = new Ping().Send("live.bilibili.com", ConfigManager.CurrentConfig.Timeout);
             }
             else
             {
                 pingReply = new Ping().Send("live.bilibili.com");
             }
         }
         catch (Exception)
         {
         }
         if (pingReply != null && pingReply.Status == IPStatus.Success)
         {
             Thread.Sleep(ConfigManager.CurrentConfig.RetryInterval);
             Dispatcher.Invoke(new Action(() =>
             {
                 AppendMessage(Application.Current.Resources["Retrying"].ToString(), (Color)ColorConverter.ConvertFromString("#FFE61919"));
                 biliLiveListener.Disconnect();
                 biliLiveListener = new BiliLiveListener(uint.Parse(RoomIdBox.Text), ConfigManager.CurrentConfig.Timeout);
                 biliLiveListener.PopularityRecieved += BiliLiveListener_PopularityRecieved;
                 biliLiveListener.JsonRecieved       += BiliLiveListener_JsonRecieved;
                 biliLiveListener.Connected          += BiliLiveListener_Connected;
                 biliLiveListener.ConnectionFailed   += BiliLiveListener_ConnectionFailed;
                 biliLiveListener.Connect();
             }));
         }
         else
         {
             AppendMessage(Application.Current.Resources["ConnectionFailed"].ToString(), (Color)ColorConverter.ConvertFromString("#FFE61919"));
             Thread.Sleep(ConfigManager.CurrentConfig.RetryInterval);
             BiliLiveListener_ConnectionFailed(Application.Current.Resources["CheckingNetwork"].ToString());
         }
     }
     else
     {
         Dispatcher.Invoke(new Action(() =>
         {
             ConnectBtn.IsEnabled = true;
             ConnectBtn.Content   = Application.Current.Resources["Connect"].ToString();
             PopularityBox.Text   = "0";
             RoomIdBox.IsEnabled  = true;
             RoomIdBox.Visibility = Visibility.Visible;
             InfoGrid.Visibility  = Visibility.Hidden;
             TitleBox.Text        = Application.Current.Resources["BiliLiveHelper"].ToString();
         }));
     }
 }
示例#2
0
        // About Connection

        private void Connect()
        {
            if (RoomIdBox.Text.Length == 0)
            {
                AppendMessage(Application.Current.Resources["RoomIdHint"].ToString(), (Color)ColorConverter.ConvertFromString("#FFE61919"));
                return;
            }
            ConnectBtn.IsEnabled = false;
            ConnectBtn.Content   = Application.Current.Resources["Connecting"].ToString();
            RoomIdBox.IsEnabled  = false;

            biliLiveListener = new BiliLiveListener(uint.Parse(RoomIdBox.Text), ConfigManager.CurrentConfig.Timeout);
            biliLiveListener.PopularityRecieved += BiliLiveListener_PopularityRecieved;
            biliLiveListener.JsonRecieved       += BiliLiveListener_JsonRecieved;
            biliLiveListener.Connected          += BiliLiveListener_Connected;
            biliLiveListener.ConnectionFailed   += BiliLiveListener_ConnectionFailed;
            biliLiveListener.Connect();
        }
示例#3
0
 private void ListenBtn_Click(object sender, RoutedEventArgs e)
 {
     ListenBtn.IsEnabled = false;
     if (biliLiveListener == null)
     {
         ListenBtn.Content                  = "Connecting";
         biliLiveListener                   = new BiliLiveListener(2746439, BiliLiveListener.Protocols.Tcp);
         biliLiveListener.Connected        += BiliLiveListener_Connected;
         biliLiveListener.ConnectionFailed += BiliLiveListener_ConnectionFailed;
         biliLiveListener.JsonsRecieved    += BiliLiveListener_JsonsRecieved;
         biliLiveListener.Connect();
     }
     else
     {
         ListenBtn.Content              = "Disconnecting";
         biliLiveListener.Disconnected += BiliLiveListener_Disconnected;
         biliLiveListener.Disconnect();
         biliLiveListener = null;
     }
 }
        private void ConnectBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                uint roomId = uint.Parse(RoomIdBox.Text);

                BiliLiveListener.Protocols protocol = BiliLiveListener.Protocols.Tcp;
                switch (ConnectionModeCombo.SelectedIndex)
                {
                case 0:
                    protocol = BiliLiveListener.Protocols.Tcp;
                    break;

                case 1:
                    protocol = BiliLiveListener.Protocols.Wss;
                    break;

                case 2:
                    protocol = BiliLiveListener.Protocols.Ws;
                    break;
                }

                LiveListener = new BiliLiveListener(roomId, protocol);
                LiveListener.ItemsRecieved      += BiliLiveListener_ItemsRecieved;
                LiveListener.PopularityRecieved += LiveListener_PopularityRecieved;
                LiveListener.Connected          += BiliLiveListener_Connected;
                LiveListener.Disconnected       += BiliLiveListener_Disconnected;
                LiveListener.ConnectionFailed   += LiveListener_ConnectionFailed;
                LiveListener.Connect();

                ConnectionModeCombo.IsEnabled = false;
                ConnectBtn.IsEnabled          = false;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }