public FormPings(FormMain mainLink) { this.mainLink = mainLink; InitializeComponent(); Icon = Properties.Resources.AppIcon; if (File.Exists($@"{mainLink.LocalDir}\remote_pings.txt")) { AllPings = new Dictionary <int, PingConfiguration>(); try { using (StreamReader reader = new StreamReader($@"{mainLink.LocalDir}\remote_pings.txt")) { string line = reader.ReadLine(); while ((line = reader.ReadLine()) != null) { string[] values = line.Split(new string[] { "<;>" }, StringSplitOptions.None); int.TryParse(values[0], out int active); int.TryParse(values[3], out int method); int.TryParse(values[4], out int authActive); int.TryParse(values[5], out int useAsAuth); if (method > 3 || method < 0) { method = 0; } PingAuthentication auth = new PingAuthentication() { Active = authActive == 1, UseAsAuth = useAsAuth == 1, AuthName = values[6], AuthToken = values[7] }; AddPing(new PingConfiguration() { Active = active == 1, Name = values[1], URL = values[2], Method = (PingMethod)method, Authentication = auth }); } } } catch { AllPings = new Dictionary <int, PingConfiguration>(); } } else { AllPings = new Dictionary <int, PingConfiguration>(); } foreach (int key in AllPings.Keys) { listViewPings.Items.Add(new ListViewItem() { Name = key.ToString(), Text = AllPings[key].Name, Checked = AllPings[key].Active }); } }
private async void ButtonTestPing_Click(object sender, EventArgs e) { PingMethod chosenMethod = PingMethod.Post; if (radioButtonMethodPut.Checked) { chosenMethod = PingMethod.Put; } else if (radioButtonMethodGet.Checked) { chosenMethod = PingMethod.Get; } else if (radioButtonMethodDelete.Checked) { chosenMethod = PingMethod.Delete; } PingAuthentication auth = new PingAuthentication() { Active = textBoxAuthToken.Text.Trim() != "", UseAsAuth = radioButtonUseAuthField.Checked, AuthName = textBoxAuthName.Text, AuthToken = textBoxAuthToken.Text }; PingConfiguration tempPing = new PingConfiguration() { Active = false, Name = textBoxName.Text, URL = textBoxURL.Text, Method = chosenMethod, Authentication = auth }; bool result = await tempPing.PingServerAsync(null, null); if (result) { MessageBox.Show("Ping test successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Ping test unsuccessful\nCheck your settings", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }
private void FormPing_FormClosing(object sender, FormClosingEventArgs e) { if (textBoxName.Text != "") { if (addNew) { PingMethod chosenMethod = PingMethod.Post; if (radioButtonMethodPut.Checked) { chosenMethod = PingMethod.Put; } else if (radioButtonMethodGet.Checked) { chosenMethod = PingMethod.Get; } else if (radioButtonMethodDelete.Checked) { chosenMethod = PingMethod.Delete; } PingAuthentication auth = new PingAuthentication() { Active = textBoxAuthToken.Text != "", UseAsAuth = radioButtonUseAuthField.Checked, AuthName = textBoxAuthName.Text, AuthToken = textBoxAuthToken.Text }; pingLink.AllPings[reservedId] = new PingConfiguration() { Active = false, Name = textBoxName.Text, URL = textBoxURL.Text, Method = chosenMethod, Authentication = auth }; pingLink.listViewPings.Items.Add(new ListViewItem() { Name = reservedId.ToString(), Text = textBoxName.Text, Checked = false }); } else { if (pingLink.AllPings.ContainsKey(reservedId)) { pingLink.AllPings[reservedId].Active = config.Active; pingLink.AllPings[reservedId].Name = textBoxName.Text; pingLink.AllPings[reservedId].URL = textBoxURL.Text; if (radioButtonMethodPut.Checked) { pingLink.AllPings[reservedId].Method = PingMethod.Put; } else if (radioButtonMethodGet.Checked) { pingLink.AllPings[reservedId].Method = PingMethod.Get; } else if (radioButtonMethodDelete.Checked) { pingLink.AllPings[reservedId].Method = PingMethod.Delete; } else { pingLink.AllPings[reservedId].Method = PingMethod.Post; } pingLink.AllPings[reservedId].Authentication.Active = textBoxAuthToken.Text.Trim() != ""; pingLink.AllPings[reservedId].Authentication.UseAsAuth = radioButtonUseAuthField.Checked; pingLink.AllPings[reservedId].Authentication.AuthName = textBoxAuthName.Text; pingLink.AllPings[reservedId].Authentication.AuthToken = textBoxAuthToken.Text; pingLink.listViewPings.Items[pingLink.listViewPings.Items.IndexOfKey(reservedId.ToString())] = new ListViewItem() { Name = reservedId.ToString(), Text = textBoxName.Text, Checked = config.Active }; } } } }