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 ! --- .../Images/application-logs.png | Bin 0 -> 16421 bytes .../Images/embedded-logs.png | Bin 0 -> 19230 bytes .../Tango.MachineStudio.Logging/Images/events.png | Bin 0 -> 32989 bytes .../Navigation/LoggingNavigationView.cs | 3 + .../Parsing/ApplicationLogFileParser.cs | 64 +++++++ .../Parsing/EmbeddedLogFileParser.cs | 70 ++++++++ .../Parsing/ILogFileParser.cs | 15 ++ .../Tango.MachineStudio.Logging/Parsing/LogFile.cs | 15 ++ .../Tango.MachineStudio.Logging.csproj | 31 +++- .../ViewModelLocator.cs | 24 ++- .../ViewModels/ApplicationLogsViewVM.cs | 99 +++++++++++ .../ViewModels/EventsViewVM.cs | 195 ++++++++++++++++++++ .../ViewModels/HomeViewVM.cs | 28 +++ .../ViewModels/MainViewVM.cs | 192 -------------------- .../Views/ApplicationLogsView.xaml | 196 +++++++++++++++++++++ .../Views/ApplicationLogsView.xaml.cs | 28 +++ .../Views/EventsView.xaml | 9 +- .../Views/HomeView.xaml | 87 +++++++++ .../Views/HomeView.xaml.cs | 28 +++ .../Views/MainView.xaml | 8 +- .../Views/TimelineWrapperView.xaml | 2 +- 21 files changed, 895 insertions(+), 199 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/application-logs.png create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/embedded-logs.png create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/events.png create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/ApplicationLogFileParser.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/EmbeddedLogFileParser.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/ILogFileParser.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/LogFile.cs 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 create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/ApplicationLogsView.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/ApplicationLogsView.xaml.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/HomeView.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/HomeView.xaml.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/application-logs.png b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/application-logs.png new file mode 100644 index 000000000..584379dc8 Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/application-logs.png differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/embedded-logs.png b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/embedded-logs.png new file mode 100644 index 000000000..86cd56486 Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/embedded-logs.png differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/events.png b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/events.png new file mode 100644 index 000000000..437679cd6 Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Images/events.png differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Navigation/LoggingNavigationView.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Navigation/LoggingNavigationView.cs index 6f4fcbceb..e8a14cc3d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Navigation/LoggingNavigationView.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Navigation/LoggingNavigationView.cs @@ -8,7 +8,10 @@ namespace Tango.MachineStudio.Logging.Navigation { public enum LoggingNavigationView { + HomeView, EventsView, TimelineView, + ApplicationLogsView, + EmbeddedLogsView, } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/ApplicationLogFileParser.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/ApplicationLogFileParser.cs new file mode 100644 index 000000000..d082aeca6 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/ApplicationLogFileParser.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Tango.Logging; + +namespace Tango.MachineStudio.Logging.Parsing +{ + public class ApplicationLogFileParser : ILogFileParser + { + public List GetLogFiles() + { + List logFiles = new List(); + + foreach (var file in Directory.GetFiles(FileLogger.DefaultLogsFolder, "*.log").Where(x => Path.GetFileName(x).StartsWith("Tango.MachineStudio.UI"))) + { + String dateString = Path.GetFileNameWithoutExtension(file).Replace("Tango.MachineStudio.UI-", ""); + DateTime date = DateTime.ParseExact(dateString, "dd-MM-yyyy_HH-mm-ss", CultureInfo.InvariantCulture); + logFiles.Add(new LogFile() { DateTime = date, File = file }); + } + + return logFiles; + } + + public List Parse(LogFile logFile) + { + List logItems = new List(); + + String text = File.ReadAllText(logFile.File); + var logs = Regex.Split(text, @"(\[\d{2}:\d{2}:\d{2}.\d{2}\])"); + + for (int i = 1; i < logs.Length; i += 2) + { + try + { + DateTime date = DateTime.ParseExact(logs[i].Replace("[", "").Replace("]", ""), "HH:mm:ss.ff", CultureInfo.InvariantCulture); + String rest = logs[i + 1]; + + var entries = Regex.Split(rest, @"\[(.*?)\]"); + + MessageLogItem item = new MessageLogItem(); + item.TimeStamp = new DateTime(logFile.DateTime.Year, logFile.DateTime.Month, logFile.DateTime.Day, date.Hour, date.Minute, date.Second, date.Millisecond); + item.Category = (LogCategory)Enum.Parse(typeof(LogCategory), entries[1]); + item.CallerFile = entries[3]; + item.CallerMethodName = entries[5]; + item.CallerLineNumber = int.Parse(entries[7]); + item.Message = new String(entries[8].Skip(2).ToArray()); + + logItems.Add(item); + } + catch (Exception ex) + { + //TODO: What to do now ? + } + } + + return logItems; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/EmbeddedLogFileParser.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/EmbeddedLogFileParser.cs new file mode 100644 index 000000000..76ca0d162 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/EmbeddedLogFileParser.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Tango.Integration.Operation; +using Tango.Logging; +using Tango.Settings; + +namespace Tango.MachineStudio.Logging.Parsing +{ + public class EmbeddedLogFileParser : ILogFileParser + { + public List GetLogFiles() + { + List logFiles = new List(); + + foreach (var file in Directory.GetFiles(SettingsManager.DefaultFolder + "\\embedded logs", "*.log").Where(x => Path.GetFileName(x).StartsWith("embedded"))) + { + String dateString = Path.GetFileNameWithoutExtension(file).Replace("embedded-", ""); + DateTime date = DateTime.ParseExact(dateString, "dd-MM-yyyy_HH-mm-ss", CultureInfo.InvariantCulture); + logFiles.Add(new LogFile() { DateTime = date, File = file }); + } + + return logFiles; + } + + public List Parse(LogFile logFile) + { + List logItems = new List(); + + String text = File.ReadAllText(logFile.File); + var logs = Regex.Split(text, @"(\[\d{2}:\d{2}:\d{2}.\d{2}\])"); + + for (int i = 1; i < logs.Length; i += 2) + { + try + { + DateTime date = DateTime.ParseExact(logs[i].Replace("[", "").Replace("]", ""), "HH:mm:ss.ff", CultureInfo.InvariantCulture); + String rest = logs[i + 1]; + + var entries = Regex.Split(rest, @"\[(.*?)\]"); + + EmbeddedLogItem item = new EmbeddedLogItem(new PMR.Debugging.DebugLogResponse() + { + Category = (PMR.Debugging.DebugLogCategory)Enum.Parse(typeof(PMR.Debugging.DebugLogCategory), entries[1]), + FileName = entries[3], + LineNumber = uint.Parse(entries[5]), + ModuleId = uint.Parse(entries[7]), + Filter = uint.Parse(entries[9]), + Message = new String(entries[10].Skip(2).ToArray()) + }); + + item.TimeStamp = new DateTime(logFile.DateTime.Year, logFile.DateTime.Month, logFile.DateTime.Day, date.Hour, date.Minute, date.Second, date.Millisecond); + + logItems.Add(item); + } + catch (Exception ex) + { + //TODO: What to do now ? + } + } + + return logItems; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/ILogFileParser.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/ILogFileParser.cs new file mode 100644 index 000000000..05003c1a2 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/ILogFileParser.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Logging.Parsing +{ + public interface ILogFileParser + { + List Parse(LogFile logFile); + + List GetLogFiles(); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/LogFile.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/LogFile.cs new file mode 100644 index 000000000..4248bdbdc --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Parsing/LogFile.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Logging.Parsing +{ + public class LogFile + { + public DateTime DateTime { get; set; } + + public String File { get; set; } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Tango.MachineStudio.Logging.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Tango.MachineStudio.Logging.csproj index b893dcb53..42229544a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Tango.MachineStudio.Logging.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Tango.MachineStudio.Logging.csproj @@ -93,17 +93,29 @@ + + + + + - + + EventDetailsView.xaml + + ApplicationLogsView.xaml + EventsView.xaml + + HomeView.xaml + MainView.xaml @@ -189,10 +201,18 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -209,5 +229,14 @@ + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModelLocator.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModelLocator.cs index ef6923e27..0b1af937f 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModelLocator.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModelLocator.cs @@ -18,17 +18,35 @@ namespace Tango.MachineStudio.Logging static ViewModelLocator() { ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); - SimpleIoc.Default.Register(); + SimpleIoc.Default.Register(); + SimpleIoc.Default.Register(); + SimpleIoc.Default.Register(); SimpleIoc.Default.Unregister(); SimpleIoc.Default.Register(() => new LoggingNavigationManager()); } - public static MainViewVM MainViewVM + public static EventsViewVM EventsViewVM { get { - return ServiceLocator.Current.GetInstance(); + return ServiceLocator.Current.GetInstance(); + } + } + + public static ApplicationLogsViewVM ApplicationLogsViewVM + { + get + { + return ServiceLocator.Current.GetInstance(); + } + } + + public static HomeViewVM HomeViewVM + { + get + { + return ServiceLocator.Current.GetInstance(); } } } 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); - } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/ApplicationLogsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/ApplicationLogsView.xaml new file mode 100644 index 000000000..1274f6523 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/ApplicationLogsView.xaml @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Real-Time + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/ApplicationLogsView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/ApplicationLogsView.xaml.cs new file mode 100644 index 000000000..6cdf6ea53 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/ApplicationLogsView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.MachineStudio.Logging.Views +{ + /// + /// Interaction logic for EventsView.xaml + /// + public partial class ApplicationLogsView : UserControl + { + public ApplicationLogsView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/EventsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/EventsView.xaml index d92e56ddc..3089ad610 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/EventsView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/EventsView.xaml @@ -12,7 +12,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Tango.MachineStudio.Logging.Views" mc:Ignorable="d" - d:DesignHeight="1080" d:DesignWidth="1920" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> + d:DesignHeight="1080" d:DesignWidth="1920" d:DataContext="{d:DesignInstance Type=vm:EventsViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.EventsViewVM}"> @@ -56,6 +56,13 @@ + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/HomeView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/HomeView.xaml new file mode 100644 index 000000000..b41351064 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/HomeView.xaml @@ -0,0 +1,87 @@ + + + + + + + + + + Machine Studio logs information from multiple source. + + + + • Machine Events are predefined events that occurs only when a set of predefined actions have occurred (e.g 'Job executed', 'Thread Break'). + + + • Application Logs are the standard machine studio logs which can be used to trace issues in code. + + + • Embedded Logs are logs transmitted from the machine's embedded device software. + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/HomeView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/HomeView.xaml.cs new file mode 100644 index 000000000..36d261a2f --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/HomeView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.MachineStudio.Logging.Views +{ + /// + /// Interaction logic for HomeView.xaml + /// + public partial class HomeView : UserControl + { + public HomeView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/MainView.xaml index 6d5f98b51..b6ac29893 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/MainView.xaml @@ -13,11 +13,17 @@ xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:vm="clr-namespace:Tango.MachineStudio.Logging.ViewModels" mc:Ignorable="d" - d:DesignHeight="1080" d:DesignWidth="1920" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> + d:DesignHeight="1080" d:DesignWidth="1920" d:DataContext="{d:DesignInstance Type=vm:EventsViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.EventsViewVM}"> + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/TimelineWrapperView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/TimelineWrapperView.xaml index abab55264..b436c55f5 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/TimelineWrapperView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Views/TimelineWrapperView.xaml @@ -8,7 +8,7 @@ xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:local="clr-namespace:Tango.MachineStudio.Logging.Views" mc:Ignorable="d" - d:DesignHeight="1080" d:DesignWidth="1920" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> + d:DesignHeight="1080" d:DesignWidth="1920" d:DataContext="{d:DesignInstance Type=vm:EventsViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.EventsViewVM}"> -- cgit v1.3.1