annotate ServerMonitor/Controls/FileCheckControl.cs @ 3:96f0b028176d

File check
author Brad Greco <brad@bgreco.net>
date Fri, 11 Jan 2019 22:34:18 -0500
parents
children 7127d5b5ac75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
1 using System;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
2 using System.Collections.Generic;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
3 using System.ComponentModel;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
4 using System.Drawing;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
5 using System.Data;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
6 using System.Linq;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
7 using System.Text;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
8 using System.Windows.Forms;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
9
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
10 namespace ServerMonitorApp
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
11 {
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
12 [CheckType(typeof(FileCheck))]
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
13 public partial class FileCheckControl : CheckControl
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
14 {
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
15 public FileCheckControl()
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
16 {
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
17 InitializeComponent();
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
18 }
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
19
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
20 private void DiskSpaceCheckControl_Load(object sender, EventArgs e)
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
21 {
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
22 FileSizeComparisonComboBox.SelectedIndex = 0;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
23 DateModifiedComparisonComboBox.SelectedIndex = 0;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
24 }
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
25
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
26 public override void LoadCheck(Check check1)
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
27 {
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
28 FileCheck check = (FileCheck)check1;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
29 FileTextBox.Text = check.File;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
30 FileSizeCheckBox.Checked = check.CheckFileSize;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
31 FileSizeComparisonComboBox.SelectedIndex = check.FileSizeLessThan ? 0 : 1;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
32 FileSizeTextBox.Text = check.FileSizeInSelectedUnits.ToString();
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
33 FileSizeUnitsComboBox.SelectedIndex = (int)check.FileSizeUnits;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
34 DateModifiedCheckBox.Checked = check.CheckDateModified;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
35 DateModifiedComparisonComboBox.SelectedIndex = check.DateModifiedOlderThan ? 0 : 1;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
36 DateModifiedTextBox.Text = check.DateModified.ToString();
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
37 DateModifiedUnitsComboBox.SelectedIndex = (int)check.DateModifiedUnits;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
38
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
39 if (FileSizeTextBox.Text == "0")
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
40 FileSizeTextBox.Clear();
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
41 if (DateModifiedTextBox.Text == "0")
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
42 DateModifiedTextBox.Clear();
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
43 }
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
44
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
45 public override void UpdateCheck(Check check1)
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
46 {
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
47 FileCheck check = (FileCheck)check1;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
48 check.File = FileTextBox.Text;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
49 check.CheckFileSize = FileSizeCheckBox.Checked;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
50 check.FileSizeLessThan = FileSizeComparisonComboBox.SelectedIndex == 0;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
51 try
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
52 {
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
53 check.FileSizeInSelectedUnits = double.Parse(FileSizeTextBox.Text);
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
54 }
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
55 catch
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
56 {
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
57 if (check.CheckFileSize)
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
58 throw new UpdateCheckException("File size must be numeric.");
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
59 else
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
60 check.FileSizeInSelectedUnits = 0;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
61 }
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
62 check.FileSizeUnits = (SizeUnits)FileSizeUnitsComboBox.SelectedIndex;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
63 check.CheckDateModified = DateModifiedCheckBox.Checked;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
64 check.DateModifiedOlderThan = DateModifiedComparisonComboBox.SelectedIndex == 0;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
65 try
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
66 {
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
67 check.DateModified = double.Parse(DateModifiedTextBox.Text);
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
68 }
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
69 catch
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
70 {
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
71 if (check.CheckDateModified)
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
72 throw new UpdateCheckException("Date modified must be numeric.");
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
73 else
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
74 check.DateModified = 0;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
75 }
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
76 check.DateModifiedUnits = (TimeUnits)DateModifiedUnitsComboBox.SelectedIndex;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
77 }
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
78 }
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
79 }