annotate ServerMonitor/Controls/HttpCheckControl.cs @ 18:b713b9db4c82

HTTP checks.
author Brad Greco <brad@bgreco.net>
date Mon, 27 May 2019 15:40:44 -0400
parents 7127d5b5ac75
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
1 using System;
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
2
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
3 namespace ServerMonitorApp
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
4 {
9
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 1
diff changeset
5 /// <summary>Control for editing an HTTP check.</summary>
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
6 [CheckType(typeof(HttpCheck))]
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
7 public partial class HttpCheckControl : CheckControl
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
8 {
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
9 public HttpCheckControl()
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
10 {
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
11 InitializeComponent();
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
12 }
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
13
18
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
14 private void HttpCheckControl_Load(object sender, System.EventArgs e)
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
15 {
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
16 // Initialize the combo boxes to non-empty values.
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
17 MethodComboBox.SelectedIndex = 0;
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
18 }
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
19
9
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 1
diff changeset
20 /// <summary>Sets the values of the controls from a check's properties.</summary>
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
21 public override void LoadCheck(Check check1)
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
22 {
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
23 HttpCheck check = (HttpCheck)check1;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
24 UrlTextBox.Text = check.Url;
18
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
25 MethodComboBox.SelectedItem = check.Method ?? "GET";
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
26 ResponseCodeCheckBox.Checked = check.CheckResponseCode;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
27 ResponseCodeTextBox.Text = check.ResponseCode.ToString();
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
28 ResponseLengthCheckbox.Checked = check.CheckResponseLength;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
29 ResponseLengthMinTextBox.Text = check.ResponseLengthMin;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
30 ResponseLengthMaxTextBox.Text = check.ResponseLengthMax;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
31 ResponseBodyCheckBox.Checked = check.CheckResponseBody;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
32 ResponseBodyComboBox.SelectedIndex = (int)check.ResponseBodyMatchType;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
33 ResponseBodyTextBox.Text = check.ResponseBodyPattern;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
34 ResponseBodyRegexCheckBox.Checked = check.ResponseBodyUseRegex;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
35 }
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
36
9
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 1
diff changeset
37 /// <summary>Updates the properties of a check from user input.</summary>
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
38 public override void UpdateCheck(Check check1)
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
39 {
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
40 HttpCheck check = (HttpCheck)check1;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
41 check.Url = UrlTextBox.Text.Trim();
18
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
42 check.Method = MethodComboBox.SelectedItem.ToString();
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
43 check.CheckResponseCode = ResponseCodeCheckBox.Checked;
1
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
44 try
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
45 {
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
46 check.ResponseCode = int.Parse(ResponseCodeTextBox.Text);
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
47 }
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
48 catch
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
49 {
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
50 throw new UpdateCheckException("Response code must be an integer.");
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
51 }
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
52 check.CheckResponseLength = ResponseLengthCheckbox.Checked;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
53 check.ResponseLengthMin = ResponseLengthMinTextBox.Text;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
54 check.ResponseLengthMax = ResponseLengthMaxTextBox.Text;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
55 check.CheckResponseBody = ResponseBodyCheckBox.Checked;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
56 check.ResponseBodyMatchType = (MatchType)ResponseBodyComboBox.SelectedIndex;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
57 check.ResponseBodyPattern = ResponseBodyTextBox.Text;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
58 check.ResponseBodyUseRegex = ResponseBodyRegexCheckBox.Checked;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
59 }
18
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
60
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
61 private void MethodComboBox_SelectedIndexChanged(object sender, EventArgs e)
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
62 {
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
63 if (MethodComboBox.SelectedIndex == 1)
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
64 {
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
65 ResponseBodyCheckBox.Checked = false;
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
66 ResponseBodyCheckBox.Enabled = false;
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
67 }
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
68 else
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
69 {
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
70 ResponseBodyCheckBox.Enabled = true;
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
71 }
b713b9db4c82 HTTP checks.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
72 }
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
73 }
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
74 }