Mercurial > servermonitor
annotate ServerMonitor/Controls/HttpCheckControl.cs @ 19:b3128fe10d57
Add About form and license.
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Wed, 29 May 2019 20:18:37 -0400 |
parents | b713b9db4c82 |
children |
rev | line source |
---|---|
18 | 1 using System; |
2 | |
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 | 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 | 14 private void HttpCheckControl_Load(object sender, System.EventArgs e) |
15 { | |
16 // Initialize the combo boxes to non-empty values. | |
17 MethodComboBox.SelectedIndex = 0; | |
18 } | |
19 | |
9 | 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 | 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 | 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 | 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 | 60 |
61 private void MethodComboBox_SelectedIndexChanged(object sender, EventArgs e) | |
62 { | |
63 if (MethodComboBox.SelectedIndex == 1) | |
64 { | |
65 ResponseBodyCheckBox.Checked = false; | |
66 ResponseBodyCheckBox.Enabled = false; | |
67 } | |
68 else | |
69 { | |
70 ResponseBodyCheckBox.Enabled = true; | |
71 } | |
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 } |