diff --git a/GitVersion.yml b/GitVersion.yml new file mode 100644 index 00000000..85cfd271 --- /dev/null +++ b/GitVersion.yml @@ -0,0 +1,6 @@ +assembly-versioning-scheme: MajorMinorPatchTag +mode: ContinuousDelivery +branches: {} +ignore: + sha: [] +merge-message-formats: {} diff --git a/appveyor.gitversion.yml b/appveyor.gitversion.yml new file mode 100644 index 00000000..c5762524 --- /dev/null +++ b/appveyor.gitversion.yml @@ -0,0 +1,9 @@ +install: + - choco install gitversion.portable -pre -y + +before_build: + - nuget restore + - ps: gitversion /l console /output buildserver /updateAssemblyInfo + +build: + project: scr\LogExpert.sln \ No newline at end of file diff --git a/build/Build.cs b/build/Build.cs index 2f490e85..8aa70116 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -5,9 +5,12 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using JetBrains.Annotations; +using Nuke.Common.Tools.DotCover; +using Nuke.Common.Tools.ReportGenerator; using Microsoft.Build.Execution; using Nuke.Common; -using Nuke.Common.BuildServers; +using Nuke.Common.CI.AppVeyor; +using Nuke.Common.CI.AppVeyor.Configuration; using Nuke.Common.Execution; using Nuke.Common.Git; using Nuke.Common.IO; @@ -18,12 +21,10 @@ using Nuke.Common.Tools.GitVersion; using Nuke.Common.Tools.NuGet; using Nuke.Common.Tools.NUnit; -using Nuke.Common.Utilities; using Nuke.Common.Utilities.Collections; using Nuke.GitHub; using static Nuke.Common.EnvironmentInfo; using static Nuke.Common.IO.FileSystemTasks; -using static Nuke.Common.IO.PathConstruction; using static Nuke.Common.Tools.MSBuild.MSBuildTasks; using static Nuke.Common.Tools.DotNet.DotNetTasks; using static Nuke.Common.IO.TextTasks; @@ -42,11 +43,13 @@ class Build : NukeBuild /// - Microsoft VSCode https://nuke.build/vscode public static int Main() => Execute(x => x.Test); - [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] private readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; + [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] + readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; [Solution] readonly Solution Solution; [GitRepository] readonly GitRepository GitRepository; - [GitVersion] readonly GitVersion GitVersion; + [GitVersion(UpdateBuildNumber = true)] + readonly Nuke.Common.Tools.GitVersion.GitVersion GitVersion; AbsolutePath SourceDirectory => RootDirectory / "src"; @@ -80,7 +83,7 @@ Version Version patch = AppVeyor.Instance.BuildNumber; } - return new Version(1, 8, patch); + return new Version(1, 8, 8, patch); } } @@ -88,7 +91,8 @@ Version Version string VersionString => $"{Version.Major}.{Version.Minor}.{Version.Build}"; [Parameter("Version Information string")] - string VersionInformationString => $"{VersionString}.Branch.{GitVersion.BranchName}.{GitVersion.Sha} {Configuration}"; + //.Branch.{GitVersion.BranchName}.{GitVersion.Sha} removed for testing purpose + string VersionInformationString => $"{VersionString} {Configuration}"; [Parameter("Version file string")] string VersionFileString => $"{Version.Major}.{Version.Minor}.0"; diff --git a/build/Configuration/Configuration.cs b/build/Configuration/Configuration.cs new file mode 100644 index 00000000..fd740356 --- /dev/null +++ b/build/Configuration/Configuration.cs @@ -0,0 +1,15 @@ +using System.ComponentModel; + +using Nuke.Common.Tooling; + +[TypeConverter(typeof(TypeConverter))] +public class Configuration : Enumeration +{ + public static Configuration Debug = new Configuration { Value = nameof(Debug) }; + public static Configuration Release = new Configuration { Value = nameof(Release) }; + + public static implicit operator string(Configuration configuration) + { + return configuration.Value; + } +} \ No newline at end of file diff --git a/build/_build.csproj b/build/_build.csproj index ccb775d3..3f08fed0 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -1,48 +1,51 @@ - - - - Exe - netcoreapp2.0 - false - - False - CS0649;CS0169 - - - - - + + + + Exe + netcoreapp3.1 + + false + + False + CS0649;CS0169 + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all runtime; build; native; contentfiles; analyzers - - - all - runtime; build; native; contentfiles; analyzers - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/ColumnizerLib.UnitTests/ColumnizerLib.UnitTests.csproj b/src/ColumnizerLib.UnitTests/ColumnizerLib.UnitTests.csproj index b086efdc..120fd833 100644 --- a/src/ColumnizerLib.UnitTests/ColumnizerLib.UnitTests.csproj +++ b/src/ColumnizerLib.UnitTests/ColumnizerLib.UnitTests.csproj @@ -59,10 +59,10 @@ - 3.12.0 + 3.13.3 - 3.15.1 + 4.2.1 diff --git a/src/JsonColumnizer/JsonColumnizer.csproj b/src/JsonColumnizer/JsonColumnizer.csproj index e2dc7401..b4b16a89 100644 --- a/src/JsonColumnizer/JsonColumnizer.csproj +++ b/src/JsonColumnizer/JsonColumnizer.csproj @@ -72,7 +72,7 @@ - 12.0.2 + 13.0.1 diff --git a/src/JsonCompactColumnizer/JsonCompactColumnizer.csproj b/src/JsonCompactColumnizer/JsonCompactColumnizer.csproj index 14e629ae..d4c70ce3 100644 --- a/src/JsonCompactColumnizer/JsonCompactColumnizer.csproj +++ b/src/JsonCompactColumnizer/JsonCompactColumnizer.csproj @@ -76,7 +76,7 @@ - 12.0.2 + 13.0.1 diff --git a/src/LogExpert.Tests/LogExpert.Tests.csproj b/src/LogExpert.Tests/LogExpert.Tests.csproj index 5d92c994..4477ab1d 100644 --- a/src/LogExpert.Tests/LogExpert.Tests.csproj +++ b/src/LogExpert.Tests/LogExpert.Tests.csproj @@ -63,13 +63,13 @@ - 4.13.0 + 4.17.2 - 3.12.0 + 3.13.3 - 3.15.1 + 4.2.1 diff --git a/src/LogExpert/Classes/Bookmark/BookmarkDataProvider.cs b/src/LogExpert/Classes/Bookmark/BookmarkDataProvider.cs index 6bdae183..80296305 100644 --- a/src/LogExpert/Classes/Bookmark/BookmarkDataProvider.cs +++ b/src/LogExpert/Classes/Bookmark/BookmarkDataProvider.cs @@ -1,10 +1,8 @@ using System; using System.Collections.Generic; -using System.Reflection; -using System.Text; using NLog; -namespace LogExpert +namespace LogExpert.Classes.Bookmark { internal class BookmarkDataProvider : IBookmarkData { @@ -18,12 +16,12 @@ internal class BookmarkDataProvider : IBookmarkData internal BookmarkDataProvider() { - BookmarkList = new SortedList(); + BookmarkList = new SortedList(); } - internal BookmarkDataProvider(SortedList bookmarkList) + internal BookmarkDataProvider(SortedList bookmarkList) { - this.BookmarkList = bookmarkList; + BookmarkList = bookmarkList; } #endregion @@ -47,13 +45,10 @@ internal BookmarkDataProvider(SortedList bookmarkList) #endregion #region Properties + + public BookmarkCollection Bookmarks => new BookmarkCollection(BookmarkList); - public BookmarkCollection Bookmarks - { - get { return new BookmarkCollection(this.BookmarkList); } - } - - internal SortedList BookmarkList { get; set; } + internal SortedList BookmarkList { get; set; } #endregion @@ -67,23 +62,23 @@ public void ToggleBookmark(int lineNum) } else { - AddBookmark(new Bookmark(lineNum)); + AddBookmark(new LogExpert.Bookmark(lineNum)); } } public bool IsBookmarkAtLine(int lineNum) { - return this.BookmarkList.ContainsKey(lineNum); + return BookmarkList.ContainsKey(lineNum); } public int GetBookmarkIndexForLine(int lineNum) { - return this.BookmarkList.IndexOfKey(lineNum); + return BookmarkList.IndexOfKey(lineNum); } - public Bookmark GetBookmarkForLine(int lineNum) + public LogExpert.Bookmark GetBookmarkForLine(int lineNum) { - return this.BookmarkList[lineNum]; + return BookmarkList[lineNum]; } #endregion @@ -92,8 +87,8 @@ public Bookmark GetBookmarkForLine(int lineNum) internal void ShiftBookmarks(int offset) { - SortedList newBookmarkList = new SortedList(); - foreach (Bookmark bookmark in this.BookmarkList.Values) + SortedList newBookmarkList = new SortedList(); + foreach (LogExpert.Bookmark bookmark in BookmarkList.Values) { int line = bookmark.LineNum - offset; if (line >= 0) @@ -102,26 +97,26 @@ internal void ShiftBookmarks(int offset) newBookmarkList.Add(line, bookmark); } } - this.BookmarkList = newBookmarkList; + BookmarkList = newBookmarkList; } internal int FindPrevBookmarkIndex(int lineNum) { - IList values = this.BookmarkList.Values; - for (int i = this.BookmarkList.Count - 1; i >= 0; --i) + IList values = BookmarkList.Values; + for (int i = BookmarkList.Count - 1; i >= 0; --i) { if (values[i].LineNum <= lineNum) { return i; } } - return this.BookmarkList.Count - 1; + return BookmarkList.Count - 1; } internal int FindNextBookmarkIndex(int lineNum) { - IList values = this.BookmarkList.Values; - for (int i = 0; i < this.BookmarkList.Count; ++i) + IList values = BookmarkList.Values; + for (int i = 0; i < BookmarkList.Count; ++i) { if (values[i].LineNum >= lineNum) { @@ -133,7 +128,7 @@ internal int FindNextBookmarkIndex(int lineNum) internal void RemoveBookmarkForLine(int lineNum) { - this.BookmarkList.Remove(lineNum); + BookmarkList.Remove(lineNum); OnBookmarkRemoved(); } @@ -141,22 +136,22 @@ internal void RemoveBookmarksForLines(List lineNumList) { foreach (int lineNum in lineNumList) { - this.BookmarkList.Remove(lineNum); + BookmarkList.Remove(lineNum); } OnBookmarkRemoved(); } - internal void AddBookmark(Bookmark bookmark) + internal void AddBookmark(LogExpert.Bookmark bookmark) { - this.BookmarkList.Add(bookmark.LineNum, bookmark); + BookmarkList.Add(bookmark.LineNum, bookmark); OnBookmarkAdded(); } internal void ClearAllBookmarks() { _logger.Debug("Removing all bookmarks"); - this.BookmarkList.Clear(); + BookmarkList.Clear(); OnAllBookmarksRemoved(); } @@ -164,26 +159,17 @@ internal void ClearAllBookmarks() protected void OnBookmarkAdded() { - if (BookmarkAdded != null) - { - BookmarkAdded(this, new EventArgs()); - } + BookmarkAdded?.Invoke(this, EventArgs.Empty); } protected void OnBookmarkRemoved() { - if (BookmarkRemoved != null) - { - BookmarkRemoved(this, new EventArgs()); - } + BookmarkRemoved?.Invoke(this, EventArgs.Empty); } protected void OnAllBookmarksRemoved() { - if (AllBookmarksRemoved != null) - { - AllBookmarksRemoved(this, new EventArgs()); - } + AllBookmarksRemoved?.Invoke(this, EventArgs.Empty); } } } \ No newline at end of file diff --git a/src/LogExpert/Classes/Log/LogStreamReaderBase.cs b/src/LogExpert/Classes/Log/LogStreamReaderBase.cs index e845e545..59b5ffcd 100644 --- a/src/LogExpert/Classes/Log/LogStreamReaderBase.cs +++ b/src/LogExpert/Classes/Log/LogStreamReaderBase.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Text; -using System.Threading.Tasks; namespace LogExpert.Classes.Log { diff --git a/src/LogExpert/Classes/Log/LogfileReader.cs b/src/LogExpert/Classes/Log/LogfileReader.cs index 624795d3..02231715 100644 --- a/src/LogExpert/Classes/Log/LogfileReader.cs +++ b/src/LogExpert/Classes/Log/LogfileReader.cs @@ -990,8 +990,7 @@ private void ReadToBufferList(ILogFileInfo logFileInfo, long filePos, int startL int droppedLines = logBuffer.PrevBuffersDroppedLinesSum; filePos = reader.Position; - while (ReadLine(reader, logBuffer.StartLine + logBuffer.LineCount, - logBuffer.StartLine + logBuffer.LineCount + droppedLines, out var line)) + while (ReadLine(reader, logBuffer.StartLine + logBuffer.LineCount, logBuffer.StartLine + logBuffer.LineCount + droppedLines, out var line)) { LogLine logLine = new LogLine(); if (_shouldStop) @@ -1645,6 +1644,7 @@ private ILogStreamReader GetLogStreamReader(Stream stream, EncodingOptions encod return IsXmlMode ? new XmlBlockSplitter(new XmlLogReader(reader), XmlLogConfig) : reader; } + private ILogStreamReader CreateLogStreamReader(Stream stream, EncodingOptions encodingOptions, bool useSystemReader) { if (useSystemReader) diff --git a/src/LogExpert/Classes/Log/PositionAwareStreamReaderBase.cs b/src/LogExpert/Classes/Log/PositionAwareStreamReaderBase.cs index 99e648bb..246197ba 100644 --- a/src/LogExpert/Classes/Log/PositionAwareStreamReaderBase.cs +++ b/src/LogExpert/Classes/Log/PositionAwareStreamReaderBase.cs @@ -8,9 +8,9 @@ public abstract class PositionAwareStreamReaderBase : LogStreamReaderBase { #region Fields - protected const int MAX_LINE_LEN = 20000; + private const int MAX_LINE_LEN = 20000; - private static readonly Encoding[] _preambleEncodings = new Encoding[] { Encoding.UTF8, Encoding.Unicode, Encoding.BigEndianUnicode, Encoding.UTF32 }; + private static readonly Encoding[] _preambleEncodings = { Encoding.UTF8, Encoding.Unicode, Encoding.BigEndianUnicode, Encoding.UTF32 }; private readonly BufferedStream _stream; private readonly StreamReader _reader; @@ -30,8 +30,8 @@ protected PositionAwareStreamReaderBase(Stream stream, EncodingOptions encodingO _preambleLength = DetectPreambleLengthAndEncoding(out Encoding detectedEncoding); - Encoding usedEncoding = getUsedEncoding(encodingOptions, detectedEncoding); - _posIncPrecomputed = getPosIncPrecomputed(usedEncoding); + Encoding usedEncoding = GetUsedEncoding(encodingOptions, detectedEncoding); + _posIncPrecomputed = GetPosIncPrecomputed(usedEncoding); _reader = new StreamReader(_stream, usedEncoding, true); @@ -71,6 +71,8 @@ public sealed override long Position public sealed override bool IsBufferComplete => true; + protected static int MaxLineLen => MAX_LINE_LEN; + #endregion #region Public methods @@ -90,7 +92,10 @@ protected override void Dispose(bool disposing) public override unsafe int ReadChar() { - if (IsDisposed) throw new ObjectDisposedException(ToString()); + if (IsDisposed) + { + throw new ObjectDisposedException(ToString()); + } try { @@ -154,7 +159,7 @@ private int DetectPreambleLengthAndEncoding(out Encoding detectedEncoding) int readLen = _stream.Read(readPreamble, 0, 4); if (readLen >= 2) { - foreach (Encoding encoding in PositionAwareStreamReaderBase._preambleEncodings) + foreach (Encoding encoding in _preambleEncodings) { byte[] preamble = encoding.GetPreamble(); bool fail = false; @@ -180,7 +185,7 @@ private int DetectPreambleLengthAndEncoding(out Encoding detectedEncoding) return 0; } - private Encoding getUsedEncoding(EncodingOptions encodingOptions, Encoding detectedEncoding) + private Encoding GetUsedEncoding(EncodingOptions encodingOptions, Encoding detectedEncoding) { if (encodingOptions.Encoding != null) { @@ -192,26 +197,25 @@ private Encoding getUsedEncoding(EncodingOptions encodingOptions, Encoding detec return detectedEncoding; } - if (encodingOptions.DefaultEncoding != null) - { - return encodingOptions.DefaultEncoding; - } - - return Encoding.Default; + return encodingOptions.DefaultEncoding ?? Encoding.Default; } - private int getPosIncPrecomputed(Encoding usedEncoding) + private int GetPosIncPrecomputed(Encoding usedEncoding) { - if (usedEncoding is UTF8Encoding) + switch (usedEncoding) { - return 0; - } - - if (usedEncoding is UnicodeEncoding) - { - return 2; + case UTF8Encoding _: + { + return 0; + } + case UnicodeEncoding _: + { + return 2; + } + default: + { + return 1; + } } - - return 1; } #endregion diff --git a/src/LogExpert/Classes/Log/PositionAwareStreamReaderLegacy.cs b/src/LogExpert/Classes/Log/PositionAwareStreamReaderLegacy.cs index 23053154..a3af3488 100644 --- a/src/LogExpert/Classes/Log/PositionAwareStreamReaderLegacy.cs +++ b/src/LogExpert/Classes/Log/PositionAwareStreamReaderLegacy.cs @@ -6,17 +6,16 @@ public class PositionAwareStreamReaderLegacy : PositionAwareStreamReaderBase { #region Fields - private readonly char[] charBuffer = new char[MAX_LINE_LEN]; + private readonly char[] _charBuffer = new char[MaxLineLen]; - private int _charBufferPos = 0; - private bool _crDetect = false; + private int _charBufferPos; + private bool _crDetect; #endregion #region cTor - public PositionAwareStreamReaderLegacy(Stream stream, EncodingOptions encodingOptions) - : base(stream, encodingOptions) + public PositionAwareStreamReaderLegacy(Stream stream, EncodingOptions encodingOptions) : base(stream, encodingOptions) { } @@ -36,35 +35,37 @@ public override string ReadLine() switch (readChar) { case '\n': + { _crDetect = false; - return getLineAndResetCharBufferPos(); + return GetLineAndResetCharBufferPos(); + } case '\r': + { if (_crDetect) { - return getLineAndResetCharBufferPos(); - } - else - { - _crDetect = true; + return GetLineAndResetCharBufferPos(); } + + _crDetect = true; break; + } default: + { if (_crDetect) { _crDetect = false; - string line = getLineAndResetCharBufferPos(); - appendToCharBuffer(readChar); + string line = GetLineAndResetCharBufferPos(); + AppendToCharBuffer(readChar); return line; } - else - { - appendToCharBuffer(readChar); - } + + AppendToCharBuffer(readChar); break; + } } } - string result = getLineAndResetCharBufferPos(); + string result = GetLineAndResetCharBufferPos(); if (readInt == -1 && result.Length == 0 && !_crDetect) { return null; // EOF @@ -75,7 +76,7 @@ public override string ReadLine() protected override void ResetReader() { - resetCharBufferPos(); + ResetCharBufferPos(); base.ResetReader(); } @@ -84,22 +85,22 @@ protected override void ResetReader() #region Private Methods - private string getLineAndResetCharBufferPos() + private string GetLineAndResetCharBufferPos() { - string result = new string(charBuffer, 0, _charBufferPos); - resetCharBufferPos(); + string result = new string(_charBuffer, 0, _charBufferPos); + ResetCharBufferPos(); return result; } - private void appendToCharBuffer(char readChar) + private void AppendToCharBuffer(char readChar) { - if (_charBufferPos < MAX_LINE_LEN) + if (_charBufferPos < MaxLineLen) { - charBuffer[_charBufferPos++] = readChar; + _charBuffer[_charBufferPos++] = readChar; } } - private void resetCharBufferPos() + private void ResetCharBufferPos() { _charBufferPos = 0; } diff --git a/src/LogExpert/Classes/Log/PositionAwareStreamReaderSystem.cs b/src/LogExpert/Classes/Log/PositionAwareStreamReaderSystem.cs index edd385c6..589ea48a 100644 --- a/src/LogExpert/Classes/Log/PositionAwareStreamReaderSystem.cs +++ b/src/LogExpert/Classes/Log/PositionAwareStreamReaderSystem.cs @@ -21,8 +21,7 @@ public class PositionAwareStreamReaderSystem : PositionAwareStreamReaderBase #region cTor - public PositionAwareStreamReaderSystem(Stream stream, EncodingOptions encodingOptions) - : base(stream, encodingOptions) + public PositionAwareStreamReaderSystem(Stream stream, EncodingOptions encodingOptions) : base(stream, encodingOptions) { } @@ -37,7 +36,7 @@ public override string ReadLine() if (_newLineSequenceLength == 0) { - _newLineSequenceLength = guessNewLineSequenceLength(reader); + _newLineSequenceLength = GuessNewLineSequenceLength(reader); } string line = reader.ReadLine(); @@ -46,9 +45,9 @@ public override string ReadLine() { MovePosition(Encoding.GetByteCount(line) + _newLineSequenceLength); - if (line.Length > MAX_LINE_LEN) + if (line.Length > MaxLineLen) { - line = line.Remove(MAX_LINE_LEN); + line = line.Remove(MaxLineLen); } } @@ -59,7 +58,7 @@ public override string ReadLine() #region Private Methods - private int guessNewLineSequenceLength(StreamReader reader) + private int GuessNewLineSequenceLength(StreamReader reader) { long currentPos = Position; diff --git a/src/LogExpert/Controls/LogWindow/LogWindow.cs b/src/LogExpert/Controls/LogWindow/LogWindow.cs index 8c1d6700..1a1c3820 100644 --- a/src/LogExpert/Controls/LogWindow/LogWindow.cs +++ b/src/LogExpert/Controls/LogWindow/LogWindow.cs @@ -4,6 +4,7 @@ using System.Windows.Forms; using LogExpert.Dialogs; using System.Threading; +using LogExpert.Classes.Bookmark; using LogExpert.Classes.ILogLineColumnizerCallback; using NLog; using WeifenLuo.WinFormsUI.Docking; diff --git a/src/LogExpert/LogExpert.csproj b/src/LogExpert/LogExpert.csproj index d2e2dd5e..7a381d6f 100644 --- a/src/LogExpert/LogExpert.csproj +++ b/src/LogExpert/LogExpert.csproj @@ -44,14 +44,8 @@ ..\Solution Items\Key.snk - - - False - ..\..\lib\CookComputing.XmlRpcV2.dll - - @@ -586,12 +580,12 @@ WinFormsUI + - 4.6.7 + 4.7.15 -