diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels')
| -rw-r--r-- | Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels/MainViewVM.cs | 94 |
1 files changed, 92 insertions, 2 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels/MainViewVM.cs index 38784b790..326c78787 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels/MainViewVM.cs @@ -1,24 +1,114 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.BL.Entities; +using Tango.BL.Enumerations; using Tango.PPC.Common; +using Tango.PPC.Common.Notifications; +using Tango.PPC.Common.Notifications.NotificationItems; namespace Tango.PPC.Events.ViewModels { /// <summary> - /// Represents the main view VM and entry point for <see cref="Synchronization.MyModule"/>. + /// Represents the main view VM and entry point for <see cref="Events.EventsModule"/>. /// </summary> /// <seealso cref="Tango.PPC.Common.PPCViewModel" /> public class MainViewVM : PPCViewModel { + private Dictionary<EventTypes, NotificationItem> _notifications; + + private ObservableCollection<MachinesEvent> _currentEvents; + /// <summary> + /// Gets or sets the current events. + /// </summary> + public ObservableCollection<MachinesEvent> CurrentEvents + { + get { return _currentEvents; } + set { _currentEvents = value; RaisePropertyChangedAuto(); } + } + + /// <summary> + /// Initializes a new instance of the <see cref="MainViewVM"/> class. + /// </summary> + public MainViewVM() + { + CurrentEvents = new ObservableCollection<MachinesEvent>(); + _notifications = new Dictionary<EventTypes, NotificationItem>(); + } + /// <summary> /// Called when the application has been started /// </summary> public override void OnApplicationStarted() { - //Start initializing here rather then in the constructor. + EventLogger.EventReceived += EventLogger_EventReceived; + EventLogger.EventResolved += EventLogger_EventResolved; + } + + private void EventLogger_EventReceived(object sender, MachinesEvent ev) + { + InvokeUI(() => + { + if (ev.Group != EventTypesGroups.Transport) + { + CurrentEvents.Insert(0, ev); + + if (ev.Group != EventTypesGroups.Application && ev.Group != EventTypesGroups.Transport) + { + var notificationItem = new MessageNotificationItem(); + notificationItem.CanClose = false; + notificationItem.Message = ev.EventType.Description; + notificationItem.ExpandedMessage = ev.Description; + notificationItem.Pressed += (_, __) => + { + NotificationProvider.ShowInfo($"{ev.EventType.Description} Selected !"); + }; + + switch (ev.Category) + { + case EventTypesCategories.Info: + notificationItem.MessageType = MessageNotificationItem.MessageNotificationItemTypes.Info; + break; + case EventTypesCategories.Warning: + notificationItem.MessageType = MessageNotificationItem.MessageNotificationItemTypes.Warning; + break; + case EventTypesCategories.Error: + notificationItem.MessageType = MessageNotificationItem.MessageNotificationItemTypes.Error; + break; + case EventTypesCategories.Critical: + notificationItem.MessageType = MessageNotificationItem.MessageNotificationItemTypes.Error; + break; + } + + NotificationProvider.PushNotification(notificationItem); + _notifications.Add(ev.EventType.Type, notificationItem); + } + } + }); + } + + private void EventLogger_EventResolved(object sender, MachinesEvent ev) + { + InvokeUI(() => + { + if (ev.Group != EventTypesGroups.Transport) + { + CurrentEvents.Remove(ev); + + if (ev.Group != EventTypesGroups.Application && ev.Group != EventTypesGroups.Transport) + { + if (_notifications.ContainsKey(ev.EventType.Type)) + { + var notification = _notifications[ev.EventType.Type]; + _notifications.Remove(ev.EventType.Type); + NotificationProvider.PopNotification(notification); + } + } + } + }); } } } |
