Mercurial > servermonitor
annotate ServerMonitor/Forms/ServerSummaryForm.cs @ 11:75ca86e0862c
Add setting to hide to notification area.
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Mon, 15 Apr 2019 19:24:25 -0400 |
parents | 9e77c0dccb66 |
children | 7626b099aefd |
rev | line source |
---|---|
10 | 1 using NAppUpdate.Framework; |
2 using NAppUpdate.Framework.Sources; | |
3 using NAppUpdate.Framework.Tasks; | |
4 using ServerMonitorApp.Properties; | |
4 | 5 using System; |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
6 using System.Collections.Generic; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
7 using System.ComponentModel; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
8 using System.Data; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
9 using System.Drawing; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
10 using System.Linq; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
11 using System.Text; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
12 using System.Windows.Forms; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
13 |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
14 namespace ServerMonitorApp |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
15 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
16 public partial class ServerSummaryForm : Form |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
17 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
18 private readonly Dictionary<Server, ServerForm> serverForms = new Dictionary<Server, ServerForm>(); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
19 private ServerMonitor monitor; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
20 |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
21 public ServerSummaryForm() |
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 InitializeComponent(); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
24 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
25 |
4 | 26 public void AlertServerForm(Check check) |
27 { | |
28 bool existingForm = serverForms.ContainsKey(check.Server); | |
29 ServerForm form = ShowServerForm(check.Server, false); | |
30 Win32Helpers.FlashWindowEx(form); | |
31 if (!existingForm) | |
32 { | |
33 form.ShowLog(check); | |
34 } | |
35 } | |
36 | |
37 public void ShowBalloon(CheckResult result) | |
38 { | |
39 string title = string.Format("{0}: {1} failed", result.Check.Server.Name, result.Check.Name); | |
40 NotifyIcon.Tag = result; | |
41 NotifyIcon.ShowBalloonTip(30000, title, result.Message, GetToolTipIcon(result.CheckStatus)); | |
42 } | |
43 | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
44 private void ServerSummaryForm_Load(object sender, EventArgs e) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
45 { |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
46 Size size = Settings.Default.SummaryFormSize; |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
47 if (size.Height > 0 && size.Width > 0) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
48 Size = size; |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
49 |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
50 Helpers.FormatImageButton(NewServerButton); |
4 | 51 Helpers.FormatImageButton(SettingsButton); |
52 monitor = new ServerMonitor(this); | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
53 while (true) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
54 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
55 try |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
56 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
57 monitor.LoadServers(); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
58 break; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
59 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
60 catch (Exception ex) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
61 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
62 DialogResult result = MessageBox.Show("Could not load servers. Please fix or delete the file " + monitor.ConfigFile + Environment.NewLine + Environment.NewLine |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
63 + "Error details:" + Environment.NewLine + ex.GetAllMessages(), |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
64 "Error loading servers", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
65 if (result == DialogResult.Cancel) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
66 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
67 Environment.Exit(1); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
68 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
69 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
70 } |
4 | 71 monitor.CheckStatusChanged += Monitor_CheckStatusChanged; |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
72 RefreshDisplay(); |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
73 CollectPrivateKeyPasswords(); |
10 | 74 CheckForUpdate(); |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
75 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
76 |
4 | 77 private ServerForm ShowServerForm(Server server, bool activate = true) |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
78 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
79 bool isNewServer = false; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
80 if (server == null) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
81 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
82 server = new Server(); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
83 monitor.AddServer(server); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
84 isNewServer = true; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
85 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
86 if (serverForms.TryGetValue(server, out ServerForm form)) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
87 { |
4 | 88 if (activate) |
89 form.Activate(); | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
90 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
91 else |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
92 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
93 form = new ServerForm(monitor, server, isNewServer); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
94 serverForms[server] = form; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
95 form.FormClosing += ServerForm_FormClosing; |
4 | 96 form.Show(activate); |
97 } | |
98 return form; | |
99 } | |
100 | |
101 private void RefreshDisplay() | |
102 { | |
103 ServerPanel.Controls.Clear(); | |
104 foreach (Server server in monitor.Servers) | |
105 { | |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
106 server.EnabledChanged -= Server_EnabledChanged; |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
107 server.EnabledChanged += Server_EnabledChanged; |
4 | 108 ServerSummaryControl control = new ServerSummaryControl(server); |
109 control.ContextMenuStrip = ServerContextMenu; | |
110 control.Click += ServerSummaryControl_Click; | |
111 ServerPanel.Controls.Add(control); | |
112 } | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
113 UpdateIcon(); |
4 | 114 } |
115 | |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
116 private void RefreshServer(Server server) |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
117 { |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
118 ServerPanel.Controls.Cast<ServerSummaryControl>().FirstOrDefault(c => c.Server == server).Refresh(); |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
119 UpdateIcon(); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
120 } |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
121 |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
122 private void UpdateIcon() |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
123 { |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
124 CheckStatus status = monitor.Servers |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
125 .Select(s => s.Enabled |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
126 ? s.Status |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
127 : s.KeyStatus == KeyStatus.NeedPassword ? CheckStatus.Warning : CheckStatus.Success) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
128 .DefaultIfEmpty(CheckStatus.Success) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
129 .Max(); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
130 Icon = status.GetIcon(); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
131 NotifyIcon.Icon = Icon; |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
132 } |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
133 |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
134 private void CollectPrivateKeyPasswords() |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
135 { |
6
c1dffaac66fa
- Don't show multiple password dialogs for the same key if the first one was cancelled.
Brad Greco <brad@bgreco.net>
parents:
5
diff
changeset
|
136 List<string> triedKeys = new List<string>(); |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
137 foreach (Server server in monitor.Servers) |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
138 { |
6
c1dffaac66fa
- Don't show multiple password dialogs for the same key if the first one was cancelled.
Brad Greco <brad@bgreco.net>
parents:
5
diff
changeset
|
139 if (triedKeys.Contains(server.KeyFile)) |
c1dffaac66fa
- Don't show multiple password dialogs for the same key if the first one was cancelled.
Brad Greco <brad@bgreco.net>
parents:
5
diff
changeset
|
140 continue; |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
141 ServerForm.OpenPrivateKey(monitor, server, this); |
6
c1dffaac66fa
- Don't show multiple password dialogs for the same key if the first one was cancelled.
Brad Greco <brad@bgreco.net>
parents:
5
diff
changeset
|
142 triedKeys.Add(server.KeyFile); |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
143 } |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
144 } |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
145 |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
146 private void Server_EnabledChanged(object sender, EventArgs e) |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
147 { |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
148 RefreshServer((Server)sender); |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
149 } |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
150 |
4 | 151 private void Monitor_CheckStatusChanged(object sender, CheckStatusChangedEventArgs e) |
152 { | |
153 if (e.CheckResult != null) | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
154 { |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
155 RefreshServer(e.Check.Server); |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
156 } |
4 | 157 } |
158 | |
159 private ToolTipIcon GetToolTipIcon(CheckStatus status) | |
160 { | |
161 switch (status) | |
162 { | |
163 case CheckStatus.Error: return ToolTipIcon.Error; | |
164 case CheckStatus.Warning: return ToolTipIcon.Warning; | |
165 case CheckStatus.Information: return ToolTipIcon.Info; | |
166 default: return ToolTipIcon.None; | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
167 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
168 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
169 |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
170 private void ServerSummaryControl_Click(object sender, EventArgs e) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
171 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
172 ShowServerForm(((ServerSummaryControl)sender).Server); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
173 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
174 |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
175 private void ServerForm_FormClosing(object sender, FormClosingEventArgs e) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
176 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
177 ServerForm form = (ServerForm)sender; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
178 form.FormClosing -= ServerForm_FormClosing; |
4 | 179 Server server = form.Server; |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
180 serverForms.Remove(form.Server); |
4 | 181 if (server.IsEmpty()) |
182 { | |
183 monitor.DeleteServer(server); | |
184 } | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
185 RefreshDisplay(); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
186 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
187 |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
188 private void NewServerButton_Click(object sender, EventArgs e) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
189 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
190 ShowServerForm(null); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
191 } |
4 | 192 |
193 private void ServerSummaryForm_FormClosing(object sender, FormClosingEventArgs e) | |
194 { | |
11
75ca86e0862c
Add setting to hide to notification area.
Brad Greco <brad@bgreco.net>
parents:
10
diff
changeset
|
195 if ((e.CloseReason == CloseReason.None || e.CloseReason == CloseReason.UserClosing) && Settings.Default.HideToNotificationArea) |
4 | 196 { |
197 Hide(); | |
198 e.Cancel = true; | |
199 } | |
200 } | |
201 | |
202 private void SettingsButton_Click(object sender, EventArgs e) | |
203 { | |
204 new SettingsForm().Show(); | |
205 } | |
206 | |
207 private void NotifyIcon_BalloonTipClicked(object sender, EventArgs e) | |
208 { | |
209 CheckResult result = (CheckResult)(sender as NotifyIcon).Tag; | |
210 ServerForm form = ShowServerForm(result.Check.Server); | |
211 form.ShowLog(result.Check); | |
212 form.WindowState = FormWindowState.Normal; | |
213 } | |
214 | |
215 private void ServerContextMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e) | |
216 { | |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
217 Server server = GetClickedServer((ContextMenuStrip)e.ClickedItem.Owner); |
4 | 218 if (e.ClickedItem == DeleteServerMenuItem) |
219 { | |
220 ServerContextMenu.Close(); | |
221 DialogResult result = MessageBox.Show( | |
222 string.Format("The server \"{0}\" and its {1} {2} will be deleted.", server.Name, server.Checks.Count, server.Checks.Count == 1 ? "check" : "checks"), | |
223 "Delete server", | |
224 MessageBoxButtons.OKCancel, | |
225 MessageBoxIcon.Warning ); | |
226 if (result == DialogResult.OK) | |
227 { | |
228 monitor.DeleteServer(server); | |
229 RefreshDisplay(); | |
230 } | |
231 } | |
232 else if (e.ClickedItem == ToggleEnableServerMenuItem) | |
233 { | |
234 bool enable = ToggleEnableServerMenuItem.Text == "Enable"; | |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
235 if (enable) |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
236 { |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
237 ServerContextMenu.Close(); |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
238 ServerForm.OpenPrivateKey(monitor, server, this); |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
239 } |
4 | 240 server.Enabled = enable; |
241 RefreshDisplay(); | |
242 } | |
243 } | |
244 | |
245 private void ServerContextMenu_Opening(object sender, CancelEventArgs e) | |
246 { | |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
247 Server server = GetClickedServer((ContextMenuStrip)sender); |
4 | 248 ToggleEnableServerMenuItem.Text = server.Enabled ? "Disable" : "Enable"; |
249 } | |
250 | |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
251 private Server GetClickedServer(ContextMenuStrip menu) |
4 | 252 { |
253 return ((ServerSummaryControl)menu.SourceControl).Server; | |
254 } | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
255 |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
256 private void ServerSummaryForm_ResizeEnd(object sender, EventArgs e) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
257 { |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
258 Settings.Default.SummaryFormSize = Size; |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
259 Settings.Default.Save(); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
260 } |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
261 |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
262 protected override void WndProc(ref Message m) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
263 { |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
264 if (m.Msg == Win32Helpers.WM_SHOWMONITOR) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
265 ShowWindow(); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
266 base.WndProc(ref m); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
267 } |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
268 |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
269 private void NotifyIcon_MouseClick(object sender, MouseEventArgs e) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
270 { |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
271 if (e.Button == MouseButtons.Left) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
272 ShowWindow(); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
273 else if (e.Button == MouseButtons.Right) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
274 NotificationIconMenu.Show(); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
275 } |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
276 |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
277 private void ShowWindow() |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
278 { |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
279 if (WindowState == FormWindowState.Minimized) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
280 WindowState = FormWindowState.Normal; |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
281 Show(); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
282 TopMost = true; |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
283 TopMost = false; |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
284 Activate(); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
285 } |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
286 |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
287 private void NotificationIconMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
288 { |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
289 if (e.ClickedItem == ShowServerMonitorMenuItem) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
290 ShowWindow(); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
291 else if (e.ClickedItem == ExitMenuItem) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
292 Application.Exit(); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
293 } |
10 | 294 |
295 private void CheckForUpdate() | |
296 { | |
297 //System.Threading.Thread.Sleep(5000); | |
298 UpdateManager manager = UpdateManager.Instance; | |
299 manager.ReinstateIfRestarted(); | |
11
75ca86e0862c
Add setting to hide to notification area.
Brad Greco <brad@bgreco.net>
parents:
10
diff
changeset
|
300 manager.UpdateSource = new SimpleWebSource("https://www.bgreco.net/test/servermonitor.xml"); |
10 | 301 if (manager.State == UpdateManager.UpdateProcessState.NotChecked) |
302 manager.BeginCheckForUpdates(CheckForUpdatesCallback, null); | |
303 } | |
304 | |
305 private void CheckForUpdatesCallback(IAsyncResult result) | |
306 { | |
307 UpdateManager manager = UpdateManager.Instance; | |
308 if (manager.UpdatesAvailable > 0) | |
309 { | |
310 GetUpdateInfo(out string version, out string _); | |
311 if (Settings.Default.IgnoreUpdate != version) | |
312 Invoke((MethodInvoker)(() => UpdatePanel.Show())); | |
313 } | |
314 } | |
315 | |
316 private void PrepareUpdatesCallback(IAsyncResult result) | |
317 { | |
318 UpdateManager manager = UpdateManager.Instance; | |
319 manager.EndCheckForUpdates(result); | |
320 manager.ApplyUpdates(true); | |
321 } | |
322 | |
323 private void UpdateLabel_Click(object sender, EventArgs e) | |
324 { | |
325 GetUpdateInfo(out string version, out string changeMessage); | |
326 string message = "Server Monitor version {0} is available for download." + Environment.NewLine | |
327 + Environment.NewLine | |
328 + "What's new:" + Environment.NewLine | |
329 + "{1}" + Environment.NewLine | |
330 + Environment.NewLine | |
331 + "Would you like to download and apply the update now?"; | |
332 using (UpdateDialog dialog = new UpdateDialog { Message = string.Format(message, version, changeMessage) }) | |
333 { | |
334 DialogResult result = dialog.ShowDialog(); | |
335 if (dialog.Checked && result == DialogResult.Cancel) | |
336 { | |
337 Settings.Default.IgnoreUpdate = version; | |
338 Settings.Default.Save(); | |
339 UpdatePanel.Hide(); | |
340 } | |
341 if (result != DialogResult.OK) | |
342 return; | |
343 } | |
344 UpdateManager.Instance.BeginPrepareUpdates(PrepareUpdatesCallback, null); | |
345 } | |
346 | |
347 private void GetUpdateInfo(out string version, out string changeMessage) | |
348 { | |
349 string[] parts = UpdateManager.Instance.Tasks.First().Description.Split(new char[] { ':' }, 2); | |
350 version = parts[0]; | |
351 changeMessage = parts[1]; | |
352 } | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
353 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
354 } |