aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-03-27 19:51:29 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-03-27 19:51:29 +0300
commit953fc4deb9d94a63afe07d66ccf78ff42f54c3bb (patch)
tree9bc9eb73130a7f8bdc82f8f64b81476f78123d52 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs
parent69fb24f927bd0954a2765c71b09545df3fbba73c (diff)
downloadTango-953fc4deb9d94a63afe07d66ccf78ff42f54c3bb.tar.gz
Tango-953fc4deb9d94a63afe07d66ccf78ff42f54c3bb.zip
Working on logging module!
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs115
1 files changed, 101 insertions, 14 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs
index 2b773c1c2..81b0a587c 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs
@@ -7,10 +7,12 @@ using System.Text;
using System.Threading.Tasks;
using Tango.BL;
using Tango.BL.Entities;
+using Tango.Core.Commands;
using Tango.MachineStudio.Common.EventLogging;
using Tango.MachineStudio.Common.Messages;
using Tango.MachineStudio.Common.Notifications;
using Tango.MachineStudio.Common.StudioApplication;
+using Tango.MachineStudio.Logging.Navigation;
using Tango.SharedUI;
namespace Tango.MachineStudio.Logging.ViewModels
@@ -20,9 +22,9 @@ namespace Tango.MachineStudio.Logging.ViewModels
private INotificationProvider _notification;
private IStudioApplicationManager _application;
private IEventLogger _eventLogger;
- private DateVM _realTimeDate;
private ObservableCollection<MachinesEvent> _realTimeEvents;
private Machine _connectedMachine;
+ private LoggingNavigationManager _navigation;
private Machine _selectedMachine;
public Machine SelectedMachine
@@ -45,30 +47,88 @@ namespace Tango.MachineStudio.Logging.ViewModels
set { _selectedEvent = value; RaisePropertyChangedAuto(); OnSelectedEventChanged(); }
}
- private ObservableCollection<DateVM> _dates;
- public ObservableCollection<DateVM> Dates
+ private ObservableCollection<DateTime> _dates;
+ public ObservableCollection<DateTime> Dates
{
get { return _dates; }
set { _dates = value; RaisePropertyChangedAuto(); }
}
- private DateVM _selectedDate;
- public DateVM SelectedDate
+ private DateTime _selectedDate;
+ public DateTime SelectedDate
{
get { return _selectedDate; }
set { _selectedDate = value; RaisePropertyChangedAuto(); OnSelectedDateChanged(); }
}
- public MainViewVM(INotificationProvider notification, IEventLogger eventLogger, IStudioApplicationManager application)
+ private DateTime _minDate;
+ public DateTime MinDate
{
+ get { return _minDate; }
+ set { _minDate = value; RaisePropertyChangedAuto(); }
+ }
+
+ private DateTime _maxDate;
+ public DateTime MaxDate
+ {
+ get { return _maxDate; }
+ set { _maxDate = value; RaisePropertyChangedAuto(); }
+ }
+
+
+ private bool _isRealTime;
+ public bool IsRealTime
+ {
+ get { return _isRealTime; }
+ set { _isRealTime = value; RaisePropertyChangedAuto(); OnSelectedDateChanged(); }
+ }
+
+ private ObservableCollection<TimelineEventGroup> _timelineEventGroups;
+ public ObservableCollection<TimelineEventGroup> TimelineEventGroups
+ {
+ get { return _timelineEventGroups; }
+ set { _timelineEventGroups = value; RaisePropertyChangedAuto(); }
+ }
+
+ private TimeSpan _timelineMaxTime;
+ public TimeSpan TimelineMaxTime
+ {
+ get { return _timelineMaxTime; }
+ set { _timelineMaxTime = value; RaisePropertyChangedAuto(); }
+ }
+
+ private double _timelineScaleFactor;
+ public double TimelineScaleFactor
+ {
+ get { return _timelineScaleFactor; }
+ set
+ {
+
+ if (value < 0.1) value = 0.1;
+
+ _timelineScaleFactor = value;
+ RaisePropertyChangedAuto();
+ }
+ }
+
+ public RelayCommand<MachinesEvent> DisplayTimelineCommand { get; set; }
+
+ public RelayCommand NavigateToEventsCommand { get; set; }
+
+ public MainViewVM(INotificationProvider notification, IEventLogger eventLogger, IStudioApplicationManager application, LoggingNavigationManager navigation)
+ {
+ _navigation = navigation;
_application = application;
_notification = notification;
_eventLogger = eventLogger;
- _realTimeDate = new DateVM(DateTime.Now) { Description = "Real Time" };
_realTimeEvents = new ObservableCollection<MachinesEvent>();
_eventLogger.NewLog += _eventLogger_NewLog;
+ TimelineScaleFactor = 10;
+
RegisterMessage<MachineConnectionChangedMessage>(OnMachineConnectionChanged);
+ DisplayTimelineCommand = new RelayCommand<MachinesEvent>(DisplayTimeline);
+ NavigateToEventsCommand = new RelayCommand(() => _navigation.NavigateTo(LoggingNavigationView.EventsView));
}
private void OnMachineConnectionChanged(MachineConnectionChangedMessage msg)
@@ -88,7 +148,7 @@ namespace Tango.MachineStudio.Logging.ViewModels
{
InvokeUI(() =>
{
- _realTimeEvents.Add(machineEvent);
+ _realTimeEvents.Insert(0, machineEvent);
});
}
@@ -96,27 +156,30 @@ namespace Tango.MachineStudio.Logging.ViewModels
{
if (SelectedMachine != null)
{
- Dates = new ObservableCollection<DateVM>();
+ Dates = new ObservableCollection<DateTime>();
if (SelectedMachine == _connectedMachine)
{
- Dates.Add(_realTimeDate);
+ IsRealTime = true;
}
foreach (var day in SelectedMachine.MachinesEvents.GroupBy(x => x.DateTime.DayOfYear).Select(x => x.First().DateTime).OrderByDescending(x => x))
{
- Dates.Add(new DateVM(day));
+ Dates.Add(day);
}
+ MinDate = Dates.Min();
+ MaxDate = Dates.Max();
+
SelectedDate = Dates.FirstOrDefault();
}
}
private void OnSelectedDateChanged()
{
- if (SelectedDate != null)
+ if (SelectedDate != null && SelectedMachine != null)
{
- if (SelectedDate == _realTimeDate)
+ if (IsRealTime)
{
Events = _realTimeEvents;
}
@@ -129,10 +192,34 @@ namespace Tango.MachineStudio.Logging.ViewModels
private void OnSelectedEventChanged()
{
- if (SelectedEvent != null)
+ if (SelectedEvent != null && SelectedEvent.Type != BL.Enumerations.EventTypes.ApplicationStarted)
{
_notification.ShowInfo(SelectedEvent.Description);
}
}
+
+ private void DisplayTimeline(MachinesEvent ev)
+ {
+ var events = Events.OrderBy(x => x.DateTime).SkipWhile(x => x != ev).Skip(1).TakeWhile(x => x.DateTime > ev.DateTime && x.Type != BL.Enumerations.EventTypes.ApplicationStarted).ToObservableCollection();
+ events.Insert(0, ev);
+
+ TimelineEventGroups = new ObservableCollection<TimelineEventGroup>();
+
+ foreach (var group in events.GroupBy(x => x.Group))
+ {
+ TimelineEventGroup evGroup = new TimelineEventGroup(group.Key.ToString().ToWords());
+
+ foreach (var e in group)
+ {
+ evGroup.Events.Add(e);
+ }
+
+ TimelineEventGroups.Add(evGroup);
+ }
+
+ TimelineMaxTime = events.Max(x => x.DateTime) - events.Min(x => x.DateTime);
+
+ _navigation.NavigateTo(LoggingNavigationView.TimelineView);
+ }
}
}