From ca293b80c52a54c73251fbf3cd50741fb5653ae9 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 15 Apr 2018 19:51:07 +0300 Subject: Lots Of Work ! --- .../ViewModels/ApplicationLogsViewVM.cs | 99 +++++++++++ .../ViewModels/EventsViewVM.cs | 195 +++++++++++++++++++++ .../ViewModels/HomeViewVM.cs | 28 +++ .../ViewModels/MainViewVM.cs | 192 -------------------- 4 files changed, 322 insertions(+), 192 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/ApplicationLogsViewVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/HomeViewVM.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/ApplicationLogsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/ApplicationLogsViewVM.cs new file mode 100644 index 000000000..8ddc544c0 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/ApplicationLogsViewVM.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.Logging; +using Tango.MachineStudio.Logging.Navigation; +using Tango.MachineStudio.Logging.Parsing; +using Tango.SharedUI; + +namespace Tango.MachineStudio.Logging.ViewModels +{ + public class ApplicationLogsViewVM : ViewModel + { + private ApplicationLogFileParser _parser; + private List _logFiles; + + private ObservableCollection _logs; + public ObservableCollection Logs + { + get { return _logs; } + set { _logs = value; RaisePropertyChangedAuto(); } + } + + private ObservableCollection _dates; + public ObservableCollection Dates + { + get { return _dates; } + set { _dates = value; RaisePropertyChangedAuto(); } + } + + private DateTime _selectedDate; + public DateTime SelectedDate + { + get { return _selectedDate; } + set { _selectedDate = value; RaisePropertyChangedAuto(); OnSelectedDateChanged(); } + } + + 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(); } + } + + public RelayCommand NavigateToHomeCommand { get; set; } + + public ApplicationLogsViewVM(LoggingNavigationManager navigation) + { + NavigateToHomeCommand = new RelayCommand(() => navigation.NavigateTo(LoggingNavigationView.HomeView)); + + _parser = new ApplicationLogFileParser(); + + _logFiles = _parser.GetLogFiles(); + Dates = new ObservableCollection(_logFiles.Select(x => x.DateTime).OrderBy(x => x)); + + SelectedDate = Dates.Last(); + + MinDate = Dates.Min(); + MaxDate = Dates.Max(); + } + + private void OnSelectedDateChanged() + { + if (IsRealTime) + { + //Events = _realTimeEvents; + } + else + { + List logs = new List(); + + foreach (var logFile in _logFiles.Where(x => x.DateTime.Date == SelectedDate.Date)) + { + logs.AddRange(_parser.Parse(logFile)); + } + + Logs = logs.ToObservableCollection(); + } + } + } +} 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 new file mode 100644 index 000000000..361adef01 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs @@ -0,0 +1,195 @@ +using GalaSoft.MvvmLight.Messaging; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +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.MachineStudio.Logging.Views; +using Tango.SharedUI; + +namespace Tango.MachineStudio.Logging.ViewModels +{ + public class EventsViewVM : ViewModel + { + private INotificationProvider _notification; + private IStudioApplicationManager _application; + private IEventLogger _eventLogger; + private ObservableCollection _realTimeEvents; + private Machine _connectedMachine; + private LoggingNavigationManager _navigation; + + private Machine _selectedMachine; + public Machine SelectedMachine + { + get { return _selectedMachine; } + set { _selectedMachine = value; RaisePropertyChangedAuto(); OnSelectedMachineChanged(); } + } + + private ObservableCollection _events; + public ObservableCollection Events + { + get { return _events; } + set { _events = value; RaisePropertyChangedAuto(); } + } + + private MachinesEvent _selectedEvent; + public MachinesEvent SelectedEvent + { + get { return _selectedEvent; } + set { _selectedEvent = value; RaisePropertyChangedAuto(); OnSelectedEventChanged(); } + } + + private ObservableCollection _dates; + public ObservableCollection Dates + { + get { return _dates; } + set { _dates = value; RaisePropertyChangedAuto(); } + } + + private DateTime _selectedDate; + public DateTime SelectedDate + { + get { return _selectedDate; } + set { _selectedDate = value; RaisePropertyChangedAuto(); OnSelectedDateChanged(); } + } + + 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 TimelineViewVM _timelineViewVM; + + public TimelineViewVM TimelineViewVM + { + get { return _timelineViewVM; } + set { _timelineViewVM = value; RaisePropertyChangedAuto(); } + } + + public RelayCommand DisplayTimelineCommand { get; set; } + + public RelayCommand NavigateToEventsCommand { get; set; } + + public RelayCommand NavigateToHomeCommand { get; set; } + + public EventsViewVM(INotificationProvider notification, IEventLogger eventLogger, IStudioApplicationManager application, LoggingNavigationManager navigation) + { + TimelineViewVM = new TimelineViewVM(notification); + + _navigation = navigation; + _application = application; + _notification = notification; + _eventLogger = eventLogger; + _realTimeEvents = new ObservableCollection(); + _eventLogger.NewLog += _eventLogger_NewLog; + + RegisterMessage(OnMachineConnectionChanged); + DisplayTimelineCommand = new RelayCommand(DisplayTimeline); + NavigateToEventsCommand = new RelayCommand(() => _navigation.NavigateTo(LoggingNavigationView.EventsView)); + NavigateToHomeCommand = new RelayCommand(() => _navigation.NavigateTo(LoggingNavigationView.HomeView)); + } + + private void OnMachineConnectionChanged(MachineConnectionChangedMessage msg) + { + if (msg.Machine != null) + { + _connectedMachine = ObservablesEntitiesAdapter.Instance.Machines.SingleOrDefault(x => x.SerialNumber == msg.Machine.SerialNumber); + SelectedMachine = _connectedMachine; + } + else + { + _connectedMachine = null; + } + } + + private void _eventLogger_NewLog(object sender, MachinesEvent machineEvent) + { + InvokeUI(() => + { + _realTimeEvents.Insert(0, machineEvent); + }); + } + + private void OnSelectedMachineChanged() + { + if (SelectedMachine != null) + { + Dates = new ObservableCollection(); + + if (SelectedMachine == _connectedMachine) + { + IsRealTime = true; + } + + foreach (var day in SelectedMachine.MachinesEvents.GroupBy(x => x.DateTime.DayOfYear).Select(x => x.First().DateTime).OrderByDescending(x => x)) + { + Dates.Add(day); + } + + MinDate = Dates.Min(); + MaxDate = Dates.Max(); + + SelectedDate = Dates.FirstOrDefault(); + } + } + + private void OnSelectedDateChanged() + { + if (SelectedDate != null && SelectedMachine != null) + { + if (IsRealTime) + { + Events = _realTimeEvents; + } + else + { + Events = SelectedMachine.MachinesEvents.Where(x => x.DateTime.DayOfYear == SelectedDate.Date.DayOfYear).OrderByDescending(x => x.DateTime).ToObservableCollection(); + } + } + } + + private void OnSelectedEventChanged() + { + if (SelectedEvent != null && SelectedEvent.Type != BL.Enumerations.EventTypes.ApplicationStarted) + { + _notification.ShowModalDialog(new EventDetailsViewVM(SelectedEvent), (x) => { }, () => { }); + } + } + + 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); + + TimelineViewVM.Initialize(events.ToList()); + + _navigation.NavigateTo(LoggingNavigationView.TimelineView); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/HomeViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/HomeViewVM.cs new file mode 100644 index 000000000..b87323491 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/HomeViewVM.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.MachineStudio.Logging.Navigation; +using Tango.SharedUI; + +namespace Tango.MachineStudio.Logging.ViewModels +{ + public class HomeViewVM : ViewModel + { + private LoggingNavigationManager _navigation; + + public RelayCommand NavigateToCommand { get; set; } + + public HomeViewVM(LoggingNavigationManager navigation) + { + _navigation = navigation; + + NavigateToCommand = new RelayCommand((view) => + { + navigation.NavigateTo((LoggingNavigationView)Enum.Parse(typeof(LoggingNavigationView), view)); + }); + } + } +} 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 deleted file mode 100644 index e5121e709..000000000 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs +++ /dev/null @@ -1,192 +0,0 @@ -using GalaSoft.MvvmLight.Messaging; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -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.MachineStudio.Logging.Views; -using Tango.SharedUI; - -namespace Tango.MachineStudio.Logging.ViewModels -{ - public class MainViewVM : ViewModel - { - private INotificationProvider _notification; - private IStudioApplicationManager _application; - private IEventLogger _eventLogger; - private ObservableCollection _realTimeEvents; - private Machine _connectedMachine; - private LoggingNavigationManager _navigation; - - private Machine _selectedMachine; - public Machine SelectedMachine - { - get { return _selectedMachine; } - set { _selectedMachine = value; RaisePropertyChangedAuto(); OnSelectedMachineChanged(); } - } - - private ObservableCollection _events; - public ObservableCollection Events - { - get { return _events; } - set { _events = value; RaisePropertyChangedAuto(); } - } - - private MachinesEvent _selectedEvent; - public MachinesEvent SelectedEvent - { - get { return _selectedEvent; } - set { _selectedEvent = value; RaisePropertyChangedAuto(); OnSelectedEventChanged(); } - } - - private ObservableCollection _dates; - public ObservableCollection Dates - { - get { return _dates; } - set { _dates = value; RaisePropertyChangedAuto(); } - } - - private DateTime _selectedDate; - public DateTime SelectedDate - { - get { return _selectedDate; } - set { _selectedDate = value; RaisePropertyChangedAuto(); OnSelectedDateChanged(); } - } - - 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 TimelineViewVM _timelineViewVM; - - public TimelineViewVM TimelineViewVM - { - get { return _timelineViewVM; } - set { _timelineViewVM = value; RaisePropertyChangedAuto(); } - } - - public RelayCommand DisplayTimelineCommand { get; set; } - - public RelayCommand NavigateToEventsCommand { get; set; } - - public MainViewVM(INotificationProvider notification, IEventLogger eventLogger, IStudioApplicationManager application, LoggingNavigationManager navigation) - { - TimelineViewVM = new TimelineViewVM(notification); - - _navigation = navigation; - _application = application; - _notification = notification; - _eventLogger = eventLogger; - _realTimeEvents = new ObservableCollection(); - _eventLogger.NewLog += _eventLogger_NewLog; - - RegisterMessage(OnMachineConnectionChanged); - DisplayTimelineCommand = new RelayCommand(DisplayTimeline); - NavigateToEventsCommand = new RelayCommand(() => _navigation.NavigateTo(LoggingNavigationView.EventsView)); - } - - private void OnMachineConnectionChanged(MachineConnectionChangedMessage msg) - { - if (msg.Machine != null) - { - _connectedMachine = ObservablesEntitiesAdapter.Instance.Machines.SingleOrDefault(x => x.SerialNumber == msg.Machine.SerialNumber); - SelectedMachine = _connectedMachine; - } - else - { - _connectedMachine = null; - } - } - - private void _eventLogger_NewLog(object sender, MachinesEvent machineEvent) - { - InvokeUI(() => - { - _realTimeEvents.Insert(0, machineEvent); - }); - } - - private void OnSelectedMachineChanged() - { - if (SelectedMachine != null) - { - Dates = new ObservableCollection(); - - if (SelectedMachine == _connectedMachine) - { - IsRealTime = true; - } - - foreach (var day in SelectedMachine.MachinesEvents.GroupBy(x => x.DateTime.DayOfYear).Select(x => x.First().DateTime).OrderByDescending(x => x)) - { - Dates.Add(day); - } - - MinDate = Dates.Min(); - MaxDate = Dates.Max(); - - SelectedDate = Dates.FirstOrDefault(); - } - } - - private void OnSelectedDateChanged() - { - if (SelectedDate != null && SelectedMachine != null) - { - if (IsRealTime) - { - Events = _realTimeEvents; - } - else - { - Events = SelectedMachine.MachinesEvents.Where(x => x.DateTime.DayOfYear == SelectedDate.Date.DayOfYear).OrderByDescending(x => x.DateTime).ToObservableCollection(); - } - } - } - - private void OnSelectedEventChanged() - { - if (SelectedEvent != null && SelectedEvent.Type != BL.Enumerations.EventTypes.ApplicationStarted) - { - _notification.ShowModalDialog(new EventDetailsViewVM(SelectedEvent), (x) => { }, () => { }); - } - } - - 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); - - TimelineViewVM.Initialize(events.ToList()); - - _navigation.NavigateTo(LoggingNavigationView.TimelineView); - } - } -} -- cgit v1.3.1