comparison 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
comparison
equal deleted inserted replaced
17:68d7834dc28e 18:b713b9db4c82
1 namespace ServerMonitorApp 1 using System;
2
3 namespace ServerMonitorApp
2 { 4 {
3 /// <summary>Control for editing an HTTP check.</summary> 5 /// <summary>Control for editing an HTTP check.</summary>
4 [CheckType(typeof(HttpCheck))] 6 [CheckType(typeof(HttpCheck))]
5 public partial class HttpCheckControl : CheckControl 7 public partial class HttpCheckControl : CheckControl
6 { 8 {
7 public HttpCheckControl() 9 public HttpCheckControl()
8 { 10 {
9 InitializeComponent(); 11 InitializeComponent();
10 } 12 }
11 13
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
12 /// <summary>Sets the values of the controls from a check's properties.</summary> 20 /// <summary>Sets the values of the controls from a check's properties.</summary>
13 public override void LoadCheck(Check check1) 21 public override void LoadCheck(Check check1)
14 { 22 {
15 HttpCheck check = (HttpCheck)check1; 23 HttpCheck check = (HttpCheck)check1;
16 UrlTextBox.Text = check.Url; 24 UrlTextBox.Text = check.Url;
25 MethodComboBox.SelectedItem = check.Method ?? "GET";
17 ResponseCodeCheckBox.Checked = check.CheckResponseCode; 26 ResponseCodeCheckBox.Checked = check.CheckResponseCode;
18 ResponseCodeTextBox.Text = check.ResponseCode.ToString(); 27 ResponseCodeTextBox.Text = check.ResponseCode.ToString();
19 ResponseLengthCheckbox.Checked = check.CheckResponseLength; 28 ResponseLengthCheckbox.Checked = check.CheckResponseLength;
20 ResponseLengthMinTextBox.Text = check.ResponseLengthMin; 29 ResponseLengthMinTextBox.Text = check.ResponseLengthMin;
21 ResponseLengthMaxTextBox.Text = check.ResponseLengthMax; 30 ResponseLengthMaxTextBox.Text = check.ResponseLengthMax;
28 /// <summary>Updates the properties of a check from user input.</summary> 37 /// <summary>Updates the properties of a check from user input.</summary>
29 public override void UpdateCheck(Check check1) 38 public override void UpdateCheck(Check check1)
30 { 39 {
31 HttpCheck check = (HttpCheck)check1; 40 HttpCheck check = (HttpCheck)check1;
32 check.Url = UrlTextBox.Text.Trim(); 41 check.Url = UrlTextBox.Text.Trim();
42 check.Method = MethodComboBox.SelectedItem.ToString();
33 check.CheckResponseCode = ResponseCodeCheckBox.Checked; 43 check.CheckResponseCode = ResponseCodeCheckBox.Checked;
34 try 44 try
35 { 45 {
36 check.ResponseCode = int.Parse(ResponseCodeTextBox.Text); 46 check.ResponseCode = int.Parse(ResponseCodeTextBox.Text);
37 } 47 }
45 check.CheckResponseBody = ResponseBodyCheckBox.Checked; 55 check.CheckResponseBody = ResponseBodyCheckBox.Checked;
46 check.ResponseBodyMatchType = (MatchType)ResponseBodyComboBox.SelectedIndex; 56 check.ResponseBodyMatchType = (MatchType)ResponseBodyComboBox.SelectedIndex;
47 check.ResponseBodyPattern = ResponseBodyTextBox.Text; 57 check.ResponseBodyPattern = ResponseBodyTextBox.Text;
48 check.ResponseBodyUseRegex = ResponseBodyRegexCheckBox.Checked; 58 check.ResponseBodyUseRegex = ResponseBodyRegexCheckBox.Checked;
49 } 59 }
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 }
50 } 73 }
51 } 74 }