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 +++ .../Tango.PPC.Jobs/ViewModels/MainViewVM.cs | 56 ------------ .../Modules/Tango.PPC.Storage/Views/MainView.xaml | 2 +- 7 files changed, 284 insertions(+), 62 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Resources/Styles.xaml (limited to 'Software/Visual_Studio/PPC/Modules') 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); + }); + }); + } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs index af2e44615..5b4a3e403 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs @@ -20,13 +20,6 @@ namespace Tango.PPC.Jobs.ViewModels /// public class MainViewVM : PPCViewModel { - private Dictionary _notifications; - - public MainViewVM() : base() - { - _notifications = new Dictionary(); - } - /// /// Called when the application has been started. /// @@ -34,8 +27,6 @@ namespace Tango.PPC.Jobs.ViewModels { MachineProvider.MachineOperator.PrintingCompleted += MachineOperator_PrintingCompleted; MachineProvider.MachineOperator.PrintingFailed += MachineOperator_PrintingFailed; - MachineProvider.MachineOperator.MachineEventsStateProvider.NewEvents += MachineEventsStateProvider_NewEvents; - MachineProvider.MachineOperator.MachineEventsStateProvider.EventsResolved += MachineEventsStateProvider_EventsResolved; } /// @@ -88,52 +79,5 @@ namespace Tango.PPC.Jobs.ViewModels })); } } - - private void MachineEventsStateProvider_NewEvents(object sender, IEnumerable events) - { - foreach (var item in events) - { - var notificationItem = new MessageNotificationItem(); - notificationItem.CanClose = false; - notificationItem.Message = item.EventType.Description; - notificationItem.ExpandedMessage = item.Description; - notificationItem.Pressed += (_, __) => - { - NotificationProvider.ShowInfo($"{item.EventType.Description} Selected !"); - }; - - switch (item.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(item.EventType.Type, notificationItem); - } - } - - private void MachineEventsStateProvider_EventsResolved(object sender, IEnumerable events) - { - foreach (var item in events) - { - if (_notifications.ContainsKey(item.EventType.Type)) - { - var notification = _notifications[item.EventType.Type]; - _notifications.Remove(item.EventType.Type); - NotificationProvider.PopNotification(notification); - } - } - } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/Views/MainView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/Views/MainView.xaml index 840149c98..3b098f557 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/Views/MainView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/Views/MainView.xaml @@ -15,7 +15,7 @@ - + -- cgit v1.3.1