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. --- .../Modules/Tango.PPC.Events/Resources/Styles.xaml | 76 ++++++++++++++++ .../Tango.PPC.Events/Tango.PPC.Events.csproj | 6 +- .../Tango.PPC.Events/ViewModels/MainViewVM.cs | 94 ++++++++++++++++++- .../Modules/Tango.PPC.Events/Views/MainView.xaml | 101 ++++++++++++++++++++- .../Tango.PPC.Events/Views/MainView.xaml.cs | 11 +++ 5 files changed, 283 insertions(+), 5 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Resources/Styles.xaml (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Events') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Resources/Styles.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Resources/Styles.xaml new file mode 100644 index 000000000..d0f24c5bb --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Resources/Styles.xaml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Tango.PPC.Events.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Tango.PPC.Events.csproj index 02929e18e..09347c02e 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Tango.PPC.Events.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Tango.PPC.Events.csproj @@ -69,6 +69,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + Designer MSBuild:Compile @@ -144,7 +148,7 @@ - + \ No newline at end of file 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); + } + } + } + }); } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Views/MainView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Views/MainView.xaml index b5666d367..7351be38b 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Views/MainView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Views/MainView.xaml @@ -5,10 +5,107 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:vm="clr-namespace:Tango.PPC.Events.ViewModels" xmlns:global="clr-namespace:Tango.PPC.Events" + xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" xmlns:local="clr-namespace:Tango.PPC.Events.Views" mc:Ignorable="d" d:DesignHeight="1280" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> - - EVENTS + + + + + + + + + + + + + + + + + + + + + Events + + + + + + + + + + + + + + + + + + + + + + + + + + + + # + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Views/MainView.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Views/MainView.xaml.cs index 6a8fe6b5a..26caab36e 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Views/MainView.xaml.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Views/MainView.xaml.cs @@ -24,5 +24,16 @@ namespace Tango.PPC.Events.Views { InitializeComponent(); } + + private void dataGridEvent_SelectionChanged(object sender, EventArgs e) + { + Task.Delay(100).ContinueWith((x) => + { + this.BeginInvoke(() => + { + dataGridEvent.LayoutRows(false); + }); + }); + } } } -- cgit v1.3.1