comparison ServerMonitor/Forms/ServerSummaryForm.cs @ 8:052aa62cb42a

Single instance. Add autorun option. Add icons. General enhancements.
author Brad Greco <brad@bgreco.net>
date Sat, 09 Mar 2019 20:14:03 -0500
parents c1dffaac66fa
children 9e77c0dccb66
comparison
equal deleted inserted replaced
7:8486ab7d2357 8:052aa62cb42a
38 NotifyIcon.ShowBalloonTip(30000, title, result.Message, GetToolTipIcon(result.CheckStatus)); 38 NotifyIcon.ShowBalloonTip(30000, title, result.Message, GetToolTipIcon(result.CheckStatus));
39 } 39 }
40 40
41 private void ServerSummaryForm_Load(object sender, EventArgs e) 41 private void ServerSummaryForm_Load(object sender, EventArgs e)
42 { 42 {
43 Size size = Settings.Default.SummaryFormSize;
44 if (size.Height > 0 && size.Width > 0)
45 Size = size;
46
43 Helpers.FormatImageButton(NewServerButton); 47 Helpers.FormatImageButton(NewServerButton);
44 Helpers.FormatImageButton(SettingsButton); 48 Helpers.FormatImageButton(SettingsButton);
45 monitor = new ServerMonitor(this); 49 monitor = new ServerMonitor(this);
46 while (true) 50 while (true)
47 { 51 {
59 { 63 {
60 Environment.Exit(1); 64 Environment.Exit(1);
61 } 65 }
62 } 66 }
63 } 67 }
64 NotifyIcon.Icon = new Icon(Icon, 16, 16);
65 monitor.CheckStatusChanged += Monitor_CheckStatusChanged; 68 monitor.CheckStatusChanged += Monitor_CheckStatusChanged;
66 RefreshDisplay(); 69 RefreshDisplay();
67 CollectPrivateKeyPasswords(); 70 CollectPrivateKeyPasswords();
68 } 71 }
69 72
101 ServerSummaryControl control = new ServerSummaryControl(server); 104 ServerSummaryControl control = new ServerSummaryControl(server);
102 control.ContextMenuStrip = ServerContextMenu; 105 control.ContextMenuStrip = ServerContextMenu;
103 control.Click += ServerSummaryControl_Click; 106 control.Click += ServerSummaryControl_Click;
104 ServerPanel.Controls.Add(control); 107 ServerPanel.Controls.Add(control);
105 } 108 }
109 UpdateIcon();
106 } 110 }
107 111
108 private void RefreshServer(Server server) 112 private void RefreshServer(Server server)
109 { 113 {
110 ServerPanel.Controls.Cast<ServerSummaryControl>().FirstOrDefault(c => c.Server == server).Refresh(); 114 ServerPanel.Controls.Cast<ServerSummaryControl>().FirstOrDefault(c => c.Server == server).Refresh();
115 UpdateIcon();
116 }
117
118 private void UpdateIcon()
119 {
120 CheckStatus status = monitor.Servers
121 .Select(s => s.Enabled
122 ? s.Status
123 : s.KeyStatus == KeyStatus.NeedPassword ? CheckStatus.Warning : CheckStatus.Success)
124 .DefaultIfEmpty(CheckStatus.Success)
125 .Max();
126 Icon = status.GetIcon();
127 NotifyIcon.Icon = Icon;
111 } 128 }
112 129
113 private void CollectPrivateKeyPasswords() 130 private void CollectPrivateKeyPasswords()
114 { 131 {
115 List<string> triedKeys = new List<string>(); 132 List<string> triedKeys = new List<string>();
128 } 145 }
129 146
130 private void Monitor_CheckStatusChanged(object sender, CheckStatusChangedEventArgs e) 147 private void Monitor_CheckStatusChanged(object sender, CheckStatusChangedEventArgs e)
131 { 148 {
132 if (e.CheckResult != null) 149 if (e.CheckResult != null)
150 {
133 RefreshServer(e.Check.Server); 151 RefreshServer(e.Check.Server);
152 }
134 } 153 }
135 154
136 private ToolTipIcon GetToolTipIcon(CheckStatus status) 155 private ToolTipIcon GetToolTipIcon(CheckStatus status)
137 { 156 {
138 switch (status) 157 switch (status)
227 246
228 private Server GetClickedServer(ContextMenuStrip menu) 247 private Server GetClickedServer(ContextMenuStrip menu)
229 { 248 {
230 return ((ServerSummaryControl)menu.SourceControl).Server; 249 return ((ServerSummaryControl)menu.SourceControl).Server;
231 } 250 }
251
252 private void ServerSummaryForm_ResizeEnd(object sender, EventArgs e)
253 {
254 Settings.Default.SummaryFormSize = Size;
255 Settings.Default.Save();
256 }
257
258 protected override void WndProc(ref Message m)
259 {
260 if (m.Msg == Win32Helpers.WM_SHOWMONITOR)
261 ShowWindow();
262 base.WndProc(ref m);
263 }
264
265 private void NotifyIcon_MouseClick(object sender, MouseEventArgs e)
266 {
267 if (e.Button == MouseButtons.Left)
268 ShowWindow();
269 else if (e.Button == MouseButtons.Right)
270 NotificationIconMenu.Show();
271 }
272
273 private void ShowWindow()
274 {
275 if (WindowState == FormWindowState.Minimized)
276 WindowState = FormWindowState.Normal;
277 Show();
278 TopMost = true;
279 TopMost = false;
280 Activate();
281 }
282
283 private void NotificationIconMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
284 {
285 if (e.ClickedItem == ShowServerMonitorMenuItem)
286 ShowWindow();
287 else if (e.ClickedItem == ExitMenuItem)
288 Application.Exit();
289 }
232 } 290 }
233 } 291 }