diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels')
2 files changed, 224 insertions, 9 deletions
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 index 8ddc544c0..d51607004 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/ApplicationLogsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/ApplicationLogsViewVM.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using Tango.Core.Commands; using Tango.Logging; +using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.Logging.Navigation; using Tango.MachineStudio.Logging.Parsing; using Tango.SharedUI; @@ -16,9 +17,13 @@ namespace Tango.MachineStudio.Logging.ViewModels { private ApplicationLogFileParser _parser; private List<LogFile> _logFiles; + private INotificationProvider _notification; - private ObservableCollection<MessageLogItem> _logs; - public ObservableCollection<MessageLogItem> Logs + private ControlledObservableCollection<LogItemBase> _realTimeLogs; + private List<LogItemBase> _pausedLogs; + + private ControlledObservableCollection<LogItemBase> _logs; + public ControlledObservableCollection<LogItemBase> Logs { get { return _logs; } set { _logs = value; RaisePropertyChangedAuto(); } @@ -60,10 +65,31 @@ namespace Tango.MachineStudio.Logging.ViewModels set { _isRealTime = value; RaisePropertyChangedAuto(); OnSelectedDateChanged(); } } + private bool _realTimePaused; + public bool RealTimePaused + { + get { return _realTimePaused; } + set + { + _realTimePaused = value; + RaisePropertyChangedAuto(); + + if (!_realTimePaused) + { + _realTimeLogs.InsertRange(0, _pausedLogs); + _pausedLogs.Clear(); + } + } + } + public RelayCommand NavigateToHomeCommand { get; set; } - public ApplicationLogsViewVM(LoggingNavigationManager navigation) + public RelayCommand ToggleRealTimePaused { get; set; } + + public ApplicationLogsViewVM(LoggingNavigationManager navigation, INotificationProvider notification) { + _notification = notification; + NavigateToHomeCommand = new RelayCommand(() => navigation.NavigateTo(LoggingNavigationView.HomeView)); _parser = new ApplicationLogFileParser(); @@ -71,28 +97,59 @@ namespace Tango.MachineStudio.Logging.ViewModels _logFiles = _parser.GetLogFiles(); Dates = new ObservableCollection<DateTime>(_logFiles.Select(x => x.DateTime).OrderBy(x => x)); + _realTimeLogs = new ControlledObservableCollection<LogItemBase>(); + _pausedLogs = new List<LogItemBase>(); + + IsRealTime = true; + RealTimePaused = true; + SelectedDate = Dates.Last(); MinDate = Dates.Min(); MaxDate = Dates.Max(); + + LogManager.NewLog += LogManager_NewLog; + + ToggleRealTimePaused = new RelayCommand(() => RealTimePaused = !RealTimePaused); + } + + private void LogManager_NewLog(object sender, LogItemBase log) + { + if (!RealTimePaused) + { + InvokeUI(() => + { + _realTimeLogs.Insert(0, log); + }); + } + else + { + _pausedLogs.Add(log); + } } - private void OnSelectedDateChanged() + private async void OnSelectedDateChanged() { if (IsRealTime) { - //Events = _realTimeEvents; + Logs = _realTimeLogs; } else { - List<MessageLogItem> logs = new List<MessageLogItem>(); + List<LogItemBase> logs = new List<LogItemBase>(); - foreach (var logFile in _logFiles.Where(x => x.DateTime.Date == SelectedDate.Date)) + using (_notification.PushTaskItem("Loading application logs...")) { - logs.AddRange(_parser.Parse(logFile)); + await Task.Factory.StartNew(() => + { + foreach (var logFile in _logFiles.Where(x => x.DateTime.Date == SelectedDate.Date)) + { + logs.AddRange(_parser.Parse(logFile)); + } + }); } - Logs = logs.ToObservableCollection(); + Logs = new ControlledObservableCollection<LogItemBase>(logs); } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EmbeddedLogsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EmbeddedLogsViewVM.cs new file mode 100644 index 000000000..126f61402 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EmbeddedLogsViewVM.cs @@ -0,0 +1,158 @@ +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.Integration.Operation; +using Tango.Logging; +using Tango.MachineStudio.Common.Notifications; +using Tango.MachineStudio.Common.StudioApplication; +using Tango.MachineStudio.Logging.Navigation; +using Tango.MachineStudio.Logging.Parsing; +using Tango.SharedUI; + +namespace Tango.MachineStudio.Logging.ViewModels +{ + public class EmbeddedLogsViewVM : ViewModel + { + private EmbeddedLogFileParser _parser; + private List<LogFile> _logFiles; + private INotificationProvider _notification; + + private ControlledObservableCollection<LogItemBase> _realTimeLogs; + private List<LogItemBase> _pausedLogs; + + private ControlledObservableCollection<LogItemBase> _logs; + public ControlledObservableCollection<LogItemBase> Logs + { + get { return _logs; } + set { _logs = value; RaisePropertyChangedAuto(); } + } + + private ObservableCollection<DateTime> _dates; + public ObservableCollection<DateTime> 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 bool _realTimePaused; + public bool RealTimePaused + { + get { return _realTimePaused; } + set + { + _realTimePaused = value; + RaisePropertyChangedAuto(); + + if (!_realTimePaused) + { + _realTimeLogs.InsertRange(0, _pausedLogs); + _pausedLogs.Clear(); + } + } + } + + public RelayCommand NavigateToHomeCommand { get; set; } + + public RelayCommand ToggleRealTimePaused { get; set; } + + public EmbeddedLogsViewVM(LoggingNavigationManager navigation, IStudioApplicationManager application, INotificationProvider notification) + { + _notification = notification; + + NavigateToHomeCommand = new RelayCommand(() => navigation.NavigateTo(LoggingNavigationView.HomeView)); + + _parser = new EmbeddedLogFileParser(); + + _logFiles = _parser.GetLogFiles(); + Dates = new ObservableCollection<DateTime>(_logFiles.Select(x => x.DateTime).OrderBy(x => x)); + + _realTimeLogs = new ControlledObservableCollection<LogItemBase>(); + _pausedLogs = new List<LogItemBase>(); + + IsRealTime = true; + RealTimePaused = true; + + SelectedDate = Dates.Last(); + + MinDate = Dates.Min(); + MaxDate = Dates.Max(); + + MachineOperator.EmbeddedLogManager.NewLog += EmbeddedLogManager_NewLog; + + ToggleRealTimePaused = new RelayCommand(() => RealTimePaused = !RealTimePaused); + } + + private void EmbeddedLogManager_NewLog(object sender, LogItemBase log) + { + if (!RealTimePaused) + { + InvokeUI(() => + { + _realTimeLogs.Insert(0, log); + }); + } + else + { + _pausedLogs.Add(log); + } + } + + private async void OnSelectedDateChanged() + { + if (IsRealTime) + { + Logs = _realTimeLogs; + } + else + { + List<LogItemBase> logs = new List<LogItemBase>(); + + using (_notification.PushTaskItem("Loading embedded device logs...")) + { + await Task.Factory.StartNew(() => + { + foreach (var logFile in _logFiles.Where(x => x.DateTime.Date == SelectedDate.Date)) + { + logs.AddRange(_parser.Parse(logFile)); + } + }); + } + + Logs = new ControlledObservableCollection<LogItemBase>(logs); + } + } + } +} |
