aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Utilities/Tango.LogViewer.UI/LogViewerManager.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/LogViewerManager.cs
parent124ad4150f80c6846fdee41dbbda9848c105f6e5 (diff)
downloadTango-00a491d9.tar.gz
Tango-00a491d9.zip
merge
Diffstat (limited to 'Software/Visual_Studio/Utilities/Tango.LogViewer.UI/LogViewerManager.cs')
-rw-r--r--Software/Visual_Studio/Utilities/Tango.LogViewer.UI/LogViewerManager.cs126
1 files changed, 0 insertions, 126 deletions
diff --git a/Software/Visual_Studio/Utilities/Tango.LogViewer.UI/LogViewerManager.cs b/Software/Visual_Studio/Utilities/Tango.LogViewer.UI/LogViewerManager.cs
deleted file mode 100644
index 3615eb50a..000000000
--- a/Software/Visual_Studio/Utilities/Tango.LogViewer.UI/LogViewerManager.cs
+++ /dev/null
@@ -1,126 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Tango.Logging;
-using Tango.LogViewer.UI.LogViewerFileParser;
-
-namespace Tango.LogViewer.UI
-{
- public class LogViewerManager
- {
- private ILogViewerParser _parser;
-
- public LogFile LogFile { get; set; }
-
- public string FileName { get; set; }
-
- public bool IsEmbeddedLog { get; set; }
-
- public int CountOfSet { get; set; }
-
- public LogViewerManager()
- {
- LogFile = null; ;
- }
-
- /// <summary>
- /// Create LogFile by given path.
- /// </summary>
- /// <param name="file">The file.</param>
- public void InitLogFile(String file)
- {
- LogFile = GetLogFile(file);
- }
-
- /// <summary>
- /// Gets set of log files by path.
- /// </summary>
- public LogFile GetLogFile(string filePath)
- {
- if (!File.Exists(filePath))
- {
- throw new IOException("File not found.");
- }
- if (Path.GetExtension(filePath) != ".log")
- {
- throw new IOException("Invalid log file extension. extension must be *.log");
- }
-
- var directoryName = Path.GetDirectoryName(filePath);
- var logfileName = Path.GetFileNameWithoutExtension(filePath);
- String fileName = logfileName;
- int index = logfileName.IndexOf("-");
- if (index >= 0)
- {
- fileName = logfileName.Substring(0, index);
- }
- int indexPos = logfileName.IndexOf(FileLogger.FILE_SET_EXTENSION);
- if (indexPos > 0)
- {
- logfileName = logfileName.Substring(0, indexPos);
- }
-
- String dateString = System.IO.Path.GetFileNameWithoutExtension(filePath).Replace($"{fileName}-", "").Replace("_session", "");
- indexPos = dateString.IndexOf(FileLogger.FILE_SET_EXTENSION);
- int indexOfFile = 0;
- CountOfSet = 0;
- if (indexPos > 0)
- {
- string fileNameIndex = dateString.Substring(indexPos + FileLogger.FILE_SET_EXTENSION.Length);
- string[] fileEntries = Directory.GetFiles(directoryName, $"{logfileName}*{Path.GetExtension(filePath)}").Where(x => Path.GetFileName(x).StartsWith(logfileName)).OrderBy(x => x).ToArray();
- CountOfSet = fileEntries.Length;
- int.TryParse(fileNameIndex, out indexOfFile);
- dateString = dateString.Substring(0, indexPos);
- }
- DateTime date = DateTime.ParseExact(dateString, "dd-MM-yyyy_HH-mm-ss", CultureInfo.InvariantCulture);
- return (new LogFile() { DateTime = date, File = filePath, FileName = logfileName, PartOfSet = indexOfFile > 0, SetStartIndex = indexOfFile, SetCount = CountOfSet });
- }
-
- /// <summary>
- /// Parses the this LogFile.
- /// </summary>
- public List<LogItemBase> Parse()
- {
- IsEmbeddedLog = false;
- FileName = "";
- List<LogItemBase> logItems = new List<LogItemBase>();
- if (LogFile == null)
- return logItems;
-
- FileName = LogFile.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);
-
- string[] fileEntries = Directory.GetFiles(directoryName, $"{FileName}*{extension}").Where(x => Path.GetFileName(x).StartsWith(FileName)).OrderBy(x => x).ToArray();
-
- foreach (var file in fileEntries)
- {
- _parser.Parse(file, LogFile.DateTime, ref logItems);
- }
- }
- else
- {
- _parser.Parse(LogFile.File, LogFile.DateTime, ref logItems);
- }
-
- return logItems;
- }
- }
-}