diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-12-07 22:46:37 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-12-07 22:46:37 +0200 |
| commit | 00f7facd947e0e8ce05a43d4f9d036e8f9a6a69e (patch) | |
| tree | e8b839ab42dbb7fc05e7398a9fb1b3e4941fa6c1 /Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate | |
| parent | a6e6af346bf160b4a83163a6f1b268920cf2005c (diff) | |
| download | Tango-00f7facd947e0e8ce05a43d4f9d036e8f9a6a69e.tar.gz Tango-00f7facd947e0e8ce05a43d4f9d036e8f9a6a69e.zip | |
Implemented auto check for update notification on PPC...
Related Work Items: #1460
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs | 13 | ||||
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs | 61 |
2 files changed, 74 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs index 299e18e57..3655aa462 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs @@ -11,6 +11,19 @@ namespace Tango.PPC.Common.MachineUpdate { public interface IMachineUpdateManager { + /// <summary> + /// Occurs when an application update is available. + /// </summary> + event EventHandler<CheckForUpdateResponse> UpdateAvailable; + + /// <summary> + /// Gets or sets a value indicating whether to automatically check for new application updates. + /// </summary> + bool AutoCheckForUpdates { get; set; } + + /// <summary> + /// Gets the current machine update progress status. + /// </summary> MachineUpdateProgress Status { get; } /// <summary> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs index 658c323de..e98f6d717 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs @@ -37,10 +37,17 @@ namespace Tango.PPC.Common.MachineUpdate private IPackageRunner _packageRunner; private PPCWebClient _client; private List<LogItemBase> _logs; + private System.Timers.Timer _checkForUpdateTimer; + private bool _isUpdating; #region Events /// <summary> + /// Occurs when an application update is available. + /// </summary> + public event EventHandler<CheckForUpdateResponse> UpdateAvailable; + + /// <summary> /// Occurs when there is a text log message available. /// </summary> public event EventHandler<string> ProgressLog; @@ -55,12 +62,25 @@ namespace Tango.PPC.Common.MachineUpdate #region Properties private MachineUpdateProgress _status; + /// <summary> + /// Gets the current machine update progress status. + /// </summary> public MachineUpdateProgress Status { get { return _status; } private set { _status = value; RaisePropertyChangedAuto(); } } + private bool _autoCheckForUpdates; + /// <summary> + /// Gets or sets a value indicating whether to automatically check for new application updates. + /// </summary> + public bool AutoCheckForUpdates + { + get { return _autoCheckForUpdates; } + set { _autoCheckForUpdates = value; RaisePropertyChangedAuto(); } + } + #endregion #region Constructors @@ -79,6 +99,10 @@ namespace Tango.PPC.Common.MachineUpdate _logs = new List<LogItemBase>(); LogManager.NewLog += LogManager_NewLog; + + _checkForUpdateTimer = new System.Timers.Timer(TimeSpan.FromMinutes(1).TotalMilliseconds); + _checkForUpdateTimer.Elapsed += _checkForUpdateTimer_Elapsed; + _checkForUpdateTimer.Start(); } #endregion @@ -159,6 +183,8 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log(xx, "Error notifying update failed."); } } + + _isUpdating = false; } private async void OnCompleted(MachineUpdateResult result, TaskCompletionSource<MachineUpdateResult> completionSource, DownloadUpdateResponse response, String dbBackupFile) @@ -186,6 +212,8 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log(ex, "Error notifying update completed."); } } + + _isUpdating = false; } private void OnCompleted(UpdateDBResponse response) @@ -205,6 +233,8 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log(ex, "Error notifying database completed."); } } + + _isUpdating = false; } private void OnFailed(Exception ex, UpdateDBResponse response, bool performDatabaseRollback, String dbBackupFile, Tango.Core.DataSource localDataSource) @@ -256,6 +286,8 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log(xx, "Error notifying database failed."); } } + + _isUpdating = false; } private String GetLogsStringAndClear() @@ -295,6 +327,8 @@ namespace Tango.PPC.Common.MachineUpdate try { + _isUpdating = true; + var machineServiceAddress = SettingsManager.Default.GetOrCreate<PPCSettings>().GetMachineServiceAddress(); LogManager.Log($"Starting machine update for serial number {serialNumber}..."); @@ -594,6 +628,7 @@ namespace Tango.PPC.Common.MachineUpdate return Task.Factory.StartNew(() => { + _isUpdating = true; UpdateDBResponse update_response = null; var localDataSource = SettingsManager.Default.GetOrCreate<CoreSettings>().DataSource; bool performDatabaseRollback = false; @@ -930,5 +965,31 @@ namespace Tango.PPC.Common.MachineUpdate } #endregion + + #region Auto Check For Update + + private async void _checkForUpdateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) + { + if (AutoCheckForUpdates && !_isUpdating) + { + _checkForUpdateTimer.Stop(); + + try + { + var response = await CheckForUpdate(_machineProvider.Machine.SerialNumber); + if (response.IsUpdateAvailable) + { + _checkForUpdateTimer.Interval = TimeSpan.FromMinutes(60).TotalMilliseconds; + LogManager.Log($"New application version detected ({response.Version}). Raising event..."); + UpdateAvailable?.Invoke(this, response); + } + } + catch { } + + _checkForUpdateTimer.Start(); + } + } + + #endregion } } |
