Advertisement
SonOfABeach

Untitled

Jan 13th, 2015
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Status_Check
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         string[] ServerName = { "Playstation Network", "XBOX Live" };
  16.         string[] ServerURL = { "https://support.us.playstation.com/app/answers/detail/a_id/237/~/psn-status%3A-on", "https://support.xbox.com/en-US/xbox-live-status" };
  17.         string[] Element = { "rn_AnswerText", "XboxLiveCoreServices" };
  18.         char[] ElementChar = { '!', 'L' };
  19.         int[] ElementNum = { 1, 189 };
  20.  
  21.         int Retry_Time = 60;
  22.         int tick = 60;
  23.  
  24.         public Form1()
  25.         {
  26.             InitializeComponent();
  27.         }
  28.  
  29.         private void MessageBox_Popup_Show(string Name)
  30.         {
  31.             MessageBox_Popup Mp = new MessageBox_Popup();
  32.             if (!Mp.IsShown)
  33.             {
  34.                 Mp.Show();
  35.                 Mp.Message = Name;
  36.             }
  37.         }
  38.  
  39.         private void Form1_Load(object sender, EventArgs e)
  40.         {
  41.             this.Width = 239;
  42.             this.Height = 216;
  43.             nsComboBox1.SelectedIndex = 0;
  44.         }
  45.  
  46.         private void nsButton1_Click(object sender, EventArgs e)
  47.         {
  48.             if (nsButton1.Text == "Start Checking")
  49.             {
  50.                 if (nsRadioButton1.Checked)
  51.                     webBrowser1.Url = new Uri(ServerURL[nsComboBox1.SelectedIndex]);
  52.                 else
  53.                     webBrowser1.Url = new Uri(nsTextBox1.Text);
  54.                 nsButton1.Text = "Stop Checking";
  55.                 this.Height = 272;
  56.                 Refresh_Timer.Enabled = true;
  57.                 nsComboBox1.Enabled = false;
  58.                 nsTextBox1.Enabled = false;
  59.                 nsRadioButton1.Enabled = false;
  60.                 nsRadioButton2.Enabled = false;
  61.             }
  62.             else
  63.             {
  64.                 nsButton1.Text = "Start Checking";
  65.                 this.Height = 216;
  66.                 Refresh_Timer.Enabled = false;
  67.                 nsComboBox1.Enabled = true;
  68.                 nsTextBox1.Enabled = true;
  69.                 nsRadioButton1.Enabled = true;
  70.                 nsRadioButton2.Enabled = true;
  71.  
  72.                 tick = Retry_Time;
  73.                 nsLabel2.Visible = false;
  74.                 nsLabel3.Value2 = "Connecting...";
  75.             }
  76.         }
  77.  
  78.         private void nsRadioButton1_CheckedChanged(object sender)
  79.         {
  80.             nsComboBox1.Enabled = nsRadioButton1.Checked;
  81.             nsTextBox1.Enabled = !nsRadioButton1.Checked;
  82.         }
  83.  
  84.         private void Refresh_Timer_Tick(object sender, EventArgs e)
  85.         {
  86.             nsLabel2.Value1 = "Retrying In";
  87.             nsLabel2.Value2 = tick.ToString() + " Seconds";
  88.             tick--;
  89.             if (tick == 0)
  90.             {
  91.                 nsLabel2.Value1 = "Refreshing";
  92.                 nsLabel2.Value2 = "...";
  93.                 webBrowser1.Refresh();
  94.                 tick = Retry_Time;
  95.             }
  96.         }
  97.  
  98.         private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
  99.         {
  100.             nsLabel2.Visible = true;
  101.             if (nsRadioButton1.Checked)//Server
  102.             {
  103.                 try
  104.                 {
  105.                     string Text = webBrowser1.Document.GetElementById(Element[nsComboBox1.SelectedIndex]).InnerHtml;
  106.                     if (Text[ElementNum[nsComboBox1.SelectedIndex]] == ElementChar[nsComboBox1.SelectedIndex])
  107.                     {
  108.                         nsLabel3.Value2 = " Offline";
  109.                     }
  110.                     else
  111.                     {
  112.                         nsLabel3.Value2 = " Online";
  113.                         MessageBox_Popup_Show(ServerName[nsComboBox1.SelectedIndex]);
  114.                     }
  115.                 }
  116.                 catch
  117.                 {
  118.                     nsLabel3.Value2 = "Error";
  119.                 }
  120.             }
  121.             else//Website
  122.             {
  123.                 try
  124.                 {
  125.                     string Text = webBrowser1.Document.GetElementById("mainTitle").InnerText;
  126.                     if (Text == "This page can’t be displayed")
  127.                     {
  128.                         nsLabel3.Value2 = " Offline";
  129.                     }
  130.                     else
  131.                     {
  132.                         nsLabel3.Value2 = " Online";
  133.                         MessageBox_Popup_Show(nsTextBox1.Text);
  134.                     }
  135.                 }
  136.                 catch
  137.                 {
  138.                     nsLabel3.Value2 = " Online";
  139.                     MessageBox_Popup_Show(nsTextBox1.Text);
  140.                 }
  141.             }
  142.         }
  143.     }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement