From a7d1b350a7e6789942bd755f4a8dd48fb15a1a0a Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Mon, 25 May 2020 14:13:28 +0300 Subject: Batch import/export jobs. --- .../Tango.PPC.Jobs/ViewModels/JobsViewVM.cs | 111 ++++++++++++++------- 1 file changed, 74 insertions(+), 37 deletions(-) (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs index f9029ed8c..c41a9ef5d 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs @@ -38,6 +38,7 @@ using Tango.PPC.Jobs.ViewContracts; using Tango.Core.ExtensionMethods; using Tango.PPC.Common.Synchronization; using Tango.PPC.Jobs.NotificationItems; +using Tango.PPC.Storage.Models; namespace Tango.PPC.Jobs.ViewModels { @@ -763,37 +764,64 @@ namespace Tango.PPC.Jobs.ViewModels var selected_job = SelectedJobs.FirstOrDefault(); if (selected_job == null) return; + var selectedJobs = SelectedJobs.ToList(); + ClearSelection(); var result = await NavigationManager. NavigateForResult( - new Storage.Models.StorageNavigationRequest() + StorageNavigationRequest>( + new StorageNavigationRequest() { - Intent = Storage.Models.StorageNavigationIntent.SaveFile, + Intent = selectedJobs.Count == 1 ? StorageNavigationIntent.SaveFile : StorageNavigationIntent.SaveFiles, DefaultFileName = selected_job.Name, Filter = ExplorerFileDefinition.Job.Extension, - Title = "Save Job File", + Title = selectedJobs.Count == 1 ? "Save Job File" : "Save Job Files", }); if (result != null) { - try + if (selectedJobs.Count == 1) { - var jobFile = await selected_job.ToJobFile(); + try + { + var jobFile = await selected_job.ToJobFile(); - using (FileStream fs = new FileStream(result.Path + ExplorerFileDefinition.Job.Extension, FileMode.Create)) + using (FileStream fs = new FileStream(result.Path + ExplorerFileDefinition.Job.Extension, FileMode.Create)) + { + jobFile.WriteTo(fs); + } + + await NotificationProvider.ShowSuccess("Job saved successfully."); + } + catch (Exception ex) { - jobFile.WriteTo(fs); + LogManager.Log(ex, $"Error saving job {selected_job.Name} to file."); + await NotificationProvider.ShowError($"An error occurred while trying to save the job.\n{ex.Message}"); } - - await NotificationProvider.ShowSuccess("Job saved successfully."); } - catch (Exception ex) + else { - LogManager.Log(ex, $"Error saving job {selected_job.Name} to file."); - await NotificationProvider.ShowError($"An error occurred while trying to save the job.\n{ex.Message}"); + foreach (var job in selectedJobs) + { + try + { + var jobFile = await job.ToJobFile(); + + using (FileStream fs = new FileStream(Path.Combine(result.Path, jobFile.Name) + ExplorerFileDefinition.Job.Extension, FileMode.Create)) + { + jobFile.WriteTo(fs); + } + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error saving job {job.Name} to file."); + await NotificationProvider.ShowError($"An error occurred while trying to save the job.\n{ex.Message}"); + } + } + + await NotificationProvider.ShowSuccess("Jobs saved successfully."); } } } @@ -802,7 +830,7 @@ namespace Tango.PPC.Jobs.ViewModels #region Handle Job File Loading From Storage - private async void HandleJobFileLoaded(ExplorerFileItem jobFile) + private async void HandleJobFileLoaded(List jobFiles) { var vm = await NotificationProvider.ShowDialog(); @@ -810,30 +838,35 @@ namespace Tango.PPC.Jobs.ViewModels { using (ObservablesContext jobContext = ObservablesContext.CreateDefault()) { - try + foreach (var jobFile in jobFiles) { - JobFile jFile = JobFile.Parser.ParseFrom(File.ReadAllBytes(jobFile.Path)); - var job = await Job.FromJobFile(jFile, MachineProvider.Machine.Guid, AuthenticationProvider.CurrentUser.Guid); - job.JobSource = JobSource.Local; - jobContext.Jobs.Add(job); - await jobContext.SaveChangesAsync(); - LoadJobs(() => + try { - if (vm.ImportAndEdit) - { - var postJob = Jobs.SingleOrDefault(x => x.Guid == job.Guid); - if (postJob != null) - { - SelectJob(postJob, true); - } - } - }); + JobFile jFile = JobFile.Parser.ParseFrom(File.ReadAllBytes(jobFile.Path)); + var job = await Job.FromJobFile(jFile, MachineProvider.Machine.Guid, AuthenticationProvider.CurrentUser.Guid); + job.JobSource = JobSource.Local; + jobContext.Jobs.Add(job); + await jobContext.SaveChangesAsync(); + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error occurred while trying to import job from file {jobFile.Path}."); + await NotificationProvider.ShowError($"An error occurred while trying to import the selected job file.\n{ex.Message}"); + } } - catch (Exception ex) + + LoadJobs(() => { - LogManager.Log(ex, $"Error occurred while trying to import job from file {jobFile.Path}."); - await NotificationProvider.ShowError($"An error occurred while trying to import the selected job file.\n{ex.Message}"); - } + //Editing of a job is currently deprecated due to enabling multiple job imports. + //if (vm.ImportAndEdit) + //{ + // var postJob = Jobs.SingleOrDefault(x => x.Guid == job.Guid); + // if (postJob != null) + // { + // SelectJob(postJob, true); + // } + //} + }); } } } @@ -842,8 +875,10 @@ namespace Tango.PPC.Jobs.ViewModels #region Handle TCC File Loading From Storage - private async void HandleColorProfileFileLoaded(ExplorerFileItem tccFile) + private async void HandleColorProfileFileLoaded(List tccFiles) { + var tccFile = tccFiles.FirstOrDefault(); + try { DetectionColorFile tcc = DetectionColorFile.Parser.ParseFrom(File.ReadAllBytes(tccFile.Path)); @@ -872,8 +907,10 @@ namespace Tango.PPC.Jobs.ViewModels #region Handle Pulse TWN Loading From Storage - private async void HandlePulseFileLoaded(ExplorerFileItem twnFile) + private async void HandlePulseFileLoaded(List twnFiles) { + var twnFile = twnFiles.FirstOrDefault(); + TwnFile twn = TwnFile.FromFile(twnFile.Path); BitmapSource preview = twn.Thumbnail.ToBitmapSource(); @@ -907,7 +944,7 @@ namespace Tango.PPC.Jobs.ViewModels NotificationProvider.ShowSuccess("Your job list is now synchronized."); }); }; - item.Closed += (_, __) => + item.Closed += (_, __) => { _isJobsSynchronizationNotificationActive = false; }; -- cgit v1.3.1 From 7689f77fe2f356d17a5ad59dbeb4a0fed3ca4a0d Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Mon, 25 May 2020 17:27:24 +0300 Subject: Added PPC power up sequence support ! Refactored AppBarItems implementation. --- .../Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs | 17 +-- .../Connection/DefaultMachineProvider.cs | 1 + .../Tango.PPC.Common/Notifications/AppBarItem.cs | 10 ++ .../Notifications/AppBarPriority.cs | 15 +++ .../Notifications/INotificationProvider.cs | 10 +- .../PPC/Tango.PPC.Common/Tango.PPC.Common.csproj | 3 +- .../Tango.PPC.UI/AppBarItems/PowerUpAppBarItem.cs | 31 +++++ .../AppBarItems/PowerUpAppBarItemView.xaml | 30 +++++ .../AppBarItems/PowerUpAppBarItemView.xaml.cs | 28 ++++ .../Notifications/DefaultNotificationProvider.cs | 38 +++--- .../PPC/Tango.PPC.UI/Tango.PPC.UI.csproj | 10 +- .../PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs | 42 +++++- .../PPC/Tango.PPC.UI/Views/LayoutView.xaml | 17 ++- .../Tango.Emulations/Emulators/MachineEmulator.cs | 41 +++++- .../Operation/IMachineOperator.cs | 33 ++++- .../Tango.Integration/Operation/MachineOperator.cs | 150 +++++++++++++++------ 16 files changed, 396 insertions(+), 80 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/AppBarPriority.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerUpAppBarItem.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerUpAppBarItemView.xaml create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerUpAppBarItemView.xaml.cs (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs index 03cd5bfff..b4a30cb39 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs @@ -9,6 +9,7 @@ using Tango.Integration.Operation; using Tango.PMR.Printing; using Tango.PPC.Common; using Tango.PPC.Common.Navigation; +using Tango.PPC.Common.Notifications; using Tango.PPC.Jobs.AppBarItems; using Tango.PPC.Jobs.AppButtons; using Tango.PPC.Jobs.Dialogs; @@ -25,6 +26,7 @@ namespace Tango.PPC.Jobs.ViewModels { private StopPrintingButton _stop_job_btn; private JobHandler _handler; + private JobProgressAppBarItem _appBarItem; #region Properties @@ -142,9 +144,10 @@ namespace Tango.PPC.Jobs.ViewModels if (MachineProvider.MachineOperator.IsPrinting && _handler != null && !_handler.IsCanceled) { - NotificationProvider.PushAppBarItem().Pressed += (_, __) => + _appBarItem = NotificationProvider.PushAppBarItem(); + _appBarItem.Pressed += (_, __) => { - NotificationProvider.CurrentAppBarItem.Close(); + _appBarItem?.Close(); NavigationManager.NavigateTo(nameof(JobProgressView)); }; } @@ -159,10 +162,7 @@ namespace Tango.PPC.Jobs.ViewModels IsDisplayJobOutline = false; - if (NotificationProvider.HasAppBarItem && NotificationProvider.CurrentAppBarItem is JobProgressAppBarItem) - { - NotificationProvider.CurrentAppBarItem.Close(); - } + _appBarItem?.Close(); if (_handler != null && !_handler.Status.IsFailed) { @@ -232,10 +232,7 @@ namespace Tango.PPC.Jobs.ViewModels _stop_job_btn.Pop(); } - if (NotificationProvider.HasAppBarItem && NotificationProvider.CurrentAppBarItem is JobProgressAppBarItem) - { - NotificationProvider.CurrentAppBarItem.Close(); - } + _appBarItem?.Close(); if (_handler != null) { 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 3d77aa4e2..84190d373 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs @@ -104,6 +104,7 @@ namespace Tango.PPC.Common.Connection MachineOperator.UseKeepAlive = true; MachineOperator.EnableMachineStatusUpdates = true; MachineOperator.EnableDiagnostics = true; + MachineOperator.EnablePowerUpSequence = true; MachineOperator.EnableEmbeddedDebugging = settings.EnableEmbeddedDebugLogs; MachineOperator.EnableAutomaticThreadLoading = settings.EnableAutomaticThreadLoading; MachineOperator.JobRunsLogger.JobSource = BL.Enumerations.JobSource.Local; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/AppBarItem.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/AppBarItem.cs index 1c47d2a97..fdd66a56b 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/AppBarItem.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/AppBarItem.cs @@ -13,6 +13,16 @@ namespace Tango.PPC.Common.Notifications /// public abstract class AppBarItem : ItemBase { + private AppBarPriority _priority; + public AppBarPriority Priority + { + get { return _priority; } + set { _priority = value; RaisePropertyChangedAuto(); } + } + public AppBarItem() + { + Priority = AppBarPriority.Normal; + } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/AppBarPriority.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/AppBarPriority.cs new file mode 100644 index 000000000..bd8547f5d --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/AppBarPriority.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Common.Notifications +{ + public enum AppBarPriority + { + Low, + Normal, + High + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/INotificationProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/INotificationProvider.cs index 4a0627d70..950b8d23f 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/INotificationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/INotificationProvider.cs @@ -34,14 +34,14 @@ namespace Tango.PPC.Common.Notifications ObservableCollection TaskBarItems { get; } /// - /// Gets the current application bar item. + /// Gets the application bar items. /// - AppBarItem CurrentAppBarItem { get; } + ObservableCollection AppBarItems { get; } /// - /// Gets a value indicating whether this instance has application bar item. + /// Gets a value indicating whether this instance has any application bar items. /// - bool HasAppBarItem { get; } + bool HasAppBarItems { get; } /// /// Gets a value indicating whether this instance has notification items. @@ -182,7 +182,7 @@ namespace Tango.PPC.Common.Notifications /// /// /// - AppBarItem PushAppBarItem() where T : AppBarItem; + T PushAppBarItem() where T : AppBarItem; /// /// Pops the application bar item. diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj index 9bdba2c63..14c1a54ff 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj @@ -168,6 +168,7 @@ + @@ -462,7 +463,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerUpAppBarItem.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerUpAppBarItem.cs new file mode 100644 index 000000000..966e78769 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerUpAppBarItem.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PMR.Power; +using Tango.PPC.Common.Notifications; + +namespace Tango.PPC.UI.AppBarItems +{ + public class PowerUpAppBarItem : AppBarItem + { + private StartPowerUpResponse _status; + public StartPowerUpResponse Status + { + get { return _status; } + set { _status = value; RaisePropertyChangedAuto(); } + } + + /// + /// Gets or sets the view type. + /// + public override Type ViewType + { + get + { + return typeof(PowerUpAppBarItemView); + } + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerUpAppBarItemView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerUpAppBarItemView.xaml new file mode 100644 index 000000000..b6b769c69 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerUpAppBarItemView.xaml @@ -0,0 +1,30 @@ + + + + + + + + + + % + Completed + + + + + + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerUpAppBarItemView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerUpAppBarItemView.xaml.cs new file mode 100644 index 000000000..599f24d3b --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerUpAppBarItemView.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.AppBarItems +{ + /// + /// Interaction logic for PowerOffAppBarItemView.xaml + /// + public partial class PowerUpAppBarItemView : UserControl + { + public PowerUpAppBarItemView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs index 3b1e1e2f5..e9de2538e 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs @@ -48,6 +48,11 @@ namespace Tango.PPC.UI.Notifications /// public ObservableCollection NotificationItems { get; private set; } + /// + /// Gets the application bar items. + /// + public ObservableCollection AppBarItems { get; private set; } + /// /// Gets the notification items view. /// @@ -65,6 +70,10 @@ namespace Tango.PPC.UI.Notifications { NotificationsVisible = true; NotificationItems = new ObservableCollection(); + + AppBarItems = new ObservableCollection(); + CollectionViewSource.GetDefaultView(AppBarItems).SortDescriptions.Add(new SortDescription(nameof(AppBarItem.Priority), ListSortDirection.Ascending)); + TaskBarItems = new ObservableCollection(); _pendingMessageBoxes = new ConcurrentQueue>(); _pendingDialogs = new ConcurrentQueue>(); @@ -472,22 +481,12 @@ namespace Tango.PPC.UI.Notifications /// public bool IsInGlobalBusyState { get; private set; } - private AppBarItem _currentAppBarItem; - /// - /// Gets the current application bar item. - /// - public AppBarItem CurrentAppBarItem - { - get { return _currentAppBarItem; } - set { _currentAppBarItem = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(HasAppBarItem)); } - } - /// /// Gets a value indicating whether this instance has application bar item. /// - public bool HasAppBarItem + public bool HasAppBarItems { - get { return CurrentAppBarItem != null; } + get { return AppBarItems.Count > 0; } } /// @@ -498,8 +497,9 @@ namespace Tango.PPC.UI.Notifications public AppBarItem PushAppBarItem(AppBarItem appBarItem) { LogManager.Log($"Pushing AppBarItem '{appBarItem.GetType().Name}'."); - CurrentAppBarItem = appBarItem; + AppBarItems.Add(appBarItem); appBarItem.RemoveAction = () => PopAppBarItem(appBarItem); + RaisePropertyChanged(nameof(HasAppBarItems)); return appBarItem; } @@ -508,9 +508,9 @@ namespace Tango.PPC.UI.Notifications /// /// /// - public AppBarItem PushAppBarItem() where T : AppBarItem + public T PushAppBarItem() where T : AppBarItem { - return PushAppBarItem(Activator.CreateInstance()); + return PushAppBarItem(Activator.CreateInstance()) as T; } /// @@ -519,8 +519,12 @@ namespace Tango.PPC.UI.Notifications /// The application bar item. public void PopAppBarItem(AppBarItem appBarItem) { - LogManager.Log($"Popping out AppBarItem '{appBarItem.GetType().Name}'."); - CurrentAppBarItem = null; + InvokeUI(() => + { + LogManager.Log($"Popping out AppBarItem '{appBarItem.GetType().Name}'."); + AppBarItems.Remove(appBarItem); + RaisePropertyChanged(nameof(HasAppBarItems)); + }); } /// 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 10d3a82a5..0cdf78614 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 @@ -114,7 +114,11 @@ GlobalVersionInfo.cs + + + PowerUpAppBarItemView.xaml + PowerOffAppBarItemView.xaml @@ -238,6 +242,10 @@ RestartingSystemView.xaml + + MSBuild:Compile + Designer + Designer MSBuild:Compile @@ -705,7 +713,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 b53a54682..e84fd81a1 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs @@ -21,6 +21,7 @@ using Tango.PPC.Common.WatchDog; using Tango.PPC.UI.Dialogs; using Tango.SharedUI; using System.Data.Entity; +using Tango.PPC.UI.AppBarItems; namespace Tango.PPC.UI.ViewModels { @@ -33,6 +34,7 @@ namespace Tango.PPC.UI.ViewModels private DispatcherTimer _date_timer; private bool _isPowerUpDialogShown; private bool _isThreadLoadingShown; + private PowerUpAppBarItem _powerUpAppBar; private DateTime _currentDateTime; /// @@ -64,11 +66,47 @@ namespace Tango.PPC.UI.ViewModels { base.OnApplicationReady(); MachineProvider.MachineOperator.CartridgeValidationRequestReceived += MachineOperator_CartridgeValidationRequestReceived; - MachineProvider.MachineOperator.PowerUpStarted += MachineOperator_PowerUpStarted; + MachineProvider.MachineOperator.FirmwareStarted += MachineOperator_FirmwareStarted; MachineProvider.MachineOperator.ThreadLoadingStatusChanged += MachineOperator_ThreadLoadingStatusChanged; MachineProvider.MachineOperator.ThreadLoadingConfirmationRequired += MachineOperator_ThreadLoadingConfirmationRequired; + + MachineProvider.MachineOperator.PowerUpStarted += MachineOperator_PowerUpStarted; + MachineProvider.MachineOperator.PowerUpProgress += MachineOperator_PowerUpProgress; + MachineProvider.MachineOperator.PowerUpEnded += MachineOperator_PowerUpEnded; + } + + #region Power Up + + private void MachineOperator_PowerUpEnded(object sender, EventArgs e) + { + _powerUpAppBar?.Close(); + _powerUpAppBar = null; + } + + private void MachineOperator_PowerUpProgress(object sender, PMR.Power.StartPowerUpResponse status) + { + if (_powerUpAppBar != null) + { + _powerUpAppBar.Status = status; + } } + private void MachineOperator_PowerUpStarted(object sender, PMR.Power.StartPowerUpResponse e) + { + InvokeUI(() => + { + if (_powerUpAppBar != null) + { + _powerUpAppBar.Close(); + } + + _powerUpAppBar = NotificationProvider.PushAppBarItem(); + _powerUpAppBar.Priority = AppBarPriority.Low; + }); + } + + #endregion + #region Event Handlers /// @@ -101,7 +139,7 @@ namespace Tango.PPC.UI.ViewModels }); } - private async void MachineOperator_PowerUpStarted(object sender, EventArgs e) + private async void MachineOperator_FirmwareStarted(object sender, EventArgs e) { if (_isPowerUpDialogShown) { diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml index 1700749c2..21cc90f2d 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml @@ -284,8 +284,21 @@ - - + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs index c2be3c22b..0fe3f280d 100644 --- a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs +++ b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs @@ -425,6 +425,9 @@ namespace Tango.Emulations.Emulators case MessageType.AbortHeadCleaningRequest: HandleAbortHeadCleaningRequest(MessageFactory.ParseTangoMessageFromContainer(container)); break; + case MessageType.StartPowerUpRequest: + HandleStartPowerUpRequest(MessageFactory.ParseTangoMessageFromContainer(container)); + break; } } @@ -750,7 +753,7 @@ namespace Tango.Emulations.Emulators } progress += Math.Min((centimeter_per_second / 1000d), (unit_length + (i == units - 1 ? (job.ProcessParameters.DryerBufferLength * ProcessParametersTable.DRYER_METERS_PER_CYCLE + ProcessParametersTable.DRYER_TO_SPOOL_LENGTH_METERS) : 0)) - progress); - + double currentPosition = 0; double nextStopPosition = unit_length; for (int seg_index = 0; seg_index < _current_job_ticket.Segments.Count(); seg_index++) @@ -836,7 +839,7 @@ namespace Tango.Emulations.Emulators { if (_current_job_resume_token == null) { - Transporter.SendResponse(new JobResponse() + Transporter.SendResponse(new JobResponse() { Status = new PMR.Printing.JobStatus() { @@ -847,7 +850,7 @@ namespace Tango.Emulations.Emulators } else { - Transporter.SendResponse(new ResumeCurrentJobResponse() + Transporter.SendResponse(new ResumeCurrentJobResponse() { Status = new PMR.Printing.JobStatus() { @@ -1582,6 +1585,38 @@ namespace Tango.Emulations.Emulators } } + private async void HandleStartPowerUpRequest(TangoMessage request) + { + await Transporter.SendResponse(new StartPowerUpResponse() { Message = "Power up started...", ProgressPercentage = 10, State = PowerUpState.BuiltInTest }, request.Container.Token); + Thread.Sleep(1000); + + await Transporter.SendResponse(new StartPowerUpResponse() { Message = "Testing dispensers...", ProgressPercentage = 20, State = PowerUpState.DispenserPressureBuildupTest }, request.Container.Token); + Thread.Sleep(1000); + + await Transporter.SendResponse(new StartPowerUpResponse() { Message = "Heating started...", ProgressPercentage = 30, State = PowerUpState.HeatingStarted }, request.Container.Token); + Thread.Sleep(1000); + + await Transporter.SendResponse(new StartPowerUpResponse() { Message = "Heating started...", ProgressPercentage = 40, State = PowerUpState.HwConfig }, request.Container.Token); + Thread.Sleep(1000); + + await Transporter.SendResponse(new StartPowerUpResponse() { Message = "Hardware configuration...", ProgressPercentage = 50, State = PowerUpState.HwConfig }, request.Container.Token); + Thread.Sleep(1000); + + await Transporter.SendResponse(new StartPowerUpResponse() { Message = "Initializing blower...", ProgressPercentage = 60, State = PowerUpState.InitialBlowerActivation }, request.Container.Token); + Thread.Sleep(1000); + + await Transporter.SendResponse(new StartPowerUpResponse() { Message = "Thread detection...", ProgressPercentage = 70, State = PowerUpState.ThreadDetection }, request.Container.Token); + Thread.Sleep(1000); + + await Transporter.SendResponse(new StartPowerUpResponse() { Message = "Waiting for cooler...", ProgressPercentage = 80, State = PowerUpState.WaitForCooler }, request.Container.Token); + Thread.Sleep(4000); + + await Transporter.SendResponse(new StartPowerUpResponse() { Message = "Ready to dye...", ProgressPercentage = 90, State = PowerUpState.MachineReadyToDye }, request.Container.Token,new TransportResponseConfig() + { + Completed = true + }); + } + #endregion #region Public Methods diff --git a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs index 761ed5644..d006848de 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs @@ -24,6 +24,7 @@ using Tango.Integration.JobRuns; using Tango.Integration.Emergency; using Tango.PMR.MachineStatus; using Tango.PMR.ThreadLoading; +using Tango.PMR.Power; namespace Tango.Integration.Operation { @@ -187,7 +188,32 @@ namespace Tango.Integration.Operation /// /// Occurs when the machine was connected and device has reported IsAfterReset. /// - event EventHandler PowerUpStarted; + event EventHandler FirmwareStarted; + + /// + /// Occurs when the power up sequence has started. + /// + event EventHandler PowerUpStarted; + + /// + /// Occurs when the power up sequence progress has changed. + /// + event EventHandler PowerUpProgress; + + /// + /// Occurs when power up sequence has completed successfully. + /// + event EventHandler PowerUpCompleted; + + /// + /// Occurs when power up sequence has failed. + /// + event EventHandler PowerUpFailed; + + /// + /// Occurs when power up sequence has ended. Could be due to no response to the request! + /// + event EventHandler PowerUpEnded; /// /// Occurs when power down has started. @@ -244,6 +270,11 @@ namespace Tango.Integration.Operation /// bool EnableAutomaticThreadLoading { get; set; } + /// + /// Gets or sets a value indicating whether to enable the power sequence tracking. + /// + bool EnablePowerUpSequence { 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 e6db7fcfc..c40429375 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -214,7 +214,7 @@ namespace Tango.Integration.Operation /// /// Occurs when the machine was connected and device has reported IsAfterReset. /// - public event EventHandler PowerUpStarted; + public event EventHandler FirmwareStarted; /// /// Occurs when power down has started. @@ -241,6 +241,31 @@ namespace Tango.Integration.Operation /// public event EventHandler ThreadLoadingFailed; + /// + /// Occurs when the power up sequence has started. + /// + public event EventHandler PowerUpStarted; + + /// + /// Occurs when the power up sequence progress has changed. + /// + public event EventHandler PowerUpProgress; + + /// + /// Occurs when power up sequence has completed successfully. + /// + public event EventHandler PowerUpCompleted; + + /// + /// Occurs when power up sequence has failed. + /// + public event EventHandler PowerUpFailed; + + /// + /// Occurs when power up sequence has ended. Could be due to no response to the request! + /// + public event EventHandler PowerUpEnded; + #endregion #region Properties @@ -507,6 +532,16 @@ namespace Tango.Integration.Operation } } + private bool _enablePowerUpSequence; + /// + /// Gets or sets a value indicating whether to enable the power sequence tracking. + /// + public bool EnablePowerUpSequence + { + get { return _enablePowerUpSequence; } + set { _enablePowerUpSequence = value; RaisePropertyChangedAuto(); } + } + /// /// Gets or sets the machine events state provider used to get notifications about current machine events and errors. /// @@ -1242,6 +1277,11 @@ namespace Tango.Integration.Operation OnEnableMachineStatusUpdatesChanged(EnableMachineStatusUpdates); OnEnableAutomaticThreadLoadingChanged(EnableAutomaticThreadLoading); + if (EnablePowerUpSequence) + { + TrackPowerUpSequence(); + } + if (EnableJobResume) { ResumeJob(); @@ -1249,7 +1289,7 @@ namespace Tango.Integration.Operation if (response.Message.IsAfterReset) { - PowerUpStarted?.Invoke(this, new EventArgs()); + FirmwareStarted?.Invoke(this, new EventArgs()); } } catch (Exception ex) @@ -1269,6 +1309,76 @@ namespace Tango.Integration.Operation #region Private Methods + private void TrackPowerUpSequence() + { + LogManager.Log("Starting power up sequence tracking..."); + + bool started = false; + bool completed = false; + PowerUpState lastState = PowerUpState.None; + + SendContinuousRequest(new StartPowerUpRequest(), new TransportContinuousRequestConfig() + { + ShouldLog = true, + Timeout = TimeSpan.FromSeconds(5) + }).Subscribe((response) => + { + if (!started) + { + started = true; + PowerUpStarted?.Invoke(this, response); + } + + PowerUpProgress?.Invoke(this, response); + + var state = response.Message.State; + + if (state != lastState) + { + LogManager.Log($"Power up sequence state changed to '{state}'..."); + + switch (state) + { + case PowerUpState.Error: + completed = true; + LogManager.Log($"Power up sequence failed with state '{state}'. ({response.Message.Message})"); + PowerUpFailed?.Invoke(this, response); + PowerUpEnded?.Invoke(this, new EventArgs()); + break; + case PowerUpState.Cancelled: + completed = true; + LogManager.Log($"Power up sequence canceled with state '{state}'. ({response.Message.Message})"); + PowerUpEnded?.Invoke(this, new EventArgs()); + break; + case PowerUpState.MachineReadyToDye: + completed = true; + LogManager.Log($"Power up sequence completed successfully with state '{state}'. ({response.Message.Message})"); + PowerUpCompleted?.Invoke(this, response); + PowerUpEnded?.Invoke(this, new EventArgs()); + break; + } + + lastState = state; + } + + }, (ex) => + { + if (!completed) + { + completed = true; + LogManager.Log(ex, "Power up sequence tracking failed."); + PowerUpEnded?.Invoke(this, new EventArgs()); + } + }, () => + { + if (!completed) + { + completed = true; + PowerUpEnded?.Invoke(this, new EventArgs()); + } + }); + } + private async void ResumeJob() { LogManager.Log("Checking if a job is in progress..."); @@ -1420,42 +1530,6 @@ namespace Tango.Integration.Operation } } - /// - /// Logs the request sent. - /// - /// The message. - //protected void LogRequestSent(IMessage message) - //{ - // if (!(message is FileChunkUploadRequest) && !(message is FileDownloadRequest)) - // { - // //LogManager.Log($"{GetExtendedComponentName()}: Sending request '{message.GetType().Name}'...\n{message.ToJsonString()}"); - // OnRequestSent(message); - // } - //} - - /// - /// Logs the request failed. - /// - /// The message. - //protected void LogRequestFailed(IMessage message, Exception ex) - //{ - // //LogManager.Log($"{GetExtendedComponentName()}: Request failed '{message.GetType().Name}'...\n{message.ToJsonString()}\n{ex.ToString()}", LogCategory.Error); - // OnRequestFailed(message, ex); - //} - - /// - /// Logs the response received. - /// - /// The message. - //protected void LogResponseReceived(IMessage message) - //{ - // if (!(message is FileChunkUploadResponse) && !(message is FileDownloadResponse)) - // { - // //LogManager.Log($"{GetExtendedComponentName()}: Response received '{message.GetType().Name}'...\n{message.ToJsonString()}"); - // OnResponseReceived(message); - // } - //} - /// /// Creates a PMR job segment. /// -- cgit v1.3.1