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 +++++++++++++++++++++ 1 file changed, 101 insertions(+) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs') 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; } } } -- cgit v1.3.1