From 51e7f202329c868df770c5e4dd55779a07758023 Mon Sep 17 00:00:00 2001 From: miltob Date: Tue, 14 May 2019 17:40:19 +1000 Subject: [PATCH] AutoColumnize throws an Exception with multiple files if no bookmarks are found #102 Update the AutoColumnizer logic to fix the bug. --- .../AutoColumnizer.Tests.csproj | 94 ---------- .../AutoColumnizerTest.cs | 75 -------- .../Properties/AssemblyInfo.cs | 20 -- .../SquareBracketColumnizerTest_01.txt | 2 - .../SquareBracketColumnizerTest_02.txt | 3 - .../SquareBracketColumnizerTest_03.txt | 4 - .../SquareBracketColumnizerTest_04.txt | 5 - src/AutoColumnizer/AutoColumnizer.cs | 172 +++++++----------- src/ColumnizerLib/ColumnizerLib.csproj | 1 - src/ColumnizerLib/IAutoColumnizer.cs | 12 -- .../IAutoLogLineColumnizerCallback.cs | 4 - src/LogExpert.Tests/ColumnizerManagerTest.cs | 124 +++++++++++++ .../JsonCompactColumnizerTest.cs | 80 ++++---- src/LogExpert.Tests/LogExpert.Tests.csproj | 6 + src/LogExpert.Tests/LogWindowTest.cs | 21 +++ src/LogExpert.sln | 24 +-- .../Classes/Columnizer/ColumnizerManager.cs | 140 ++++++++++++++ src/LogExpert/Classes/Log/LogfileReader.cs | 2 +- src/LogExpert/Classes/PluginRegistry.cs | 2 +- src/LogExpert/Classes/Util.cs | 34 +--- .../LogTabWindow/LogTabWindowPrivate.cs | 9 +- .../LogTabWindow/LogTabWindowPublic.cs | 3 +- src/LogExpert/Controls/LogWindow/LogWindow.cs | 9 +- .../Controls/LogWindow/LogWindowPrivate.cs | 25 +-- .../Controls/LogWindow/LogWindowsPublic.cs | 15 +- src/LogExpert/Dialogs/SettingsDialog.cs | 7 +- .../Entities/DefaultLogfileColumnizer.cs | 2 +- src/LogExpert/LogExpert.csproj | 1 + 28 files changed, 430 insertions(+), 466 deletions(-) delete mode 100644 src/AutoColumnizer.Tests/AutoColumnizer.Tests.csproj delete mode 100644 src/AutoColumnizer.Tests/AutoColumnizerTest.cs delete mode 100644 src/AutoColumnizer.Tests/Properties/AssemblyInfo.cs delete mode 100644 src/AutoColumnizer.Tests/TestData/SquareBracketColumnizerTest_01.txt delete mode 100644 src/AutoColumnizer.Tests/TestData/SquareBracketColumnizerTest_02.txt delete mode 100644 src/AutoColumnizer.Tests/TestData/SquareBracketColumnizerTest_03.txt delete mode 100644 src/AutoColumnizer.Tests/TestData/SquareBracketColumnizerTest_04.txt delete mode 100644 src/ColumnizerLib/IAutoColumnizer.cs create mode 100644 src/LogExpert.Tests/ColumnizerManagerTest.cs create mode 100644 src/LogExpert.Tests/LogWindowTest.cs create mode 100644 src/LogExpert/Classes/Columnizer/ColumnizerManager.cs diff --git a/src/AutoColumnizer.Tests/AutoColumnizer.Tests.csproj b/src/AutoColumnizer.Tests/AutoColumnizer.Tests.csproj deleted file mode 100644 index a3960743..00000000 --- a/src/AutoColumnizer.Tests/AutoColumnizer.Tests.csproj +++ /dev/null @@ -1,94 +0,0 @@ - - - - - Debug - AnyCPU - {BCD44C89-636F-4BC9-9097-25FA56BFD6E3} - Library - Properties - AutoColumnizer.Tests - AutoColumnizer.Tests - v4.7.2 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 15.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - - - - - - - - - - - - 4.10.1 - - - 3.11.0 - - - 3.13.0 - - - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - - - {b57259a3-4ed7-4f8b-a252-29e799a56b9e} - AutoColumnizer - - - {e72c2bb1-34de-4d66-a830-9647c3837833} - ColumnizerLib - - - {f0c0d370-f416-44ed-939a-b4827d15ac14} - LogExpert - - - - - \ No newline at end of file diff --git a/src/AutoColumnizer.Tests/AutoColumnizerTest.cs b/src/AutoColumnizer.Tests/AutoColumnizerTest.cs deleted file mode 100644 index 61262efa..00000000 --- a/src/AutoColumnizer.Tests/AutoColumnizerTest.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using LogExpert; -using Moq; -using NUnit.Framework; - -namespace AutoColumnizer.Tests -{ - /// - /// Summary description for AutoColumnizerTest - /// - [TestFixture] - public class AutoColumnizerTest - { - [TestCase("Square Bracket Columnizer", "30/08/2018 08:51:42.712 [TRACE] [a] hello", "30/08/2018 08:51:42.712 [DATAIO] [b] world", null, null, null)] - [TestCase("Square Bracket Columnizer", "30/08/2018 08:51:42.712 [TRACE] hello", "30/08/2018 08:51:42.712 [DATAIO][] world", null, null, null)] - [TestCase("Square Bracket Columnizer", "", "30/08/2018 08:51:42.712 [TRACE] hello", "30/08/2018 08:51:42.712 [TRACE] hello", "[DATAIO][b][c] world", null)] - [TestCase("Timestamp Columnizer", "30/08/2018 08:51:42.712 no bracket 1", "30/08/2018 08:51:42.712 no bracket 2", "30/08/2018 08:51:42.712 [TRACE] with bracket 1", "30/08/2018 08:51:42.712 [TRACE] with bracket 2", "no bracket 3")] - public void FindColumnizer_ReturnCorrectColumnizer(string expectedColumnizerName, string line0, string line1, string line2, string line3, string line4) - { - LogExpert.AutoColumnizer autoColumnizer = new LogExpert.AutoColumnizer(); - string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "test"); - - Mock autoLogLineColumnizerCallbackMock = new Mock(); - - autoLogLineColumnizerCallbackMock.Setup(a => a.GetLogLine(0)).Returns(new TestLogLine() - { - FullLine = line0, - LineNumber = 0 - }); - - autoLogLineColumnizerCallbackMock.Setup(a => a.GetLogLine(1)).Returns(new TestLogLine() - { - FullLine = line1, - LineNumber = 1 - }); - - autoLogLineColumnizerCallbackMock.Setup(a => a.GetLogLine(2)).Returns(new TestLogLine() - { - FullLine = line2, - LineNumber = 2 - }); - - autoLogLineColumnizerCallbackMock.Setup(a => a.GetLogLine(3)).Returns(new TestLogLine() - { - FullLine = line3, - LineNumber = 3 - }); - autoLogLineColumnizerCallbackMock.Setup(a => a.GetLogLine(4)).Returns(new TestLogLine() - { - FullLine = line4, - LineNumber = 4 - }); - - autoLogLineColumnizerCallbackMock.Setup(a => a.GetRegisteredColumnizers()).Returns(new List(new ILogLineColumnizer[] - { - new SquareBracketColumnizer(0, false), - new ClfColumnizer(), - new TimestampColumnizer(), - })); - - var result = autoColumnizer.FindColumnizer(path, autoLogLineColumnizerCallbackMock.Object); - - Assert.AreEqual(expectedColumnizerName, result.GetName()); - } - - private class TestLogLine : ILogLine - { - public string Text => FullLine; - public string FullLine { get; set; } - public int LineNumber { get; set; } - } - } -} \ No newline at end of file diff --git a/src/AutoColumnizer.Tests/Properties/AssemblyInfo.cs b/src/AutoColumnizer.Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index d57e1c06..00000000 --- a/src/AutoColumnizer.Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("AutoColumnizer.Tests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("AutoColumnizer.Tests")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2019")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -[assembly: ComVisible(false)] - -[assembly: Guid("bcd44c89-636f-4bc9-9097-25fa56bfd6e3")] - -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/AutoColumnizer.Tests/TestData/SquareBracketColumnizerTest_01.txt b/src/AutoColumnizer.Tests/TestData/SquareBracketColumnizerTest_01.txt deleted file mode 100644 index d9f25f74..00000000 --- a/src/AutoColumnizer.Tests/TestData/SquareBracketColumnizerTest_01.txt +++ /dev/null @@ -1,2 +0,0 @@ -30/08/2018 08:51:42.712 [TRACE] [a] hello -30/08/2018 08:51:42.712 [DATAIO] [b] world \ No newline at end of file diff --git a/src/AutoColumnizer.Tests/TestData/SquareBracketColumnizerTest_02.txt b/src/AutoColumnizer.Tests/TestData/SquareBracketColumnizerTest_02.txt deleted file mode 100644 index 3bf3daa6..00000000 --- a/src/AutoColumnizer.Tests/TestData/SquareBracketColumnizerTest_02.txt +++ /dev/null @@ -1,3 +0,0 @@ - -30/08/2018 08:51:42.712 [TRACE] hello -30/08/2018 08:51:42.712 [DATAIO][] world \ No newline at end of file diff --git a/src/AutoColumnizer.Tests/TestData/SquareBracketColumnizerTest_03.txt b/src/AutoColumnizer.Tests/TestData/SquareBracketColumnizerTest_03.txt deleted file mode 100644 index 4c438f9e..00000000 --- a/src/AutoColumnizer.Tests/TestData/SquareBracketColumnizerTest_03.txt +++ /dev/null @@ -1,4 +0,0 @@ - -30/08/2018 08:51:42.712 [TRACE] hello -30/08/2018 08:51:42.712 [TRACE] hello -[DATAIO][b][c] world \ No newline at end of file diff --git a/src/AutoColumnizer.Tests/TestData/SquareBracketColumnizerTest_04.txt b/src/AutoColumnizer.Tests/TestData/SquareBracketColumnizerTest_04.txt deleted file mode 100644 index c2ffb13b..00000000 --- a/src/AutoColumnizer.Tests/TestData/SquareBracketColumnizerTest_04.txt +++ /dev/null @@ -1,5 +0,0 @@ -30/08/2018 08:51:42.712 no bracket 1 -30/08/2018 08:51:42.712 no bracket 2 -30/08/2018 08:51:42.712 [TRACE] with bracket 1 -30/08/2018 08:51:42.712 [TRACE] with bracket 2 -no bracket 3 \ No newline at end of file diff --git a/src/AutoColumnizer/AutoColumnizer.cs b/src/AutoColumnizer/AutoColumnizer.cs index 2a4ba98d..4e327fc7 100644 --- a/src/AutoColumnizer/AutoColumnizer.cs +++ b/src/AutoColumnizer/AutoColumnizer.cs @@ -1,108 +1,66 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace LogExpert -{ - public class AutoColumnizer : ILogLineColumnizer, IAutoColumnizer - { - #region ILogLineColumnizer implementation - - public string Text => GetName(); - - public bool IsTimeshiftImplemented() - { - return true; - } - - public string GetName() - { - return "Auto Columnizer"; - } - - public string GetDescription() - { - return "Automatically find the right columnizer for any file"; - } - - public ILogLineColumnizer FindColumnizer(string fileName, IAutoLogLineColumnizerCallback logFileReader) - { - if (logFileReader == null || string.IsNullOrEmpty(fileName)) - { - return logFileReader.GetDefaultColumnizer(); - } - - List loglines = new List - { - // Sampling a few lines to select the correct columnizer - logFileReader.GetLogLine(0), - logFileReader.GetLogLine(1), - logFileReader.GetLogLine(2), - logFileReader.GetLogLine(3), - logFileReader.GetLogLine(4), - logFileReader.GetLogLine(5), - logFileReader.GetLogLine(25), - logFileReader.GetLogLine(100), - logFileReader.GetLogLine(200), - logFileReader.GetLogLine(400) - }; - - var registeredColumnizer = logFileReader.GetRegisteredColumnizers(); - - List> priorityListOfColumnizers = new List>(); - - foreach (ILogLineColumnizer logLineColumnizer in registeredColumnizer) - { - var columnizerPriority = logLineColumnizer as IColumnizerPriority; - Priority priority = default(Priority); - if (columnizerPriority != null) - { - priority = columnizerPriority.GetPriority(fileName, loglines); - } - - priorityListOfColumnizers.Add(new Tuple(priority, logLineColumnizer)); - } - - ILogLineColumnizer lineColumnizer = priorityListOfColumnizers.OrderByDescending(a => a.Item1).Select(a => a.Item2).First(); - - return lineColumnizer; - } - - public int GetColumnCount() - { - throw new NotImplementedException(); - } - - public string[] GetColumnNames() - { - throw new NotImplementedException(); - } - - public IColumnizedLogLine SplitLine(ILogLineColumnizerCallback callback, ILogLine line) - { - throw new NotImplementedException(); - } - - public void SetTimeOffset(int msecOffset) - { - throw new NotImplementedException(); - } - - public int GetTimeOffset() - { - throw new NotImplementedException(); - } - - public DateTime GetTimestamp(ILogLineColumnizerCallback callback, ILogLine line) - { - throw new NotImplementedException(); - } - - public void PushValue(ILogLineColumnizerCallback callback, int column, string value, string oldValue) - { - } - - #endregion ILogLineColumnizer implementation - } +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace LogExpert +{ + public class AutoColumnizer : ILogLineColumnizer + { + #region ILogLineColumnizer implementation + + public string Text => GetName(); + + public bool IsTimeshiftImplemented() + { + return true; + } + + public string GetName() + { + return "Auto Columnizer"; + } + + public string GetDescription() + { + return "Automatically find the right columnizer for any file"; + } + + + public int GetColumnCount() + { + throw new NotImplementedException(); + } + + public string[] GetColumnNames() + { + throw new NotImplementedException(); + } + + public IColumnizedLogLine SplitLine(ILogLineColumnizerCallback callback, ILogLine line) + { + throw new NotImplementedException(); + } + + public void SetTimeOffset(int msecOffset) + { + throw new NotImplementedException(); + } + + public int GetTimeOffset() + { + throw new NotImplementedException(); + } + + public DateTime GetTimestamp(ILogLineColumnizerCallback callback, ILogLine line) + { + throw new NotImplementedException(); + } + + public void PushValue(ILogLineColumnizerCallback callback, int column, string value, string oldValue) + { + } + + #endregion ILogLineColumnizer implementation + } } \ No newline at end of file diff --git a/src/ColumnizerLib/ColumnizerLib.csproj b/src/ColumnizerLib/ColumnizerLib.csproj index 034e6914..f0235e77 100644 --- a/src/ColumnizerLib/ColumnizerLib.csproj +++ b/src/ColumnizerLib/ColumnizerLib.csproj @@ -55,7 +55,6 @@ - diff --git a/src/ColumnizerLib/IAutoColumnizer.cs b/src/ColumnizerLib/IAutoColumnizer.cs deleted file mode 100644 index 32c49a89..00000000 --- a/src/ColumnizerLib/IAutoColumnizer.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace LogExpert -{ - public interface IAutoColumnizer - { - ILogLineColumnizer FindColumnizer(string fileName, IAutoLogLineColumnizerCallback logFileReader); - } -} \ No newline at end of file diff --git a/src/ColumnizerLib/IAutoLogLineColumnizerCallback.cs b/src/ColumnizerLib/IAutoLogLineColumnizerCallback.cs index fca4c832..e427eb1c 100644 --- a/src/ColumnizerLib/IAutoLogLineColumnizerCallback.cs +++ b/src/ColumnizerLib/IAutoLogLineColumnizerCallback.cs @@ -13,9 +13,5 @@ public interface IAutoLogLineColumnizerCallback /// Number of the line to be retrieved /// A string with line content or null if line number is out of range ILogLine GetLogLine(int lineNum); - - IList GetRegisteredColumnizers(); - - ILogLineColumnizer GetDefaultColumnizer(); } } \ No newline at end of file diff --git a/src/LogExpert.Tests/ColumnizerManagerTest.cs b/src/LogExpert.Tests/ColumnizerManagerTest.cs new file mode 100644 index 00000000..eea375b3 --- /dev/null +++ b/src/LogExpert.Tests/ColumnizerManagerTest.cs @@ -0,0 +1,124 @@ +using JsonColumnizer; +using LogExpert.Classes.Columnizer; +using Moq; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.IO; + +namespace LogExpert.Tests +{ + /// + /// Summary description for AutoColumnizerTest + /// + [TestFixture] + public class ColumnizerManagerTest + { + [TestCase("Square Bracket Columnizer", "30/08/2018 08:51:42.712 [TRACE] [a] hello", "30/08/2018 08:51:42.712 [DATAIO] [b] world", null, null, null)] + [TestCase("Square Bracket Columnizer", "30/08/2018 08:51:42.712 [TRACE] hello", "30/08/2018 08:51:42.712 [DATAIO][] world", null, null, null)] + [TestCase("Square Bracket Columnizer", "", "30/08/2018 08:51:42.712 [TRACE] hello", "30/08/2018 08:51:42.712 [TRACE] hello", "[DATAIO][b][c] world", null)] + [TestCase("Timestamp Columnizer", "30/08/2018 08:51:42.712 no bracket 1", "30/08/2018 08:51:42.712 no bracket 2", "30/08/2018 08:51:42.712 [TRACE] with bracket 1", "30/08/2018 08:51:42.712 [TRACE] with bracket 2", "no bracket 3")] + public void FindColumnizer_ReturnCorrectColumnizer(string expectedColumnizerName, string line0, string line1, string line2, string line3, string line4) + { + string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "test"); + + Mock autoLogLineColumnizerCallbackMock = new Mock(); + + autoLogLineColumnizerCallbackMock.Setup(a => a.GetLogLine(0)).Returns(new TestLogLine() + { + FullLine = line0, + LineNumber = 0 + }); + + autoLogLineColumnizerCallbackMock.Setup(a => a.GetLogLine(1)).Returns(new TestLogLine() + { + FullLine = line1, + LineNumber = 1 + }); + + autoLogLineColumnizerCallbackMock.Setup(a => a.GetLogLine(2)).Returns(new TestLogLine() + { + FullLine = line2, + LineNumber = 2 + }); + + autoLogLineColumnizerCallbackMock.Setup(a => a.GetLogLine(3)).Returns(new TestLogLine() + { + FullLine = line3, + LineNumber = 3 + }); + autoLogLineColumnizerCallbackMock.Setup(a => a.GetLogLine(4)).Returns(new TestLogLine() + { + FullLine = line4, + LineNumber = 4 + }); + + var result = ColumnizerManager.FindColumnizer(path, autoLogLineColumnizerCallbackMock.Object); + + Assert.AreEqual(expectedColumnizerName, result.GetName()); + } + + + [TestCase(@".\TestData\JsonColumnizerTest_01.txt", typeof(JsonCompactColumnizer))] + [TestCase(@".\TestData\SquareBracketColumnizerTest_02.txt", typeof(SquareBracketColumnizer))] + public void FindReplacementForAutoColumnizer_ValidTextFile_ReturnCorrectColumnizer( + string fileName, Type columnizerType) + { + string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName); + LogfileReader reader = new LogfileReader(path, new EncodingOptions(), true, 40, 50, new MultifileOptions()); + reader.ReadFiles(); + + Mock autoColumnizer = new Mock(); + autoColumnizer.Setup(a => a.GetName()).Returns("Auto Columnizer"); + + // TODO: When DI container is ready, we can mock this set up. + PluginRegistry.GetInstance().RegisteredColumnizers.Add(new JsonCompactColumnizer()); + var result = ColumnizerManager.FindReplacementForAutoColumnizer(fileName, reader, autoColumnizer.Object); + + Assert.AreEqual(result.GetType(), columnizerType); + } + + [TestCase(@".\TestData\FileNotExists.txt", typeof(DefaultLogfileColumnizer))] + public void DecideColumnizerByName_WhenReaderIsNotReady_ReturnCorrectColumnizer( + string fileName, Type columnizerType) + { + string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName); + + Mock autoColumnizer = new Mock(); + autoColumnizer.Setup(a => a.GetName()).Returns("Auto Columnizer"); + + // TODO: When DI container is ready, we can mock this set up. + PluginRegistry.GetInstance().RegisteredColumnizers.Add(new JsonCompactColumnizer()); + var result = ColumnizerManager.DecideColumnizerByName(fileName, + PluginRegistry.GetInstance().RegisteredColumnizers); + + Assert.AreEqual(result.GetType(), columnizerType); + } + + [TestCase(@"Invalid Name", typeof(DefaultLogfileColumnizer))] + [TestCase(@"JSON Columnizer", typeof(JsonColumnizer.JsonColumnizer))] + public void DecideColumnizerByName_ValidTextFile_ReturnCorrectColumnizer( + string columnizerName, Type columnizerType) + { + string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, columnizerName); + + Mock autoColumnizer = new Mock(); + autoColumnizer.Setup(a => a.GetName()).Returns("Auto Columnizer"); + + // TODO: When DI container is ready, we can mock this set up. + PluginRegistry.GetInstance().RegisteredColumnizers.Add(new JsonColumnizer.JsonColumnizer()); + + var result = ColumnizerManager.DecideColumnizerByName(columnizerName, + PluginRegistry.GetInstance().RegisteredColumnizers); + + Assert.AreEqual(result.GetType(), columnizerType); + } + + private class TestLogLine : ILogLine + { + public string Text => FullLine; + public string FullLine { get; set; } + public int LineNumber { get; set; } + } + } +} \ No newline at end of file diff --git a/src/LogExpert.Tests/JsonCompactColumnizerTest.cs b/src/LogExpert.Tests/JsonCompactColumnizerTest.cs index 4be9a15b..4b5a68a4 100644 --- a/src/LogExpert.Tests/JsonCompactColumnizerTest.cs +++ b/src/LogExpert.Tests/JsonCompactColumnizerTest.cs @@ -1,40 +1,40 @@ -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.IO; - -namespace LogExpert.Tests -{ - [TestFixture] - public class JsonCompactColumnizerTest - { - [TestCase(@".\TestData\JsonCompactColumnizerTest_01.json", Priority.PerfectlySupport)] - // As long as the json file contains one of the pre-defined key, it's perfectly supported. - [TestCase(@".\TestData\JsonCompactColumnizerTest_02.json", Priority.PerfectlySupport)] - [TestCase(@".\TestData\JsonCompactColumnizerTest_03.json", Priority.WellSupport)] - public void GetPriority_HappyFile_PriorityMatches(string fileName, Priority priority) - { - var jsonCompactColumnizer = new JsonColumnizer.JsonCompactColumnizer(); - string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName); - LogfileReader logFileReader = new LogfileReader(path, new EncodingOptions(), true, 40, 50, new MultifileOptions()); - logFileReader.ReadFiles(); - List loglines = new List - { - // Sampling a few lines to select the correct columnizer - logFileReader.GetLogLine(0), - logFileReader.GetLogLine(1), - logFileReader.GetLogLine(2), - logFileReader.GetLogLine(3), - logFileReader.GetLogLine(4), - logFileReader.GetLogLine(5), - logFileReader.GetLogLine(25), - logFileReader.GetLogLine(100), - logFileReader.GetLogLine(200), - logFileReader.GetLogLine(400) - }; - - var result = jsonCompactColumnizer.GetPriority(path, loglines); - Assert.AreEqual(result, priority); - } - } -} +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.IO; + +namespace LogExpert.Tests +{ + [TestFixture] + public class JsonCompactColumnizerTest + { + [TestCase(@".\TestData\JsonCompactColumnizerTest_01.json", Priority.PerfectlySupport)] + // As long as the json file contains one of the pre-defined key, it's perfectly supported. + [TestCase(@".\TestData\JsonCompactColumnizerTest_02.json", Priority.PerfectlySupport)] + [TestCase(@".\TestData\JsonCompactColumnizerTest_03.json", Priority.WellSupport)] + public void GetPriority_HappyFile_PriorityMatches(string fileName, Priority priority) + { + var jsonCompactColumnizer = new JsonColumnizer.JsonCompactColumnizer(); + string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName); + LogfileReader logFileReader = new LogfileReader(path, new EncodingOptions(), true, 40, 50, new MultifileOptions()); + logFileReader.ReadFiles(); + List loglines = new List + { + // Sampling a few lines to select the correct columnizer + logFileReader.GetLogLine(0), + logFileReader.GetLogLine(1), + logFileReader.GetLogLine(2), + logFileReader.GetLogLine(3), + logFileReader.GetLogLine(4), + logFileReader.GetLogLine(5), + logFileReader.GetLogLine(25), + logFileReader.GetLogLine(100), + logFileReader.GetLogLine(200), + logFileReader.GetLogLine(400) + }; + + var result = jsonCompactColumnizer.GetPriority(path, loglines); + Assert.AreEqual(result, priority); + } + } +} diff --git a/src/LogExpert.Tests/LogExpert.Tests.csproj b/src/LogExpert.Tests/LogExpert.Tests.csproj index 0590deb7..f706a83e 100644 --- a/src/LogExpert.Tests/LogExpert.Tests.csproj +++ b/src/LogExpert.Tests/LogExpert.Tests.csproj @@ -42,15 +42,21 @@ + + + + + 4.10.1 + 3.10.1 diff --git a/src/LogExpert.Tests/LogWindowTest.cs b/src/LogExpert.Tests/LogWindowTest.cs new file mode 100644 index 00000000..239e1991 --- /dev/null +++ b/src/LogExpert.Tests/LogWindowTest.cs @@ -0,0 +1,21 @@ + +using NUnit.Framework; +using System; + +namespace LogExpert.Tests +{ + [TestFixture] + public class LogWindowTest + { + // TODO: Add more tests when DI container is ready. + [TestCase(@".\TestData\JsonColumnizerTest_01.txt", typeof(DefaultLogfileColumnizer))] + public void Instantiate_JsonFile_BuildCorrectColumnizer(string fileName, Type columnizerType) + { + LogTabWindow logTabWindow = new LogTabWindow(null, 0, false); + LogWindow logWindow = + new LogWindow(logTabWindow, fileName, false, false); + + Assert.AreEqual(columnizerType, logWindow.CurrentColumnizer.GetType()); + } + } +} diff --git a/src/LogExpert.sln b/src/LogExpert.sln index 09efd1da..83a4e008 100644 --- a/src/LogExpert.sln +++ b/src/LogExpert.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27130.2026 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28803.352 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LogExpert", "LogExpert\LogExpert.csproj", "{F0C0D370-F416-44ED-939A-B4827D15AC14}" ProjectSection(ProjectDependencies) = postProject @@ -45,8 +45,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JsonCompactColumnizer", "Js EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoColumnizer", "AutoColumnizer\AutoColumnizer.csproj", "{B57259A3-4ED7-4F8B-A252-29E799A56B9E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoColumnizer.Tests", "AutoColumnizer.Tests\AutoColumnizer.Tests.csproj", "{BCD44C89-636F-4BC9-9097-25FA56BFD6E3}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "..\build\_build.csproj", "{CFA0360E-BA8D-4D6F-AF76-63D8282109FA}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SftpFileSystemx86", "SftpFileSystemx86\SftpFileSystemx86.csproj", "{3D01E923-5219-488B-B0A7-98521841E680}" @@ -324,24 +322,6 @@ Global {B57259A3-4ED7-4F8B-A252-29E799A56B9E}.Release|Mixed Platforms.Build.0 = Release|Any CPU {B57259A3-4ED7-4F8B-A252-29E799A56B9E}.Release|Win32.ActiveCfg = Release|Any CPU {B57259A3-4ED7-4F8B-A252-29E799A56B9E}.Release|Win32.Build.0 = Release|Any CPU - {BCD44C89-636F-4BC9-9097-25FA56BFD6E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BCD44C89-636F-4BC9-9097-25FA56BFD6E3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BCD44C89-636F-4BC9-9097-25FA56BFD6E3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {BCD44C89-636F-4BC9-9097-25FA56BFD6E3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {BCD44C89-636F-4BC9-9097-25FA56BFD6E3}.Debug|Win32.ActiveCfg = Debug|Any CPU - {BCD44C89-636F-4BC9-9097-25FA56BFD6E3}.Debug|Win32.Build.0 = Debug|Any CPU - {BCD44C89-636F-4BC9-9097-25FA56BFD6E3}.DebugNoTimeout|Any CPU.ActiveCfg = Debug|Any CPU - {BCD44C89-636F-4BC9-9097-25FA56BFD6E3}.DebugNoTimeout|Any CPU.Build.0 = Debug|Any CPU - {BCD44C89-636F-4BC9-9097-25FA56BFD6E3}.DebugNoTimeout|Mixed Platforms.ActiveCfg = Debug|Any CPU - {BCD44C89-636F-4BC9-9097-25FA56BFD6E3}.DebugNoTimeout|Mixed Platforms.Build.0 = Debug|Any CPU - {BCD44C89-636F-4BC9-9097-25FA56BFD6E3}.DebugNoTimeout|Win32.ActiveCfg = Debug|Any CPU - {BCD44C89-636F-4BC9-9097-25FA56BFD6E3}.DebugNoTimeout|Win32.Build.0 = Debug|Any CPU - {BCD44C89-636F-4BC9-9097-25FA56BFD6E3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BCD44C89-636F-4BC9-9097-25FA56BFD6E3}.Release|Any CPU.Build.0 = Release|Any CPU - {BCD44C89-636F-4BC9-9097-25FA56BFD6E3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {BCD44C89-636F-4BC9-9097-25FA56BFD6E3}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {BCD44C89-636F-4BC9-9097-25FA56BFD6E3}.Release|Win32.ActiveCfg = Release|Any CPU - {BCD44C89-636F-4BC9-9097-25FA56BFD6E3}.Release|Win32.Build.0 = Release|Any CPU {CFA0360E-BA8D-4D6F-AF76-63D8282109FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {CFA0360E-BA8D-4D6F-AF76-63D8282109FA}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {CFA0360E-BA8D-4D6F-AF76-63D8282109FA}.Debug|Win32.ActiveCfg = Debug|Any CPU diff --git a/src/LogExpert/Classes/Columnizer/ColumnizerManager.cs b/src/LogExpert/Classes/Columnizer/ColumnizerManager.cs new file mode 100644 index 00000000..992bf19c --- /dev/null +++ b/src/LogExpert/Classes/Columnizer/ColumnizerManager.cs @@ -0,0 +1,140 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; + +namespace LogExpert.Classes.Columnizer +{ + public class ColumnizerManager + { + public static ILogLineColumnizer FindColumnizerByName(string name, IList list) + { + foreach (ILogLineColumnizer columnizer in list) + { + if (columnizer.GetName().Equals(name)) + { + return columnizer; + } + } + return null; + } + + public static ILogLineColumnizer DecideColumnizerByName(string name, IList list) + { + foreach (ILogLineColumnizer columnizer in list) + { + if (columnizer.GetName().Equals(name)) + { + return columnizer; + } + } + + return FindColumnizer(null, null); + } + + public static ILogLineColumnizer CloneColumnizer(ILogLineColumnizer columnizer) + { + if (columnizer == null) + { + return null; + } + ConstructorInfo cti = columnizer.GetType().GetConstructor(Type.EmptyTypes); + if (cti != null) + { + object o = cti.Invoke(new object[] { }); + if (o is IColumnizerConfigurator) + { + ((IColumnizerConfigurator)o).LoadConfig(ConfigManager.ConfigDir); + } + return (ILogLineColumnizer)o; + } + return null; + } + + /// + /// This method implemented the "auto columnizer" feature. + /// This method should be called after each columnizer is changed to update the columizer. + /// + /// + /// + /// + /// + public static ILogLineColumnizer FindReplacementForAutoColumnizer(string fileName, + IAutoLogLineColumnizerCallback logFileReader, + ILogLineColumnizer logLineColumnizer) + { + if (logLineColumnizer == null || logLineColumnizer.GetName() == "Auto Columnizer") + { + return FindColumnizer(fileName, logFileReader); + } + return logLineColumnizer; + } + + public static ILogLineColumnizer FindBetterColumnizer(string fileName, + IAutoLogLineColumnizerCallback logFileReader, + ILogLineColumnizer logLineColumnizer) + { + var newColumnizer = FindColumnizer(fileName, logFileReader); + if (newColumnizer.GetType().Equals(logLineColumnizer.GetType())) + { + return null; + } + return newColumnizer; + } + + /// + /// This method will search all registered columnizer and return one according to the priority that returned + /// by the each columnizer. + /// + /// + /// + /// + public static ILogLineColumnizer FindColumnizer(string fileName, IAutoLogLineColumnizerCallback logFileReader) + { + if (string.IsNullOrEmpty(fileName)) + { + return new DefaultLogfileColumnizer(); + } + + List loglines = new List(); + + if (logFileReader != null) + { + loglines = new List() + { + // Sampling a few lines to select the correct columnizer + logFileReader.GetLogLine(0), + logFileReader.GetLogLine(1), + logFileReader.GetLogLine(2), + logFileReader.GetLogLine(3), + logFileReader.GetLogLine(4), + logFileReader.GetLogLine(5), + logFileReader.GetLogLine(25), + logFileReader.GetLogLine(100), + logFileReader.GetLogLine(200), + logFileReader.GetLogLine(400) + }; + } + + var registeredColumnizer = PluginRegistry.GetInstance().RegisteredColumnizers; + + List> priorityListOfColumnizers = new List>(); + + foreach (ILogLineColumnizer logLineColumnizer in registeredColumnizer) + { + Priority priority = default; + if (logLineColumnizer is IColumnizerPriority columnizerPriority) + { + priority = columnizerPriority.GetPriority(fileName, loglines); + } + + priorityListOfColumnizers.Add(new Tuple(priority, logLineColumnizer)); + } + + ILogLineColumnizer lineColumnizer = priorityListOfColumnizers.OrderByDescending(a => a.Item1).Select(a => a.Item2).First(); + + return lineColumnizer; + } + } +} diff --git a/src/LogExpert/Classes/Log/LogfileReader.cs b/src/LogExpert/Classes/Log/LogfileReader.cs index 2c305418..e9036a1c 100644 --- a/src/LogExpert/Classes/Log/LogfileReader.cs +++ b/src/LogExpert/Classes/Log/LogfileReader.cs @@ -11,7 +11,7 @@ namespace LogExpert { - public class LogfileReader + public class LogfileReader : IAutoLogLineColumnizerCallback { #region Fields diff --git a/src/LogExpert/Classes/PluginRegistry.cs b/src/LogExpert/Classes/PluginRegistry.cs index 244fe041..088270a9 100644 --- a/src/LogExpert/Classes/PluginRegistry.cs +++ b/src/LogExpert/Classes/PluginRegistry.cs @@ -15,7 +15,7 @@ namespace LogExpert /// It all has started with Columnizers only. So the different types of plugins have no common super interface. I didn't change it /// to keep existing plugin API stable. In a future version this may change. /// - internal class PluginRegistry + public class PluginRegistry { #region Fields diff --git a/src/LogExpert/Classes/Util.cs b/src/LogExpert/Classes/Util.cs index 86c42bc0..9a2b0984 100644 --- a/src/LogExpert/Classes/Util.cs +++ b/src/LogExpert/Classes/Util.cs @@ -374,38 +374,6 @@ public static unsafe int YetiLevenshtein(char* s1, int l1, char* s2, int l2, int return i; } - - public static ILogLineColumnizer FindColumnizerByName(string name, IList list) - { - foreach (ILogLineColumnizer columnizer in list) - { - if (columnizer.GetName().Equals(name)) - { - return columnizer; - } - } - return null; - } - - public static ILogLineColumnizer CloneColumnizer(ILogLineColumnizer columnizer) - { - if (columnizer == null) - { - return null; - } - ConstructorInfo cti = columnizer.GetType().GetConstructor(Type.EmptyTypes); - if (cti != null) - { - object o = cti.Invoke(new object[] { }); - if (o is IColumnizerConfigurator) - { - ((IColumnizerConfigurator) o).LoadConfig(ConfigManager.ConfigDir); - } - return (ILogLineColumnizer) o; - } - return null; - } - /// /// Returns true, if the given string is null or empty /// @@ -552,7 +520,7 @@ private static bool TestFilterMatch(FilterParams filterParams, ILogLine line, } } - // + // private static bool TestMatchSub(FilterParams filterParams, string line, string lowerSearchText, string searchText, Regex rex, bool exactMatch) { diff --git a/src/LogExpert/Controls/LogTabWindow/LogTabWindowPrivate.cs b/src/LogExpert/Controls/LogTabWindow/LogTabWindowPrivate.cs index fe0fecc2..1b256dc4 100644 --- a/src/LogExpert/Controls/LogTabWindow/LogTabWindowPrivate.cs +++ b/src/LogExpert/Controls/LogTabWindow/LogTabWindowPrivate.cs @@ -10,6 +10,7 @@ using System.Text; using System.Threading; using System.Windows.Forms; +using LogExpert.Classes.Columnizer; using LogExpert.Dialogs; using WeifenLuo.WinFormsUI.Docking; @@ -699,7 +700,7 @@ private void StatusLineEventWorker(StatusLineEventArgs e) } // tailState: 0,1,2 = on/off/off by Trigger - // syncMode: 0 = normal (no), 1 = time synced + // syncMode: 0 = normal (no), 1 = time synced private Icon CreateLedIcon(int level, bool dirty, int tailState, int syncMode) { Rectangle iconRect = leds[0]; @@ -1082,12 +1083,8 @@ private void StartTool(string cmd, string args, bool sysoutPipe, string columniz if (sysoutPipe) { - ILogLineColumnizer columnizer = Util.FindColumnizerByName(columnizerName, + ILogLineColumnizer columnizer = ColumnizerManager.DecideColumnizerByName(columnizerName, PluginRegistry.GetInstance().RegisteredColumnizers); - if (columnizer == null) - { - columnizer = PluginRegistry.GetInstance().RegisteredColumnizers[0]; - } _logger.Info("Starting external tool with sysout redirection: {0} {1}", cmd, args); startInfo.UseShellExecute = false; diff --git a/src/LogExpert/Controls/LogTabWindow/LogTabWindowPublic.cs b/src/LogExpert/Controls/LogTabWindow/LogTabWindowPublic.cs index bd004f46..13021da0 100644 --- a/src/LogExpert/Controls/LogTabWindow/LogTabWindowPublic.cs +++ b/src/LogExpert/Controls/LogTabWindow/LogTabWindowPublic.cs @@ -6,6 +6,7 @@ using System.Text; using System.Text.RegularExpressions; using System.Windows.Forms; +using LogExpert.Classes.Columnizer; using LogExpert.Dialogs; using WeifenLuo.WinFormsUI.Docking; @@ -252,7 +253,7 @@ public ILogLineColumnizer FindColumnizerByFileMask(string fileName) { if (Regex.IsMatch(fileName, entry.mask)) { - ILogLineColumnizer columnizer = Util.FindColumnizerByName(entry.columnizerName, + ILogLineColumnizer columnizer = ColumnizerManager.FindColumnizerByName(entry.columnizerName, PluginRegistry.GetInstance().RegisteredColumnizers); return columnizer; } diff --git a/src/LogExpert/Controls/LogWindow/LogWindow.cs b/src/LogExpert/Controls/LogWindow/LogWindow.cs index 48aa55e1..d7849901 100644 --- a/src/LogExpert/Controls/LogWindow/LogWindow.cs +++ b/src/LogExpert/Controls/LogWindow/LogWindow.cs @@ -17,6 +17,7 @@ using System.Linq; using NLog; using WeifenLuo.WinFormsUI.Docking; +using LogExpert.Classes.Columnizer; namespace LogExpert { @@ -165,8 +166,7 @@ public LogWindow(LogTabWindow parent, string fileName, bool isTempFile, tableLayoutPanel1.ColumnStyles[0].Width = 100; parentLogTabWin.HighlightSettingsChanged += parent_HighlightSettingsChanged; - - SetColumnizer(PluginRegistry.GetInstance().RegisteredColumnizers[0]); + SetColumnizer(null); patternArgs.maxMisses = 5; patternArgs.minWeight = 1; @@ -596,11 +596,6 @@ public IList GetRegisteredColumnizers() return PluginRegistry.GetInstance().RegisteredColumnizers; } - public ILogLineColumnizer GetDefaultColumnizer() - { - return new DefaultLogfileColumnizer(); - } - public int GetLineCount() { return logWindow.logFileReader.LineCount; diff --git a/src/LogExpert/Controls/LogWindow/LogWindowPrivate.cs b/src/LogExpert/Controls/LogWindow/LogWindowPrivate.cs index 57483323..d933feaf 100644 --- a/src/LogExpert/Controls/LogWindow/LogWindowPrivate.cs +++ b/src/LogExpert/Controls/LogWindow/LogWindowPrivate.cs @@ -17,6 +17,7 @@ using System.Linq; using NLog; using WeifenLuo.WinFormsUI.Docking; +using LogExpert.Classes.Columnizer; namespace LogExpert { @@ -393,13 +394,13 @@ private void SetGuiAfterLoading() { if (reloadMemento == null) { - columnizer = Util.CloneColumnizer(columnizer); + columnizer = ColumnizerManager.CloneColumnizer(columnizer); } } else { // Default Columnizers - columnizer = Util.CloneColumnizer(PluginRegistry.GetInstance().RegisteredColumnizers[0]); + columnizer = ColumnizerManager.CloneColumnizer(ColumnizerManager.FindColumnizer(FileName, logFileReader)); } } @@ -543,11 +544,10 @@ private void LoadingFinished() { _logger.Info("File loading complete."); - IAutoColumnizer autoColumnizer = currentColumnizer as IAutoColumnizer; - - if (autoColumnizer != null) + var newColumnizer = ColumnizerManager.FindBetterColumnizer(FileName, logFileReader, CurrentColumnizer); + if (newColumnizer != null) { - currentColumnizer = autoColumnizer.FindColumnizer(FileName, new ColumnizerCallback(this)); + PreSelectColumnizer(newColumnizer); } StatusLineText(""); @@ -888,12 +888,14 @@ private void PreSelectColumnizer(ILogLineColumnizer columnizer) else { CurrentColumnizer = forcedColumnizerForLoading = - PluginRegistry.GetInstance().RegisteredColumnizers[0]; + ColumnizerManager.FindColumnizer(FileName, logFileReader); } } private void SetColumnizer(ILogLineColumnizer columnizer) { + columnizer = ColumnizerManager.FindReplacementForAutoColumnizer(FileName, logFileReader, columnizer); + int timeDiff = 0; if (CurrentColumnizer != null && CurrentColumnizer.IsTimeshiftImplemented()) { @@ -912,13 +914,6 @@ private void SetColumnizerInternal(ILogLineColumnizer columnizer) { _logger.Info("SetColumnizerInternal(): {0}", columnizer.GetName()); - IAutoColumnizer autoColumnizer = columnizer as IAutoColumnizer; - - if (autoColumnizer != null) - { - columnizer = autoColumnizer.FindColumnizer(FileName, new ColumnizerCallback(this)); - } - ILogLineColumnizer oldColumnizer = CurrentColumnizer; bool oldColumnizerIsXmlType = CurrentColumnizer is ILogLineXmlColumnizer; bool oldColumnizerIsPreProcess = CurrentColumnizer is IPreProcessColumnizer; @@ -2779,7 +2774,7 @@ private void WritePipeTab(IList lineEntryList, string title) private void FilterRestore(LogWindow newWin, PersistenceData persistenceData) { newWin.WaitForLoadingFinished(); - ILogLineColumnizer columnizer = Util.FindColumnizerByName(persistenceData.columnizerName, + ILogLineColumnizer columnizer = ColumnizerManager.FindColumnizerByName(persistenceData.columnizerName, PluginRegistry.GetInstance().RegisteredColumnizers); if (columnizer != null) { diff --git a/src/LogExpert/Controls/LogWindow/LogWindowsPublic.cs b/src/LogExpert/Controls/LogWindow/LogWindowsPublic.cs index ccef1d08..6b2879bb 100644 --- a/src/LogExpert/Controls/LogWindow/LogWindowsPublic.cs +++ b/src/LogExpert/Controls/LogWindow/LogWindowsPublic.cs @@ -16,6 +16,7 @@ using System.Collections; using System.Linq; using WeifenLuo.WinFormsUI.Docking; +using LogExpert.Classes.Columnizer; namespace LogExpert { @@ -46,7 +47,7 @@ public void LoadFile(string fileName, EncodingOptions encodingOptions) { if (this.reloadMemento == null) { - columnizer = Util.CloneColumnizer(columnizer); + columnizer = ColumnizerManager.CloneColumnizer(columnizer); } } PreSelectColumnizer(columnizer); @@ -272,20 +273,20 @@ public void WaitForLoadingFinished() public void ForceColumnizer(ILogLineColumnizer columnizer) { - this.forcedColumnizer = Util.CloneColumnizer(columnizer); + this.forcedColumnizer = ColumnizerManager.CloneColumnizer(columnizer); SetColumnizer(this.forcedColumnizer); } public void ForceColumnizerForLoading(ILogLineColumnizer columnizer) { - this.forcedColumnizerForLoading = Util.CloneColumnizer(columnizer); + this.forcedColumnizerForLoading = ColumnizerManager.CloneColumnizer(columnizer); } public void PreselectColumnizer(string columnizerName) { - ILogLineColumnizer columnizer = Util.FindColumnizerByName(columnizerName, + ILogLineColumnizer columnizer = ColumnizerManager.FindColumnizerByName(columnizerName, PluginRegistry.GetInstance().RegisteredColumnizers); - PreSelectColumnizer(Util.CloneColumnizer(columnizer)); + PreSelectColumnizer(ColumnizerManager.CloneColumnizer(columnizer)); } public void ColumnizerConfigChanged() @@ -883,7 +884,7 @@ public void SetBookmarkFromTrigger(int lineNum, string comment) } catch (ArgumentException) { - // occurs on invalid regex + // occurs on invalid regex } if (this.bookmarkProvider.IsBookmarkAtLine(lineNum)) { @@ -1480,7 +1481,7 @@ public ILogLine GetCurrentLine() public ILogLine GetLine(int lineNum) { - if (lineNum < 0 || lineNum >= this.logFileReader.LineCount) + if (lineNum < 0 || logFileReader == null || lineNum >= this.logFileReader.LineCount) { return null; } diff --git a/src/LogExpert/Dialogs/SettingsDialog.cs b/src/LogExpert/Dialogs/SettingsDialog.cs index 11d08dc2..6c28cfc3 100644 --- a/src/LogExpert/Dialogs/SettingsDialog.cs +++ b/src/LogExpert/Dialogs/SettingsDialog.cs @@ -7,6 +7,7 @@ using System.Windows.Forms; using System.IO; using System.Runtime.InteropServices; +using LogExpert.Classes.Columnizer; namespace LogExpert.Dialogs { @@ -283,12 +284,8 @@ private void FillColumnizerList() row.Cells.Add(cell); row.Cells[0].Value = maskEntry.mask; - ILogLineColumnizer columnizer = Util.FindColumnizerByName(maskEntry.columnizerName, + ILogLineColumnizer columnizer = ColumnizerManager.DecideColumnizerByName(maskEntry.columnizerName, PluginRegistry.GetInstance().RegisteredColumnizers); - if (columnizer == null) - { - columnizer = PluginRegistry.GetInstance().RegisteredColumnizers[0]; - } row.Cells[1].Value = columnizer.GetName(); columnizerDataGridView.Rows.Add(row); diff --git a/src/LogExpert/Entities/DefaultLogfileColumnizer.cs b/src/LogExpert/Entities/DefaultLogfileColumnizer.cs index 1a1c754e..b21471ce 100644 --- a/src/LogExpert/Entities/DefaultLogfileColumnizer.cs +++ b/src/LogExpert/Entities/DefaultLogfileColumnizer.cs @@ -5,7 +5,7 @@ namespace LogExpert { - internal class DefaultLogfileColumnizer : ILogLineColumnizer + public class DefaultLogfileColumnizer : ILogLineColumnizer { #region ILogLineColumnizer Members diff --git a/src/LogExpert/LogExpert.csproj b/src/LogExpert/LogExpert.csproj index d52e51b0..da4c6847 100644 --- a/src/LogExpert/LogExpert.csproj +++ b/src/LogExpert/LogExpert.csproj @@ -58,6 +58,7 @@ Properties\AssemblyVersion.cs +