From 24292197223caf2ffa1a771c38b2e2f7418ad03e Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 15 Dec 2019 16:13:47 +0200 Subject: Added PowerDown and ThreadLoading to PMR. Removed old ThreadLoading from PMR diagnostics. --- .../ThreadLoading/ContinueThreadLoadingRequest.proto | 11 +++++++++++ .../ThreadLoading/ContinueThreadLoadingResponse.proto | 9 +++++++++ .../ThreadLoading/StartThreadLoadingRequest.proto | 9 +++++++++ .../ThreadLoading/StartThreadLoadingResponse.proto | 12 ++++++++++++ .../PMR/Messages/ThreadLoading/ThreadLoadingState.proto | 15 +++++++++++++++ 5 files changed, 56 insertions(+) create mode 100644 Software/PMR/Messages/ThreadLoading/ContinueThreadLoadingRequest.proto create mode 100644 Software/PMR/Messages/ThreadLoading/ContinueThreadLoadingResponse.proto create mode 100644 Software/PMR/Messages/ThreadLoading/StartThreadLoadingRequest.proto create mode 100644 Software/PMR/Messages/ThreadLoading/StartThreadLoadingResponse.proto create mode 100644 Software/PMR/Messages/ThreadLoading/ThreadLoadingState.proto (limited to 'Software/PMR/Messages/ThreadLoading') diff --git a/Software/PMR/Messages/ThreadLoading/ContinueThreadLoadingRequest.proto b/Software/PMR/Messages/ThreadLoading/ContinueThreadLoadingRequest.proto new file mode 100644 index 000000000..5bae29bd7 --- /dev/null +++ b/Software/PMR/Messages/ThreadLoading/ContinueThreadLoadingRequest.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +import "ProcessParameters.proto"; + +package Tango.PMR.ThreadLoading; +option java_package = "com.twine.tango.pmr.threadloading"; + +message ContinueThreadLoadingRequest +{ + PMR.Printing.ProcessParameters ProcessParameters = 1; +} \ No newline at end of file diff --git a/Software/PMR/Messages/ThreadLoading/ContinueThreadLoadingResponse.proto b/Software/PMR/Messages/ThreadLoading/ContinueThreadLoadingResponse.proto new file mode 100644 index 000000000..b937fbb34 --- /dev/null +++ b/Software/PMR/Messages/ThreadLoading/ContinueThreadLoadingResponse.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package Tango.PMR.ThreadLoading; +option java_package = "com.twine.tango.pmr.threadloading"; + +message ContinueThreadLoadingResponse +{ + +} \ No newline at end of file diff --git a/Software/PMR/Messages/ThreadLoading/StartThreadLoadingRequest.proto b/Software/PMR/Messages/ThreadLoading/StartThreadLoadingRequest.proto new file mode 100644 index 000000000..c0c3d3257 --- /dev/null +++ b/Software/PMR/Messages/ThreadLoading/StartThreadLoadingRequest.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package Tango.PMR.ThreadLoading; +option java_package = "com.twine.tango.pmr.threadloading"; + +message StartThreadLoadingRequest +{ + +} \ No newline at end of file diff --git a/Software/PMR/Messages/ThreadLoading/StartThreadLoadingResponse.proto b/Software/PMR/Messages/ThreadLoading/StartThreadLoadingResponse.proto new file mode 100644 index 000000000..be8136741 --- /dev/null +++ b/Software/PMR/Messages/ThreadLoading/StartThreadLoadingResponse.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +import "ThreadLoadingState.proto"; + +package Tango.PMR.ThreadLoading; +option java_package = "com.twine.tango.pmr.threadloading"; + +message StartThreadLoadingResponse +{ + ThreadLoadingState State = 1; + string ErrorReason = 2; +} \ No newline at end of file diff --git a/Software/PMR/Messages/ThreadLoading/ThreadLoadingState.proto b/Software/PMR/Messages/ThreadLoading/ThreadLoadingState.proto new file mode 100644 index 000000000..7f0eb5f98 --- /dev/null +++ b/Software/PMR/Messages/ThreadLoading/ThreadLoadingState.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package Tango.PMR.ThreadLoading; +option java_package = "com.twine.tango.pmr.threadloading"; + +enum ThreadLoadingState +{ + None = 0; + Preparing = 1; + ReadyForLoading = 2; + PreparationError = 3; + Finalizing = 4; + FinalizationError = 5; + Completed = 6; +} \ No newline at end of file -- cgit v1.3.1 From 7eb7994e4061638068d8f407337557eedf3fd4ee Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Tue, 17 Dec 2019 08:45:16 +0200 Subject: complete power and loading proto files --- Software/PMR/Messages/Power/PowerDownState.proto | 16 +++++++++++++++- .../ThreadLoading/ContinueThreadLoadingResponse.proto | 5 ++++- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'Software/PMR/Messages/ThreadLoading') diff --git a/Software/PMR/Messages/Power/PowerDownState.proto b/Software/PMR/Messages/Power/PowerDownState.proto index b9fc97f1a..25c42ffb5 100644 --- a/Software/PMR/Messages/Power/PowerDownState.proto +++ b/Software/PMR/Messages/Power/PowerDownState.proto @@ -7,5 +7,19 @@ enum PowerDownState { //Fill the states. None = 0; - Completed = 1; + Init = 1; + StopRunningJob = 2; + HeadClean = 3; + MixerFlush = 4; + HeatersOff = 5; + StoreData = 6; + SetValvePosition = 7; + WaitForTemperature = 8; + WaitForProcesses = 9; + TurnOffDryerFan = 10; + TurnOffCooler = 11; + TurnOffBlower = 12; + PowerOffCompleted = 13; + Error = 14; + Cancelled = 15; } \ No newline at end of file diff --git a/Software/PMR/Messages/ThreadLoading/ContinueThreadLoadingResponse.proto b/Software/PMR/Messages/ThreadLoading/ContinueThreadLoadingResponse.proto index b937fbb34..5763dbb2c 100644 --- a/Software/PMR/Messages/ThreadLoading/ContinueThreadLoadingResponse.proto +++ b/Software/PMR/Messages/ThreadLoading/ContinueThreadLoadingResponse.proto @@ -1,9 +1,12 @@ syntax = "proto3"; +import "ThreadLoadingState.proto"; + package Tango.PMR.ThreadLoading; option java_package = "com.twine.tango.pmr.threadloading"; message ContinueThreadLoadingResponse { - + ThreadLoadingState State = 1; + string ErrorReason = 2; } \ No newline at end of file -- cgit v1.3.1 From 41b950b3f3f7fa0384cccd13ed4ef38119bbcbcf Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Wed, 18 Dec 2019 15:52:25 +0200 Subject: Fixed ContinueThreadLoadingResponse. Refactored ActionLog Difference data structure to node tree. --- .../ContinueThreadLoadingResponse.proto | 5 +- .../ViewModels/MainViewVM.cs | 19 ++- .../ViewModels/MainViewVM.cs | 23 +++- .../Tango.MachineStudio.UI/ViewModelLocator.cs | 2 +- .../Tango.BL/ActionLogs/BasicActionLogComparer.cs | 82 +++++++++---- .../Tango.BL/ActionLogs/DefaultActionLogManager.cs | 132 +++++++++++---------- .../Tango.BL/ActionLogs/IActionLogComparable.cs | 5 +- .../Tango.BL/ActionLogs/IActionLogManager.cs | 15 ++- .../Visual_Studio/Tango.BL/DTO/BrushStopDTO.cs | 5 + .../Visual_Studio/Tango.BL/DTO/ColorCatalogDTO.cs | 10 ++ .../Tango.BL/DTO/ColorCatalogsGroupDTO.cs | 10 ++ .../Tango.BL/DTO/ColorCatalogsItemDTO.cs | 5 + .../Tango.BL/DTO/ColorCatalogsItemsRecipeDTO.cs | 5 +- Software/Visual_Studio/Tango.BL/DTO/JobDTO.cs | 5 + Software/Visual_Studio/Tango.BL/DTO/SegmentDTO.cs | 5 + .../Visual_Studio/Tango.BL/Entities/ActionLog.cs | 20 ++-- .../Tango.BL/Enumerations/ActionLogType.cs | 2 + .../Visual_Studio/Tango.BL/ObservableEntity.cs | 14 ++- .../Visual_Studio/Tango.BL/ObservableEntityDTO.cs | 14 ++- Software/Visual_Studio/Tango.BL/Tango.BL.csproj | 3 +- .../Tango.BL/ValueObjects/ActionLogDifference.cs | 26 +++- .../ValueObjects/ActionLogDifferenceValue.cs | 26 ++++ 22 files changed, 311 insertions(+), 122 deletions(-) create mode 100644 Software/Visual_Studio/Tango.BL/ValueObjects/ActionLogDifferenceValue.cs (limited to 'Software/PMR/Messages/ThreadLoading') diff --git a/Software/PMR/Messages/ThreadLoading/ContinueThreadLoadingResponse.proto b/Software/PMR/Messages/ThreadLoading/ContinueThreadLoadingResponse.proto index 5763dbb2c..b937fbb34 100644 --- a/Software/PMR/Messages/ThreadLoading/ContinueThreadLoadingResponse.proto +++ b/Software/PMR/Messages/ThreadLoading/ContinueThreadLoadingResponse.proto @@ -1,12 +1,9 @@ syntax = "proto3"; -import "ThreadLoadingState.proto"; - package Tango.PMR.ThreadLoading; option java_package = "com.twine.tango.pmr.threadloading"; message ContinueThreadLoadingResponse { - ThreadLoadingState State = 1; - string ErrorReason = 2; + } \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Catalogs/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Catalogs/ViewModels/MainViewVM.cs index 4d88a71d9..404a459d3 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Catalogs/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Catalogs/ViewModels/MainViewVM.cs @@ -17,6 +17,10 @@ using Microsoft.Win32; using Tango.Core.Helpers; using System.IO; using Tango.MachineStudio.Catalogs.Excel; +using Tango.BL.ActionLogs; +using Tango.MachineStudio.Common.Authentication; +using Tango.BL.Enumerations; +using Tango.BL.DTO; namespace Tango.MachineStudio.Catalogs.ViewModels { @@ -25,6 +29,9 @@ namespace Tango.MachineStudio.Catalogs.ViewModels private ObservablesContext _catalogsContext; private ObservablesContext _activeCatalogContext; private INotificationProvider _notification; + private IActionLogManager _actionLogManager; + private IAuthenticationProvider _authentication; + private ColorCatalogDTO _catalogBeforeSave; #region Properties @@ -151,9 +158,11 @@ namespace Tango.MachineStudio.Catalogs.ViewModels /// Initializes a new instance of the class. /// /// The notification provider. - public MainViewVM(INotificationProvider notificationProvider) : this() + public MainViewVM(INotificationProvider notificationProvider, IActionLogManager actionLogManager, IAuthenticationProvider authenticationProvider) : this() { + _actionLogManager = actionLogManager; _notification = notificationProvider; + _authentication = authenticationProvider; } #endregion @@ -206,6 +215,8 @@ namespace Tango.MachineStudio.Catalogs.ViewModels SelectedItem = SelectedGroup.ColorCatalogsItems.FirstOrDefault(); } + _catalogBeforeSave = ColorCatalogDTO.FromObservable(ActiveCatalog); + View.NavigateTo(CatalogsNavigationView.CatalogView); } catch (Exception ex) @@ -233,6 +244,7 @@ namespace Tango.MachineStudio.Catalogs.ViewModels { IsFree = false; await SelectedCatalog.DeleteCascadeAsync(_catalogsContext); + _actionLogManager.InsertLog(ActionLogType.CatalogDeleted, _authentication.CurrentUser, SelectedCatalog.Name, SelectedCatalog, "Catalog deleted using Machine Studio."); SelectedCatalog = null; } catch (Exception ex) @@ -265,6 +277,7 @@ namespace Tango.MachineStudio.Catalogs.ViewModels newCatalog.Company = "Twine"; _catalogsContext.ColorCatalogs.Add(newCatalog); await _catalogsContext.SaveChangesAsync(); + _actionLogManager.InsertLog(ActionLogType.CatalogCreated, _authentication.CurrentUser, newCatalog.Name, newCatalog, "Catalog created using Machine Studio."); SelectedCatalog = newCatalog; EditSelectedCatalog(); } @@ -308,6 +321,10 @@ namespace Tango.MachineStudio.Catalogs.ViewModels ActiveCatalog.LastUpdated = DateTime.UtcNow; await _activeCatalogContext.SaveChangesAsync(); await LoadCatalogs(); + + var activeCatalogDTO = ColorCatalogDTO.FromObservable(ActiveCatalog); + _actionLogManager.InsertLog(ActionLogType.CatalogSaved, _authentication.CurrentUser, ActiveCatalog.Name, _catalogBeforeSave, activeCatalogDTO, "Catalog created using Machine Studio."); + _catalogBeforeSave = activeCatalogDTO; _notification.ShowInfo("Catalog updated successfully."); } catch (Exception ex) diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index d598e2458..4b276462e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -1928,7 +1928,7 @@ namespace Tango.MachineStudio.Developer.ViewModels _activeJobDbContext.SaveChanges(); var afterJobDTO = JobDTO.FromObservable(ActiveJob); - _actionLogManager.InsertLog(ActionLogType.JobSaved, AuthenticationProvider.CurrentUser, _beforeSaveJobDTO.Name, _beforeSaveJobDTO, afterJobDTO, "Job saved from research module in Machine Studio.").GetAwaiter().GetResult(); + _actionLogManager.InsertLog(ActionLogType.JobSaved, AuthenticationProvider.CurrentUser, _beforeSaveJobDTO.Name, _beforeSaveJobDTO, afterJobDTO, "Job saved from research module in Machine Studio."); _beforeSaveJobDTO = afterJobDTO; _machineDbContext.Entry(SelectedMachineJob).Reload(); @@ -2191,6 +2191,8 @@ namespace Tango.MachineStudio.Developer.ViewModels { if (_notification.ShowQuestion("Are you sure you want to delete the selected jobs?")) { + var jobsToReport = SelectedJobs.Select(x => JobDTO.FromObservable(x)).ToList(); + LogManager.Log(String.Format("Removing {0} jobs...", SelectedJobs.Count)); SelectedJobs.ToList().ForEach(x => { @@ -2202,6 +2204,11 @@ namespace Tango.MachineStudio.Developer.ViewModels LogManager.Log("Saving selected machine to database..."); await SelectedMachine.SaveAsync(_machineDbContext); } + + foreach (var job in jobsToReport) + { + _actionLogManager.InsertLog(ActionLogType.JobDeleted, AuthenticationProvider.CurrentUser, job.Name, job, "Job deleted using Machine Studio.", true); + } } } } @@ -2258,6 +2265,7 @@ namespace Tango.MachineStudio.Developer.ViewModels LogManager.Log("Saving selected machine to database..."); await SelectedMachine.SaveAsync(_machineDbContext); + _actionLogManager.InsertLog(ActionLogType.JobCreated, AuthenticationProvider.CurrentUser, newJob.Name, newJob, "Job created using Machine Studio."); SelectedMachineJob = newJob; LoadSelectedJob(); } @@ -2388,6 +2396,11 @@ namespace Tango.MachineStudio.Developer.ViewModels LogManager.Log("Saving selected machine to database..."); await SelectedMachine.SaveAsync(_machineDbContext); + foreach (var job in SelectedJobs) + { + _actionLogManager.InsertLog(ActionLogType.JobCreated, AuthenticationProvider.CurrentUser, job.Name, job, "Job created using Machine Studio."); + } + CanWork = true; } } @@ -2611,6 +2624,8 @@ namespace Tango.MachineStudio.Developer.ViewModels LogManager.Log($"Importing job files..."); + List jobsToReport = new List(); + foreach (var file in dlg.FileNames) { var bytes = File.ReadAllBytes(file); @@ -2619,10 +2634,16 @@ namespace Tango.MachineStudio.Developer.ViewModels job.JobSource = JobSource.Remote; _machineDbContext.Jobs.Add(job); + jobsToReport.Add(job); } await _machineDbContext.SaveChangesAsync(); + foreach (var job in jobsToReport) + { + _actionLogManager.InsertLog(ActionLogType.JobImported, AuthenticationProvider.CurrentUser, job.Name, job, "New job imported using Machine Studio."); + } + IsFree = true; _notification.ShowInfo($"Jobs imported successfully."); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs index a61f14746..6c550ffda 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs @@ -95,7 +95,7 @@ namespace Tango.MachineStudio.UI TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); - TangoIOC.Default.Register(new DefaultActionLogManager() { ThrowExceptions = false }); + TangoIOC.Default.Register(); TangoIOC.Default.Register(new TeamFoundationServiceExtendedClient("https://twinetfs.visualstudio.com", String.Empty, "szzfokrceo4rhd4eqi5qpmxn3pa5iwl3q7tlqd36l2m7smz2ynoa")); diff --git a/Software/Visual_Studio/Tango.BL/ActionLogs/BasicActionLogComparer.cs b/Software/Visual_Studio/Tango.BL/ActionLogs/BasicActionLogComparer.cs index 61fc373a8..af52bf394 100644 --- a/Software/Visual_Studio/Tango.BL/ActionLogs/BasicActionLogComparer.cs +++ b/Software/Visual_Studio/Tango.BL/ActionLogs/BasicActionLogComparer.cs @@ -11,19 +11,36 @@ namespace Tango.BL.ActionLogs { public class BasicActionLogComparer { - public Task> Compare(IActionLogComparable before, IActionLogComparable after) + public Task Compare(IActionLogComparable before, IActionLogComparable after) { - return Task.Factory.StartNew>(() => + return Task.Factory.StartNew(() => { - List diffs = new List(); + ActionLogDifference diff = new ActionLogDifference(); + diff.Name = GetComponentName(before, after); - Compare(diffs, before, after, null); + Compare(diff, before, after, null); + RemoveNoDifferences(diff); - return diffs; + return diff; }); } - private void Compare(List diffs, Object before, Object after, HashSet scannedObjects) + private void RemoveNoDifferences(ActionLogDifference diff) + { + foreach (var child in diff.Children.ToList()) + { + if (!child.HasDifference) + { + diff.Children.Remove(child); + } + else + { + RemoveNoDifferences(child); + } + } + } + + private void Compare(ActionLogDifference diff, Object before, Object after, HashSet scannedObjects) { if (scannedObjects == null) { @@ -46,7 +63,7 @@ namespace Tango.BL.ActionLogs String component = GetComponentName(before, after); - foreach (var prop in GetProperties(before, after)) + foreach (var prop in GetProperties(before, after).OrderByDescending(x => x.PropertyType.IsPrimitive || x.PropertyType.IsValueType || x.PropertyType == typeof(String))) { if (GetShouldIgnore(prop, before, after)) continue; @@ -65,14 +82,14 @@ namespace Tango.BL.ActionLogs afterValue = prop.GetValue(after); } - if (afterValue == null && beforeValue != null) AddDiff(diffs, component, prop.Name, beforeValue, afterValue); - if (afterValue != null && beforeValue == null) AddDiff(diffs, component, prop.Name, beforeValue, afterValue); + if (afterValue == null && beforeValue != null) AddValueDiff(diff, prop.Name, beforeValue, afterValue); + if (afterValue != null && beforeValue == null) AddValueDiff(diff, prop.Name, beforeValue, afterValue); if (afterValue != null && beforeValue != null) { if (!afterValue.Equals(beforeValue)) { - AddDiff(diffs, component, prop.Name, beforeValue, afterValue); + AddValueDiff(diff, prop.Name, beforeValue, afterValue); } } } @@ -91,7 +108,7 @@ namespace Tango.BL.ActionLogs afterPropInstance = prop.GetValue(after); } - Compare(diffs, beforePropInstance, afterPropInstance, scannedObjects); + Compare(AddChildDiff(diff, prop.Name), beforePropInstance, afterPropInstance, scannedObjects); } else { @@ -108,18 +125,18 @@ namespace Tango.BL.ActionLogs afterCollection = prop.GetValue(after) as IList; } - if (beforeCollection != null && beforeCollection == null) + if (beforeCollection != null && afterCollection == null) { for (int i = 0; i < beforeCollection.Count; i++) { - Compare(diffs, beforeCollection[i], null, scannedObjects); + Compare(AddChildDiff(diff, GetActionLogName(beforeCollection[i],prop.Name)), beforeCollection[i], null, scannedObjects); } } else if (beforeCollection == null && afterCollection != null) { for (int i = 0; i < afterCollection.Count; i++) { - Compare(diffs, null, afterCollection[i], scannedObjects); + Compare(AddChildDiff(diff, GetActionLogName(afterCollection[i], prop.Name)), null, afterCollection[i], scannedObjects); } } @@ -129,27 +146,52 @@ namespace Tango.BL.ActionLogs { var beforeItem = i < beforeCollection.Count ? beforeCollection[i] : null; var afterItem = i < afterCollection.Count ? afterCollection[i] : null; - Compare(diffs, beforeItem, afterItem, scannedObjects); + Compare(AddChildDiff(diff, GetActionLogName(beforeItem, prop.Name)), beforeItem, afterItem, scannedObjects); } } } } } - private void AddDiff(List diffs, String component, String property, object before, object after) + private void AddValueDiff(ActionLogDifference diff, String property, object before, object after) { - diffs.Add(new ActionLogDifference() + diff.Children.Add(new ActionLogDifferenceValue() { - Component = component, - Property = property, + Name = property, Before = before, After = after }); } + private ActionLogDifference AddChildDiff(ActionLogDifference diff, String property) + { + ActionLogDifference childDiff = new ActionLogDifference(); + childDiff.Name = property; + diff.Children.Add(childDiff); + return childDiff; + } + private String GetComponentName(Object before, Object after) { - return after != null ? after.GetType().Name : before.GetType().Name; + var afterCast = after as IActionLogComparable; + var beforeCast = before as IActionLogComparable; + + var name = afterCast != null ? afterCast.GetActionName() : beforeCast.GetActionName(); + + return name; + } + + private String GetActionLogName(Object obj, String defaultName) + { + var objCast = obj as IActionLogComparable; + if (objCast != null) + { + return objCast.GetActionName(); + } + else + { + return defaultName; + } } private PropertyInfo GetProperty(String name, Object before, Object after) diff --git a/Software/Visual_Studio/Tango.BL/ActionLogs/DefaultActionLogManager.cs b/Software/Visual_Studio/Tango.BL/ActionLogs/DefaultActionLogManager.cs index 23562bee0..9d632bccc 100644 --- a/Software/Visual_Studio/Tango.BL/ActionLogs/DefaultActionLogManager.cs +++ b/Software/Visual_Studio/Tango.BL/ActionLogs/DefaultActionLogManager.cs @@ -14,109 +14,113 @@ namespace Tango.BL.ActionLogs { public class DefaultActionLogManager : ExtendedObject, IActionLogManager { - public bool ThrowExceptions { get; set; } - - public DefaultActionLogManager() + public void InsertLog(ActionLogType type, string userGuid, string relatedObjectName, string relatedObjectGuid, ActionLogDifference difference, string message = null) { - ThrowExceptions = true; - } - - public async Task InsertLog(ActionLogType type, string userGuid, string relatedObjectName, string relatedObjectGuid, List differences, string message = null) - { - using (ObservablesContext db = ObservablesContext.CreateDefault()) + Task.Factory.StartNew(() => { - try + using (ObservablesContext db = ObservablesContext.CreateDefault()) { - ActionLog log = new ActionLog(); - log.ActionType = type; - log.LastUpdated = DateTime.UtcNow; - log.UserGuid = userGuid; - log.RelatedObjectName = relatedObjectName; - log.RelatedObjectGuid = relatedObjectGuid; - log.Message = message; - log.Differences = differences; + try + { + ActionLog log = new ActionLog(); + log.ActionType = type; + log.LastUpdated = DateTime.UtcNow; + log.UserGuid = userGuid; + log.RelatedObjectName = relatedObjectName; + log.RelatedObjectGuid = relatedObjectGuid; + log.Message = message; + log.DifferenceObject = difference; - db.ActionLogs.Add(log); + db.ActionLogs.Add(log); - await db.SaveChangesAsync(); + db.SaveChanges(); - LogManager.Log($"Action log '{type}' inserted."); + LogManager.Log($"Action log '{type}' inserted."); - if (differences != null && differences.Count > 0) - { - Debug.WriteLine($"Action log differences:\n{differences.ToJsonString()}"); + if (difference != null && difference.Children.Count > 0) + { + Debug.WriteLine($"Action log differences:\n{difference.ToJsonString()}"); + } } - } - catch (Exception ex) - { - LogManager.Log(ex, $"Error inserting action log '{type}'."); - - if (ThrowExceptions) + catch (Exception ex) { - throw ex; + LogManager.Log(ex, $"Error inserting action log '{type}'."); } } - } + }); } - public async Task InsertLog(ActionLogType type, string userGuid, string relatedObjectName, IActionLogComparable relatedObjectBefore, IActionLogComparable relatedObjectAfter, string message = null) + public void InsertLog(ActionLogType type, string userGuid, string relatedObjectName, IActionLogComparable relatedObjectBefore, IActionLogComparable relatedObjectAfter, string message = null) { - List diffs = null; - - try + Task.Factory.StartNew(() => { - if (relatedObjectAfter != null) + ActionLogDifference diff = null; + + try { - diffs = await relatedObjectAfter.CompareTo(relatedObjectBefore); + diff = new BasicActionLogComparer().Compare(relatedObjectBefore, relatedObjectAfter).Result; } - else + catch (Exception ex) { - diffs = await relatedObjectBefore.CompareTo(relatedObjectAfter); + LogManager.Log(ex, $"Error while comparing for action log '{type}'."); } - } - catch (Exception ex) - { - LogManager.Log(ex, $"Error while comparing for action log '{type}'."); - if (ThrowExceptions) + if (diff.Children.Count > 0) { - throw ex; + InsertLog(type, userGuid, relatedObjectName, GetRelatedObjectGuid(relatedObjectBefore, relatedObjectAfter), diff, message); } - } + else + { + LogManager.Log($"Action log '{type}' was about to be inserted but skipped due to no differences."); + } + }); + } + + public void InsertLog(ActionLogType type, User user, string relatedObjectName, IActionLogComparable relatedObjectBefore, IActionLogComparable relatedObjectAfter, string message = null) + { + InsertLog(type, user.Guid, relatedObjectName, relatedObjectBefore, relatedObjectAfter, message); + } + + public void InsertLog(ActionLogType type, string userGuid, string relatedObjectName, string relatedObjectGuid, string message = null) + { + InsertLog(type, userGuid, relatedObjectName, relatedObjectGuid, null, message); + } - if (diffs.Count > 0) + public void InsertLog(ActionLogType type, User user, string relatedObjectName, IActionLogComparable relatedObject, string message = null, bool serializeRelatedObject = false) + { + if (serializeRelatedObject) { - await InsertLog(type, userGuid, relatedObjectName, relatedObjectAfter.Guid, diffs, message); + InsertLog(type, user.Guid, relatedObjectName, relatedObject, null, message); } else { - LogManager.Log($"Action log '{type}' was about to be inserted but skipped due to no differences."); + InsertLog(type, user.Guid, relatedObjectName, relatedObject?.Guid, message); } } - public Task InsertLog(ActionLogType type, User user, string relatedObjectName, IActionLogComparable relatedObjectBefore, IActionLogComparable relatedObjectAfter, string message = null) + public void InsertLog(ActionLogType type, string userGuid, string message = null) { - return InsertLog(type, user.Guid, relatedObjectName, relatedObjectBefore, relatedObjectAfter, message); + InsertLog(type, userGuid, null, null, message); } - public Task InsertLog(ActionLogType type, string userGuid, string relatedObjectName, string relatedObjectGuid, string message = null) + public void InsertLog(ActionLogType type, User user, string message = null) { - return InsertLog(type, userGuid, relatedObjectName, relatedObjectGuid, null, message); + InsertLog(type, user.Guid, message); } - public Task InsertLog(ActionLogType type, User user, string relatedObjectName, IObservableEntity relatedObject, string message = null) + private String GetRelatedObjectGuid(IActionLogComparable before, IActionLogComparable after) { - return InsertLog(type, user.Guid, relatedObjectName, relatedObject?.Guid, message); - } + if (before != null) + { + return before.Guid; + } - public Task InsertLog(ActionLogType type, string userGuid, string message = null) - { - return InsertLog(type, userGuid, null, null, message); - } + if (after != null) + { + return after.Guid; + } - public Task InsertLog(ActionLogType type, User user, string message = null) - { - return InsertLog(type, user.Guid, message); + return null; } } } diff --git a/Software/Visual_Studio/Tango.BL/ActionLogs/IActionLogComparable.cs b/Software/Visual_Studio/Tango.BL/ActionLogs/IActionLogComparable.cs index de534141b..d98dd9122 100644 --- a/Software/Visual_Studio/Tango.BL/ActionLogs/IActionLogComparable.cs +++ b/Software/Visual_Studio/Tango.BL/ActionLogs/IActionLogComparable.cs @@ -10,12 +10,13 @@ namespace Tango.BL.ActionLogs public interface IActionLogComparable { String Guid { get; } - Task> CompareTo(IActionLogComparable before); + Task CompareTo(IActionLogComparable before); bool ShouldActionLogIgnore(String propName); + String GetActionName(); } public interface IActionLogComparable : IActionLogComparable where T : class { - Task> CompareTo(T before); + Task CompareTo(T before); } } diff --git a/Software/Visual_Studio/Tango.BL/ActionLogs/IActionLogManager.cs b/Software/Visual_Studio/Tango.BL/ActionLogs/IActionLogManager.cs index fd903bbba..36fb62ed4 100644 --- a/Software/Visual_Studio/Tango.BL/ActionLogs/IActionLogManager.cs +++ b/Software/Visual_Studio/Tango.BL/ActionLogs/IActionLogManager.cs @@ -11,13 +11,12 @@ namespace Tango.BL.ActionLogs { public interface IActionLogManager { - bool ThrowExceptions { get; set; } - Task InsertLog(ActionLogType type, String userGuid, String relatedObjectName, String relatedObjectGuid, List differences, String message = null); - Task InsertLog(ActionLogType type, String userGuid, String relatedObjectName, IActionLogComparable relatedObjectBefore, IActionLogComparable relatedObjectAfter, String message = null); - Task InsertLog(ActionLogType type, User user, String relatedObjectName, IActionLogComparable relatedObjectBefore, IActionLogComparable relatedObjectAfter, String message = null); - Task InsertLog(ActionLogType type, String userGuid, String relatedObjectName, String relatedObjectGuid, String message = null); - Task InsertLog(ActionLogType type, User user, String relatedObjectName, IObservableEntity relatedObject, String message = null); - Task InsertLog(ActionLogType type, String userGuid, String message = null); - Task InsertLog(ActionLogType type, User user, String message = null); + void InsertLog(ActionLogType type, String userGuid, String relatedObjectName, String relatedObjectGuid, ActionLogDifference diffference, String message = null); + void InsertLog(ActionLogType type, String userGuid, String relatedObjectName, IActionLogComparable relatedObjectBefore, IActionLogComparable relatedObjectAfter, String message = null); + void InsertLog(ActionLogType type, User user, String relatedObjectName, IActionLogComparable relatedObjectBefore, IActionLogComparable relatedObjectAfter, String message = null); + void InsertLog(ActionLogType type, String userGuid, String relatedObjectName, String relatedObjectGuid, String message = null); + void InsertLog(ActionLogType type, User user, String relatedObjectName, IActionLogComparable relatedObject, String message = null, bool serializeRelatedObject = false); + void InsertLog(ActionLogType type, String userGuid, String message = null); + void InsertLog(ActionLogType type, User user, String message = null); } } diff --git a/Software/Visual_Studio/Tango.BL/DTO/BrushStopDTO.cs b/Software/Visual_Studio/Tango.BL/DTO/BrushStopDTO.cs index 585f2f2ee..fd1d707b5 100644 --- a/Software/Visual_Studio/Tango.BL/DTO/BrushStopDTO.cs +++ b/Software/Visual_Studio/Tango.BL/DTO/BrushStopDTO.cs @@ -13,5 +13,10 @@ namespace Tango.BL.DTO { return propName == nameof(Corrected); } + + protected override string OnGetActionLogName() + { + return $"BrushStop '{StopIndex}'"; + } } } diff --git a/Software/Visual_Studio/Tango.BL/DTO/ColorCatalogDTO.cs b/Software/Visual_Studio/Tango.BL/DTO/ColorCatalogDTO.cs index 012e7aede..7daa98aca 100644 --- a/Software/Visual_Studio/Tango.BL/DTO/ColorCatalogDTO.cs +++ b/Software/Visual_Studio/Tango.BL/DTO/ColorCatalogDTO.cs @@ -9,6 +9,16 @@ namespace Tango.BL.DTO { public class ColorCatalogDTO : ColorCatalogDTOBase { + public List ColorCatalogsGroups { get; set; } + public ColorCatalogDTO() + { + ColorCatalogsGroups = new List(); + } + + protected override string OnGetActionLogName() + { + return $"'{Name}' Catalog"; + } } } diff --git a/Software/Visual_Studio/Tango.BL/DTO/ColorCatalogsGroupDTO.cs b/Software/Visual_Studio/Tango.BL/DTO/ColorCatalogsGroupDTO.cs index 8115923e5..50c5e051e 100644 --- a/Software/Visual_Studio/Tango.BL/DTO/ColorCatalogsGroupDTO.cs +++ b/Software/Visual_Studio/Tango.BL/DTO/ColorCatalogsGroupDTO.cs @@ -9,6 +9,16 @@ namespace Tango.BL.DTO { public class ColorCatalogsGroupDTO : ColorCatalogsGroupDTOBase { + public List ColorCatalogsItems { get; set; } + public ColorCatalogsGroupDTO() + { + ColorCatalogsItems = new List(); + } + + protected override string OnGetActionLogName() + { + return $"Color Group '{Name}'"; + } } } diff --git a/Software/Visual_Studio/Tango.BL/DTO/ColorCatalogsItemDTO.cs b/Software/Visual_Studio/Tango.BL/DTO/ColorCatalogsItemDTO.cs index 46b33b715..5e0fd3115 100644 --- a/Software/Visual_Studio/Tango.BL/DTO/ColorCatalogsItemDTO.cs +++ b/Software/Visual_Studio/Tango.BL/DTO/ColorCatalogsItemDTO.cs @@ -9,6 +9,11 @@ namespace Tango.BL.DTO { public class ColorCatalogsItemDTO : ColorCatalogsItemDTOBase { + public List ColorCatalogsItemsRecipes { get; set; } + protected override string OnGetActionLogName() + { + return $"Color Item '{Name}'"; + } } } diff --git a/Software/Visual_Studio/Tango.BL/DTO/ColorCatalogsItemsRecipeDTO.cs b/Software/Visual_Studio/Tango.BL/DTO/ColorCatalogsItemsRecipeDTO.cs index 07c7695e1..34b061df8 100644 --- a/Software/Visual_Studio/Tango.BL/DTO/ColorCatalogsItemsRecipeDTO.cs +++ b/Software/Visual_Studio/Tango.BL/DTO/ColorCatalogsItemsRecipeDTO.cs @@ -9,6 +9,9 @@ namespace Tango.BL.DTO { public class ColorCatalogsItemsRecipeDTO : ColorCatalogsItemsRecipeDTOBase { - + protected override string OnGetActionLogName() + { + return $"Color Recipe for RML '{RmlGuid}'"; + } } } diff --git a/Software/Visual_Studio/Tango.BL/DTO/JobDTO.cs b/Software/Visual_Studio/Tango.BL/DTO/JobDTO.cs index 36f7ea9be..176d97251 100644 --- a/Software/Visual_Studio/Tango.BL/DTO/JobDTO.cs +++ b/Software/Visual_Studio/Tango.BL/DTO/JobDTO.cs @@ -22,5 +22,10 @@ namespace Tango.BL.DTO propName == nameof(JobDTO.Status) || propName == nameof(JobDTO.IsSynchronized); } + + protected override string OnGetActionLogName() + { + return $"'{Name}' Job"; + } } } diff --git a/Software/Visual_Studio/Tango.BL/DTO/SegmentDTO.cs b/Software/Visual_Studio/Tango.BL/DTO/SegmentDTO.cs index 09f581db2..00d74ec30 100644 --- a/Software/Visual_Studio/Tango.BL/DTO/SegmentDTO.cs +++ b/Software/Visual_Studio/Tango.BL/DTO/SegmentDTO.cs @@ -15,5 +15,10 @@ namespace Tango.BL.DTO { BrushStops = new List(); } + + protected override string OnGetActionLogName() + { + return $"Segment '{SegmentIndex}'"; + } } } diff --git a/Software/Visual_Studio/Tango.BL/Entities/ActionLog.cs b/Software/Visual_Studio/Tango.BL/Entities/ActionLog.cs index af88ee7f1..bb122872f 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/ActionLog.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/ActionLog.cs @@ -12,7 +12,7 @@ namespace Tango.BL.Entities { public class ActionLog : ActionLogBase { - private List _differences; + private ActionLogDifference _differenceObject; [NotMapped] [JsonIgnore] @@ -24,35 +24,35 @@ namespace Tango.BL.Entities [NotMapped] [JsonIgnore] - public List Differences + public ActionLogDifference DifferenceObject { get { - if (_differences != null) + if (_differenceObject != null) { try { - _differences = JsonConvert.DeserializeObject>(Difference); + _differenceObject = JsonConvert.DeserializeObject(Difference); } catch { - _differences = new List(); + _differenceObject = new ActionLogDifference(); } } else { - _differences = new List(); + _differenceObject = new ActionLogDifference(); } - return _differences; + return _differenceObject; } set { - _differences = value; + _differenceObject = value; - if (_differences != null) + if (_differenceObject != null) { - Difference = JsonConvert.SerializeObject(_differences); + Difference = JsonConvert.SerializeObject(_differenceObject); } } } diff --git a/Software/Visual_Studio/Tango.BL/Enumerations/ActionLogType.cs b/Software/Visual_Studio/Tango.BL/Enumerations/ActionLogType.cs index 94eb07cda..5114538ef 100644 --- a/Software/Visual_Studio/Tango.BL/Enumerations/ActionLogType.cs +++ b/Software/Visual_Studio/Tango.BL/Enumerations/ActionLogType.cs @@ -50,6 +50,8 @@ namespace Tango.BL.Enumerations JobDeleted = 301, [Description("Job Saved")] JobSaved = 302, + [Description("Job Imported")] + JobImported = 303, //Machines [Description("Machine Created")] diff --git a/Software/Visual_Studio/Tango.BL/ObservableEntity.cs b/Software/Visual_Studio/Tango.BL/ObservableEntity.cs index 11aca0e99..36e1a4ef8 100644 --- a/Software/Visual_Studio/Tango.BL/ObservableEntity.cs +++ b/Software/Visual_Studio/Tango.BL/ObservableEntity.cs @@ -663,12 +663,12 @@ namespace Tango.BL #region Action Log - public Task> CompareTo(T before) + public Task CompareTo(T before) { return new BasicActionLogComparer().Compare(before as IActionLogComparable, this); } - Task> IActionLogComparable.CompareTo(IActionLogComparable before) + Task IActionLogComparable.CompareTo(IActionLogComparable before) { return CompareTo(before as T); } @@ -683,6 +683,16 @@ namespace Tango.BL return false; } + string IActionLogComparable.GetActionName() + { + return OnGetActionLogName(); + } + + protected virtual String OnGetActionLogName() + { + return this.GetType().Name; + } + #endregion } } diff --git a/Software/Visual_Studio/Tango.BL/ObservableEntityDTO.cs b/Software/Visual_Studio/Tango.BL/ObservableEntityDTO.cs index f587147e1..cb49f3769 100644 --- a/Software/Visual_Studio/Tango.BL/ObservableEntityDTO.cs +++ b/Software/Visual_Studio/Tango.BL/ObservableEntityDTO.cs @@ -210,12 +210,12 @@ namespace Tango.BL return EqualsToObservable(observable); } - public Task> CompareTo(DTO before) + public Task CompareTo(DTO before) { return new BasicActionLogComparer().Compare(before, this); } - Task> IActionLogComparable.CompareTo(IActionLogComparable before) + Task IActionLogComparable.CompareTo(IActionLogComparable before) { return CompareTo(before as DTO); } @@ -229,5 +229,15 @@ namespace Tango.BL { return false; } + + string IActionLogComparable.GetActionName() + { + return OnGetActionLogName(); + } + + protected virtual String OnGetActionLogName() + { + return this.GetType().Name; + } } } diff --git a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj index 469e23165..2f9cf489e 100644 --- a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj +++ b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj @@ -510,6 +510,7 @@ + @@ -590,7 +591,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.BL/ValueObjects/ActionLogDifference.cs b/Software/Visual_Studio/Tango.BL/ValueObjects/ActionLogDifference.cs index a89348249..d15ddc9c7 100644 --- a/Software/Visual_Studio/Tango.BL/ValueObjects/ActionLogDifference.cs +++ b/Software/Visual_Studio/Tango.BL/ValueObjects/ActionLogDifference.cs @@ -1,4 +1,5 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,9 +9,24 @@ namespace Tango.BL.ValueObjects { public class ActionLogDifference { - public String Component { get; set; } - public String Property { get; set; } - public Object Before { get; set; } - public Object After { get; set; } + public String Name { get; set; } + + public List Children { get; set; } + + [JsonIgnore] + public virtual bool HasDifference + { + get { return Children.Any(x => x.HasDifference); } + } + + public ActionLogDifference() + { + Children = new List(); + } + + public override string ToString() + { + return $"{Name} | Children[{Children.Count}]"; + } } } diff --git a/Software/Visual_Studio/Tango.BL/ValueObjects/ActionLogDifferenceValue.cs b/Software/Visual_Studio/Tango.BL/ValueObjects/ActionLogDifferenceValue.cs new file mode 100644 index 000000000..145fcd9b7 --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/ValueObjects/ActionLogDifferenceValue.cs @@ -0,0 +1,26 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.BL.ValueObjects +{ + public class ActionLogDifferenceValue : ActionLogDifference + { + public Object Before { get; set; } + public Object After { get; set; } + + [JsonIgnore] + public override bool HasDifference + { + get { return Before != After; } + } + + public override string ToString() + { + return $"{Name}: Before: {Before} != After: {After}"; + } + } +} -- cgit v1.3.1 From 1208554e06da8aec1b074932df488769572ffcfb Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 19 Dec 2019 18:01:01 +0200 Subject: Implemented auto thread loading. Implemented advanced settings for technician. Implemented thread loading on emulator. Removed PowerUpSelectedRML from settings. Now using LoadedRml settings for ThreadLoading and PowerUp. --- Software/PMR/Messages/Common/MessageType.proto | 2 + .../ThreadLoading/StopThreadLoadingRequest.proto | 9 ++ .../ThreadLoading/StopThreadLoadingResponse.proto | 9 ++ .../Tango.PPC.MachineSettings/Views/MainView.xaml | 62 +++++++- .../Connection/DefaultMachineProvider.cs | 3 +- .../PPC/Tango.PPC.Common/PPCSettings.cs | 25 ++- .../PPC/Tango.PPC.UI/Dialogs/PowerUpView.xaml | 2 +- .../Tango.PPC.UI/Dialogs/ThreadLoadingView.xaml | 47 ++++++ .../Tango.PPC.UI/Dialogs/ThreadLoadingView.xaml.cs | 28 ++++ .../Tango.PPC.UI/Dialogs/ThreadLoadingViewVM.cs | 155 +++++++++++++++++++ .../PPC/Tango.PPC.UI/Images/thread_loading.gif | Bin 0 -> 4467469 bytes .../PPC/Tango.PPC.UI/Images/thread_loading.png | Bin 0 -> 7209 bytes .../PPC/Tango.PPC.UI/Tango.PPC.UI.csproj | 12 +- .../PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs | 76 ++++++++- .../Tango.BL/Entities/ProcessParametersTable.cs | 8 + .../Tango.Emulations/Emulators/MachineEmulator.cs | 64 +++++++- .../ExternalBridge/EmulatorExternalBridge.cs | 1 + .../ExternalBridge/ExternalBridgeTcpClient.cs | 1 + .../Operation/IMachineOperator.cs | 31 ++++ .../Tango.Integration/Operation/MachineOperator.cs | 170 ++++++++++++++++++++- .../ThreadLoadingConfirmationRequiredEventArgs.cs | 27 ++++ .../Tango.Integration/Tango.Integration.csproj | 3 +- .../Visual_Studio/Tango.PMR/Common/MessageType.cs | 9 +- .../Tango.PMR/Power/PowerDownState.cs | 28 +++- Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj | 4 +- .../ThreadLoading/StopThreadLoadingRequest.cs | 131 ++++++++++++++++ .../ThreadLoading/StopThreadLoadingResponse.cs | 131 ++++++++++++++++ .../Tango.MachineEM.UI/ViewModels/MainViewVM.cs | 33 ++++ .../Tango.MachineEM.UI/Views/MainView.xaml | 143 +++++++++-------- 29 files changed, 1124 insertions(+), 90 deletions(-) create mode 100644 Software/PMR/Messages/ThreadLoading/StopThreadLoadingRequest.proto create mode 100644 Software/PMR/Messages/ThreadLoading/StopThreadLoadingResponse.proto create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingView.xaml create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingView.xaml.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingViewVM.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Images/thread_loading.gif create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Images/thread_loading.png create mode 100644 Software/Visual_Studio/Tango.Integration/Operation/ThreadLoadingConfirmationRequiredEventArgs.cs create mode 100644 Software/Visual_Studio/Tango.PMR/ThreadLoading/StopThreadLoadingRequest.cs create mode 100644 Software/Visual_Studio/Tango.PMR/ThreadLoading/StopThreadLoadingResponse.cs (limited to 'Software/PMR/Messages/ThreadLoading') diff --git a/Software/PMR/Messages/Common/MessageType.proto b/Software/PMR/Messages/Common/MessageType.proto index 65acd1054..3e5b54456 100644 --- a/Software/PMR/Messages/Common/MessageType.proto +++ b/Software/PMR/Messages/Common/MessageType.proto @@ -278,4 +278,6 @@ enum MessageType StartThreadLoadingResponse = 11001; ContinueThreadLoadingRequest = 11002; ContinueThreadLoadingResponse = 11003; + StopThreadLoadingRequest = 11004; + StopThreadLoadingResponse = 11005; } diff --git a/Software/PMR/Messages/ThreadLoading/StopThreadLoadingRequest.proto b/Software/PMR/Messages/ThreadLoading/StopThreadLoadingRequest.proto new file mode 100644 index 000000000..03f5df91f --- /dev/null +++ b/Software/PMR/Messages/ThreadLoading/StopThreadLoadingRequest.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package Tango.PMR.ThreadLoading; +option java_package = "com.twine.tango.pmr.threadloading"; + +message StopThreadLoadingRequest +{ + +} \ No newline at end of file diff --git a/Software/PMR/Messages/ThreadLoading/StopThreadLoadingResponse.proto b/Software/PMR/Messages/ThreadLoading/StopThreadLoadingResponse.proto new file mode 100644 index 000000000..4725d3647 --- /dev/null +++ b/Software/PMR/Messages/ThreadLoading/StopThreadLoadingResponse.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package Tango.PMR.ThreadLoading; +option java_package = "com.twine.tango.pmr.threadloading"; + +message StopThreadLoadingResponse +{ + +} \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/Views/MainView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/Views/MainView.xaml index 4a2f1e253..5f453c874 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/Views/MainView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/Views/MainView.xaml @@ -11,7 +11,7 @@ xmlns:global="clr-namespace:Tango.PPC.MachineSettings" xmlns:local="clr-namespace:Tango.PPC.MachineSettings.Views" mc:Ignorable="d" - d:DesignHeight="3000" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> + d:DesignHeight="3600" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> @@ -242,12 +242,70 @@ - Once enabled, synchronization occurres automatically in the background. you can choose to synchronize right now. + Once enabled, synchronization occurs automatically in the background. you can choose to synchronize right now. Synchronize Now + + + + + + + Embedded COM Port + + + + + Emergency COM Port + + + + + Enable Emergency Screen + + + + + Enable Embedded Debug Logs + + + + + Enable Automatic Thread Loading Support + + + + + Display PowerUp Screen + + + + + Enable Job Liquid Quantity Validation + + + + + Always Start in Technician Mode + + + + + Gradient Resolution CM + + + + + + + Please restart the application for advanced settings to take effect. + + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs index eae09a7e7..6d90ece73 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs @@ -82,7 +82,8 @@ namespace Tango.PPC.Common.Connection MachineOperator.UseKeepAlive = true; MachineOperator.EnableMachineStatusUpdates = true; MachineOperator.EnableDiagnostics = false; - MachineOperator.EnableEmbeddedDebugging = true; + MachineOperator.EnableEmbeddedDebugging = settings.EnableEmbeddedDebugLogs; + MachineOperator.EnableAutomaticThreadLoading = settings.EnableAutomaticThreadLoading; MachineOperator.FirmwareUpgradeMode = Integration.Upgrade.FirmwareUpgradeModes.DFU | Integration.Upgrade.FirmwareUpgradeModes.TFP_PACKAGE; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs index cb17f5be3..96fe39a9b 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs @@ -199,11 +199,6 @@ namespace Tango.PPC.Common /// public String FirmwareVersion { get; set; } - /// - /// Gets or sets the last power up selected RML. - /// - public String LastPowerUpSelectedRmlGuid { get; set; } - /// /// Gets or sets a value indicating whether to display the power up screen. /// @@ -219,6 +214,21 @@ namespace Tango.PPC.Common /// public bool AutoCheckForUpdates { get; set; } + /// + /// Gets or sets a value indicating whether to enable the automatic thread loading support. + /// + public bool EnableAutomaticThreadLoading { get; set; } + + /// + /// Gets or sets a value indicating whether to display the thread loading screen. + /// + public bool DisplayAutomaticThreadLoadingScreen { get; set; } + + /// + /// Gets or sets a value indicating whether to enable embedded debug logs. + /// + public bool EnableEmbeddedDebugLogs { get; set; } + /// /// Gets the machine service address. /// @@ -259,8 +269,11 @@ namespace Tango.PPC.Common SynchronizationInterval = TimeSpan.FromMinutes(60); FirmwareVersion = "1.0.0.0"; DisplayPowerUpScreen = true; - PowerUpScreenTimeout = TimeSpan.FromSeconds(20); + PowerUpScreenTimeout = TimeSpan.FromSeconds(60); AutoCheckForUpdates = true; + EnableAutomaticThreadLoading = true; + DisplayAutomaticThreadLoadingScreen = true; + EnableEmbeddedDebugLogs = true; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/PowerUpView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/PowerUpView.xaml index 776233955..28f922898 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/PowerUpView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/PowerUpView.xaml @@ -20,7 +20,7 @@ Minimal temperature - CONTINUE + CONTINUE auto select in diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingView.xaml new file mode 100644 index 000000000..98f2e1381 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingView.xaml @@ -0,0 +1,47 @@ + + + + + + Thread Loading + + + + + The machine is ready for loading the thread. Please load the selected thread below and press 'continue'. + + + CONTINUE + + + + The machine is now loading the thread. please wait... + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingView.xaml.cs new file mode 100644 index 000000000..d4c737bcc --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.PPC.UI.Dialogs +{ + /// + /// Interaction logic for PowerUpView.xaml + /// + public partial class ThreadLoadingView : UserControl + { + public ThreadLoadingView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingViewVM.cs new file mode 100644 index 000000000..5e5370416 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingViewVM.cs @@ -0,0 +1,155 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using Tango.Core.Commands; +using Tango.Integration.Operation; +using Tango.PMR.ThreadLoading; +using Tango.PPC.Common.Connection; +using Tango.SharedUI; + +namespace Tango.PPC.UI.Dialogs +{ + public class ThreadLoadingViewVM : DialogViewVM + { + public class ThreadLoadingResult + { + public bool IsCompleted { get; set; } + public Exception FailedException { get; set; } + } + + private ThreadLoadingConfirmationRequiredEventArgs _confirmationArgs; + + public ThreadLoadingResult Result { get; set; } + + public IMachineProvider MachineProvider { get; set; } + + private StartThreadLoadingResponse _status; + public StartThreadLoadingResponse Status + { + get { return _status; } + set { _status = value; RaisePropertyChangedAuto(); } + } + + private bool _isFinalizing; + public bool IsFinalizing + { + get { return _isFinalizing; } + set { _isFinalizing = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + + public List Rmls { get; set; } + + private Rml _selectedRml; + public Rml SelectedRml + { + get { return _selectedRml; } + set { _selectedRml = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + + public RelayCommand ContinueCommand { get; set; } + + public ThreadLoadingViewVM(IMachineProvider machineProvider, ThreadLoadingConfirmationRequiredEventArgs confirmationArgs) + { + CanClose = true; + _confirmationArgs = confirmationArgs; + ContinueCommand = new RelayCommand(ContinueThreadLoading, () => !IsFinalizing && SelectedRml != null); + MachineProvider = machineProvider; + MachineProvider.MachineOperator.ThreadLoadingStatusChanged += MachineOperator_ThreadLoadingStatusChanged; + MachineProvider.MachineOperator.ThreadLoadingCompleted += MachineOperator_ThreadLoadingCompleted; + MachineProvider.MachineOperator.ThreadLoadingFailed += MachineOperator_ThreadLoadingFailed; + } + + private async void ContinueThreadLoading() + { + IsFinalizing = true; + + try + { + await Task.Factory.StartNew(() => { _confirmationArgs.Confirm(SelectedRml.GetActiveProcessGroup().ProcessParametersTables.FirstOrDefault()); }); + } + catch (Exception ex) + { + Result = new ThreadLoadingResult() + { + FailedException = ex, + }; + + IsFinalizing = false; + + if (IsVisible) + { + InvokeUI(() => + { + Accept(); + }); + } + } + } + + private void MachineOperator_ThreadLoadingCompleted(object sender, StartThreadLoadingResponse e) + { + Result = new ThreadLoadingResult() + { + IsCompleted = true + }; + + if (IsVisible) + { + InvokeUI(() => + { + Accept(); + }); + } + } + + private void MachineOperator_ThreadLoadingFailed(object sender, StartThreadLoadingResponse e) + { + Result = new ThreadLoadingResult() + { + FailedException = new Exception(e.ErrorReason), + }; + + if (IsVisible) + { + InvokeUI(() => + { + Accept(); + }); + } + } + + private void MachineOperator_ThreadLoadingStatusChanged(object sender, StartThreadLoadingResponse e) + { + Status = e; + + if(Status.State == ThreadLoadingState.Finalizing) + { + IsFinalizing = true; + } + } + + protected override void Cancel() + { + IsFinalizing = false; + ClearEvents(); + base.Cancel(); + } + + protected override void Accept() + { + IsFinalizing = false; + ClearEvents(); + base.Accept(); + } + + private void ClearEvents() + { + MachineProvider.MachineOperator.ThreadLoadingStatusChanged -= MachineOperator_ThreadLoadingStatusChanged; + MachineProvider.MachineOperator.ThreadLoadingCompleted -= MachineOperator_ThreadLoadingCompleted; + MachineProvider.MachineOperator.ThreadLoadingFailed -= MachineOperator_ThreadLoadingFailed; + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/thread_loading.gif b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/thread_loading.gif new file mode 100644 index 000000000..a89f37004 Binary files /dev/null and b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/thread_loading.gif differ diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/thread_loading.png b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/thread_loading.png new file mode 100644 index 000000000..5d536e7ae Binary files /dev/null and b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/thread_loading.png differ diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj index 49b0c81d1..0dbabbf56 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj @@ -136,6 +136,9 @@ InsufficientLiquidQuantityView.xaml + + ThreadLoadingView.xaml + PowerUpView.xaml @@ -149,6 +152,7 @@ + UpdateFromFileView.xaml @@ -246,6 +250,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + Designer MSBuild:Compile @@ -409,6 +417,8 @@ + + @@ -671,7 +681,7 @@ if $(ConfigurationName) == Debug copy /Y "$(TargetDir)Packages" "$(TargetDir)" - + \ No newline at end of file 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 8a4d20b76..eeb11ffab 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs @@ -63,6 +63,7 @@ namespace Tango.PPC.UI.ViewModels base.OnApplicationReady(); MachineProvider.MachineOperator.CartridgeValidationRequestReceived += MachineOperator_CartridgeValidationRequestReceived; MachineProvider.MachineOperator.PowerUpStarted += MachineOperator_PowerUpStarted; + MachineProvider.MachineOperator.ThreadLoadingConfirmationRequired += MachineOperator_ThreadLoadingConfirmationRequired; } #region Event Handlers @@ -120,7 +121,7 @@ namespace Tango.PPC.UI.ViewModels rmls = await new RmlsCollectionBuilder(db).SetAll().WithSite(MachineProvider.Machine.SiteGuid).BuildListAsync(); } - var selectedRml = rmls.SingleOrDefault(x => x.Guid == Settings.LastPowerUpSelectedRmlGuid); + var selectedRml = rmls.SingleOrDefault(x => x.Guid == Settings.LoadedRmlGuid); vm = new PowerUpViewVM(); vm.Rmls = rmls; @@ -165,7 +166,7 @@ namespace Tango.PPC.UI.ViewModels LogManager.Log("Uploading process parameters..."); var r = MachineProvider.MachineOperator.UploadProcessParameters(processToLoad).Result; - Settings.LastPowerUpSelectedRmlGuid = vm.IsSelectedRml ? vm.SelectedRml.Guid : null; + Settings.LoadedRmlGuid = vm.IsSelectedRml ? vm.SelectedRml.Guid : null; Settings.Save(); } } @@ -177,6 +178,77 @@ namespace Tango.PPC.UI.ViewModels }); } + private async void MachineOperator_ThreadLoadingConfirmationRequired(object sender, ThreadLoadingConfirmationRequiredEventArgs e) + { + LogManager.Log("Thread loading confirmation detected, showing thread loading screen..."); + + if (!Settings.DisplayAutomaticThreadLoadingScreen) + { + LogManager.Log("Thread loading screen disabled. skipping..."); + return; + } + + ThreadLoadingViewVM vm; + + try + { + LogManager.Log("Loading site rmls..."); + + List rmls = new List(); + + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + rmls = await new RmlsCollectionBuilder(db).SetAll().WithSite(MachineProvider.Machine.SiteGuid).WithActiveParametersGroup().BuildListAsync(); + } + + var selectedRml = rmls.SingleOrDefault(x => x.Guid == Settings.LoadedRmlGuid); + + vm = new ThreadLoadingViewVM(MachineProvider, e); + vm.Rmls = rmls; + vm.SelectedRml = selectedRml != null ? selectedRml : rmls.FirstOrDefault(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error initializing thread loading screen."); + return; + } + + InvokeUI(async () => + { + await NotificationProvider.ShowDialog(vm); + + LogManager.Log("Thread loading screen closed."); + + if (!vm.DialogResult) + { + LogManager.Log("Thread loading screen aborted by user. No operation was performed."); + return; + } + + try + { + if (vm.Result.IsCompleted) + { + await NotificationProvider.ShowSuccess("Thread loading completed successfully."); + } + else + { + await NotificationProvider.ShowError($"Thread loading failed due to the following reason:\n{vm.Result.FailedException.FlattenException()}"); + } + + if (vm.SelectedRml != null) + { + Settings.LoadedRmlGuid = vm.SelectedRml.Guid; + Settings.Save(); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error occurred after thread loading screen closed."); + } + }); + } + #endregion } } diff --git a/Software/Visual_Studio/Tango.BL/Entities/ProcessParametersTable.cs b/Software/Visual_Studio/Tango.BL/Entities/ProcessParametersTable.cs index a0df58c08..729d01951 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/ProcessParametersTable.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/ProcessParametersTable.cs @@ -5,6 +5,7 @@ using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core.ExtensionMethods; namespace Tango.BL.Entities { @@ -58,5 +59,12 @@ namespace Tango.BL.Entities return heaters.Average(); } + + public PMR.Printing.ProcessParameters ToProcessParametersPMR() + { + PMR.Printing.ProcessParameters p = new PMR.Printing.ProcessParameters(); + this.MapPrimitivesTo(p); + return p; + } } } diff --git a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs index e4b081e9e..7537e4676 100644 --- a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs +++ b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs @@ -33,6 +33,7 @@ using System.Diagnostics; using Tango.Core.ExtensionMethods; using Tango.PMR.MachineStatus; using Tango.PMR.Power; +using Tango.PMR.ThreadLoading; namespace Tango.Emulations.Emulators { @@ -51,6 +52,7 @@ namespace Tango.Emulations.Emulators } private const int MAX_CHUNK_LENGTH = 4000; + private static Random _rnd = new Random(); private StartDiagnosticsRequest _diagnosticsRequest; private bool _cancelJob; private List _motorJoggingRequestTypes; @@ -76,6 +78,8 @@ namespace Tango.Emulations.Emulators private FileUploadRequest _lastFileUploadRequest; private bool _isAfterReset; private bool _abortPowerDown; + private bool _isThreadLoadingStarted; + private String _threadLoadingToken; #region Properties @@ -405,6 +409,12 @@ namespace Tango.Emulations.Emulators case MessageType.AbortPowerDownRequest: HandleAbortPowerDownRequest(MessageFactory.ParseTangoMessageFromContainer(container)); break; + case MessageType.StartThreadLoadingRequest: + HandleStartThreadLoadingRequest(MessageFactory.ParseTangoMessageFromContainer(container)); + break; + case MessageType.ContinueThreadLoadingRequest: + HandleContinueThreadLoadingRequest(MessageFactory.ParseTangoMessageFromContainer(container)); + break; } } @@ -1383,7 +1393,7 @@ namespace Tango.Emulations.Emulators { ProgressPercentage = 100, Message = "Machine is turned off", - State = PowerDownState.Completed + State = PowerDownState.PowerOffCompleted }, request.Container.Token, true); }); } @@ -1395,6 +1405,38 @@ namespace Tango.Emulations.Emulators await Transporter.SendResponse(new AbortPowerDownResponse(), request.Container.Token); } + private async void HandleStartThreadLoadingRequest(TangoMessage request) + { + _isThreadLoadingStarted = true; + _threadLoadingToken = request.Container.Token; + await Transporter.SendResponse(new StartThreadLoadingResponse(), request.Container.Token); + } + + private async void HandleContinueThreadLoadingRequest(TangoMessage request) + { + if (_threadLoadingToken != null) + { + await Transporter.SendResponse(new ContinueThreadLoadingResponse(), request.Container.Token); + + await Task.Delay(1000); + await Transporter.SendResponse(new StartThreadLoadingResponse() { State = ThreadLoadingState.Finalizing }, _threadLoadingToken); + await Task.Delay(8000); + + if (_rnd.Next(0, 100) > 50) + { + await Transporter.SendResponse(new StartThreadLoadingResponse() { State = ThreadLoadingState.Completed }, _threadLoadingToken); + } + else + { + await Transporter.SendResponse(new StartThreadLoadingResponse() { State = ThreadLoadingState.FinalizationError, ErrorReason = "Emulator random error." }, _threadLoadingToken); + } + } + else + { + await Transporter.SendResponse(new ContinueThreadLoadingResponse(), request.Container.Token, null, ErrorCode.GeneralError, "StartThreadLoadingRequest was never sent."); + } + } + #endregion #region Public Methods @@ -1410,6 +1452,26 @@ namespace Tango.Emulations.Emulators return response.Message.Index; } + public async void StartThreadLoading() + { + await Transporter.SendResponse(new StartThreadLoadingResponse() { State = ThreadLoadingState.ReadyForLoading }, _threadLoadingToken); + } + + public async void FinalizeThreadLoading() + { + await Transporter.SendResponse(new StartThreadLoadingResponse() { State = ThreadLoadingState.Finalizing }, _threadLoadingToken); + await Task.Delay(3000); + + if (_rnd.Next(0, 100) > 50) + { + await Transporter.SendResponse(new StartThreadLoadingResponse() { State = ThreadLoadingState.Completed }, _threadLoadingToken); + } + else + { + await Transporter.SendResponse(new StartThreadLoadingResponse() { State = ThreadLoadingState.FinalizationError, ErrorReason = "Emulator random error." }, _threadLoadingToken); + } + } + #endregion } } diff --git a/Software/Visual_Studio/Tango.Emulations/ExternalBridge/EmulatorExternalBridge.cs b/Software/Visual_Studio/Tango.Emulations/ExternalBridge/EmulatorExternalBridge.cs index c1aaa3cd6..1fba528f8 100644 --- a/Software/Visual_Studio/Tango.Emulations/ExternalBridge/EmulatorExternalBridge.cs +++ b/Software/Visual_Studio/Tango.Emulations/ExternalBridge/EmulatorExternalBridge.cs @@ -44,6 +44,7 @@ namespace Tango.Emulations.ExternalBridge EnableDiagnostics = true; EnableEmbeddedDebugging = true; EnableEventsNotification = true; + EnableAutomaticThreadLoading = true; String address = new string(Guid.NewGuid().ToString().Replace("-", "").TakeLast(4).ToArray()); diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs index 3bbef3eb6..d3344aa16 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs @@ -133,6 +133,7 @@ namespace Tango.Integration.ExternalBridge OnEnableEventsNotification(EnableEventsNotification); OnEnableApplicationLogsChanged(EnableApplicationLogs); OnEnableMachineStatusUpdatesChanged(EnableMachineStatusUpdates); + OnEnableAutomaticThreadLoadingChanged(EnableAutomaticThreadLoading); } } diff --git a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs index b5b7b7393..8156ef8c7 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs @@ -23,6 +23,7 @@ using Tango.PMR.FirmwareUpgrade; using Tango.Integration.JobRuns; using Tango.Integration.Emergency; using Tango.PMR.MachineStatus; +using Tango.PMR.ThreadLoading; namespace Tango.Integration.Operation { @@ -63,6 +64,11 @@ namespace Tango.Integration.Operation /// MachineStatus MachineStatus { get; } + /// + /// Gets the current thread loading status. + /// + StartThreadLoadingResponse ThreadLoadingStatus { get; } + /// /// Gets or sets the firmware upgrade mode. /// @@ -198,6 +204,26 @@ namespace Tango.Integration.Operation /// event EventHandler PowerDownStarted; + /// + /// Occurs when the thread loading status has changed. + /// + event EventHandler ThreadLoadingStatusChanged; + + /// + /// Occurs when a thread loading confirmation is required. + /// + event EventHandler ThreadLoadingConfirmationRequired; + + /// + /// Occurs when thread loading has completed. + /// + event EventHandler ThreadLoadingCompleted; + + /// + /// Occurs when thread loading has failed. + /// + event EventHandler ThreadLoadingFailed; + /// /// Gets or sets a value indicating whether direct the embedded device to send diagnostics messages. /// @@ -223,6 +249,11 @@ namespace Tango.Integration.Operation /// bool EnableMachineStatusUpdates { get; set; } + /// + /// Gets or sets a value indicating whether to enable automatic thread loading support. + /// + bool EnableAutomaticThreadLoading { get; set; } + /// /// Gets the last process parameters table sent to the embedded device. /// diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs index e142066b6..74c64930b 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -42,6 +42,7 @@ using Newtonsoft.Json; using Tango.PMR.Integration; using System.Globalization; using Tango.PMR.Power; +using Tango.PMR.ThreadLoading; namespace Tango.Integration.Operation { @@ -68,6 +69,7 @@ namespace Tango.Integration.Operation private bool _eventsSent; private bool _debugSent; private bool _machineStatusSent; + private bool _threadLoadingSent; private EmbeddedLogItem _last_embedded_debug_log; private static RunningJobStatus _last_job_status; private bool _isPowerDownRequestInProgress; @@ -224,6 +226,26 @@ namespace Tango.Integration.Operation /// public event EventHandler PowerDownStarted; + /// + /// Occurs when the thread loading status has changed. + /// + public event EventHandler ThreadLoadingStatusChanged; + + /// + /// Occurs when a thread loading confirmation is required. + /// + public event EventHandler ThreadLoadingConfirmationRequired; + + /// + /// Occurs when thread loading has completed. + /// + public event EventHandler ThreadLoadingCompleted; + + /// + /// Occurs when thread loading has failed. + /// + public event EventHandler ThreadLoadingFailed; + #endregion #region Properties @@ -271,7 +293,17 @@ namespace Tango.Integration.Operation public MachineStatus MachineStatus { get { return _machineStatus; } - set { _machineStatus = value; RaisePropertyChangedAuto(); } + private set { _machineStatus = value; RaisePropertyChangedAuto(); } + } + + private StartThreadLoadingResponse _threadLoadingStatus; + /// + /// Gets the current thread loading status. + /// + public StartThreadLoadingResponse ThreadLoadingStatus + { + get { return _threadLoadingStatus; } + private set { _threadLoadingStatus = value; RaisePropertyChangedAuto(); } } /// @@ -409,6 +441,21 @@ namespace Tango.Integration.Operation } } + private bool _enableAutomaticThreadLoading; + /// + /// Gets or sets a value indicating whether to enable automatic thread loading support. + /// + public bool EnableAutomaticThreadLoading + { + get { return _enableAutomaticThreadLoading; } + set + { + _enableAutomaticThreadLoading = value; + RaisePropertyChangedAuto(); + OnEnableAutomaticThreadLoadingChanged(value); + } + } + private bool _enableJobResume; /// /// Gets or sets a value indicating whether to check whether a job is in progress after connection was successful. @@ -745,6 +792,65 @@ namespace Tango.Integration.Operation } } + protected virtual async void OnEnableAutomaticThreadLoadingChanged(bool value) + { + if (value && State == TransportComponentState.Connected && !_threadLoadingSent) + { + var request = new StartThreadLoadingRequest(); + + bool responseLogged = false; + _threadLoadingSent = true; + + SendContinuousRequest(request).ObserveOn(new NewThreadScheduler()).Subscribe( + (response) => + { + OnThreadLoadingStatusChanged(response); + + if (!responseLogged) + { + LogResponseReceived(response.Message); + responseLogged = true; + } + }, + (ex) => + { + _threadLoadingSent = false; + + if (!(ex is ContinuousResponseAbortedException)) + { + LogRequestFailed(request, ex); + } + }, + () => + { + _threadLoadingSent = false; + LogManager.Log("Thread loading response completed!?", LogCategory.Warning); + }); + + LogRequestSent(request); + } + else if (_threadLoadingSent) + { + _threadLoadingSent = false; + + if (State == TransportComponentState.Connected) + { + var req = new StopThreadLoadingRequest(); + + try + { + LogRequestSent(req); + var res = await SendRequest(req); + LogResponseReceived(res.Message); + } + catch (Exception ex) + { + LogRequestFailed(req, ex); + } + } + } + } + /// /// Invokes the event. /// @@ -797,7 +903,7 @@ namespace Tango.Integration.Operation } /// - /// Called when the machine status has been update + /// Called when the machine status has been updated. /// /// The response. protected async virtual void OnMachineStatusChanged(StartMachineStatusUpdateResponse response) @@ -824,9 +930,9 @@ namespace Tango.Integration.Operation case MachineState.Ready: Status = MachineStatuses.ReadyToDye; break; - //case MachineState.Sleep: - // Status = MachineStatuses.Standby; - // break; + case MachineState.Sleep: + Status = MachineStatuses.Standby; + break; case MachineState.PowerOff: Status = MachineStatuses.ShuttingDown; if (!_isPowerDownRequestInProgress) @@ -845,6 +951,59 @@ namespace Tango.Integration.Operation } } + /// + /// Called when the thread loading status has been changed. + /// + /// The response. + protected virtual void OnThreadLoadingStatusChanged(StartThreadLoadingResponse response) + { + bool changed = (ThreadLoadingStatus == null || response.State != ThreadLoadingStatus.State || response.ErrorReason != ThreadLoadingStatus.ErrorReason); + + if (changed) + { + ThreadLoadingStatus = response; + ThreadLoadingStatusChanged?.Invoke(this, response); + + LogManager.Log($"Thread Loading Status Changed: {ThreadLoadingStatus.State}."); + + switch (ThreadLoadingStatus.State) + { + case ThreadLoadingState.ReadyForLoading: + + LogManager.Log("Thread loading is ready for loading. Invoking confirmation event..."); + + ThreadLoadingConfirmationRequired?.Invoke(this, new ThreadLoadingConfirmationRequiredEventArgs((processTable) => + { + //Confirm Action + try + { + var process = processTable.ToProcessParametersPMR(); + LogManager.Log($"Thread loading confirmation received with process parameters:\n{process.ToJsonString()}"); + LogManager.Log("Sending continue thread loading request..."); + var r = SendRequest(new ContinueThreadLoadingRequest() + { + ProcessParameters = process, + }).Result; + } + catch (Exception ex) + { + LogManager.Log(ex, "Error confirming thread loading sequence."); + } + }) + { + Status = ThreadLoadingStatus, + }); + break; + case ThreadLoadingState.Completed: + ThreadLoadingCompleted?.Invoke(this, ThreadLoadingStatus); + break; + case ThreadLoadingState.FinalizationError: + ThreadLoadingFailed?.Invoke(this, ThreadLoadingStatus); + break; + } + } + } + /// /// Called when the request has been sent /// @@ -1065,6 +1224,7 @@ namespace Tango.Integration.Operation OnEnableEmbeddedDebuggingChanged(EnableEmbeddedDebugging); OnEnableEventsNotification(EnableEventsNotification); OnEnableMachineStatusUpdatesChanged(EnableMachineStatusUpdates); + OnEnableAutomaticThreadLoadingChanged(EnableAutomaticThreadLoading); if (EnableJobResume) { diff --git a/Software/Visual_Studio/Tango.Integration/Operation/ThreadLoadingConfirmationRequiredEventArgs.cs b/Software/Visual_Studio/Tango.Integration/Operation/ThreadLoadingConfirmationRequiredEventArgs.cs new file mode 100644 index 000000000..e5594dd01 --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Operation/ThreadLoadingConfirmationRequiredEventArgs.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using Tango.PMR.ThreadLoading; + +namespace Tango.Integration.Operation +{ + public class ThreadLoadingConfirmationRequiredEventArgs : EventArgs + { + private Action _confirm; + + public StartThreadLoadingResponse Status { get; set; } + + internal ThreadLoadingConfirmationRequiredEventArgs(Action confirm) + { + _confirm = confirm; + } + + public void Confirm(ProcessParametersTable processTable) + { + _confirm.Invoke(processTable); + } + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj index 5a4fcadf1..a3feac546 100644 --- a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj +++ b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj @@ -112,6 +112,7 @@ + @@ -198,7 +199,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.PMR/Common/MessageType.cs b/Software/Visual_Studio/Tango.PMR/Common/MessageType.cs index 77ebbef51..d50803fed 100644 --- a/Software/Visual_Studio/Tango.PMR/Common/MessageType.cs +++ b/Software/Visual_Studio/Tango.PMR/Common/MessageType.cs @@ -22,7 +22,7 @@ namespace Tango.PMR.Common { static MessageTypeReflection() { byte[] descriptorData = global::System.Convert.FromBase64String( string.Concat( - "ChFNZXNzYWdlVHlwZS5wcm90bxIQVGFuZ28uUE1SLkNvbW1vbiqwNgoLTWVz", + "ChFNZXNzYWdlVHlwZS5wcm90bxIQVGFuZ28uUE1SLkNvbW1vbirvNgoLTWVz", "c2FnZVR5cGUSCAoETm9uZRAAEhEKDUVycm9yUmVzcG9uc2UQARIUChBDYWxj", "dWxhdGVSZXF1ZXN0EAMSFQoRQ2FsY3VsYXRlUmVzcG9uc2UQBBITCg9Qcm9n", "cmVzc1JlcXVlc3QQBRIUChBQcm9ncmVzc1Jlc3BvbnNlEAYSHAoYU3R1YkNh", @@ -177,8 +177,9 @@ namespace Tango.PMR.Common { "Ym9ydFBvd2VyRG93blJlc3BvbnNlEJNOEh4KGVN0YXJ0VGhyZWFkTG9hZGlu", "Z1JlcXVlc3QQ+FUSHwoaU3RhcnRUaHJlYWRMb2FkaW5nUmVzcG9uc2UQ+VUS", "IQocQ29udGludWVUaHJlYWRMb2FkaW5nUmVxdWVzdBD6VRIiCh1Db250aW51", - "ZVRocmVhZExvYWRpbmdSZXNwb25zZRD7VUIcChpjb20udHdpbmUudGFuZ28u", - "cG1yLmNvbW1vbmIGcHJvdG8z")); + "ZVRocmVhZExvYWRpbmdSZXNwb25zZRD7VRIdChhTdG9wVGhyZWFkTG9hZGlu", + "Z1JlcXVlc3QQ/FUSHgoZU3RvcFRocmVhZExvYWRpbmdSZXNwb25zZRD9VUIc", + "Chpjb20udHdpbmUudGFuZ28ucG1yLmNvbW1vbmIGcHJvdG8z")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Tango.PMR.Common.MessageType), }, null)); @@ -470,6 +471,8 @@ namespace Tango.PMR.Common { [pbr::OriginalName("StartThreadLoadingResponse")] StartThreadLoadingResponse = 11001, [pbr::OriginalName("ContinueThreadLoadingRequest")] ContinueThreadLoadingRequest = 11002, [pbr::OriginalName("ContinueThreadLoadingResponse")] ContinueThreadLoadingResponse = 11003, + [pbr::OriginalName("StopThreadLoadingRequest")] StopThreadLoadingRequest = 11004, + [pbr::OriginalName("StopThreadLoadingResponse")] StopThreadLoadingResponse = 11005, } #endregion diff --git a/Software/Visual_Studio/Tango.PMR/Power/PowerDownState.cs b/Software/Visual_Studio/Tango.PMR/Power/PowerDownState.cs index 92ac94dc2..2d0396ddc 100644 --- a/Software/Visual_Studio/Tango.PMR/Power/PowerDownState.cs +++ b/Software/Visual_Studio/Tango.PMR/Power/PowerDownState.cs @@ -22,9 +22,15 @@ namespace Tango.PMR.Power { static PowerDownStateReflection() { byte[] descriptorData = global::System.Convert.FromBase64String( string.Concat( - "ChRQb3dlckRvd25TdGF0ZS5wcm90bxIPVGFuZ28uUE1SLlBvd2VyKikKDlBv", - "d2VyRG93blN0YXRlEggKBE5vbmUQABINCglDb21wbGV0ZWQQAUIbChljb20u", - "dHdpbmUudGFuZ28ucG1yLnBvd2VyYgZwcm90bzM=")); + "ChRQb3dlckRvd25TdGF0ZS5wcm90bxIPVGFuZ28uUE1SLlBvd2VyKqYCCg5Q", + "b3dlckRvd25TdGF0ZRIICgROb25lEAASCAoESW5pdBABEhIKDlN0b3BSdW5u", + "aW5nSm9iEAISDQoJSGVhZENsZWFuEAMSDgoKTWl4ZXJGbHVzaBAEEg4KCkhl", + "YXRlcnNPZmYQBRINCglTdG9yZURhdGEQBhIUChBTZXRWYWx2ZVBvc2l0aW9u", + "EAcSFgoSV2FpdEZvclRlbXBlcmF0dXJlEAgSFAoQV2FpdEZvclByb2Nlc3Nl", + "cxAJEhMKD1R1cm5PZmZEcnllckZhbhAKEhEKDVR1cm5PZmZDb29sZXIQCxIR", + "Cg1UdXJuT2ZmQmxvd2VyEAwSFQoRUG93ZXJPZmZDb21wbGV0ZWQQDRIJCgVF", + "cnJvchAOEg0KCUNhbmNlbGxlZBAPQhsKGWNvbS50d2luZS50YW5nby5wbXIu", + "cG93ZXJiBnByb3RvMw==")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Tango.PMR.Power.PowerDownState), }, null)); @@ -38,7 +44,21 @@ namespace Tango.PMR.Power { ///Fill the states. /// [pbr::OriginalName("None")] None = 0, - [pbr::OriginalName("Completed")] Completed = 1, + [pbr::OriginalName("Init")] Init = 1, + [pbr::OriginalName("StopRunningJob")] StopRunningJob = 2, + [pbr::OriginalName("HeadClean")] HeadClean = 3, + [pbr::OriginalName("MixerFlush")] MixerFlush = 4, + [pbr::OriginalName("HeatersOff")] HeatersOff = 5, + [pbr::OriginalName("StoreData")] StoreData = 6, + [pbr::OriginalName("SetValvePosition")] SetValvePosition = 7, + [pbr::OriginalName("WaitForTemperature")] WaitForTemperature = 8, + [pbr::OriginalName("WaitForProcesses")] WaitForProcesses = 9, + [pbr::OriginalName("TurnOffDryerFan")] TurnOffDryerFan = 10, + [pbr::OriginalName("TurnOffCooler")] TurnOffCooler = 11, + [pbr::OriginalName("TurnOffBlower")] TurnOffBlower = 12, + [pbr::OriginalName("PowerOffCompleted")] PowerOffCompleted = 13, + [pbr::OriginalName("Error")] Error = 14, + [pbr::OriginalName("Cancelled")] Cancelled = 15, } #endregion diff --git a/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj b/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj index c725a3121..02b8552ad 100644 --- a/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj +++ b/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj @@ -301,6 +301,8 @@ + + @@ -319,7 +321,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.PMR/ThreadLoading/StopThreadLoadingRequest.cs b/Software/Visual_Studio/Tango.PMR/ThreadLoading/StopThreadLoadingRequest.cs new file mode 100644 index 000000000..10fe59a73 --- /dev/null +++ b/Software/Visual_Studio/Tango.PMR/ThreadLoading/StopThreadLoadingRequest.cs @@ -0,0 +1,131 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: StopThreadLoadingRequest.proto +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Tango.PMR.ThreadLoading { + + /// Holder for reflection information generated from StopThreadLoadingRequest.proto + public static partial class StopThreadLoadingRequestReflection { + + #region Descriptor + /// File descriptor for StopThreadLoadingRequest.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static StopThreadLoadingRequestReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "Ch5TdG9wVGhyZWFkTG9hZGluZ1JlcXVlc3QucHJvdG8SF1RhbmdvLlBNUi5U", + "aHJlYWRMb2FkaW5nIhoKGFN0b3BUaHJlYWRMb2FkaW5nUmVxdWVzdEIjCiFj", + "b20udHdpbmUudGFuZ28ucG1yLnRocmVhZGxvYWRpbmdiBnByb3RvMw==")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.ThreadLoading.StopThreadLoadingRequest), global::Tango.PMR.ThreadLoading.StopThreadLoadingRequest.Parser, null, null, null, null) + })); + } + #endregion + + } + #region Messages + public sealed partial class StopThreadLoadingRequest : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new StopThreadLoadingRequest()); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Tango.PMR.ThreadLoading.StopThreadLoadingRequestReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public StopThreadLoadingRequest() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public StopThreadLoadingRequest(StopThreadLoadingRequest other) : this() { + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public StopThreadLoadingRequest Clone() { + return new StopThreadLoadingRequest(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as StopThreadLoadingRequest); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(StopThreadLoadingRequest other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + return true; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(StopThreadLoadingRequest other) { + if (other == null) { + return; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + } + } + } + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Software/Visual_Studio/Tango.PMR/ThreadLoading/StopThreadLoadingResponse.cs b/Software/Visual_Studio/Tango.PMR/ThreadLoading/StopThreadLoadingResponse.cs new file mode 100644 index 000000000..e25210ceb --- /dev/null +++ b/Software/Visual_Studio/Tango.PMR/ThreadLoading/StopThreadLoadingResponse.cs @@ -0,0 +1,131 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: StopThreadLoadingResponse.proto +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Tango.PMR.ThreadLoading { + + /// Holder for reflection information generated from StopThreadLoadingResponse.proto + public static partial class StopThreadLoadingResponseReflection { + + #region Descriptor + /// File descriptor for StopThreadLoadingResponse.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static StopThreadLoadingResponseReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "Ch9TdG9wVGhyZWFkTG9hZGluZ1Jlc3BvbnNlLnByb3RvEhdUYW5nby5QTVIu", + "VGhyZWFkTG9hZGluZyIbChlTdG9wVGhyZWFkTG9hZGluZ1Jlc3BvbnNlQiMK", + "IWNvbS50d2luZS50YW5nby5wbXIudGhyZWFkbG9hZGluZ2IGcHJvdG8z")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.ThreadLoading.StopThreadLoadingResponse), global::Tango.PMR.ThreadLoading.StopThreadLoadingResponse.Parser, null, null, null, null) + })); + } + #endregion + + } + #region Messages + public sealed partial class StopThreadLoadingResponse : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new StopThreadLoadingResponse()); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Tango.PMR.ThreadLoading.StopThreadLoadingResponseReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public StopThreadLoadingResponse() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public StopThreadLoadingResponse(StopThreadLoadingResponse other) : this() { + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public StopThreadLoadingResponse Clone() { + return new StopThreadLoadingResponse(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as StopThreadLoadingResponse); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(StopThreadLoadingResponse other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + return true; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(StopThreadLoadingResponse other) { + if (other == null) { + return; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + } + } + } + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs index 1662a3ede..f42e7f161 100644 --- a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs @@ -20,6 +20,7 @@ namespace Tango.MachineEM.UI.ViewModels private TcpServer TcpServer; private bool _running; private LogManager logManager = LogManager.Default; + private bool _isThreadLoading; #region Properties @@ -101,6 +102,16 @@ namespace Tango.MachineEM.UI.ViewModels /// public RelayCommand ValidateCartridgeCommand { get; set; } + /// + /// Gets or sets the start thread loading sequence command. + /// + public RelayCommand StartThreadLoadingCommand { get; set; } + + /// + /// Gets or sets the finalize thread loading command. + /// + public RelayCommand FinalizeThreadLoadingCommand { get; set; } + #endregion #region Constructors @@ -131,6 +142,8 @@ namespace Tango.MachineEM.UI.ViewModels CancelCommand = new RelayCommand(Cancel, (x) => _running); ClearCommand = new RelayCommand(() => Log = String.Empty); ValidateCartridgeCommand = new RelayCommand(ValidateCartridge, (x) => Emulator.IsStarted); + StartThreadLoadingCommand = new RelayCommand(StartThreadLoading, (x) => Emulator.IsStarted && !_isThreadLoading); + FinalizeThreadLoadingCommand = new RelayCommand(FinalizeThreadLoading, (x) => Emulator.IsStarted && _isThreadLoading); Ports = new List() { @@ -218,6 +231,26 @@ namespace Tango.MachineEM.UI.ViewModels } } + private async void StartThreadLoading() + { + LogManager.Log("Starting thread loading sequence..."); + Emulator.StartThreadLoading(); + _isThreadLoading = true; + InvalidateRelayCommands(); + + await Task.Delay(10000); + _isThreadLoading = false; + InvalidateRelayCommands(); + } + + private void FinalizeThreadLoading() + { + LogManager.Log("Finalizing thread loading sequence..."); + Emulator.FinalizeThreadLoading(); + _isThreadLoading = false; + InvalidateRelayCommands(); + } + #endregion } } diff --git a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml index 58fbfef4c..23154aafd 100644 --- a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml @@ -53,17 +53,95 @@ + - + + + + + + + + + STATUS + + + + + + + + IDS Packs Levels + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MACHINE STATE + + + + OVERALL TEMPERATURE + + + + + + + + + + + - + HARDWARE EVENTS - +