aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels
diff options
context:
space:
mode:
authorVictoria Plitt <Victoria.Plitt@twine-s.com>2019-12-18 13:27:02 +0200
committerVictoria Plitt <Victoria.Plitt@twine-s.com>2019-12-18 13:27:02 +0200
commit41129873d38034c5679eeaf46f48e4f67fd38ba2 (patch)
tree94109a9602e91bcf7f114e3491bc8018e60bef4c /Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels
parent70e3f2699a500666d1ca4e4d5db2dbaafb339e80 (diff)
parenta61a911d1ebde107ba7bf210af7e753e692d93e2 (diff)
downloadTango-41129873d38034c5679eeaf46f48e4f67fd38ba2.tar.gz
Tango-41129873d38034c5679eeaf46f48e4f67fd38ba2.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/InternalModuleViewVM.cs17
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs26
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs32
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs85
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/PowerOffViewVM.cs134
5 files changed, 276 insertions, 18 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/InternalModuleViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/InternalModuleViewVM.cs
new file mode 100644
index 000000000..29e6417f4
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/InternalModuleViewVM.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.PPC.Common;
+
+namespace Tango.PPC.UI.ViewModels
+{
+ public class InternalModuleViewVM : PPCViewModel
+ {
+ public override void OnApplicationStarted()
+ {
+
+ }
+ }
+}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs
index 9e8a9fe34..d7717e6db 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs
@@ -10,6 +10,7 @@ using Tango.Integration.Operation;
using Tango.PPC.Common;
using Tango.PPC.Common.Modules;
using Tango.PPC.Common.Navigation;
+using Tango.PPC.UI.Views;
using Tango.PPC.UI.ViewsContracts;
using Tango.SharedUI;
@@ -121,6 +122,11 @@ namespace Tango.PPC.UI.ViewModels
/// </summary>
public RelayCommand RestartApplicationCommand { get; set; }
+ /// <summary>
+ /// Gets or sets the power off command.
+ /// </summary>
+ public RelayCommand PowerOffCommand { get; set; }
+
#endregion
#region Constructors
@@ -146,6 +152,7 @@ namespace Tango.PPC.UI.ViewModels
PowerCommand = new RelayCommand(() => IsPowerOpened = true);
RestartApplicationCommand = new RelayCommand(RestartApplication);
+ PowerOffCommand = new RelayCommand(PowerOffMachine);
}
#endregion
@@ -239,6 +246,25 @@ namespace Tango.PPC.UI.ViewModels
}
}
+ /// <summary>
+ /// Powers off the machine.
+ /// </summary>
+ private async void PowerOffMachine()
+ {
+ IsMenuOpened = false;
+ if (await NotificationProvider.ShowQuestion("Are you sure you wish to turn off the machine?"))
+ {
+ try
+ {
+ await MachineProvider.MachineOperator.PowerDown();
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error triggering power down.");
+ }
+ }
+ }
+
#endregion
#region Override Methods
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 0371e94da..49b2aef89 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs
@@ -10,6 +10,7 @@ using Tango.Core.Helpers;
using Tango.Explorer;
using Tango.PPC.Common;
using Tango.PPC.Common.MachineUpdate;
+using Tango.PPC.Common.Publish;
using Tango.PPC.Common.Web;
using Tango.PPC.UI.Dialogs;
using Tango.PPC.UI.Notifications.NotificationItems;
@@ -209,7 +210,7 @@ namespace Tango.PPC.UI.ViewModels
try
{
- _update_result = await MachineUpdateManager.Update(MachineProvider.Machine.SerialNumber, _checkUpdateResponse.SetupFirmware, _checkUpdateResponse.SetupFPGA);
+ _update_result = await MachineUpdateManager.Update(_checkUpdateResponse.SetupFirmware, _checkUpdateResponse.SetupFPGA);
LogManager.Log("Machine update completed.");
await NavigateTo(MachineUpdateView.UpdateCompletedView);
}
@@ -248,15 +249,15 @@ namespace Tango.PPC.UI.ViewModels
{
LogManager.Log("Completing machine update...");
- if (!IsDbUpdate)
+ if (IsDbUpdate || !_update_result.RequiresBinariesUpdate)
{
- String updater_exe = Path.Combine(_update_result.UpdatePackagePath, "Tango.PPC.Updater.exe");
- ApplicationManager.UpdateApplication(updater_exe, PathHelper.GetStartupPath());
+ LogManager.Log("Restarting Application...");
+ ApplicationManager.Restart();
}
else
{
- LogManager.Log("Restarting Application...");
- ApplicationManager.Restart();
+ String updater_exe = Path.Combine(_update_result.UpdatePackagePath, "Tango.PPC.Updater.exe");
+ ApplicationManager.UpdateApplication(updater_exe, PathHelper.GetStartupPath());
}
}
@@ -296,7 +297,7 @@ namespace Tango.PPC.UI.ViewModels
}
else
{
- MachineUpdateManager.AutoCheckForUpdates = MachineProvider.Machine.AutoCheckForUpdates;
+ MachineUpdateManager.EnableAutoCheckForUpdates = true;
}
}
@@ -375,7 +376,7 @@ namespace Tango.PPC.UI.ViewModels
private async void HandleSoftwareUpdatePackageLoaded(ExplorerFileItem fileItem)
{
- UpdatePackageFile packageFile = null;
+ PublishInfo packageFile = null;
try
{
@@ -383,38 +384,33 @@ namespace Tango.PPC.UI.ViewModels
}
catch (Exception ex)
{
- LogManager.Log(ex, $"Error loading update package file from {fileItem.Path}.");
+ LogManager.Log(ex, $"Error loading publish info from {fileItem.Path}.");
await NotificationProvider.ShowError("An error occurred while trying to load the selected software update package. Please make sure the package is valid.");
return;
}
- if (ApplicationManager.Version <= packageFile.Version)
- {
- await NotificationProvider.ShowError($"The selected update package (v{packageFile.Version.ToString()}) contains an older software version.");
- return;
- }
-
UpdateFromFileViewVM vm = new UpdateFromFileViewVM();
- vm.Version = packageFile.Version.ToString();
+ vm.Version = packageFile.ApplicationVersion;
await NotificationProvider.ShowDialog(vm);
if (vm.DialogResult)
{
await NavigationManager.NavigateTo(Common.Navigation.NavigationView.MachineUpdateView);
- await NavigateTo(MachineUpdateView.UpdateFromPackageView);
+ await NavigateTo(MachineUpdateView.UpdateProgressView);
LogManager.Log("Starting machine update from package...");
try
{
- _update_result = await MachineUpdateManager.UpdateFromTUP(fileItem.Path);
+ _update_result = await MachineUpdateManager.UpdateFromTUP(fileItem.Path, MachineProvider.Machine.SetupFirmware, MachineProvider.Machine.SetupFpga);
LogManager.Log("Machine update from package completed.");
await NavigateTo(MachineUpdateView.UpdateCompletedView);
}
catch (Exception ex)
{
LogManager.Log(ex, "Machine update from package failed.");
+ FailedError = ex.FlattenMessage();
await NavigateTo(MachineUpdateView.UpdateFailedFromPackageView);
}
}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs
index 01a47539e..8a4d20b76 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs
@@ -4,6 +4,9 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Threading;
+using Tango.BL;
+using Tango.BL.Builders;
+using Tango.BL.Entities;
using Tango.Core.DI;
using Tango.Integration.ExternalBridge;
using Tango.Integration.Operation;
@@ -17,6 +20,7 @@ using Tango.PPC.Common.Notifications;
using Tango.PPC.Common.WatchDog;
using Tango.PPC.UI.Dialogs;
using Tango.SharedUI;
+using System.Data.Entity;
namespace Tango.PPC.UI.ViewModels
{
@@ -58,6 +62,7 @@ namespace Tango.PPC.UI.ViewModels
{
base.OnApplicationReady();
MachineProvider.MachineOperator.CartridgeValidationRequestReceived += MachineOperator_CartridgeValidationRequestReceived;
+ MachineProvider.MachineOperator.PowerUpStarted += MachineOperator_PowerUpStarted;
}
#region Event Handlers
@@ -92,6 +97,86 @@ namespace Tango.PPC.UI.ViewModels
});
}
+ private async void MachineOperator_PowerUpStarted(object sender, EventArgs e)
+ {
+ LogManager.Log("Power up detected, showing power up screen...");
+
+ if (!Settings.DisplayPowerUpScreen)
+ {
+ LogManager.Log("Power up screen disabled. skipping...");
+ return;
+ }
+
+ PowerUpViewVM vm;
+
+ try
+ {
+ LogManager.Log("Loading site rmls...");
+
+ List<Rml> rmls = new List<Rml>();
+
+ using (ObservablesContext db = ObservablesContext.CreateDefault())
+ {
+ rmls = await new RmlsCollectionBuilder(db).SetAll().WithSite(MachineProvider.Machine.SiteGuid).BuildListAsync();
+ }
+
+ var selectedRml = rmls.SingleOrDefault(x => x.Guid == Settings.LastPowerUpSelectedRmlGuid);
+
+ vm = new PowerUpViewVM();
+ vm.Rmls = rmls;
+ vm.SelectedRml = selectedRml != null ? selectedRml : rmls.FirstOrDefault();
+ vm.IsSelectedRml = selectedRml != null;
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error initializing power up screen.");
+ return;
+ }
+
+ InvokeUI(async () =>
+ {
+ await NotificationProvider.ShowDialog<PowerUpViewVM>(vm);
+
+ await Task.Factory.StartNew(() =>
+ {
+ LogManager.Log("Power up screen closed.");
+
+ try
+ {
+ using (ObservablesContext db = ObservablesContext.CreateDefault())
+ {
+ List<ProcessParametersTable> processTables = new List<ProcessParametersTable>();
+
+ if (vm.IsSelectedRml)
+ {
+ LogManager.Log($"Selected rml '{vm.SelectedRml.Name}'...");
+ processTables = new RmlBuilder(db).Set(vm.SelectedRml.Guid).WithActiveParametersGroup().Build().GetActiveProcessGroup().ProcessParametersTables.ToList();
+ }
+ else
+ {
+ LogManager.Log("Selected minimal temperature...");
+ var rmlsToAvg = new RmlsCollectionBuilder(db).SetAll().WithSite(MachineProvider.Machine.SiteGuid).WithActiveParametersGroup().Build();
+ processTables = rmlsToAvg.Select(x => x.GetActiveProcessGroup()).SelectMany(x => x.ProcessParametersTables).ToList();
+ }
+
+ var processToLoad = processTables.OrderBy(x => x.GetAverageTemperature()).First();
+
+ LogManager.Log($"Selected process parameters:\nRML: {processToLoad.ProcessParametersTablesGroup.Rml.Name}\nGroup: {processToLoad.ProcessParametersTablesGroup.Name}\nProcess Table: {processToLoad.Name}");
+ LogManager.Log("Uploading process parameters...");
+ var r = MachineProvider.MachineOperator.UploadProcessParameters(processToLoad).Result;
+
+ Settings.LastPowerUpSelectedRmlGuid = vm.IsSelectedRml ? vm.SelectedRml.Guid : null;
+ Settings.Save();
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error occurred while trying to get and upload the proper process parameters after power screen closed.");
+ }
+ });
+ });
+ }
+
#endregion
}
}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/PowerOffViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/PowerOffViewVM.cs
new file mode 100644
index 000000000..e3ab7d111
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/PowerOffViewVM.cs
@@ -0,0 +1,134 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core.Commands;
+using Tango.Integration.Operation;
+using Tango.PMR.Power;
+using Tango.PPC.Common;
+using Tango.PPC.UI.AppBarItems;
+using Tango.PPC.UI.Views;
+
+namespace Tango.PPC.UI.ViewModels
+{
+ public class PowerOffViewVM : PPCViewModel
+ {
+ private PowerDownHandler _handler;
+ private PowerOffAppBarItem _appBarItem;
+ private int _abortTries;
+
+ private StartPowerDownResponse _status;
+ public StartPowerDownResponse Status
+ {
+ get { return _status; }
+ set { _status = value; RaisePropertyChangedAuto(); }
+ }
+
+ public RelayCommand AbortCommand { get; set; }
+
+ public PowerOffViewVM()
+ {
+ _appBarItem = new PowerOffAppBarItem();
+ _appBarItem.Pressed += (x, e) =>
+ {
+ NavigationManager.NavigateTo<InternalModule>(nameof(PowerOffView));
+ };
+ AbortCommand = new RelayCommand(AbortPowerOff);
+ }
+
+ public override void OnApplicationStarted()
+ {
+
+ }
+
+ public override void OnApplicationReady()
+ {
+ base.OnApplicationReady();
+ MachineProvider.MachineOperator.PowerDownStarted += MachineOperator_PowerDownStarted;
+ }
+
+ private void MachineOperator_PowerDownStarted(object sender, PowerDownStartedEventArgs e)
+ {
+ _abortTries = 0;
+ _handler = e.Handler;
+
+ _handler.StatusChanged += OnStatusChanged;
+ _handler.Failed += OnFailed;
+ _handler.Completed += OnCompleted;
+
+ InvokeUI(async () =>
+ {
+ await NavigationManager.NavigateTo<InternalModule>(nameof(PowerOffView));
+ NotificationProvider.PushAppBarItem(_appBarItem);
+ });
+ }
+
+ private void OnStatusChanged(object sender, PowerDownStatusChangedEventArgs e)
+ {
+ Status = e.Status;
+ _appBarItem.Status = Status;
+ }
+
+ private void OnCompleted(object sender, EventArgs e)
+ {
+ InvokeUI(async () =>
+ {
+ if (IsVisible)
+ {
+ await NavigationManager.NavigateBack();
+ }
+
+ NotificationProvider.PopAppBarItem(_appBarItem);
+ });
+ }
+
+ private void OnFailed(object sender, Exception ex)
+ {
+ InvokeUI(async () =>
+ {
+ await NotificationProvider.ShowError($"An error occurred while powering off the machine.\n{ex.FlattenMessage()}");
+
+ if (IsVisible)
+ {
+ await NavigationManager.NavigateBack();
+ }
+
+ NotificationProvider.PopAppBarItem(_appBarItem);
+ });
+ }
+
+ private async void AbortPowerOff()
+ {
+ try
+ {
+ NotificationProvider.SetGlobalBusyMessage("Aborting machine power off...");
+ await _handler.Abort();
+ await NavigationManager.NavigateBack();
+ NotificationProvider.PopAppBarItem(_appBarItem);
+ }
+ catch (Exception ex)
+ {
+ _abortTries++;
+ LogManager.Log(ex, "Power down abort error.");
+ NotificationProvider.ReleaseGlobalBusyMessage();
+ await NotificationProvider.ShowError($"An error occurred while trying to abort the power off sequence.\n{ex.FlattenMessage()}");
+
+ if (_abortTries > 2)
+ {
+ if (IsVisible)
+ {
+ await NavigationManager.NavigateBack();
+ }
+
+ NotificationProvider.PopAppBarItem(_appBarItem);
+ }
+ }
+ finally
+ {
+ NotificationProvider.ReleaseGlobalBusyMessage();
+ }
+ }
+ }
+}