# HG changeset patch # User Brad Greco # Date 1554773463 14400 # Node ID 9e77c0dccb66a09b25432116324b3463f09f6bf9 # Parent 7127d5b5ac75732faf2b517de331cb4600e08b8d Add update checker diff -r 7127d5b5ac75 -r 9e77c0dccb66 ServerMonitor/App.config --- a/ServerMonitor/App.config Mon Apr 08 21:29:54 2019 -0400 +++ b/ServerMonitor/App.config Mon Apr 08 21:31:03 2019 -0400 @@ -32,6 +32,9 @@ 0, 0 + + + diff -r 7127d5b5ac75 -r 9e77c0dccb66 ServerMonitor/Forms/ServerSummaryForm.Designer.cs --- a/ServerMonitor/Forms/ServerSummaryForm.Designer.cs Mon Apr 08 21:29:54 2019 -0400 +++ b/ServerMonitor/Forms/ServerSummaryForm.Designer.cs Mon Apr 08 21:31:03 2019 -0400 @@ -31,16 +31,19 @@ this.components = new System.ComponentModel.Container(); this.ServerPanel = new System.Windows.Forms.FlowLayoutPanel(); this.NotifyIcon = new System.Windows.Forms.NotifyIcon(this.components); + this.NotificationIconMenu = new System.Windows.Forms.ContextMenuStrip(this.components); + this.ShowServerMonitorMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ExitMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ServerContextMenu = new System.Windows.Forms.ContextMenuStrip(this.components); this.ToggleEnableServerMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.DeleteServerMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.SettingsButton = new System.Windows.Forms.Button(); this.NewServerButton = new System.Windows.Forms.Button(); - this.NotificationIconMenu = new System.Windows.Forms.ContextMenuStrip(this.components); - this.ShowServerMonitorMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.ExitMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.UpdatePanel = new System.Windows.Forms.Panel(); + this.UpdateLabel = new System.Windows.Forms.Label(); + this.NotificationIconMenu.SuspendLayout(); this.ServerContextMenu.SuspendLayout(); - this.NotificationIconMenu.SuspendLayout(); + this.UpdatePanel.SuspendLayout(); this.SuspendLayout(); // // ServerPanel @@ -62,6 +65,28 @@ this.NotifyIcon.BalloonTipClicked += new System.EventHandler(this.NotifyIcon_BalloonTipClicked); this.NotifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(this.NotifyIcon_MouseClick); // + // NotificationIconMenu + // + this.NotificationIconMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ShowServerMonitorMenuItem, + this.ExitMenuItem}); + this.NotificationIconMenu.Name = "NotificationIconMenu"; + this.NotificationIconMenu.Size = new System.Drawing.Size(161, 48); + this.NotificationIconMenu.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.NotificationIconMenu_ItemClicked); + // + // ShowServerMonitorMenuItem + // + this.ShowServerMonitorMenuItem.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold); + this.ShowServerMonitorMenuItem.Name = "ShowServerMonitorMenuItem"; + this.ShowServerMonitorMenuItem.Size = new System.Drawing.Size(160, 22); + this.ShowServerMonitorMenuItem.Text = "Server Monitor"; + // + // ExitMenuItem + // + this.ExitMenuItem.Name = "ExitMenuItem"; + this.ExitMenuItem.Size = new System.Drawing.Size(160, 22); + this.ExitMenuItem.Text = "Exit"; + // // ServerContextMenu // this.ServerContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -110,33 +135,35 @@ this.NewServerButton.UseVisualStyleBackColor = true; this.NewServerButton.Click += new System.EventHandler(this.NewServerButton_Click); // - // NotificationIconMenu + // UpdatePanel // - this.NotificationIconMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.ShowServerMonitorMenuItem, - this.ExitMenuItem}); - this.NotificationIconMenu.Name = "NotificationIconMenu"; - this.NotificationIconMenu.Size = new System.Drawing.Size(181, 70); - this.NotificationIconMenu.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.NotificationIconMenu_ItemClicked); - // - // ShowServerMonitorMenuItem + this.UpdatePanel.BackColor = System.Drawing.Color.Aquamarine; + this.UpdatePanel.Controls.Add(this.UpdateLabel); + this.UpdatePanel.Dock = System.Windows.Forms.DockStyle.Top; + this.UpdatePanel.Location = new System.Drawing.Point(0, 0); + this.UpdatePanel.Name = "UpdatePanel"; + this.UpdatePanel.Size = new System.Drawing.Size(672, 22); + this.UpdatePanel.TabIndex = 0; + this.UpdatePanel.Visible = false; // - this.ShowServerMonitorMenuItem.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold); - this.ShowServerMonitorMenuItem.Name = "ShowServerMonitorMenuItem"; - this.ShowServerMonitorMenuItem.Size = new System.Drawing.Size(180, 22); - this.ShowServerMonitorMenuItem.Text = "Server Monitor"; + // UpdateLabel // - // ExitMenuItem - // - this.ExitMenuItem.Name = "ExitMenuItem"; - this.ExitMenuItem.Size = new System.Drawing.Size(180, 22); - this.ExitMenuItem.Text = "Exit"; + this.UpdateLabel.Cursor = System.Windows.Forms.Cursors.Hand; + this.UpdateLabel.Dock = System.Windows.Forms.DockStyle.Fill; + this.UpdateLabel.Location = new System.Drawing.Point(0, 0); + this.UpdateLabel.Name = "UpdateLabel"; + this.UpdateLabel.Size = new System.Drawing.Size(672, 22); + this.UpdateLabel.TabIndex = 0; + this.UpdateLabel.Text = "Program update available"; + this.UpdateLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.UpdateLabel.Click += new System.EventHandler(this.UpdateLabel_Click); // // ServerSummaryForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(672, 395); + this.Controls.Add(this.UpdatePanel); this.Controls.Add(this.SettingsButton); this.Controls.Add(this.NewServerButton); this.Controls.Add(this.ServerPanel); @@ -146,8 +173,9 @@ this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ServerSummaryForm_FormClosing); this.Load += new System.EventHandler(this.ServerSummaryForm_Load); this.ResizeEnd += new System.EventHandler(this.ServerSummaryForm_ResizeEnd); + this.NotificationIconMenu.ResumeLayout(false); this.ServerContextMenu.ResumeLayout(false); - this.NotificationIconMenu.ResumeLayout(false); + this.UpdatePanel.ResumeLayout(false); this.ResumeLayout(false); } @@ -164,6 +192,8 @@ private System.Windows.Forms.ContextMenuStrip NotificationIconMenu; private System.Windows.Forms.ToolStripMenuItem ShowServerMonitorMenuItem; private System.Windows.Forms.ToolStripMenuItem ExitMenuItem; + private System.Windows.Forms.Panel UpdatePanel; + private System.Windows.Forms.Label UpdateLabel; } } diff -r 7127d5b5ac75 -r 9e77c0dccb66 ServerMonitor/Forms/ServerSummaryForm.cs --- a/ServerMonitor/Forms/ServerSummaryForm.cs Mon Apr 08 21:29:54 2019 -0400 +++ b/ServerMonitor/Forms/ServerSummaryForm.cs Mon Apr 08 21:31:03 2019 -0400 @@ -1,4 +1,7 @@ -using ServerMonitorApp.Properties; +using NAppUpdate.Framework; +using NAppUpdate.Framework.Sources; +using NAppUpdate.Framework.Tasks; +using ServerMonitorApp.Properties; using System; using System.Collections.Generic; using System.ComponentModel; @@ -68,6 +71,7 @@ monitor.CheckStatusChanged += Monitor_CheckStatusChanged; RefreshDisplay(); CollectPrivateKeyPasswords(); + CheckForUpdate(); } private ServerForm ShowServerForm(Server server, bool activate = true) @@ -287,5 +291,64 @@ else if (e.ClickedItem == ExitMenuItem) Application.Exit(); } + + private void CheckForUpdate() + { + //System.Threading.Thread.Sleep(5000); + UpdateManager manager = UpdateManager.Instance; + manager.ReinstateIfRestarted(); + manager.UpdateSource = new SimpleWebSource(@"c:\temp\feed.xml"); + if (manager.State == UpdateManager.UpdateProcessState.NotChecked) + manager.BeginCheckForUpdates(CheckForUpdatesCallback, null); + } + + private void CheckForUpdatesCallback(IAsyncResult result) + { + UpdateManager manager = UpdateManager.Instance; + if (manager.UpdatesAvailable > 0) + { + GetUpdateInfo(out string version, out string _); + if (Settings.Default.IgnoreUpdate != version) + Invoke((MethodInvoker)(() => UpdatePanel.Show())); + } + } + + private void PrepareUpdatesCallback(IAsyncResult result) + { + UpdateManager manager = UpdateManager.Instance; + manager.EndCheckForUpdates(result); + manager.ApplyUpdates(true); + } + + private void UpdateLabel_Click(object sender, EventArgs e) + { + GetUpdateInfo(out string version, out string changeMessage); + string message = "Server Monitor version {0} is available for download." + Environment.NewLine + + Environment.NewLine + + "What's new:" + Environment.NewLine + + "{1}" + Environment.NewLine + + Environment.NewLine + + "Would you like to download and apply the update now?"; + using (UpdateDialog dialog = new UpdateDialog { Message = string.Format(message, version, changeMessage) }) + { + DialogResult result = dialog.ShowDialog(); + if (dialog.Checked && result == DialogResult.Cancel) + { + Settings.Default.IgnoreUpdate = version; + Settings.Default.Save(); + UpdatePanel.Hide(); + } + if (result != DialogResult.OK) + return; + } + UpdateManager.Instance.BeginPrepareUpdates(PrepareUpdatesCallback, null); + } + + private void GetUpdateInfo(out string version, out string changeMessage) + { + string[] parts = UpdateManager.Instance.Tasks.First().Description.Split(new char[] { ':' }, 2); + version = parts[0]; + changeMessage = parts[1]; + } } } diff -r 7127d5b5ac75 -r 9e77c0dccb66 ServerMonitor/Forms/UpdateDialog.Designer.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ServerMonitor/Forms/UpdateDialog.Designer.cs Mon Apr 08 21:31:03 2019 -0400 @@ -0,0 +1,138 @@ +namespace ServerMonitorApp +{ + partial class UpdateDialog + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.PromptCheckBox = new System.Windows.Forms.CheckBox(); + this.YesButton = new System.Windows.Forms.Button(); + this.NoButton = new System.Windows.Forms.Button(); + this.MessageLabel = new System.Windows.Forms.Label(); + this.MessageIcon = new System.Windows.Forms.PictureBox(); + this.panel1 = new System.Windows.Forms.Panel(); + ((System.ComponentModel.ISupportInitialize)(this.MessageIcon)).BeginInit(); + this.panel1.SuspendLayout(); + this.SuspendLayout(); + // + // PromptCheckBox + // + this.PromptCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.PromptCheckBox.AutoSize = true; + this.PromptCheckBox.Location = new System.Drawing.Point(12, 17); + this.PromptCheckBox.Name = "PromptCheckBox"; + this.PromptCheckBox.Size = new System.Drawing.Size(178, 17); + this.PromptCheckBox.TabIndex = 3; + this.PromptCheckBox.Text = "&Do not ask again for this version"; + this.PromptCheckBox.UseVisualStyleBackColor = true; + this.PromptCheckBox.CheckedChanged += new System.EventHandler(this.PromptCheckBox_CheckedChanged); + // + // YesButton + // + this.YesButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.YesButton.DialogResult = System.Windows.Forms.DialogResult.OK; + this.YesButton.Location = new System.Drawing.Point(228, 13); + this.YesButton.Name = "YesButton"; + this.YesButton.Size = new System.Drawing.Size(75, 23); + this.YesButton.TabIndex = 1; + this.YesButton.Text = "&Yes"; + this.YesButton.UseVisualStyleBackColor = true; + // + // NoButton + // + this.NoButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.NoButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.NoButton.Location = new System.Drawing.Point(309, 13); + this.NoButton.Name = "NoButton"; + this.NoButton.Size = new System.Drawing.Size(75, 23); + this.NoButton.TabIndex = 2; + this.NoButton.Text = "&No"; + this.NoButton.UseVisualStyleBackColor = true; + // + // MessageLabel + // + this.MessageLabel.AutoSize = true; + this.MessageLabel.Location = new System.Drawing.Point(70, 22); + this.MessageLabel.Name = "MessageLabel"; + this.MessageLabel.Size = new System.Drawing.Size(0, 13); + this.MessageLabel.TabIndex = 3; + // + // MessageIcon + // + this.MessageIcon.Location = new System.Drawing.Point(25, 49); + this.MessageIcon.Name = "MessageIcon"; + this.MessageIcon.Size = new System.Drawing.Size(32, 32); + this.MessageIcon.TabIndex = 4; + this.MessageIcon.TabStop = false; + // + // panel1 + // + this.panel1.BackColor = System.Drawing.SystemColors.Control; + this.panel1.Controls.Add(this.YesButton); + this.panel1.Controls.Add(this.NoButton); + this.panel1.Controls.Add(this.PromptCheckBox); + this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom; + this.panel1.Location = new System.Drawing.Point(0, 123); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(396, 49); + this.panel1.TabIndex = 5; + // + // UpdateDialog + // + this.AcceptButton = this.YesButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.White; + this.CancelButton = this.NoButton; + this.ClientSize = new System.Drawing.Size(396, 172); + this.Controls.Add(this.panel1); + this.Controls.Add(this.MessageIcon); + this.Controls.Add(this.MessageLabel); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "UpdateDialog"; + this.ShowInTaskbar = false; + this.Text = "Update"; + this.Load += new System.EventHandler(this.CheckBoxDialog_Load); + ((System.ComponentModel.ISupportInitialize)(this.MessageIcon)).EndInit(); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.CheckBox PromptCheckBox; + private System.Windows.Forms.Button YesButton; + private System.Windows.Forms.Button NoButton; + private System.Windows.Forms.Label MessageLabel; + private System.Windows.Forms.PictureBox MessageIcon; + private System.Windows.Forms.Panel panel1; + } +} \ No newline at end of file diff -r 7127d5b5ac75 -r 9e77c0dccb66 ServerMonitor/Forms/UpdateDialog.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ServerMonitor/Forms/UpdateDialog.cs Mon Apr 08 21:31:03 2019 -0400 @@ -0,0 +1,33 @@ +using System; +using System.Drawing; +using System.Windows.Forms; + +namespace ServerMonitorApp +{ + /// Message dialog with an additional checkbox. + public partial class UpdateDialog : Form + { + /// Message to show. + public string Message { get; set; } + + /// Check state of the checkbox. + public bool Checked { get; private set; } + + public UpdateDialog() + { + InitializeComponent(); + } + + private void CheckBoxDialog_Load(object sender, EventArgs e) + { + MessageIcon.Image = SystemIcons.Question.ToBitmap(); + MessageLabel.Text = Message; + } + + /// Updates the public property with the checked state so it can be read by the dialog owner. + private void PromptCheckBox_CheckedChanged(object sender, EventArgs e) + { + Checked = PromptCheckBox.Checked; + } + } +} diff -r 7127d5b5ac75 -r 9e77c0dccb66 ServerMonitor/Forms/UpdateDialog.resx --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ServerMonitor/Forms/UpdateDialog.resx Mon Apr 08 21:31:03 2019 -0400 @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff -r 7127d5b5ac75 -r 9e77c0dccb66 ServerMonitor/Properties/Settings.Designer.cs --- a/ServerMonitor/Properties/Settings.Designer.cs Mon Apr 08 21:29:54 2019 -0400 +++ b/ServerMonitor/Properties/Settings.Designer.cs Mon Apr 08 21:31:03 2019 -0400 @@ -106,5 +106,17 @@ this["SummaryFormSize"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string IgnoreUpdate { + get { + return ((string)(this["IgnoreUpdate"])); + } + set { + this["IgnoreUpdate"] = value; + } + } } } diff -r 7127d5b5ac75 -r 9e77c0dccb66 ServerMonitor/Properties/Settings.settings --- a/ServerMonitor/Properties/Settings.settings Mon Apr 08 21:29:54 2019 -0400 +++ b/ServerMonitor/Properties/Settings.settings Mon Apr 08 21:31:03 2019 -0400 @@ -23,5 +23,8 @@ 0, 0 + + + \ No newline at end of file diff -r 7127d5b5ac75 -r 9e77c0dccb66 ServerMonitor/ServerMonitor.csproj --- a/ServerMonitor/ServerMonitor.csproj Mon Apr 08 21:29:54 2019 -0400 +++ b/ServerMonitor/ServerMonitor.csproj Mon Apr 08 21:31:03 2019 -0400 @@ -40,6 +40,9 @@ false + + ..\packages\NAppUpdate.Framework.0.5.1.0\lib\net40\NAppUpdate.Framework.dll + ..\packages\SSH.NET.2016.1.0\lib\net40\Renci.SshNet.dll @@ -95,6 +98,12 @@ Component + + Form + + + UpdateDialog.cs + Form @@ -179,6 +188,9 @@ HttpCheckControl.cs + + UpdateDialog.cs + CheckBoxDialog.cs diff -r 7127d5b5ac75 -r 9e77c0dccb66 ServerMonitor/packages.config --- a/ServerMonitor/packages.config Mon Apr 08 21:29:54 2019 -0400 +++ b/ServerMonitor/packages.config Mon Apr 08 21:31:03 2019 -0400 @@ -1,4 +1,5 @@  + \ No newline at end of file