diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs index c813e9752..2c3886ea4 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs @@ -135,31 +135,39 @@ namespace Tango.MachineStudio.Logging.ViewModels { using (_notification.PushTaskItem("Loading machine events...")) { - await Task.Factory.StartNew(() => + try { - _db = ObservablesContext.CreateDefault(); + await Task.Factory.StartNew(() => + { + _db = ObservablesContext.CreateDefault(); - _db.EventTypes.Load(); + _db.EventTypes.Load(); - DateTime now = DateTime.UtcNow.AddMonths(-1); + DateTime now = DateTime.UtcNow.AddMonths(-1); - _history_events = _db.MachinesEvents.Where(x => x.MachineGuid == SelectedMachine.Guid && x.DateTime > now).Include(x => x.User).Include(x => x.User.Contact).Include(x => x.Machine).ToList(); + _history_events = _db.MachinesEvents.Where(x => x.MachineGuid == SelectedMachine.Guid && x.DateTime > now).Include(x => x.User).Include(x => x.User.Contact).Include(x => x.Machine).ToList(); - Dates = new ObservableCollection<DateTime>(); + Dates = new ObservableCollection<DateTime>(); - foreach (var day in _history_events.GroupBy(x => x.DateTime.DayOfYear).Select(x => x.First().DateTime).OrderByDescending(x => x)) - { - Dates.Add(day); - } + foreach (var day in _history_events.GroupBy(x => x.DateTime.DayOfYear).Select(x => x.First().DateTime).OrderByDescending(x => x)) + { + Dates.Add(day); + } - if (Dates.Count > 0) - { - MinDate = Dates.Min(); - MaxDate = Dates.Max(); - } + if (Dates.Count > 0) + { + MinDate = Dates.Min(); + MaxDate = Dates.Max(); + } - SelectedDate = Dates.FirstOrDefault(); - }); + SelectedDate = Dates.FirstOrDefault(); + }); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error loading machine events."); + _notification.ShowError($"An error occurred while trying to load the selected machine events.\n{ex.FlattenMessage()}"); + } } } } |
