aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs
diff options
context:
space:
mode:
authorVictoria Plitt <Victoria.Plitt@twine-s.com>2019-12-09 17:00:30 +0200
committerVictoria Plitt <Victoria.Plitt@twine-s.com>2019-12-09 17:00:30 +0200
commit31ece903df45b0ab8ffb61fdd290d9fbea2a6836 (patch)
tree180be785ceb98fb828009eeae4dfa3bbc8a738b7 /Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs
parent4417c2eccb3795330144afa39e3bf271652bd31f (diff)
parentaeabb681d16451e191a1620d4eebf40549771491 (diff)
downloadTango-31ece903df45b0ab8ffb61fdd290d9fbea2a6836.tar.gz
Tango-31ece903df45b0ab8ffb61fdd290d9fbea2a6836.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs127
1 files changed, 127 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs
index 01e67d3ce..0371e94da 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs
@@ -12,6 +12,7 @@ using Tango.PPC.Common;
using Tango.PPC.Common.MachineUpdate;
using Tango.PPC.Common.Web;
using Tango.PPC.UI.Dialogs;
+using Tango.PPC.UI.Notifications.NotificationItems;
using Tango.PPC.UI.ViewsContracts;
namespace Tango.PPC.UI.ViewModels
@@ -36,6 +37,7 @@ namespace Tango.PPC.UI.ViewModels
private DbCompareResult _db_compare_result;
private bool _isChecking;
private CheckForUpdateResponse _checkUpdateResponse;
+ private UpdateAvailableNotificationItem _updateNotificationItem;
#region Properties
@@ -125,6 +127,8 @@ namespace Tango.PPC.UI.ViewModels
NavigationManager.NavigateTo(Common.Navigation.NavigationView.HomeModule);
NavigateTo(MachineUpdateView.UpdateCheckView);
});
+
+ machineUpdateManager.UpdateAvailable += MachineUpdateManager_UpdateAvailable;
}
#endregion
@@ -158,6 +162,16 @@ namespace Tango.PPC.UI.ViewModels
LatestVersion = response.Version;
await NavigateTo(MachineUpdateView.UpdateAvailableView);
}
+ else if (response.IsDatabaseUpdateAvailable)
+ {
+ IsDbUpdate = true;
+ _db_compare_result = new DbCompareResult()
+ {
+ RequiresUpdate = true,
+ UpdateDBResponse = response.UpdateDBResponse
+ };
+ await NavigateTo(MachineUpdateView.UpdateAvailableView);
+ }
else
{
_db_compare_result = await MachineUpdateManager.UpdateDBCheck(MachineProvider.Machine.SerialNumber);
@@ -275,6 +289,84 @@ namespace Tango.PPC.UI.ViewModels
base.OnApplicationReady();
StorageProvider.RegisterFileHandler(ExplorerFileDefinition.Update.Extension, HandleSoftwareUpdatePackageLoaded);
+
+ if (ApplicationManager.IsAfterUpdate)
+ {
+ RunPostUpdatePackages();
+ }
+ else
+ {
+ MachineUpdateManager.AutoCheckForUpdates = MachineProvider.Machine.AutoCheckForUpdates;
+ }
+ }
+
+ /// <summary>
+ /// Called when the navigation system has navigated to this VM view.
+ /// </summary>
+ public override void OnNavigatedTo()
+ {
+ base.OnNavigatedTo();
+
+ if (_updateNotificationItem != null)
+ {
+ _updateNotificationItem.Close();
+ _updateNotificationItem = null;
+ }
+ }
+
+ #endregion
+
+ #region Post Update Packages
+
+ private async void RunPostUpdatePackages()
+ {
+ await Task.Delay(1000);
+
+ LogManager.Log("Application was loaded after an update. Checking for required post-update packages...");
+
+ bool required = false;
+
+ try
+ {
+ required = await MachineUpdateManager.PostUpdatePackagesRequired();
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error checking for post-update packages.");
+ }
+
+ if (required)
+ {
+ LogManager.Log("Post-update packages found and needs to be installed. Navigating to machine update and running post-update packages...");
+ await NavigationManager.NavigateTo(Common.Navigation.NavigationView.MachineUpdateView);
+ await NavigateTo(MachineUpdateView.UpdateProgressView);
+ try
+ {
+ var result = await MachineUpdateManager.RunPostUpdatePackages();
+
+ LogManager.Log("Post-update packages installed successfully.");
+
+ await Task.Delay(2000);
+
+ if (result.RestartRequired)
+ {
+ LogManager.Log("Restart required. Restarting...");
+ ApplicationManager.Restart();
+ }
+ else
+ {
+ await NavigationManager.NavigateTo(Common.Navigation.NavigationView.LayoutView);
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error occurred while running post-update packages.");
+ }
+ }
+ else
+ {
+ LogManager.Log("No post-update packages installation required.");
+ }
}
#endregion
@@ -329,5 +421,40 @@ namespace Tango.PPC.UI.ViewModels
}
#endregion
+
+ #region Auto Check For Update
+
+ private void MachineUpdateManager_UpdateAvailable(object sender, CheckForUpdateResponse e)
+ {
+ if (!IsVisible && _updateNotificationItem == null)
+ {
+ LogManager.Log($"New {(e.IsDatabaseUpdateAvailable ? "database updates" : "application version")} detected ({e.Version}). Pushing notification...");
+
+ InvokeUI(() =>
+ {
+ _updateNotificationItem = new UpdateAvailableNotificationItem();
+ _updateNotificationItem.Version = Version.Parse(e.Version).ToString(3);
+ _updateNotificationItem.IsDatabaseUpdate = e.IsDatabaseUpdateAvailable && !e.IsUpdateAvailable;
+ _updateNotificationItem.Pressed += (_, __) =>
+ {
+ _updateNotificationItem = null;
+
+ if (!IsVisible)
+ {
+ LogManager.Log("Update available notification pressed. Navigating to update view...");
+ NavigationManager.NavigateTo(Common.Navigation.NavigationView.MachineUpdateView);
+ CheckForUpdates();
+ }
+ };
+ _updateNotificationItem.Closed += (_, __) =>
+ {
+ _updateNotificationItem = null;
+ };
+ NotificationProvider.PushNotification(_updateNotificationItem);
+ });
+ }
+ }
+
+ #endregion
}
}