aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs61
1 files changed, 61 insertions, 0 deletions
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
}
}