From 7658a8546a9c33a76376dff3ab646f2aceaf0a01 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 17 Jun 2018 19:06:13 +0300 Subject: Working on PPC !!! --- .../Notifications/DefaultNotificationProvider.cs | 101 +++++++++++++++++++++ .../EmptyCartridgesNotification.cs | 34 +++++++ .../EmptyCartridgesNotificationView.xaml | 15 +++ .../EmptyCartridgesNotificationView.xaml.cs | 28 ++++++ 4 files changed, 178 insertions(+) create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotification.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml.cs (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications') 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 5e4bd7c30..cbdbab848 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs @@ -11,6 +11,8 @@ using Tango.Core; using System.Collections.Concurrent; using System.Windows.Media.Imaging; using Tango.SharedUI.Helpers; +using System.Timers; +using Tango.Core.Commands; namespace Tango.PPC.UI.Notifications { @@ -21,6 +23,11 @@ namespace Tango.PPC.UI.Notifications /// public class DefaultNotificationProvider : ExtendedObject, INotificationProvider { + /// + /// Gets the collection of notification items. + /// + public ObservableCollection NotificationItems { get; private set; } + /// /// Represents a pending message box. /// @@ -44,7 +51,10 @@ namespace Tango.PPC.UI.Notifications /// public DefaultNotificationProvider() { + NotificationItems = new ObservableCollection(); _pendingMessageBoxes = new ConcurrentQueue(); + + PopNotificationCommand = new RelayCommand((x) => PopNotification(x)); } private MessageBoxVM _currentMessageBox; @@ -182,5 +192,96 @@ namespace Tango.PPC.UI.Notifications } } } + + /// + /// Inserts the notification item to the bottom of the notifications collection. + /// + /// The item. + /// + public NotificationItem PushNotification(NotificationItem item) + { + return PushNotification(item, null, false, null); + } + + /// + /// 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) + /// + public NotificationItem PushNotification(NotificationItem item, Func condition, bool autoCheck = true, TimeSpan? checkInterval = default(TimeSpan?)) + { + 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; + } + + /// + /// Removed the specified notification item. + /// + /// 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. + /// + public bool HasNotificationItems + { + get + { + return NotificationItems.Count > 0; + } + } + + public RelayCommand PopNotificationCommand { get; private set; } } } 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 new file mode 100644 index 000000000..49a0c03eb --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotification.cs @@ -0,0 +1,34 @@ +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 new file mode 100644 index 000000000..7ce525337 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml @@ -0,0 +1,15 @@ + + + + + + + + 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 new file mode 100644 index 000000000..5fab4ab44 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.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.Notifications.NotificationItems +{ + /// + /// Interaction logic for EmptyCartridgesNotification.xaml + /// + public partial class EmptyCartridgesNotificationView : UserControl + { + public EmptyCartridgesNotificationView() + { + InitializeComponent(); + } + } +} -- cgit v1.3.1