diff options
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.cs | 114 |
1 files changed, 52 insertions, 62 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 index cb4a8d49e..11d62a8ab 100644 --- a/Software/Visual_Studio/Utilities/Tango.LogViewer.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/Utilities/Tango.LogViewer.UI/ViewModels/MainViewVM.cs @@ -14,12 +14,14 @@ using System.Windows.Data; using System.Diagnostics; using System.IO; using Tango.LogViewer.UI.LogViewerFileParser; +using System.Globalization; namespace Tango.LogViewer.UI.ViewModels { public class MainViewVM: ViewModel { - private ILogViewerParser _parser; + + private LogViewerManager _logViewerManager; #region Properties public SelectedObjectCollection<LogCategory> SelectedLogCategories { get; set; } @@ -133,12 +135,29 @@ namespace Tango.LogViewer.UI.ViewModels public bool IsEmbeddedLog { get { return _isEmbeddedLog; } - set { _isEmbeddedLog = value; - RaisePropertyChangedAuto(); - } + 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; } @@ -146,6 +165,8 @@ namespace Tango.LogViewer.UI.ViewModels #region Constructors public MainViewVM() { + Culture = new CultureInfo("he-IL"); + SelectedLogCategories = new SelectedObjectCollection<LogCategory>(new ObservableCollection<LogCategory>() { LogCategory.Info, @@ -161,8 +182,11 @@ namespace Tango.LogViewer.UI.ViewModels LogCategory.Critical, LogCategory.Debug, }); + _logViewerManager = new LogViewerManager(); + IsSet = false; IsEmbeddedLog = false; - ClearFilters(); + Loading = false; + Clear(); OpeFileLogCommand = new RelayCommand(OpenLogFile); SelectedLogCategories.SynchedSource.CollectionChanged += (_, __) => { @@ -175,15 +199,22 @@ namespace Tango.LogViewer.UI.ViewModels /// <summary> /// Clears the all filters. Set filter properties to init state. /// </summary> - private void ClearFilters() + private void Clear() { - FileName = "FileName"; + FileName = ""; StartSelectedTime = TimeSpan.Zero; EndSelectedTime = TimeSpan.Zero; Filter = ""; SelectedLog = null; SelectedLogCategories.SynchedSource= SelectedLogCategories.Source; CountOfSet = 0; + IsSet = false; + if (Logs != null) + { + Logs.Clear(); + RaisePropertyChanged("Logs"); + } + } /// <summary> @@ -210,67 +241,26 @@ namespace Tango.LogViewer.UI.ViewModels /// </summary> public async void LoadLogFile(String fileName) { - ClearFilters(); - LogViewerManager.InitLogFile(fileName); + Clear(); + Loading = true; + _logViewerManager.InitLogFile(fileName); List<LogItemBase> logs = new List<LogItemBase>(); await Task.Factory.StartNew(() => - { - foreach (var logFile in LogViewerManager.LogFiles) - { - logs.AddRange(Parse(logFile)); - } - }); + { + 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); ApplyLogsFilter(); + Loading = false; } - /// <summary> - /// Parses the specified log file. - /// </summary> - public List<LogItemBase> Parse(LogFile logFile) - { - List<LogItemBase> logItems = new List<LogItemBase>(); - List<LogFile> logFiles = new List<LogFile>(); - string fileName = Path.GetFileNameWithoutExtension(logFile.File); - FileName = fileName; - IsEmbeddedLog = fileName.StartsWith("Embedded"); - if (IsEmbeddedLog) - { - _parser = new EmbeddedLogViewerParser(); - } - else - { - _parser = new ApplicationLogViewerParser(); - } - - if (logFile.PartOfSet) - { - string extension = Path.GetExtension(logFile.File); - var directoryName = Path.GetDirectoryName(logFile.File); - int indexPos = fileName.IndexOf(FileLogger.FILE_SET_EXTENSION); - if (indexPos > 0) - { - fileName = fileName.Substring(0, indexPos); - FileName = fileName; - } - string folder = logFile.File; - string[] fileEntries = Directory.GetFiles(directoryName, $"{fileName}*{extension}").Where(x => Path.GetFileName(x).StartsWith(fileName)).OrderBy(x => x).ToArray(); - CountOfSet = fileEntries.Length; - foreach (var file in fileEntries) - { - _parser.Parse(file, logFile.DateTime, ref logItems); - } - } - else - { - CountOfSet = 1; - _parser.Parse(logFile.File, logFile.DateTime, ref logItems); - } - - return logItems; - } - + #endregion #region Filtering |
