aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-01-08 16:19:50 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-01-08 16:19:50 +0200
commit68be90b29a5ea3776481ee8e2fde33083c11c670 (patch)
treeb12900aae40c50df19c67be1a5cba630ad13e334 /Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels
parent65e6368cbe7eeddd02bbd43ae5159ab4b762165f (diff)
downloadTango-68be90b29a5ea3776481ee8e2fde33083c11c670.tar.gz
Tango-68be90b29a5ea3776481ee8e2fde33083c11c670.zip
Implemented PPC events history.
Fixed PPC storage inserted navigation.
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.cs115
1 files changed, 78 insertions, 37 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 dd8b8041d..a00ff869e 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
@@ -4,11 +4,14 @@ using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Tango.BL;
using Tango.BL.Entities;
using Tango.BL.Enumerations;
using Tango.PPC.Common;
using Tango.PPC.Common.Notifications;
using Tango.PPC.Common.Notifications.NotificationItems;
+using Tango.PPC.Events.Enumerations;
+using System.Data.Entity;
namespace Tango.PPC.Events.ViewModels
{
@@ -20,6 +23,13 @@ namespace Tango.PPC.Events.ViewModels
{
private Dictionary<EventTypes, NotificationItem> _notifications;
+ private EventsSource _selectedEventsSource;
+ public EventsSource SelectedEventsSource
+ {
+ get { return _selectedEventsSource; }
+ set { _selectedEventsSource = value; RaisePropertyChangedAuto(); }
+ }
+
private ObservableCollection<MachinesEvent> _currentEvents;
/// <summary>
/// Gets or sets the current events.
@@ -31,6 +41,9 @@ namespace Tango.PPC.Events.ViewModels
}
private MachinesEvent _selectedEvent;
+ /// <summary>
+ /// Gets or sets the selected event.
+ /// </summary>
public MachinesEvent SelectedEvent
{
get { return _selectedEvent; }
@@ -38,6 +51,26 @@ namespace Tango.PPC.Events.ViewModels
}
+ private ObservableCollection<MachinesEvent> _historyEvents;
+ /// <summary>
+ /// Gets or sets the history events.
+ /// </summary>
+ public ObservableCollection<MachinesEvent> HistoryEvents
+ {
+ get { return _historyEvents; }
+ set { _historyEvents = value; RaisePropertyChangedAuto(); }
+ }
+
+ private MachinesEvent _selectedHistoryEvent;
+ /// <summary>
+ /// Gets or sets the selected event.
+ /// </summary>
+ public MachinesEvent SelectedHistoryEvent
+ {
+ get { return _selectedHistoryEvent; }
+ set { _selectedHistoryEvent = value; RaisePropertyChangedAuto(); }
+ }
+
/// <summary>
/// Initializes a new instance of the <see cref="MainViewVM"/> class.
/// </summary>
@@ -56,45 +89,55 @@ namespace Tango.PPC.Events.ViewModels
EventLogger.EventResolved += EventLogger_EventResolved;
}
+ public override async void OnApplicationReady()
+ {
+ base.OnApplicationReady();
+
+ using (var db = ObservablesContext.CreateDefault())
+ {
+ var last_week = DateTime.UtcNow.AddDays(-7);
+ HistoryEvents = (await db.MachinesEvents.Where(x => x.MachineGuid == MachineProvider.Machine.Guid && x.DateTime > last_week).Include(x => x.EventType).Where(x => (EventTypeNotificationTimes)x.EventType.EventNotificationTime != EventTypeNotificationTimes.None).ToListAsync()).OrderByDescending(x => x.DateTime).ToObservableCollection();
+ }
+ }
+
private void EventLogger_EventReceived(object sender, MachinesEvent ev)
{
InvokeUI(() =>
{
- if (ev.Group != EventTypeGroups.Transport)
+ if (ev.NotificationTime != EventTypeNotificationTimes.None)
{
CurrentEvents.Insert(0, ev);
- if (ev.Group != EventTypeGroups.Application && ev.Group != EventTypeGroups.Transport)
+ var notificationItem = new MessageNotificationItem();
+ notificationItem.CanClose = false;
+ notificationItem.Message = ev.EventType.Description;
+ notificationItem.ExpandedMessage = ev.Description;
+ notificationItem.Pressed += async (_, __) =>
{
- var notificationItem = new MessageNotificationItem();
- notificationItem.CanClose = false;
- notificationItem.Message = ev.EventType.Description;
- notificationItem.ExpandedMessage = ev.Description;
- notificationItem.Pressed += async (_, __) =>
- {
- SelectedEvent = ev;
- await NavigationManager.NavigateTo<EventsModule>();
- };
-
- switch (ev.Category)
- {
- case EventTypeCategories.Info:
- notificationItem.MessageType = MessageNotificationItem.MessageNotificationItemTypes.Info;
- break;
- case EventTypeCategories.Warning:
- notificationItem.MessageType = MessageNotificationItem.MessageNotificationItemTypes.Warning;
- break;
- case EventTypeCategories.Error:
- notificationItem.MessageType = MessageNotificationItem.MessageNotificationItemTypes.Error;
- break;
- case EventTypeCategories.Critical:
- notificationItem.MessageType = MessageNotificationItem.MessageNotificationItemTypes.Critical;
- break;
- }
+ SelectedEventsSource = EventsSource.CURRENT;
+ SelectedEvent = ev;
+ await NavigationManager.NavigateTo<EventsModule>();
+ };
- NotificationProvider.PushNotification(notificationItem);
- _notifications.Add(ev.EventType.Type, notificationItem);
+ switch (ev.Category)
+ {
+ case EventTypeCategories.Info:
+ notificationItem.MessageType = MessageNotificationItem.MessageNotificationItemTypes.Info;
+ break;
+ case EventTypeCategories.Warning:
+ notificationItem.MessageType = MessageNotificationItem.MessageNotificationItemTypes.Warning;
+ break;
+ case EventTypeCategories.Error:
+ notificationItem.MessageType = MessageNotificationItem.MessageNotificationItemTypes.Error;
+ break;
+ case EventTypeCategories.Critical:
+ notificationItem.MessageType = MessageNotificationItem.MessageNotificationItemTypes.Critical;
+ break;
}
+
+ NotificationProvider.PushNotification(notificationItem);
+ _notifications.Add(ev.EventType.Type, notificationItem);
+
}
});
}
@@ -103,18 +146,16 @@ namespace Tango.PPC.Events.ViewModels
{
InvokeUI(() =>
{
- if (ev.Group != EventTypeGroups.Transport)
+ if (ev.NotificationTime != EventTypeNotificationTimes.None)
{
CurrentEvents.Remove(ev);
+ HistoryEvents.Insert(0, ev);
- if (ev.Group != EventTypeGroups.Application && ev.Group != EventTypeGroups.Transport)
+ if (_notifications.ContainsKey(ev.EventType.Type))
{
- if (_notifications.ContainsKey(ev.EventType.Type))
- {
- var notification = _notifications[ev.EventType.Type];
- _notifications.Remove(ev.EventType.Type);
- NotificationProvider.PopNotification(notification);
- }
+ var notification = _notifications[ev.EventType.Type];
+ _notifications.Remove(ev.EventType.Type);
+ NotificationProvider.PopNotification(notification);
}
}
});