From 402099d85ff0582bb48484d47fb2c4b6deb2e020 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Wed, 20 May 2020 06:27:49 +0300 Subject: Prevent multiple job synchronization notifications. --- .../PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (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 af576ac93..f9029ed8c 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 @@ -51,6 +51,7 @@ namespace Tango.PPC.Jobs.ViewModels private ObservableCollection _catalogs; //Holds the available color catalogs for the site. private ObservableCollection _rmls; //Holds the available RML for the site. private List _colorSpaces; //Holds the available color spaces. + private bool _isJobsSynchronizationNotificationActive; public enum JobsCategory { @@ -893,16 +894,23 @@ namespace Tango.PPC.Jobs.ViewModels private void MachineDataSynchronizer_SynchronizationEnded(object sender, SynchronizationEndedEventArgs e) { - if (e.NewChangedJobs > 0) + if (e.NewChangedJobs > 0 && !_isJobsSynchronizationNotificationActive) { + _isJobsSynchronizationNotificationActive = true; + var item = NotificationProvider.PushNotification(); item.Pressed += (_, __) => { + _isJobsSynchronizationNotificationActive = false; LoadJobs(() => { NotificationProvider.ShowSuccess("Your job list is now synchronized."); }); }; + item.Closed += (_, __) => + { + _isJobsSynchronizationNotificationActive = false; + }; } } -- cgit v1.3.1 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/Dialogs/ImportJobView.xaml | 2 +- .../Tango.PPC.Jobs/ViewModels/JobsViewVM.cs | 111 ++++++++++++++------- .../Models/StorageNavigationIntent.cs | 4 +- .../Tango.PPC.Storage/ViewModels/MainViewVM.cs | 41 ++++++-- .../Modules/Tango.PPC.Storage/Views/MainView.xaml | 67 ++++++++++++- .../Storage/DefaultStorageProvider.cs | 23 +++-- .../Tango.PPC.Common/Storage/IStorageProvider.cs | 6 +- .../Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs | 12 ++- .../Tango.Explorer/ExplorerControl.cs | 90 ++++++++++++++++- .../Tango.Explorer/Themes/Generic.xaml | 50 ++++++++-- .../Tango.Touch/Controls/TouchListBox.cs | 7 +- 11 files changed, 333 insertions(+), 80 deletions(-) (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportJobView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportJobView.xaml index ac27cc00d..da51bba27 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportJobView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportJobView.xaml @@ -18,7 +18,7 @@ IMPORT JOB A job file has been selected from the storage device. press 'IMPORT' to add the job to your job list. - Edit this job after import + Edit this job after import 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; }; diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/Models/StorageNavigationIntent.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/Models/StorageNavigationIntent.cs index 2c2a7f10d..3ec14cc6f 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/Models/StorageNavigationIntent.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/Models/StorageNavigationIntent.cs @@ -9,6 +9,8 @@ namespace Tango.PPC.Storage.Models public enum StorageNavigationIntent { LoadFile, - SaveFile + LoadFiles, + SaveFile, + SaveFiles } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/ViewModels/MainViewVM.cs index 8c166379e..b9d59334c 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/ViewModels/MainViewVM.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -70,16 +71,21 @@ namespace Tango.PPC.Storage.ViewModels set { _displayItems = value; RaisePropertyChangedAuto(); } } - public RelayCommand FileSelectedCommand { get; set; } + public ObservableCollection SelectedItems { get; set; } + public RelayCommand SaveCommand { get; set; } + public RelayCommand OpenCommand { get; set; } + public MainViewVM() { + SelectedItems = new ObservableCollection(); FileSelectedCommand = new RelayCommand(OnFileSelected); - SaveCommand = new RelayCommand(OnSaveCommand, (x) => !String.IsNullOrWhiteSpace(FileName)); - Request = new StorageNavigationRequest(); + SaveCommand = new RelayCommand(OnSaveCommand, (x) => !String.IsNullOrWhiteSpace(FileName) || Request.Intent == StorageNavigationIntent.SaveFiles); + Request = new StorageNavigationRequest() { Intent = StorageNavigationIntent.LoadFiles }; + OpenCommand = new RelayCommand(OnOpenCommand, () => Request.Intent == StorageNavigationIntent.LoadFiles); } public override void OnApplicationStarted() @@ -128,7 +134,7 @@ namespace Tango.PPC.Storage.ViewModels base.OnNavigatedFrom(); DisplayItems = false; Request = null; - Request = new StorageNavigationRequest(); + Request = new StorageNavigationRequest() { Intent = StorageNavigationIntent.LoadFiles }; } /// @@ -184,7 +190,14 @@ namespace Tango.PPC.Storage.ViewModels _selectedItem = fileItem; _allow_exit = true; await NavigationManager.NavigateBack(); - StorageProvider.SubmitFileSelection(fileItem); + StorageProvider.SubmitFileSelection(new List() { fileItem }); + } + + private async void OnOpenCommand() + { + _allow_exit = true; + await NavigationManager.NavigateBack(); + StorageProvider.SubmitFileSelection(SelectedItems.ToList()); } public ExplorerFileItem GetNavigationResult() @@ -200,10 +213,22 @@ namespace Tango.PPC.Storage.ViewModels private void OnSaveCommand() { _allow_exit = true; - _selectedItem = new ExplorerFileItem() + + if (Request.Intent == StorageNavigationIntent.SaveFile) + { + _selectedItem = new ExplorerFileItem() + { + Path = CurrentPath + "\\" + FileName, + }; + } + else if (Request.Intent == StorageNavigationIntent.SaveFiles) { - Path = CurrentPath + "\\" + FileName, - }; + _selectedItem = new ExplorerFileItem() + { + Path = CurrentPath, + }; + } + NavigationManager.NavigateBack(); } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/Views/MainView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/Views/MainView.xaml index 25538a525..e8d402d89 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/Views/MainView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/Views/MainView.xaml @@ -16,7 +16,7 @@ - + @@ -32,8 +32,54 @@ - - + + + + + + + + + + OPEN + + + + + + files selected + + + + + + + + + + + @@ -43,20 +89,31 @@ SAVE - + + + Select destination folder + - + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/DefaultStorageProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/DefaultStorageProvider.cs index 46315e4b8..5f097d303 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/DefaultStorageProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/DefaultStorageProvider.cs @@ -21,7 +21,7 @@ namespace Tango.PPC.Common.Storage public class DefaultStorageProvider : ExtendedObject, IStorageProvider { private Thread _scanThread; - private Dictionary> _fileHandlers; + private Dictionary>> _fileHandlers; /// /// Occurs when a new storage drive has been inserted. @@ -58,7 +58,7 @@ namespace Tango.PPC.Common.Storage /// public DefaultStorageProvider(IPPCApplicationManager applicationManager) { - _fileHandlers = new Dictionary>(); + _fileHandlers = new Dictionary>>(); var drives = DriveInfo.GetDrives().Where(x => x.DriveType == DriveType.Removable).ToList(); if (drives.Count > 0) @@ -86,7 +86,7 @@ namespace Tango.PPC.Common.Storage /// The file extension. /// The handler. /// Cannot register multiple file handlers for the same extension. - public void RegisterFileHandler(string extension, Action handler) + public void RegisterFileHandler(string extension, Action> handler) { if (_fileHandlers.ContainsKey(extension)) { @@ -99,7 +99,7 @@ namespace Tango.PPC.Common.Storage /// Unregisters the file handler. /// /// The handler. - public void UnregisterFileHandler(Action handler) + public void UnregisterFileHandler(Action> handler) { var h = _fileHandlers.SingleOrDefault(x => x.Value == handler); @@ -112,14 +112,17 @@ namespace Tango.PPC.Common.Storage /// /// Submits a file selection. /// - /// The file item. - public void SubmitFileSelection(ExplorerFileItem fileItem) + /// The file item. + public void SubmitFileSelection(List fileItems) { - String extension = Path.GetExtension(fileItem.Path); - - if (_fileHandlers.ContainsKey(extension)) + if (fileItems != null && fileItems.Count > 0) { - _fileHandlers[extension].Invoke(fileItem); + String extension = Path.GetExtension(fileItems.First().Path); + + if (_fileHandlers.ContainsKey(extension)) + { + _fileHandlers[extension].Invoke(fileItems); + } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/IStorageProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/IStorageProvider.cs index 902021002..2a9cf4e90 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/IStorageProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Storage/IStorageProvider.cs @@ -38,18 +38,18 @@ namespace Tango.PPC.Common.Storage /// /// The file extension. /// The handler. - void RegisterFileHandler(String extension, Action handler); + void RegisterFileHandler(String extension, Action> handler); /// /// Unregisters the file handler. /// /// The handler. - void UnregisterFileHandler(Action handler); + void UnregisterFileHandler(Action> handler); /// /// Submits a file selection. /// /// The file item. - void SubmitFileSelection(ExplorerFileItem fileItem); + void SubmitFileSelection(List fileItems); } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs index 965584767..54a92aa5c 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs @@ -408,8 +408,12 @@ namespace Tango.PPC.UI.ViewModels #region Handle USB Update - private async void HandleSoftwareUpdatePackageLoaded(ExplorerFileItem fileItem) + private async void HandleSoftwareUpdatePackageLoaded(List fileItems) { + var fileItem = fileItems.FirstOrDefault(); + + if (fileItem == null) return; + PublishInfo packageFile = null; LogManager.Log("TUP file loaded from storage..."); @@ -456,8 +460,12 @@ namespace Tango.PPC.UI.ViewModels } } - private async void HandleFirmwareUpgradeLoaded(ExplorerFileItem fileItem) + private async void HandleFirmwareUpgradeLoaded(List fileItems) { + var fileItem = fileItems.FirstOrDefault(); + + if (fileItem == null) return; + LogManager.Log("TFP file loaded from storage..."); VersionPackageDescriptor packageInfo; diff --git a/Software/Visual_Studio/Tango.Explorer/ExplorerControl.cs b/Software/Visual_Studio/Tango.Explorer/ExplorerControl.cs index c1eba0b12..9561072d0 100644 --- a/Software/Visual_Studio/Tango.Explorer/ExplorerControl.cs +++ b/Software/Visual_Studio/Tango.Explorer/ExplorerControl.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Collections.Specialized; using System.IO; using System.Linq; using System.Text; @@ -14,12 +16,14 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Tango.Core.Commands; +using Tango.Touch.Controls; namespace Tango.Explorer { public class ExplorerControl : Control { private bool _changing_current_path; + private TouchListBox _listBox; public String CurrentPath { @@ -45,6 +49,14 @@ namespace Tango.Explorer public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register("SelectedItem", typeof(ExplorerItem), typeof(ExplorerControl), new PropertyMetadata(null, (d, e) => (d as ExplorerControl).OnSelectedItemChanged())); + public IEnumerable SelectedItems + { + get { return (IEnumerable)GetValue(SelectedItemsProperty); } + set { SetValue(SelectedItemsProperty, value); } + } + public static readonly DependencyProperty SelectedItemsProperty = + DependencyProperty.Register("SelectedItems", typeof(IEnumerable), typeof(ExplorerControl), new PropertyMetadata(null, (d, e) => (d as ExplorerControl).OnSelectedItemsChanged())); + public RelayCommand BackCommand { get { return (RelayCommand)GetValue(BackCommandProperty); } @@ -77,6 +89,21 @@ namespace Tango.Explorer public static readonly DependencyProperty EnableFileSelectionProperty = DependencyProperty.Register("EnableFileSelection", typeof(bool), typeof(ExplorerControl), new PropertyMetadata(true)); + public bool EnableMultiSelect + { + get { return (bool)GetValue(EnableMultiSelectProperty); } + set { SetValue(EnableMultiSelectProperty, value); } + } + public static readonly DependencyProperty EnableMultiSelectProperty = + DependencyProperty.Register("EnableMultiSelect", typeof(bool), typeof(ExplorerControl), new PropertyMetadata(false)); + + public bool IsMultiSelecting + { + get { return (bool)GetValue(IsMultiSelectingProperty); } + set { SetValue(IsMultiSelectingProperty, value); } + } + public static readonly DependencyProperty IsMultiSelectingProperty = + DependencyProperty.Register("IsMultiSelecting", typeof(bool), typeof(ExplorerControl), new PropertyMetadata(false)); static ExplorerControl() { @@ -88,10 +115,22 @@ namespace Tango.Explorer BackCommand = new RelayCommand(NavigateBack); } + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + + _listBox = GetTemplateChild("PART_ListBox") as TouchListBox; + } + private void OnCurrentPathChanged() { if (_changing_current_path) return; + if (_listBox != null) + { + _listBox.IsMultiSelecting = false; + } + _changing_current_path = true; if (CurrentPath == null) @@ -119,7 +158,7 @@ namespace Tango.Explorer private void OnSelectedItemChanged() { - if (SelectedItem != null) + if (SelectedItem != null && _listBox != null) { if (SelectedItem is ExplorerFolderItem) { @@ -128,13 +167,60 @@ namespace Tango.Explorer CurrentFolder = folder; SelectedItem = null; } - else if (SelectedItem is ExplorerFileItem && EnableFileSelection) + else if (SelectedItem is ExplorerFileItem && EnableFileSelection && !_listBox.IsMultiSelecting) { FileSelectedCommand?.Execute(SelectedItem); } } } + private void OnSelectedItemsChanged() + { + if (SelectedItems != null) + { + if (SelectedItems is INotifyCollectionChanged) + { + (SelectedItems as INotifyCollectionChanged).CollectionChanged -= ExplorerControl_CollectionChanged; + (SelectedItems as INotifyCollectionChanged).CollectionChanged += ExplorerControl_CollectionChanged; + } + + PreventMultiExtensionSelection(); + } + } + + private void ExplorerControl_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + PreventMultiExtensionSelection(); + } + + private void PreventMultiExtensionSelection() + { + if (_listBox != null && SelectedItems != null) + { + if (_listBox.IsMultiSelecting && _listBox.SelectedItems != null && _listBox.SelectedItems.Count > 1) + { + var firstItem = _listBox.SelectedItems.OfType().FirstOrDefault(); + + if (firstItem != null) + { + foreach (var item in _listBox.SelectedItems.OfType().ToList()) + { + if (item.Extension.ToLower() != firstItem.Extension.ToLower()) + { + var listBoxItem = _listBox.GetItems().FirstOrDefault(x => x.DataContext == item); + + if (listBoxItem != null) + { + listBoxItem.IsSelected = false; + _listBox.SelectedItems.Remove(item); + } + } + } + } + } + } + } + public void NavigateBack() { if (CurrentFolder != null) diff --git a/Software/Visual_Studio/Tango.Explorer/Themes/Generic.xaml b/Software/Visual_Studio/Tango.Explorer/Themes/Generic.xaml index c920ce6bc..3ef77dea1 100644 --- a/Software/Visual_Studio/Tango.Explorer/Themes/Generic.xaml +++ b/Software/Visual_Studio/Tango.Explorer/Themes/Generic.xaml @@ -2,8 +2,17 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" + xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" xmlns:local="clr-namespace:Tango.Explorer"> + + + + + + + + + - - - - - - - + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchListBox.cs b/Software/Visual_Studio/Tango.Touch/Controls/TouchListBox.cs index 87e7717be..4fa50b7e6 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchListBox.cs +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchListBox.cs @@ -138,8 +138,6 @@ namespace Tango.Touch.Controls public static readonly DependencyProperty ScrollBarVisibilityProperty = DependencyProperty.Register("ScrollBarVisibility", typeof(Visibility), typeof(TouchListBox), new PropertyMetadata(Visibility.Visible)); - - public String ValuePath { get { return (String)GetValue(ValuePathProperty); } @@ -230,7 +228,7 @@ namespace Tango.Touch.Controls } } - private List GetItems() + public List GetItems() { return _items_control.FindVisualChildren().ToList(); } @@ -299,6 +297,7 @@ namespace Tango.Touch.Controls } else { + SelectedItem = item.DataContext; ItemSelectedCommand?.Execute(item.DataContext); } } @@ -360,5 +359,7 @@ namespace Tango.Touch.Controls var element = ScrollViewer.FindVisualChildren().FirstOrDefault(x => x.DataContext == item); ScrollViewer.ScrollToElement(element); } + + } } -- 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 From 25d5ae2d526603cb5097d19f2e5f2525baa362d4 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 28 May 2020 16:41:29 +0300 Subject: JobResume refactored ! --- .../Controls/RunningJobViewer.xaml | 2 +- .../Connection/DefaultMachineProvider.cs | 1 + .../Tango.PPC.Jobs/ViewModels/MainViewVM.cs | 12 +- .../Connection/DefaultMachineProvider.cs | 2 +- .../RemoteJob/DefaultRemoteJobService.cs | 44 ++++-- .../JobRuns/BasicJobRunsLogger.cs | 18 ++- .../Operation/CachedJobOperation.cs | 18 +++ .../Tango.Integration/Operation/MachineOperator.cs | 151 +++++++++++++++------ .../Operation/PrintingEventArgs.cs | 1 + .../Operation/ResumingJobEventArgs.cs | 8 +- .../Tango.Integration/Tango.Integration.csproj | 3 +- 11 files changed, 194 insertions(+), 66 deletions(-) create mode 100644 Software/Visual_Studio/Tango.Integration/Operation/CachedJobOperation.cs (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels') diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Controls/RunningJobViewer.xaml b/Software/Visual_Studio/FSE/Tango.FSE.Common/Controls/RunningJobViewer.xaml index 8269d70e2..2cd4fa7ad 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/Controls/RunningJobViewer.xaml +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Controls/RunningJobViewer.xaml @@ -70,7 +70,7 @@ @@ -159,7 +159,7 @@