3
|
1 using System;
|
|
2
|
|
3 namespace ServerMonitorApp
|
|
4 {
|
9
|
5 /// <summary>Control for editing a file check.</summary>
|
3
|
6 [CheckType(typeof(FileCheck))]
|
|
7 public partial class FileCheckControl : CheckControl
|
|
8 {
|
|
9 public FileCheckControl()
|
|
10 {
|
|
11 InitializeComponent();
|
|
12 }
|
|
13
|
|
14 private void DiskSpaceCheckControl_Load(object sender, EventArgs e)
|
|
15 {
|
9
|
16 // Initialize the combo boxes to non-empty values.
|
3
|
17 FileSizeComparisonComboBox.SelectedIndex = 0;
|
|
18 DateModifiedComparisonComboBox.SelectedIndex = 0;
|
|
19 }
|
|
20
|
9
|
21 /// <summary>Sets the values of the controls from a check's properties.</summary>
|
3
|
22 public override void LoadCheck(Check check1)
|
|
23 {
|
|
24 FileCheck check = (FileCheck)check1;
|
|
25 FileTextBox.Text = check.File;
|
|
26 FileSizeCheckBox.Checked = check.CheckFileSize;
|
|
27 FileSizeComparisonComboBox.SelectedIndex = check.FileSizeLessThan ? 0 : 1;
|
|
28 FileSizeTextBox.Text = check.FileSizeInSelectedUnits.ToString();
|
|
29 FileSizeUnitsComboBox.SelectedIndex = (int)check.FileSizeUnits;
|
|
30 DateModifiedCheckBox.Checked = check.CheckDateModified;
|
|
31 DateModifiedComparisonComboBox.SelectedIndex = check.DateModifiedOlderThan ? 0 : 1;
|
|
32 DateModifiedTextBox.Text = check.DateModified.ToString();
|
|
33 DateModifiedUnitsComboBox.SelectedIndex = (int)check.DateModifiedUnits;
|
|
34
|
9
|
35 // Blank out text boxes that are disabled and have a blank-looking value.
|
|
36 if (FileSizeTextBox.Text == "0" && !check.CheckFileSize)
|
3
|
37 FileSizeTextBox.Clear();
|
9
|
38 if (DateModifiedTextBox.Text == "0" && !check.CheckDateModified)
|
3
|
39 DateModifiedTextBox.Clear();
|
|
40 }
|
|
41
|
9
|
42 /// <summary>Updates the properties of a check from user input.</summary>
|
3
|
43 public override void UpdateCheck(Check check1)
|
|
44 {
|
|
45 FileCheck check = (FileCheck)check1;
|
|
46 check.File = FileTextBox.Text;
|
|
47 check.CheckFileSize = FileSizeCheckBox.Checked;
|
|
48 check.FileSizeLessThan = FileSizeComparisonComboBox.SelectedIndex == 0;
|
|
49 try
|
|
50 {
|
|
51 check.FileSizeInSelectedUnits = double.Parse(FileSizeTextBox.Text);
|
|
52 }
|
|
53 catch
|
|
54 {
|
|
55 if (check.CheckFileSize)
|
|
56 throw new UpdateCheckException("File size must be numeric.");
|
|
57 else
|
|
58 check.FileSizeInSelectedUnits = 0;
|
|
59 }
|
|
60 check.FileSizeUnits = (SizeUnits)FileSizeUnitsComboBox.SelectedIndex;
|
|
61 check.CheckDateModified = DateModifiedCheckBox.Checked;
|
|
62 check.DateModifiedOlderThan = DateModifiedComparisonComboBox.SelectedIndex == 0;
|
|
63 try
|
|
64 {
|
|
65 check.DateModified = double.Parse(DateModifiedTextBox.Text);
|
|
66 }
|
|
67 catch
|
|
68 {
|
|
69 if (check.CheckDateModified)
|
|
70 throw new UpdateCheckException("Date modified must be numeric.");
|
|
71 else
|
|
72 check.DateModified = 0;
|
|
73 }
|
|
74 check.DateModifiedUnits = (TimeUnits)DateModifiedUnitsComboBox.SelectedIndex;
|
|
75 }
|
|
76 }
|
|
77 } |