From e0167674d812f90896b982fa236dc2634eb79bcb Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 27 Nov 2018 15:31:21 +0200 Subject: Working on PPC Events module. --- .../Tango.PPC.Events/ViewModels/MainViewVM.cs | 94 +++++++++++++++++++++- 1 file changed, 92 insertions(+), 2 deletions(-) (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels') 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 { /// - /// Represents the main view VM and entry point for . + /// Represents the main view VM and entry point for . /// /// public class MainViewVM : PPCViewModel { + private Dictionary _notifications; + + private ObservableCollection _currentEvents; + /// + /// Gets or sets the current events. + /// + public ObservableCollection CurrentEvents + { + get { return _currentEvents; } + set { _currentEvents = value; RaisePropertyChangedAuto(); } + } + + /// + /// Initializes a new instance of the class. + /// + public MainViewVM() + { + CurrentEvents = new ObservableCollection(); + _notifications = new Dictionary(); + } + /// /// Called when the application has been started /// 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); + } + } + } + }); } } } -- cgit v1.3.1