From 582c05b00aa1d0fd9086b4a245dcc987eee9fc39 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sat, 21 Dec 2019 19:14:00 +0200 Subject: Working some more on ActionLogs across MS. --- .../ViewModels/MainViewVM.cs | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs index 9939e4876..527159aa5 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs @@ -21,12 +21,18 @@ using Tango.MachineStudio.RML.Views; using Tango.PMR.ColorLab; using System.Data.Entity; using Tango.Core.ExtensionMethods; +using Tango.MachineStudio.Common.Authentication; +using Tango.BL.ActionLogs; +using Tango.BL.DTO; namespace Tango.MachineStudio.RML.ViewModels { public class MainViewVM : StudioViewModel { private INotificationProvider _notification; + private IAuthenticationProvider _authentication; + private IActionLogManager _actionLogManager; + private RmlDTO _rmlBeforeSave; private ObservablesContext _rmls_context; private ObservablesContext _active_context; @@ -185,9 +191,11 @@ namespace Tango.MachineStudio.RML.ViewModels public RelayCommand ImportRMLFileCommand { get; set; } - public MainViewVM(INotificationProvider notificationProvider) + public MainViewVM(INotificationProvider notificationProvider, IAuthenticationProvider authentication, IActionLogManager actionLogManager) { _notification = notificationProvider; + _authentication = authentication; + _actionLogManager = actionLogManager; ManageRmlCommand = new RelayCommand(() => LoadActiveRML(SelectedRML.Guid), () => SelectedRML != null); RemoveRmlCommand = new RelayCommand(RemoveSelectedRml, () => SelectedRML != null); CloneRmlCommand = new RelayCommand(CloneSelectedRml, () => SelectedRML != null); @@ -334,6 +342,8 @@ namespace Tango.MachineStudio.RML.ViewModels LiquidTypesRmls = LiquidTypesRmls, }; + _rmlBeforeSave = RmlDTO.FromObservable(ActiveRML); + View.NavigateTo(RmlNavigationView.RmlView); InvalidateRelayCommands(); @@ -423,6 +433,9 @@ namespace Tango.MachineStudio.RML.ViewModels _active_context.ProcessParametersTables.Add(group.ProcessParametersTables[0]); _active_context.Rmls.Add(rml); await _active_context.SaveChangesAsync(); + + _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.RmlCreated, _authentication.CurrentUser, rml.Name, rml, "Rml created using Machine Studio."); + LoadActiveRML(rml.Guid); IsFree = true; @@ -441,6 +454,9 @@ namespace Tango.MachineStudio.RML.ViewModels try { await SelectedRML.DeleteCascadeAsync(_rmls_context); + + _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.RmlDeleted, _authentication.CurrentUser, SelectedRML.Name, SelectedRML, "RML deleted from Machine Studio."); + LoadRmls(); } catch (Exception ex) @@ -504,6 +520,8 @@ namespace Tango.MachineStudio.RML.ViewModels context.Rmls.Add(cloned); await context.SaveChangesAsync(); + + _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.RmlCreated, _authentication.CurrentUser, cloned.Name, cloned, "RML cloned from Machine Studio."); } LoadRmls(); @@ -665,7 +683,13 @@ namespace Tango.MachineStudio.RML.ViewModels } } + var rmlAfter = RmlDTO.FromObservable(ActiveRML); + await _active_context.SaveChangesAsync(); + + _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.RmlSaved, _authentication.CurrentUser, _rmlBeforeSave.Name, _rmlBeforeSave, rmlAfter, "RML saved using Machine Studio."); + + _rmlBeforeSave = rmlAfter; } } catch (Exception ex) @@ -804,6 +828,8 @@ namespace Tango.MachineStudio.RML.ViewModels var rmlFile = await Rml.FromRmlFile(db, json); db.Rmls.Add(rmlFile); + + _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.RmlImported, _authentication.CurrentUser, rmlFile.Name, rmlFile, "RML imported from Machine Studio."); } await db.SaveChangesAsync(); -- cgit v1.3.1 From cd670d0404673efd095ae2baec1873b916c49c81 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sat, 21 Dec 2019 23:17:25 +0200 Subject: Implemented not existing deleted RML check for PPC update and error message. Added proper notification when trying to remove used RML onMS. --- .../ViewModels/MainViewVM.cs | 10 +++++++++- .../MachineUpdate/MachineUpdateManager.cs | 1 + .../Tango.PPC.Common/Web/CheckForUpdateRequest.cs | 2 ++ .../Tango.PPC.Common/Web/CheckForUpdateResponse.cs | 2 ++ .../Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs | 23 ++++++++++++++++++++++ .../Controllers/PPCController.cs | 4 ++++ 6 files changed, 41 insertions(+), 1 deletion(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs index 527159aa5..5c55892ba 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs @@ -445,7 +445,7 @@ namespace Tango.MachineStudio.RML.ViewModels private async void RemoveSelectedRml() { - if (_notification.ShowQuestion("Removing the selected RML will result in the loss of all related process parameters and default calibration data. Are you sure you want to delete the selected RML?")) + if (_notification.ShowQuestion("Removing the selected thread will result in the loss of all related process parameters and default calibration data. Are you sure you want to delete the selected RML?")) { IsFree = false; @@ -453,6 +453,14 @@ namespace Tango.MachineStudio.RML.ViewModels { try { + var rml_jobs = await _rmls_context.Jobs.Where(x => x.RmlGuid == SelectedRML.Guid).Include(x => x.Machine).OrderBy(x => x.Machine.SerialNumber).ToListAsync(); + + if (rml_jobs.Count > 0) + { + _notification.ShowError($"The following jobs must be removed or change thread type before the selected thread can be deleted:\n{String.Join("\n",rml_jobs.Select(x => $"{x.Machine.SerialNumber} => {x.Name}"))}"); + return; + } + await SelectedRML.DeleteCascadeAsync(_rmls_context); _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.RmlDeleted, _authentication.CurrentUser, SelectedRML.Name, SelectedRML, "RML deleted from Machine Studio."); 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 d0424254b..8d6e02020 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs @@ -852,6 +852,7 @@ namespace Tango.PPC.Common.MachineUpdate request.Rmls = db.Rmls.ToList().Select(x => new UpdatedEntity(x)).ToList(); request.HardwareVersions = db.HardwareVersions.ToList().Select(x => new UpdatedEntity(x)).ToList(); request.Catalogs = db.ColorCatalogs.ToList().Select(x => new UpdatedEntity(x)).ToList(); + request.UsedRmlsGuids = db.Jobs.Select(x => x.RmlGuid).Distinct().ToList(); } } catch (Exception ex) diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateRequest.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateRequest.cs index 3d606b918..0d86fa117 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateRequest.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateRequest.cs @@ -16,12 +16,14 @@ namespace Tango.PPC.Common.Web public List HardwareVersions { get; set; } public List Catalogs { get; set; } public DateTime MachineLastUpdated { get; set; } + public List UsedRmlsGuids { get; set; } public CheckForUpdateRequest() { Rmls = new List(); HardwareVersions = new List(); Catalogs = new List(); + UsedRmlsGuids = new List(); } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateResponse.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateResponse.cs index a857a20a1..2fb33ebdc 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateResponse.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateResponse.cs @@ -16,10 +16,12 @@ namespace Tango.PPC.Common.Web public bool SetupFirmware { get; set; } public bool SetupFPGA { get; set; } public UpdateDBResponse UpdateDBResponse { get; set; } + public List UsedNotExistingRmlsGuids { get; set; } public CheckForUpdateResponse() { UpdateDBResponse = new UpdateDBResponse(); + UsedNotExistingRmlsGuids = new List(); } } } 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 49b2aef89..0af977614 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; +using System.Data.Entity; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.BL; using Tango.Core.Commands; using Tango.Core.Helpers; using Tango.Explorer; @@ -156,6 +158,27 @@ namespace Tango.PPC.UI.ViewModels } var response = await MachineUpdateManager.CheckForUpdate(MachineProvider.Machine.SerialNumber); + + try + { + if (response.UsedNotExistingRmlsGuids.Count > 0) + { + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + var arr = response.UsedNotExistingRmlsGuids.ToArray(); + var jobs = await db.Jobs.Where(x => arr.Contains(x.RmlGuid)).ToListAsync(); + FailedError = $"The following jobs must be removed or change thread type before the system can be updated:\n{String.Join("\n", jobs.Select(x => x.Name))}"; + _isChecking = false; + await NavigateTo(MachineUpdateView.UpdateFailedView); + return; + } + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error on used RML check procedure."); + } + _checkUpdateResponse = response; if (response.IsUpdateAvailable) diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs index ade8f88bc..1bb025217 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs @@ -330,6 +330,10 @@ namespace Tango.MachineService.Controllers var hardwareVersions = db.HardwareVersions.Select(x => new { x.Guid, x.LastUpdated }).ToList(); var catalogs = db.ColorCatalogs.Select(x => new { x.Guid, x.LastUpdated }).ToList(); + var arr = request.UsedRmlsGuids.ToArray(); + var existingRml = db.Rmls.Where(x => arr.Contains(x.Guid)).Select(x => x.Guid).Distinct().ToList(); + response.UsedNotExistingRmlsGuids = arr.Where(x => !existingRml.Exists(y => y == x)).ToList(); + bool hasDatabaseUpdates = false; hasDatabaseUpdates = machine.LastUpdated > request.MachineLastUpdated; -- cgit v1.3.1