aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Utilities/Tango.LogViewer.UI/ViewModels/MainViewVM.cs
diff options
context:
space:
mode:
authorMirta <mirta@twine-s.com>2020-12-30 16:39:52 +0200
committerMirta <mirta@twine-s.com>2020-12-30 16:39:52 +0200
commit00a491d93733d4625ad329b2ba8237f445364b3f (patch)
tree4b24c6fa78d7648f4bb7cefafa464bb0b063fec4 /Software/Visual_Studio/Utilities/Tango.LogViewer.UI/ViewModels/MainViewVM.cs
parent124ad4150f80c6846fdee41dbbda9848c105f6e5 (diff)
downloadTango-00a491d9.tar.gz
Tango-00a491d9.zip
merge
Diffstat (limited to 'Software/Visual_Studio/Utilities/Tango.LogViewer.UI/ViewModels/MainViewVM.cs')
-rw-r--r--Software/Visual_Studio/Utilities/Tango.LogViewer.UI/ViewModels/MainViewVM.cs307
1 files changed, 0 insertions, 307 deletions
diff --git a/Software/Visual_Studio/Utilities/Tango.LogViewer.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/Utilities/Tango.LogViewer.UI/ViewModels/MainViewVM.cs
deleted file mode 100644
index edcdfd241..000000000
--- a/Software/Visual_Studio/Utilities/Tango.LogViewer.UI/ViewModels/MainViewVM.cs
+++ /dev/null
@@ -1,307 +0,0 @@
-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.SharedUI;
-using Tango.SharedUI.Components;
-using Microsoft.WindowsAPICodePack.Dialogs;
-using System.ComponentModel;
-using System.Windows.Data;
-using System.Diagnostics;
-using System.IO;
-using Tango.LogViewer.UI.LogViewerFileParser;
-using System.Globalization;
-using System.Windows.Input;
-using System.Windows;
-
-namespace Tango.LogViewer.UI.ViewModels
-{
- public class MainViewVM : ViewModel
- {
-
- private LogViewerManager _logViewerManager;
- #region Properties
- public SelectedObjectCollection<LogCategory> SelectedLogCategories { get; set; }
-
- private TimeSpan? _endSelectedTime;
- /// <summary>
- /// Gets or sets the end selected time of time picker.
- /// </summary>
- public TimeSpan? EndSelectedTime
- {
- get { return _endSelectedTime; }
- set
- {
- _endSelectedTime = value;
- RaisePropertyChangedAuto();
- ApplyLogsFilter();
- }
- }
-
- private TimeSpan? _startSelectedTime;
- /// <summary>
- /// Gets or sets the start selected time of time picker.
- /// </summary>
- public TimeSpan? StartSelectedTime
- {
- get { return _startSelectedTime; }
- set
- {
- _startSelectedTime = value;
- RaisePropertyChangedAuto();
- ApplyLogsFilter();
- }
- }
-
- private String _filter;
- /// <summary>
- /// Gets or sets the filter for log message.
- /// </summary>
- public String Filter
- {
- get { return _filter; }
- set
- {
- _filter = value;
- RaisePropertyChangedAuto();
- ApplyLogsFilter();
- }
- }
-
- private ObservableCollection<LogItemBase> _logs;
- /// <summary>
- /// Gets or sets the collection of LogItemBase after parsing log files.
- /// </summary>
- public ObservableCollection<LogItemBase> Logs
- {
- get { return _logs; }
- set { _logs = value; RaisePropertyChangedAuto(); }
- }
-
- private ICollectionView _logsViewSource;
-
- /// <summary>
- /// Wrapper around the Logs collection that provides filtering
- /// </summary>
- public ICollectionView LogsViewSource
- {
- get { return _logsViewSource; }
- set { _logsViewSource = value; RaisePropertyChangedAuto(); }
- }
-
- private LogItemBase _selectedLog;
- /// <summary>
- /// Gets or sets the selected log.
- /// </summary>
- public LogItemBase SelectedLog
- {
- get { return _selectedLog; }
- set { _selectedLog = value; RaisePropertyChangedAuto(); Message = _selectedLog != null ? _selectedLog.Message : ""; }
- }
-
-
- private string _fileName;
- /// <summary>
- /// Gets or sets the full path of the open file to display in Status bar.
- /// </summary>
- public string FileName
- {
- get { return _fileName; }
- set { _fileName = value; RaisePropertyChangedAuto(); }
- }
-
- private int _countOfSet;
- /// <summary>
- /// Gets or sets the count of file set to display in Status bar.
- /// </summary>
- public int CountOfSet
- {
- get { return _countOfSet; }
- set { _countOfSet = value; RaisePropertyChangedAuto(); }
- }
-
- private string _message;
- /// <summary>
- /// Gets the message of selected log item to display in right panel.
- /// </summary>
- public string Message
- {
- get { return _message; }
- set { _message = value; RaisePropertyChangedAuto(); }
-
- }
- private bool _isEmbeddedLog;
-
- public bool IsEmbeddedLog
- {
- get { return _isEmbeddedLog; }
- set { _isEmbeddedLog = value; RaisePropertyChangedAuto(); }
- }
-
- private bool _isSet;
- /// <summary>
- /// Gets or sets a value indicating whether set of files.
- /// </summary>
- public bool IsSet
- {
- get { return _isSet; }
- set { _isSet = value; RaisePropertyChangedAuto(); }
- }
-
- private bool _loading;
-
- public bool Loading
- {
- get { return _loading; }
- set { _loading = value; RaisePropertyChangedAuto(); }
- }
-
- public CultureInfo Culture { get; set; }
-
- #endregion
-
- public RelayCommand OpeFileLogCommand { get; set; }
-
- #region Constructors
- public MainViewVM()
- {
- Culture = new CultureInfo("he-IL");
-
- SelectedLogCategories = new SelectedObjectCollection<LogCategory>(new ObservableCollection<LogCategory>()
- {
- LogCategory.Info,
- LogCategory.Warning,
- LogCategory.Error,
- LogCategory.Critical,
- LogCategory.Debug,
- }, new ObservableCollection<LogCategory>()
- {
- LogCategory.Info,
- LogCategory.Warning,
- LogCategory.Error,
- LogCategory.Critical,
- LogCategory.Debug,
- });
- _logViewerManager = new LogViewerManager();
- IsSet = false;
- IsEmbeddedLog = false;
- Loading = false;
- Clear();
- OpeFileLogCommand = new RelayCommand(OpenLogFile);
- SelectedLogCategories.SynchedSource.CollectionChanged += (_, __) =>
- {
- ApplyLogsFilter();
- };
- }
- #endregion
-
- #region Loading
- /// <summary>
- /// Clears the all filters. Set filter properties to init state.
- /// </summary>
- private void Clear()
- {
- FileName = "";
- StartSelectedTime = null;
- EndSelectedTime = null;
- Filter = "";
- SelectedLog = null;
- SelectedLogCategories.SynchedSource = SelectedLogCategories.Source;
- CountOfSet = 0;
- IsSet = false;
- if (Logs != null)
- {
- Logs.Clear();
- RaisePropertyChanged("Logs");
- }
-
- }
-
- /// <summary>
- /// Opens the log file from menu.
- /// </summary>
- private void OpenLogFile()
- {
- var dialog = new CommonOpenFileDialog()
- {
- Multiselect = false,
- EnsureFileExists = true,
-
- };
- dialog.Filters.Add(new CommonFileDialogFilter("Log files", "*.log"));
- CommonFileDialogResult result = dialog.ShowDialog();
- if (result == CommonFileDialogResult.Ok)
- {
- LoadLogFile(dialog.FileName);
- }
- }
-
- /// <summary>
- /// Loads the log file from menu or command line.
- /// </summary>
- public async void LoadLogFile(String fileName)
- {
- try
- {
- Clear();
- Loading = true;
-
- Mouse.OverrideCursor = Cursors.Wait;
- _logViewerManager.InitLogFile(fileName);
- List<LogItemBase> logs = new List<LogItemBase>();
- await Task.Factory.StartNew(() =>
- {
- logs.AddRange(_logViewerManager.Parse());
- });
-
- CountOfSet = _logViewerManager.CountOfSet;
- IsSet = CountOfSet > 0 ? true : false;
- IsEmbeddedLog = _logViewerManager.IsEmbeddedLog;
- FileName = _logViewerManager.FileName;
- Logs = new ObservableCollection<LogItemBase>(logs);
- LogsViewSource = CollectionViewSource.GetDefaultView(Logs);
- StartSelectedTime = Logs.Min(x => x.TimeStamp).TimeOfDay;
- EndSelectedTime = Logs.Max(x => x.TimeStamp).TimeOfDay;
- ApplyLogsFilter();
- }
- catch (Exception ex)
- {
- Mouse.OverrideCursor = null;
- Loading = false;
- MessageBox.Show(ex.FlattenMessage());
- }
- finally
- {
- Mouse.OverrideCursor = null;
- Loading = false;
- }
- }
-
-
- #endregion
-
- #region Filtering
- /// <summary>
- /// Applies the all filters( time, categories,filter massage) to view.
- /// </summary>
- private void ApplyLogsFilter()
- {
- if (LogsViewSource != null)
- {
- LogsViewSource.Filter = (x) =>
- {
- LogItemBase log = x as LogItemBase;
- return (SelectedLogCategories.SynchedSource.Contains(log.Category) && (String.IsNullOrWhiteSpace(Filter) || log.Message.ToLower().Contains(Filter.ToLower()))
- && (StartSelectedTime == null || StartSelectedTime == TimeSpan.Zero || log.TimeStamp.TimeOfDay >= StartSelectedTime) && (EndSelectedTime == null || EndSelectedTime == TimeSpan.Zero || log.TimeStamp.TimeOfDay <= EndSelectedTime));
- };
- }
-
- }
- #endregion
-
- }
-}