diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-06-17 19:06:13 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-06-17 19:06:13 +0300 |
| commit | 7658a8546a9c33a76376dff3ab646f2aceaf0a01 (patch) | |
| tree | 10c2cee7f96268e9052e19901f49f3e0a1e75d41 /Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs | |
| parent | 22853e394b878578084db1062664c38c40e88d07 (diff) | |
| download | Tango-7658a8546a9c33a76376dff3ab646f2aceaf0a01.tar.gz Tango-7658a8546a9c33a76376dff3ab646f2aceaf0a01.zip | |
Working on PPC !!!
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs | 101 |
1 files changed, 101 insertions, 0 deletions
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 { @@ -22,6 +24,11 @@ namespace Tango.PPC.UI.Notifications public class DefaultNotificationProvider : ExtendedObject, INotificationProvider { /// <summary> + /// Gets the collection of notification items. + /// </summary> + public ObservableCollection<NotificationItem> NotificationItems { get; private set; } + + /// <summary> /// Represents a pending message box. /// </summary> private class PendingMessageBox @@ -44,7 +51,10 @@ namespace Tango.PPC.UI.Notifications /// </summary> public DefaultNotificationProvider() { + NotificationItems = new ObservableCollection<NotificationItem>(); _pendingMessageBoxes = new ConcurrentQueue<PendingMessageBox>(); + + PopNotificationCommand = new RelayCommand<NotificationItem>((x) => PopNotification(x)); } private MessageBoxVM _currentMessageBox; @@ -182,5 +192,96 @@ namespace Tango.PPC.UI.Notifications } } } + + /// <summary> + /// Inserts the notification item to the bottom of the notifications collection. + /// </summary> + /// <param name="item">The item.</param> + /// <returns></returns> + public NotificationItem PushNotification(NotificationItem item) + { + return PushNotification(item, null, false, null); + } + + /// <summary> + /// Inserts the notification item to the bottom of the notifications collection. + /// </summary> + /// <param name="item">The item.</param> + /// <param name="condition">A condition which determines if this item is still relevant.</param> + /// <param name="autoCheck">Determines whether to perform automatic checking of the condition.</param> + /// <param name="checkInterval">Determines how frequently the condition function will be invoked. (Default 1 second)</param> + /// <returns></returns> + public NotificationItem PushNotification(NotificationItem item, Func<bool> 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; + } + + /// <summary> + /// Removed the specified notification item. + /// </summary> + /// <param name="item">The item.</param> + public void PopNotification(NotificationItem item) + { + if (item.Timer != null) + { + item.Timer.Stop(); + } + + NotificationItems.Remove(item); + + RaisePropertyChanged(nameof(HasNotificationItems)); + } + + /// <summary> + /// Invokes the notification items conditions. + /// </summary> + public void InvokeNotificationItemsConditions() + { + var list = NotificationItems.ToList(); + + foreach (var item in list.Where(x => x.Condition != null)) + { + if (!item.Condition()) + { + PopNotification(item); + } + } + } + + /// <summary> + /// Gets a value indicating whether this instance has notification items. + /// </summary> + public bool HasNotificationItems + { + get + { + return NotificationItems.Count > 0; + } + } + + public RelayCommand<NotificationItem> PopNotificationCommand { get; private set; } } } |
