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 +- .../ViewModels/MachineTechViewVM.cs | 400 ++++++++++++--------- .../Tango.MachineStudio.UI/App.xaml.cs | 6 +- .../Modules/DefaultStudioModuleLoader.cs | 7 +- .../ViewModels/MainViewVM.cs | 6 +- .../Tango.MachineStudio.UI/Views/MainView.xaml.cs | 5 + 26 files changed, 1142 insertions(+), 376 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') 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}"> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs index 63aca3e70..88c50b549 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs @@ -29,6 +29,7 @@ using Tango.SharedUI; using Tango.Integration.Services; using Tango.BL.Enumerations; using Tango.BL; +using Tango.MachineStudio.Common.EventLogging; namespace Tango.MachineStudio.Technician.ViewModels { @@ -45,6 +46,7 @@ namespace Tango.MachineStudio.Technician.ViewModels private static object _elementsLock = new object(); private String _lastTechProjectFile; private INotificationProvider _notification; + private IEventLogger _eventLogger; private DateTime _lastDiagnosticsResponseUpdate; private const int MIN_DIAGNOSTICS_UPDATE_MILI = 500; @@ -171,9 +173,10 @@ namespace Tango.MachineStudio.Technician.ViewModels /// /// The application manager. /// The notification provider. - public MachineTechViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IDiagnosticsFrameProvider _diagnosticsFrameProvider) + public MachineTechViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IDiagnosticsFrameProvider _diagnosticsFrameProvider, IEventLogger eventLogger) { _notification = notificationProvider; + _eventLogger = eventLogger; _singleControllers = new Dictionary(); _multiControllers = new Dictionary(); AvailableTechItems = TechItem.GetAvailableTechItems().ToObservableCollection(); @@ -581,7 +584,8 @@ namespace Tango.MachineStudio.Technician.ViewModels else if (item is ControllerItem) { (item as ControllerItem).TechController = Adapter.TechControllers.FirstOrDefault(x => x.Guid == item.ItemGuid); - CreateElement(item); + var editor = CreateElement(item); + InitControllerItem(editor.ControllerItem); } } @@ -695,68 +699,78 @@ namespace Tango.MachineStudio.Technician.ViewModels { item.ActionExecuted += async (x, action) => { - if (action == MotorActionType.ForwardPressed) - { - await MachineOperator.StartMotorJogging(new MotorJoggingRequest() - { - Code = item.TechMotor.Code, - Direction = MotorDirection.Forward, - }); - } - else if (action == MotorActionType.ForwardReleased) + try { - await MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + CheckMachineOperator(); + + if (action == MotorActionType.ForwardPressed) { - Code = item.TechMotor.Code, - }); - } - else if (action == MotorActionType.BackwardPressed) - { - await MachineOperator.StartMotorJogging(new MotorJoggingRequest() + await MachineOperator.StartMotorJogging(new MotorJoggingRequest() + { + Code = item.TechMotor.Code, + Direction = MotorDirection.Forward, + }); + } + else if (action == MotorActionType.ForwardReleased) { - Code = item.TechMotor.Code, - Direction = MotorDirection.Backward, - }); - } - else if (action == MotorActionType.BackwardReleased) - { - await MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + await MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + { + Code = item.TechMotor.Code, + }); + } + else if (action == MotorActionType.BackwardPressed) { - Code = item.TechMotor.Code, - }); - } - else if (action == MotorActionType.HomingStarted) - { - item.HomingProgress = 0; - item.IsHoming = true; - item.IsHomingCompleted = false; - - MachineOperator.StartMotorHoming(new MotorHomingRequest() + await MachineOperator.StartMotorJogging(new MotorJoggingRequest() + { + Code = item.TechMotor.Code, + Direction = MotorDirection.Backward, + }); + } + else if (action == MotorActionType.BackwardReleased) { - Code = item.TechMotor.Code - }) - .Subscribe((response) => + await MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + { + Code = item.TechMotor.Code, + }); + } + else if (action == MotorActionType.HomingStarted) { + item.HomingProgress = 0; + item.IsHoming = true; + item.IsHomingCompleted = false; - item.HomingMaximumProgress = response.MaxProgress; - item.HomingProgress = response.Progress; + MachineOperator.StartMotorHoming(new MotorHomingRequest() + { + Code = item.TechMotor.Code + }) + .Subscribe((response) => + { - }, () => + item.HomingMaximumProgress = response.MaxProgress; + item.HomingProgress = response.Progress; + + }, () => + { + + item.IsHoming = false; + item.IsHomingCompleted = true; + + }); + } + else if (action == MotorActionType.HomingStopped) { + await MachineOperator.StopMotorHoming(new MotorAbortHomingRequest() + { + Code = item.TechMotor.Code, + }); item.IsHoming = false; - item.IsHomingCompleted = true; - - }); + } } - else if (action == MotorActionType.HomingStopped) + catch (Exception ex) { - await MachineOperator.StopMotorHoming(new MotorAbortHomingRequest() - { - Code = item.TechMotor.Code, - }); - - item.IsHoming = false; + LogManager.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action,item.TechName)); + _eventLogger.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName)); } }; } @@ -769,68 +783,78 @@ namespace Tango.MachineStudio.Technician.ViewModels { item.ActionExecuted += async (x, action) => { - if (action == MotorActionType.ForwardPressed) - { - await MachineOperator.StartDispenserJogging(new DispenserJoggingRequest() - { - Code = item.TechDispenser.Code, - Direction = MotorDirection.Forward, - }); - } - else if (action == MotorActionType.ForwardReleased) + try { - await MachineOperator.StopDispenserJogging(new DispenserAbortJoggingRequest() + CheckMachineOperator(); + + if (action == MotorActionType.ForwardPressed) { - Code = item.TechDispenser.Code, - }); - } - else if (action == MotorActionType.BackwardPressed) - { - await MachineOperator.StartDispenserJogging(new DispenserJoggingRequest() + await MachineOperator.StartDispenserJogging(new DispenserJoggingRequest() + { + Code = item.TechDispenser.Code, + Direction = MotorDirection.Forward, + }); + } + else if (action == MotorActionType.ForwardReleased) { - Code = item.TechDispenser.Code, - Direction = MotorDirection.Backward, - }); - } - else if (action == MotorActionType.BackwardReleased) - { - await MachineOperator.StopDispenserJogging(new DispenserAbortJoggingRequest() + await MachineOperator.StopDispenserJogging(new DispenserAbortJoggingRequest() + { + Code = item.TechDispenser.Code, + }); + } + else if (action == MotorActionType.BackwardPressed) { - Code = item.TechDispenser.Code, - }); - } - else if (action == MotorActionType.HomingStarted) - { - item.HomingProgress = 0; - item.IsHoming = true; - item.IsHomingCompleted = false; - - MachineOperator.StartDispenserHoming(new DispenserHomingRequest() + await MachineOperator.StartDispenserJogging(new DispenserJoggingRequest() + { + Code = item.TechDispenser.Code, + Direction = MotorDirection.Backward, + }); + } + else if (action == MotorActionType.BackwardReleased) { - Code = item.TechDispenser.Code - }) - .Subscribe((response) => + await MachineOperator.StopDispenserJogging(new DispenserAbortJoggingRequest() + { + Code = item.TechDispenser.Code, + }); + } + else if (action == MotorActionType.HomingStarted) { + item.HomingProgress = 0; + item.IsHoming = true; + item.IsHomingCompleted = false; - item.HomingMaximumProgress = response.MaxProgress; - item.HomingProgress = response.Progress; + MachineOperator.StartDispenserHoming(new DispenserHomingRequest() + { + Code = item.TechDispenser.Code + }) + .Subscribe((response) => + { + + item.HomingMaximumProgress = response.MaxProgress; + item.HomingProgress = response.Progress; + + }, () => + { + + item.IsHoming = false; + item.IsHomingCompleted = true; - }, () => + }); + } + else if (action == MotorActionType.HomingStopped) { + await MachineOperator.StopDispenserHoming(new DispenserAbortHomingRequest() + { + Code = item.TechDispenser.Code, + }); item.IsHoming = false; - item.IsHomingCompleted = true; - - }); + } } - else if (action == MotorActionType.HomingStopped) + catch (Exception ex) { - await MachineOperator.StopDispenserHoming(new DispenserAbortHomingRequest() - { - Code = item.TechDispenser.Code, - }); - - item.IsHoming = false; + LogManager.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName)); + _eventLogger.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName)); } }; } @@ -886,23 +910,33 @@ namespace Tango.MachineStudio.Technician.ViewModels { item.ActionExecuted += async (x, action) => { - if (action == MotorActionType.ForwardPressed) + try { - await MachineOperator.StartThreadJogging(new ThreadJoggingRequest() + CheckMachineOperator(); + + if (action == MotorActionType.ForwardPressed) { - Direction = MotorDirection.Forward, - }); - } - else if (action == MotorActionType.BackwardPressed) - { - await MachineOperator.StartThreadJogging(new ThreadJoggingRequest() + await MachineOperator.StartThreadJogging(new ThreadJoggingRequest() + { + Direction = MotorDirection.Forward, + }); + } + else if (action == MotorActionType.BackwardPressed) { - Direction = MotorDirection.Backward, - }); + await MachineOperator.StartThreadJogging(new ThreadJoggingRequest() + { + Direction = MotorDirection.Backward, + }); + } + else if (action == MotorActionType.ForwardReleased || action == MotorActionType.BackwardReleased) + { + await MachineOperator.StopThreadJogging(new ThreadAbortJoggingRequest()); + } } - else if (action == MotorActionType.ForwardReleased || action == MotorActionType.BackwardReleased) + catch (Exception ex) { - await MachineOperator.StopThreadJogging(new ThreadAbortJoggingRequest()); + LogManager.Log(ex, String.Format(String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName))); + _eventLogger.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName)); } }; } @@ -915,69 +949,79 @@ namespace Tango.MachineStudio.Technician.ViewModels { item.ActionExecuted += async (x, action) => { - if (action == MotorActionType.ForwardPressed) + try { - await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StartMotorJogging(new MotorJoggingRequest() + CheckMachineOperator(); + + if (action == MotorActionType.ForwardPressed) { - Code = motor.Code, - Direction = MotorDirection.Forward, - }))); - } - else if (action == MotorActionType.ForwardReleased) - { - await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StartMotorJogging(new MotorJoggingRequest() + { + Code = motor.Code, + Direction = MotorDirection.Forward, + }))); + } + else if (action == MotorActionType.ForwardReleased) { - Code = motor.Code, - }))); - } - else if (action == MotorActionType.BackwardPressed) - { - await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StartMotorJogging(new MotorJoggingRequest() + await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + { + Code = motor.Code, + }))); + } + else if (action == MotorActionType.BackwardPressed) + { + await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StartMotorJogging(new MotorJoggingRequest() + { + Code = motor.Code, + Direction = MotorDirection.Backward, + }))); + } + else if (action == MotorActionType.BackwardReleased) { - Code = motor.Code, - Direction = MotorDirection.Backward, - }))); + await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + { + Code = motor.Code, + }))); + } + //else if (action == MotorActionType.HomingStarted) + //{ + // item.HomingProgress = 0; + // item.IsHoming = true; + // item.IsHomingCompleted = false; + + // MachineOperator.StartMotorHoming(new MotorHomingRequest() + // { + // Code = item.TechMotor.Code + // }) + // .Subscribe((response) => + // { + + // item.HomingMaximumProgress = response.Message.MaxProgress; + // item.HomingProgress = response.Message.Progress; + + // }, () => + // { + + // item.IsHoming = false; + // item.IsHomingCompleted = true; + + // }); + //} + //else if (action == MotorActionType.HomingStopped) + //{ + // await MachineOperator.StopMotorHoming(new MotorAbortHomingRequest() + // { + // Code = item.TechMotor.Code, + // }); + + // item.IsHoming = false; + //} } - else if (action == MotorActionType.BackwardReleased) + catch (Exception ex) { - await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() - { - Code = motor.Code, - }))); + LogManager.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName)); + _eventLogger.Log(ex, String.Format("Error executing technician command '{0}' on item '{1}'.", action, item.TechName)); } - //else if (action == MotorActionType.HomingStarted) - //{ - // item.HomingProgress = 0; - // item.IsHoming = true; - // item.IsHomingCompleted = false; - - // MachineOperator.StartMotorHoming(new MotorHomingRequest() - // { - // Code = item.TechMotor.Code - // }) - // .Subscribe((response) => - // { - - // item.HomingMaximumProgress = response.Message.MaxProgress; - // item.HomingProgress = response.Message.Progress; - - // }, () => - // { - - // item.IsHoming = false; - // item.IsHomingCompleted = true; - - // }); - //} - //else if (action == MotorActionType.HomingStopped) - //{ - // await MachineOperator.StopMotorHoming(new MotorAbortHomingRequest() - // { - // Code = item.TechMotor.Code, - // }); - - // item.IsHoming = false; - //} }; } @@ -991,11 +1035,13 @@ namespace Tango.MachineStudio.Technician.ViewModels { try { + CheckMachineOperator(); await MachineOperator.SetDigitalOut(new SetDigitalOutRequest() { Port = item.TechIo.Port, Value = value }); } catch (Exception ex) { - //TODO: Show Exception. + LogManager.Log(ex, String.Format("Error executing technician set digital out command on '{0}'.", item.TechName)); + _eventLogger.Log(ex, String.Format("Error executing technician set digital out command on '{0}'.", item.TechName)); } }; } @@ -1010,6 +1056,7 @@ namespace Tango.MachineStudio.Technician.ViewModels { try { + CheckMachineOperator(); await MachineOperator.SetComponentValue(new SetComponentValueRequest() { Component = (ValueComponent)item.TechController.Code, @@ -1018,11 +1065,24 @@ namespace Tango.MachineStudio.Technician.ViewModels } catch (Exception ex) { - //TODO: Show Exception. + LogManager.Log(ex, String.Format("Error executing technician set value component command on '{0}'.", item.TechName)); + _eventLogger.Log(ex, String.Format("Error executing technician set value component command on '{0}'.", item.TechName)); } }; } + /// + /// Checks the machine operator. + /// + /// No machine connected. + private void CheckMachineOperator() + { + if (MachineOperator == null || MachineOperator.State != Transport.TransportComponentState.Connected) + { + throw new InvalidOperationException("No machine connected."); + } + } + #endregion #region Public Methods diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs index 76c7b3e58..1334a349d 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs @@ -28,6 +28,9 @@ namespace Tango.MachineStudio.UI protected override void OnStartup(StartupEventArgs e) { + LogManager.RegisterLogger(new VSOutputLogger()); + LogManager.RegisterLogger(new FileLogger()); + LogManager.Log("Application Started..."); base.OnStartup(e); @@ -44,9 +47,6 @@ namespace Tango.MachineStudio.UI LogManager.Categories.AddRange(SettingsManager.Default.MachineStudio.LoggingCategories); - LogManager.RegisterLogger(new VSOutputLogger()); - LogManager.RegisterLogger(new FileLogger()); - exceptionTrapper = new WpfGlobalExceptionTrapper(); exceptionTrapper.Initialize(this); exceptionTrapper.ApplicationCrashed += ExceptionTrapper_ApplicationCrashed; diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs index 121d429ec..07834393b 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs @@ -80,8 +80,12 @@ namespace Tango.MachineStudio.UI.Modules if (!_loaded) { //Preloaded + + LogManager.Log(String.Format("Loading module '{0}'...", nameof(StubsModule))); AllModules.Add(new StubsModule()); + LogManager.Log(String.Format("Loading module '{0}'...", nameof(DBModule))); AllModules.Add(new DBModule()); + LogManager.Log(String.Format("Loading module '{0}'...", nameof(MachineDesignerModule))); AllModules.Add(new MachineDesignerModule()); //Preloaded @@ -103,6 +107,7 @@ namespace Tango.MachineStudio.UI.Modules { try { + LogManager.Log(String.Format("Loading module '{0}'...", moduleType.Name)); var module = Activator.CreateInstance(moduleType) as IStudioModule; AllModules.Add(module); } @@ -117,7 +122,7 @@ namespace Tango.MachineStudio.UI.Modules catch { } } - _loaded = true; + _loaded = true; } UserModules.Clear(); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index f78cc15be..8e451cdce 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -425,7 +425,7 @@ namespace Tango.MachineStudio.UI.ViewModels { LogManager.Log(ex); _eventLogger.Log(ex, "Error connecting to machine " + x.SelectedMachine.SerialNumber); - _notificationProvider.ShowError(ex.Message); + _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Message); } InvalidateRelayCommands(); @@ -455,7 +455,7 @@ namespace Tango.MachineStudio.UI.ViewModels { LogManager.Log(ex); _eventLogger.Log(ex, "Error connecting to machine " + x.SelectedMachine.SerialNumber); - _notificationProvider.ShowError(ex.Message); + _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Message); } InvalidateRelayCommands(); @@ -472,7 +472,7 @@ namespace Tango.MachineStudio.UI.ViewModels } else { - _notificationProvider.ShowModalDialog((x) => + _notificationProvider.ShowModalDialog((x) => { DisconnectFromMachine(); }); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs index e0ae60b87..442d11cdd 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs @@ -25,6 +25,7 @@ using Tango.MachineStudio.Common; using System.Threading; using Tango.Core.Helpers; using Tango.SharedUI.Helpers; +using Tango.Logging; namespace Tango.MachineStudio.UI.Views { @@ -54,6 +55,8 @@ namespace Tango.MachineStudio.UI.Views Task.Factory.StartNew(() => { + LogManager.Default.Log("Loading modules views..."); + var item = ServiceLocator.Current.GetInstance().PushTaskItem("Loading Modules..."); var modules = _loader.UserModules.ToList(); @@ -67,6 +70,8 @@ namespace Tango.MachineStudio.UI.Views foreach (var module in modules) { + LogManager.Default.Log("Loading module view '" + module.Name + "'..."); + ThreadsHelper.InvokeUI(() => { Grid grid = new Grid(); -- cgit v1.3.1