From cc2b95c9144d8a3486314766b645021a9a914d25 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Fri, 13 Dec 2019 02:14:37 +0200 Subject: Implemented power up screen. Implemented power on emulator. Implemented power via machine operator. --- .../PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs') 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..48e59562c 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,72 @@ namespace Tango.PPC.UI.ViewModels }); } + private async void MachineOperator_PowerUpStarted(object sender, EventArgs e) + { + LogManager.Log("Power up detected, showing power up screen..."); + + PowerUpViewVM vm; + + try + { + List rmls = new List(); + + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + rmls = await db.Rmls.ToListAsync(); + } + + 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(vm); + + await Task.Factory.StartNew(() => + { + try + { + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + List processTables = new List(); + + if (vm.IsSelectedRml) + { + processTables = new RmlBuilder(db).Set(vm.SelectedRml.Guid).WithActiveParametersGroup().Build().GetActiveProcessGroup().ProcessParametersTables.ToList(); + } + else + { + var rmlsToAvg = new RmlsCollectionBuilder(db).SetAll().WithActiveParametersGroup().Build(); + processTables = rmlsToAvg.Select(x => x.GetActiveProcessGroup()).SelectMany(x => x.ProcessParametersTables).ToList(); + } + + var processToLoad = processTables.OrderBy(x => x.GetAverageTemperature()).First(); + + 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 } } -- cgit v1.3.1