From 64bcf92608faae31b7cd31ac3da5c7d1d7ebcd0b Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sat, 14 Jul 2018 21:27:57 +0300 Subject: Implemented job completed notification item. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 1572864 -> 1572864 bytes .../JobCompletedNotificationItem.cs | 20 ++++++ .../JobCompletedNotificationItemView.xaml | 16 +++++ .../JobCompletedNotificationItemView.xaml.cs | 28 ++++++++ .../Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj | 11 +++ .../Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs | 15 +++- .../Tango.PPC.Common/Notifications/AppBarItem.cs | 65 +---------------- .../Notifications/INotificationProvider.cs | 26 ++----- .../PPC/Tango.PPC.Common/Notifications/ItemBase.cs | 77 +++++++++++++++++++++ .../Notifications/NotificationItem.cs | 52 +------------- .../PPC/Tango.PPC.Common/Tango.PPC.Common.csproj | 1 + .../Notifications/DefaultNotificationProvider.cs | 61 +++------------- .../EmptyCartridgesNotification.cs | 34 --------- .../EmptyCartridgesNotificationView.xaml | 15 ---- .../EmptyCartridgesNotificationView.xaml.cs | 28 -------- .../PPC/Tango.PPC.UI/Tango.PPC.UI.csproj | 8 --- .../PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs | 1 - .../PPC/Tango.PPC.UI/Views/MainView.xaml | 10 +-- 19 files changed, 190 insertions(+), 278 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/NotificationItems/JobCompletedNotificationItem.cs create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/NotificationItems/JobCompletedNotificationItemView.xaml create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/NotificationItems/JobCompletedNotificationItemView.xaml.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/ItemBase.cs delete mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotification.cs delete mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml delete mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml.cs (limited to 'Software') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index f41a7a03a..670011fef 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index e5a22310a..1bcea900a 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/NotificationItems/JobCompletedNotificationItem.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/NotificationItems/JobCompletedNotificationItem.cs new file mode 100644 index 000000000..5c48dc606 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/NotificationItems/JobCompletedNotificationItem.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PPC.Common.Notifications; + +namespace Tango.PPC.Jobs.NotificationItems +{ + public class JobCompletedNotificationItem : NotificationItem + { + public override Type ViewType + { + get + { + return typeof(JobCompletedNotificationItemView); + } + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/NotificationItems/JobCompletedNotificationItemView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/NotificationItems/JobCompletedNotificationItemView.xaml new file mode 100644 index 000000000..b96337eff --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/NotificationItems/JobCompletedNotificationItemView.xaml @@ -0,0 +1,16 @@ + + + + + The job has been completed + + + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/NotificationItems/JobCompletedNotificationItemView.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/NotificationItems/JobCompletedNotificationItemView.xaml.cs new file mode 100644 index 000000000..b6d9797e5 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/NotificationItems/JobCompletedNotificationItemView.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.Jobs.NotificationItems +{ + /// + /// Interaction logic for JobCompletedNotificationItemView.xaml + /// + public partial class JobCompletedNotificationItemView : UserControl + { + public JobCompletedNotificationItemView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj index aafa028c7..9ff90ca42 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj @@ -92,6 +92,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -159,6 +163,10 @@ + + + JobCompletedNotificationItemView.xaml + Code @@ -322,5 +330,8 @@ + + + \ No newline at end of file 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 9a0d0f8ab..f3d16e899 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 @@ -8,6 +8,7 @@ using Tango.Integration.Operation; using Tango.PPC.Common; using Tango.PPC.Common.Navigation; using Tango.PPC.Jobs.AppBarItems; +using Tango.PPC.Jobs.NotificationItems; using Tango.PPC.Jobs.Views; namespace Tango.PPC.Jobs.ViewModels @@ -45,6 +46,18 @@ namespace Tango.PPC.Jobs.ViewModels Job = jobHandler.Job; jobHandler.StatusChanged += JobHandler_StatusChanged; jobHandler.Stopped += JobHandler_Stopped; + jobHandler.Completed += JobHandler_Completed; + } + + private void JobHandler_Completed(object sender, EventArgs e) + { + InvokeUI(() => + { + NotificationProvider.PushNotification().Pressed += (_, __) => + { + NavigationManager.NavigateTo(nameof(JobView)); + }; + }); } public override void OnNavigatedFrom() @@ -53,7 +66,7 @@ namespace Tango.PPC.Jobs.ViewModels if (MachineProvider.MachineOperator.IsPrinting) { - NotificationProvider.PushAppBarItem().Preesed += (_, __) => + NotificationProvider.PushAppBarItem().Pressed += (_, __) => { NotificationProvider.CurrentAppBarItem.Close(); NavigationManager.NavigateTo(nameof(JobProgressView)); 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 e35164cf7..1c47d2a97 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/AppBarItem.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/AppBarItem.cs @@ -11,71 +11,8 @@ namespace Tango.PPC.Common.Notifications /// /// Represents an AppBar item that can be inserted into the application header. /// - /// - public abstract class AppBarItem : IDisposable + public abstract class AppBarItem : ItemBase { - /// - /// Occurs when the AppBar item has been closed. - /// - public event EventHandler Closed; - /// - /// Occurs when the AppBar item has been pressed. - /// - public event EventHandler Preesed; - - /// - /// Gets or sets the remove action. - /// - internal Action RemoveAction { get; set; } - - /// - /// Gets or sets the AppBar view type. - /// - public abstract Type ViewType { get; } - - /// - /// Gets or sets the close command. - /// - public RelayCommand CloseCommand { get; set; } - - /// - /// Gets or sets the pressed command. - /// - /// Initializes a new instance of the class. - /// - public AppBarItem() - { - CloseCommand = new RelayCommand(Close); - PressedCommand = new RelayCommand(OnPreesed); - } - - /// - /// Called when the AppBar item has been pressed. - /// - protected virtual void OnPreesed() - { - Preesed?.Invoke(this, new EventArgs()); - } - - /// - /// Called after the close command has been raised. - /// - public virtual void Close() - { - RemoveAction?.Invoke(); - Closed?.Invoke(this, new EventArgs()); - } - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - Close(); - } } } 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 9063cef36..39cf2879f 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/INotificationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/INotificationProvider.cs @@ -87,6 +87,13 @@ namespace Tango.PPC.Common.Notifications /// The item. NotificationItem PushNotification(NotificationItem item); + /// + /// Pushes the notification. + /// + /// + /// + NotificationItem PushNotification() where T : NotificationItem; + /// /// Displays the specified dialog in a modal design. /// @@ -114,31 +121,12 @@ namespace Tango.PPC.Common.Notifications /// Task ShowDialog() where VM : DialogViewVM; - /// - /// Inserts the notification item to the bottom of the notifications collection. - /// - /// The item. - /// A condition which determines if this item is still relevant. - /// Determines whether to perform automatic checking of the condition. - /// Determines how frequently the condition function will be invoked. (Default 1 second) - NotificationItem PushNotification(NotificationItem item, Func condition, bool autoCheck = true, TimeSpan? checkInterval = null); - /// /// Removed the specified notification item. /// /// The item. void PopNotification(NotificationItem item); - /// - /// Invokes the notification items conditions. - /// - void InvokeNotificationItemsConditions(); - - /// - /// Gets the pop notification command. - /// - RelayCommand PopNotificationCommand { get; } - /// /// Gets a value indicating whether this instance is in global busy state. /// diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/ItemBase.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/ItemBase.cs new file mode 100644 index 000000000..12369948b --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/ItemBase.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.Core.Commands; + +namespace Tango.PPC.Common.Notifications +{ + public abstract class ItemBase : ExtendedObject, IDisposable + { + /// + /// Occurs when the item has been closed. + /// + public event EventHandler Closed; + + /// + /// Occurs when the item has been pressed. + /// + public event EventHandler Pressed; + + /// + /// Gets or sets the remove action. + /// + internal Action RemoveAction { get; set; } + + /// + /// Gets or sets the view type. + /// + public abstract Type ViewType { get; } + + /// + /// Gets or sets the close command. + /// + public RelayCommand CloseCommand { get; set; } + + /// + /// Gets or sets the pressed command. + /// + /// Initializes a new instance of the class. + /// + public ItemBase() + { + CloseCommand = new RelayCommand(Close); + PressedCommand = new RelayCommand(OnPreesed); + } + + /// + /// Called when the item has been pressed. + /// + protected virtual void OnPreesed() + { + Pressed?.Invoke(this, new EventArgs()); + } + + /// + /// Called after the close command has been raised. + /// + public virtual void Close() + { + RemoveAction?.Invoke(); + Closed?.Invoke(this, new EventArgs()); + } + + /// + /// Disposes the item. + /// + public void Dispose() + { + Close(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItem.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItem.cs index f5e319fa0..e1832090e 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItem.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItem.cs @@ -12,58 +12,8 @@ namespace Tango.PPC.Common.Notifications /// /// Represents a base notification item. /// - /// - public abstract class NotificationItem : ExtendedObject, IDisposable + public abstract class NotificationItem : ItemBase { - /// - /// Gets or sets the condition. - /// - internal Func Condition { get; set; } - /// - /// Gets or sets a value indicating whether [automatic check]. - /// - internal bool AutoCheck { get; set; } - - /// - /// Gets or sets the automatic check interval. - /// - internal TimeSpan AutoCheckInterval { get; set; } - - /// - /// Gets or sets the remove action. - /// - internal Action RemoveAction { get; set; } - - /// - /// Gets or sets the check timer. - /// - internal Timer Timer { get; set; } - - private String _message; - /// - /// Gets or sets the notification message. - /// - public String Message - { - get { return _message; } - set { _message = value; RaisePropertyChangedAuto(); } - } - - /// - /// Gets or sets the type of the view associated with this notification item. - /// - public abstract Type ViewType { get; } - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - if (RemoveAction != null) - { - RemoveAction(); - } - } } } 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 e48da8140..15f5d98c5 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 @@ -108,6 +108,7 @@ + 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 647fc1ef1..0ff9982ee 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs @@ -212,43 +212,20 @@ namespace Tango.PPC.UI.Notifications /// public NotificationItem PushNotification(NotificationItem item) { - return PushNotification(item, null, false, null); + item.RemoveAction = () => { PopNotification(item); }; + NotificationItems.Insert(0, item); + RaisePropertyChanged(nameof(HasNotificationItems)); + return item; } /// - /// Inserts the notification item to the bottom of the notifications collection. + /// Pushes the notification. /// - /// The item. - /// A condition which determines if this item is still relevant. - /// Determines whether to perform automatic checking of the condition. - /// Determines how frequently the condition function will be invoked. (Default 1 second) + /// /// - public NotificationItem PushNotification(NotificationItem item, Func condition, bool autoCheck = true, TimeSpan? checkInterval = default(TimeSpan?)) + public NotificationItem PushNotification() where T : NotificationItem { - item.Condition = condition; - item.AutoCheck = autoCheck; - item.AutoCheckInterval = checkInterval != null ? checkInterval.Value : TimeSpan.FromSeconds(1); - item.RemoveAction = () => { PopNotification(item); }; - NotificationItems.Insert(0, item); - - if (autoCheck && condition != null) - { - Timer timer = new Timer(); - item.Timer = timer; - timer.Interval = item.AutoCheckInterval.TotalMilliseconds; - timer.Elapsed += (x, y) => - { - if (!item.Condition()) - { - PopNotification(item); - } - }; - timer.Start(); - } - - RaisePropertyChanged(nameof(HasNotificationItems)); - - return item; + return PushNotification(Activator.CreateInstance()); } /// @@ -257,32 +234,10 @@ namespace Tango.PPC.UI.Notifications /// The item. public void PopNotification(NotificationItem item) { - if (item.Timer != null) - { - item.Timer.Stop(); - } - NotificationItems.Remove(item); - RaisePropertyChanged(nameof(HasNotificationItems)); } - /// - /// Invokes the notification items conditions. - /// - public void InvokeNotificationItemsConditions() - { - var list = NotificationItems.ToList(); - - foreach (var item in list.Where(x => x.Condition != null)) - { - if (!item.Condition()) - { - PopNotification(item); - } - } - } - /// /// Gets a value indicating whether this instance has notification items. /// diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotification.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotification.cs deleted file mode 100644 index 49a0c03eb..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotification.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.BL.Entities; -using Tango.BL.Enumerations; -using Tango.PPC.Common.Notifications; - -namespace Tango.PPC.UI.Notifications.NotificationItems -{ - public class EmptyCartridgesNotification : NotificationItem - { - public List LiquidTypes { get; set; } - - public EmptyCartridgesNotification() - { - Message = "Cartridges are empty, please replace cartridges"; - } - - public EmptyCartridgesNotification(IEnumerable liquidTypes) : this() - { - LiquidTypes = liquidTypes.ToList(); - } - - public override Type ViewType - { - get - { - return typeof(EmptyCartridgesNotificationView); - } - } - } -} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml deleted file mode 100644 index ccb6618e7..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml.cs deleted file mode 100644 index 5fab4ab44..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml.cs +++ /dev/null @@ -1,28 +0,0 @@ -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.Notifications.NotificationItems -{ - /// - /// Interaction logic for EmptyCartridgesNotification.xaml - /// - public partial class EmptyCartridgesNotificationView : UserControl - { - public EmptyCartridgesNotificationView() - { - InitializeComponent(); - } - } -} 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 2e344bdc9..dc3745bef 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 @@ -121,10 +121,6 @@ - - - EmptyCartridgesNotificationView.xaml - @@ -161,10 +157,6 @@ MainWindow.xaml Code - - Designer - MSBuild:Compile - Designer MSBuild:Compile diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs index b3a0c5b1a..11bef4827 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs @@ -9,7 +9,6 @@ using Tango.Integration.Operation; using Tango.PPC.Common; using Tango.PPC.Common.Modules; using Tango.PPC.Common.Navigation; -using Tango.PPC.UI.Notifications.NotificationItems; using Tango.PPC.UI.ViewsContracts; using Tango.SharedUI; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml index dcb19dbee..f333ea2e8 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml @@ -27,10 +27,12 @@ CurrentDialog="{Binding NotificationProvider.CurrentDialog}"> - - - - + + + + + + -- cgit v1.3.1