Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 17 additions & 29 deletions src/ColumnizerLib.UnitTests/ColumnTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using LogExpert;
using LogExpert;

using NUnit.Framework;

using System;
using System.Text;

Expand All @@ -9,44 +11,30 @@ namespace ColumnizerLib.UnitTests;
public class ColumnTests
{
[Test]
public void Column_LineCutOf()
public void Column_LineCutOff ()
{
Column column = new();

StringBuilder builder = new();
var expectedFullValue = new StringBuilder().Append('6', 4675).Append("1234").ToString();
var expectedDisplayValue = expectedFullValue[..4675] + "..."; // Using substring shorthand

for (var i = 0; i < 4675; i++)
Column column = new()
{
builder.Append("6");
}

var expected = builder + "...";
builder.Append("1234");

column.FullValue = builder.ToString();
FullValue = expectedFullValue
};

Assert.That(column.DisplayValue, Is.EqualTo(expected));
Assert.That(column.FullValue, Is.EqualTo(builder.ToString()));
Assert.That(column.DisplayValue, Is.EqualTo(expectedDisplayValue));
Assert.That(column.FullValue, Is.EqualTo(expectedFullValue));
}

[Test]
public void Column_NoLineCutOf()
public void Column_NoLineCutOff ()
{
Column column = new();

StringBuilder builder = new();

for (var i = 0; i < 4675; i++)
var expected = new StringBuilder().Append('6', 4675).ToString();
Column column = new()
{
builder.Append("6");
}

var expected = builder.ToString();

column.FullValue = expected;
FullValue = expected
};

Assert.That(column.DisplayValue, Is.EqualTo(expected));
Assert.That(column.FullValue, Is.EqualTo(expected));
Assert.That(column.DisplayValue, Is.EqualTo(column.FullValue));
}

[Test]
Expand Down
29 changes: 12 additions & 17 deletions src/ColumnizerLib/Column.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ public class Column : IColumn
private const int MAXLENGTH = 4678 - 3;
private const string REPLACEMENT = "...";

private static readonly IEnumerable<Func<string, string>> _replacements;
private static readonly List<Func<string, string>> _replacements = [
//replace tab with 3 spaces, from old coding. Needed???
input => input.Replace("\t", " ", StringComparison.Ordinal),

//shorten string if it exceeds maxLength
input => input.Length > MAXLENGTH
? string.Concat(input.AsSpan(0, MAXLENGTH), REPLACEMENT)
: input
];

private string _fullValue;

Expand All @@ -20,32 +28,19 @@ public class Column : IColumn

static Column ()
{
var replacements = new List<Func<string, string>>(
[
//replace tab with 3 spaces, from old coding. Needed???
input => input.Replace("\t", " ", StringComparison.Ordinal),

//shorten string if it exceeds maxLength
input => input.Length > MAXLENGTH
? string.Concat(input.AsSpan(0, MAXLENGTH), REPLACEMENT)
: input
]);

if (Environment.Version >= Version.Parse("6.2"))
{
//Win8 or newer support full UTF8 chars with the preinstalled fonts.
//Replace null char with UTF8 Symbol U+2400 (␀)
replacements.Add(input => input.Replace("\0", "␀", StringComparison.Ordinal));
_replacements.Add(input => input.Replace("\0", "␀", StringComparison.Ordinal));
}
else
{
//Everything below Win8 the installed fonts seems to not to support reliabel
//Replace null char with space
replacements.Add(input => input.Replace("\0", " ", StringComparison.Ordinal));
_replacements.Add(input => input.Replace("\0", " ", StringComparison.Ordinal));
}

_replacements = replacements;

EmptyColumn = new Column { FullValue = string.Empty };
}

Expand Down Expand Up @@ -77,7 +72,7 @@ public string FullValue

public string DisplayValue { get; private set; }

string ITextValue.Text => DisplayValue;
public string Text => DisplayValue;

#endregion

Expand Down
6 changes: 4 additions & 2 deletions src/ColumnizerLib/Extensions/LogLineExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
namespace LogExpert.Extensions;

//TODO: Move this to LogExpert.UI, change to internal and fix tests
public static class LogLineExtensions
{
public static string ToClipBoardText(this ILogLine logLine)
//TOOD: check if the callers are checking for null before calling
public static string ToClipBoardText (this ILogLine logLine)
{
return "\t" + (logLine.LineNumber + 1).ToString() + "\t" + logLine.FullLine;
return logLine == null ? string.Empty : $"\t{logLine.LineNumber + 1}\t{logLine.FullLine}";
}
}
4 changes: 3 additions & 1 deletion src/ColumnizerLib/ILogExpertLogger.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

namespace LogExpert;
Expand All @@ -17,6 +18,7 @@ public interface ILogExpertLogger
/// </summary>
/// <param name="msg">A message to be logged.</param>
void Info(string msg);
void Info (IFormatProvider formatProvider, string msg);

/// <summary>
/// Logs a message on DEBUG level to LogExpert#s log file. The logfile is only active in debug builds.
Expand Down
2 changes: 1 addition & 1 deletion src/ColumnizerLib/IXmlLogConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface IXmlLogConfiguration
/// Example: {"log4j", "http://jakarta.apache.org/log4j"}
///
/// </summary>
string[] Namespace { get; }
string[] GetNamespaceDeclaration ();

#endregion
}
22 changes: 21 additions & 1 deletion src/ColumnizerLib/LineEntry.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;

namespace LogExpert;

/// <summary>
/// This helper struct holds a log line and its line number (zero based).
/// This struct is used by <see cref="ILogExpertCallback"/>.
/// </summary>
/// <seealso cref="ILogExpertCallback.AddPipedTab"/>
public struct LineEntry
public struct LineEntry : IEquatable<LineEntry>
{
/// <summary>
/// The content of the line.
Expand All @@ -16,4 +18,22 @@ public struct LineEntry
/// The line number. See <see cref="ILogExpertCallback.AddPipedTab"/> for an explanation of the line number.
/// </summary>
public int LineNum { get; set; }

public override bool Equals(object obj)
{
return obj is LineEntry other && Equals(other);
}

public readonly bool Equals(LineEntry other)
{
return LineNum == other.LineNum && Equals(LogLine, other.LogLine);
}

public override readonly int GetHashCode()
{
return HashCode.Combine(LineNum, LogLine);
}

public static bool operator == (LineEntry left, LineEntry right) => left.Equals(right);
public static bool operator != (LineEntry left, LineEntry right) => !left.Equals(right);
}
4 changes: 2 additions & 2 deletions src/GlassfishColumnizer/XmlConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using LogExpert;
using LogExpert;

namespace GlassfishColumnizer;

Expand All @@ -12,7 +12,7 @@ internal class XmlConfig : IXmlLogConfiguration

public string Stylesheet { get; }

public string[] Namespace => null;
public string[] GetNamespaceDeclaration () => null;

#endregion
}
4 changes: 2 additions & 2 deletions src/Log4jXmlColumnizer/XmlConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using LogExpert;
using LogExpert;

namespace Log4jXmlColumnizer;

Expand Down Expand Up @@ -26,7 +26,7 @@ internal class XmlConfig : IXmlLogConfiguration
"</xsl:template>" +
"</xsl:stylesheet>";

public string[] Namespace => ["log4j", "http://jakarta.apache.org/log4j"];
public string[] GetNamespaceDeclaration () => ["log4j", "http://jakarta.apache.org/log4j"];

#endregion
}
29 changes: 13 additions & 16 deletions src/LogExpert.Core/Classes/Bookmark/BookmarkDataProvider.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Globalization;

using LogExpert.Core.Entities;
using LogExpert.Core.Interface;

Expand Down Expand Up @@ -27,21 +29,11 @@ public BookmarkDataProvider (SortedList<int, Entities.Bookmark> bookmarkList)

#endregion

#region Delegates

public delegate void AllBookmarksRemovedEventHandler (object sender, EventArgs e);

public delegate void BookmarkAddedEventHandler (object sender, EventArgs e);

public delegate void BookmarkRemovedEventHandler (object sender, EventArgs e);

#endregion

#region Events

public event BookmarkAddedEventHandler BookmarkAdded;
public event BookmarkRemovedEventHandler BookmarkRemoved;
public event AllBookmarksRemovedEventHandler AllBookmarksRemoved;
public event EventHandler<EventArgs> BookmarkAdded;
public event EventHandler<EventArgs> BookmarkRemoved;
public event EventHandler<EventArgs> AllBookmarksRemoved;

#endregion

Expand Down Expand Up @@ -141,8 +133,11 @@ public void RemoveBookmarkForLine (int lineNum)
OnBookmarkRemoved();
}

public void RemoveBookmarksForLines (List<int> lineNumList)
//TOOD: check if the callers are checking for null before calling
public void RemoveBookmarksForLines (IEnumerable<int> lineNumList)
{
ArgumentNullException.ThrowIfNull(lineNumList, nameof(lineNumList));

foreach (var lineNum in lineNumList)
{
_ = BookmarkList.Remove(lineNum);
Expand All @@ -152,16 +147,18 @@ public void RemoveBookmarksForLines (List<int> lineNumList)
OnBookmarkRemoved();
}


//TOOD: check if the callers are checking for null before calling
public void AddBookmark (Entities.Bookmark bookmark)
{
ArgumentNullException.ThrowIfNull(bookmark, nameof(bookmark));

BookmarkList.Add(bookmark.LineNum, bookmark);
OnBookmarkAdded();
}

public void ClearAllBookmarks ()
{
_logger.Debug("Removing all bookmarks");
_logger.Debug(CultureInfo.InvariantCulture, "Removing all bookmarks");
BookmarkList.Clear();
OnAllBookmarksRemoved();
}
Expand Down
15 changes: 8 additions & 7 deletions src/LogExpert.Core/Classes/Columnizer/ColumnizerPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace LogExpert.Core.Classes.Columnizer;

public class ColumnizerPicker
public static class ColumnizerPicker
{
public static ILogLineColumnizer FindColumnizerByName (string name, IList<ILogLineColumnizer> list)
{
Expand Down Expand Up @@ -86,20 +86,23 @@ public static ILogLineColumnizer FindBetterColumnizer (string fileName,
return newColumnizer;
}

//TOOD: check if the callers are checking for null before calling
/// <summary>
/// This method will search all registered columnizer and return one according to the priority that returned
/// by the each columnizer.
/// </summary>
/// <param name="fileName"></param>
/// <param name="logFileReader"></param>
/// <returns></returns>
public static ILogLineColumnizer FindColumnizer (string fileName, IAutoLogLineColumnizerCallback logFileReader, IList<ILogLineColumnizer> list)
public static ILogLineColumnizer FindColumnizer (string fileName, IAutoLogLineColumnizerCallback logFileReader, IList<ILogLineColumnizer> registeredColumnizer)
{
if (string.IsNullOrEmpty(fileName))
{
return new DefaultLogfileColumnizer();
}

ArgumentNullException.ThrowIfNull(registeredColumnizer, nameof(registeredColumnizer));

List<ILogLine> loglines = [];

if (logFileReader != null)
Expand All @@ -120,9 +123,7 @@ public static ILogLineColumnizer FindColumnizer (string fileName, IAutoLogLineCo
];
}

var registeredColumnizer = list;

List<Tuple<Priority, ILogLineColumnizer>> priorityListOfColumnizers = [];
List<(Priority priority, ILogLineColumnizer columnizer)> priorityListOfColumnizers = [];

foreach (ILogLineColumnizer logLineColumnizer in registeredColumnizer)
{
Expand All @@ -132,10 +133,10 @@ public static ILogLineColumnizer FindColumnizer (string fileName, IAutoLogLineCo
priority = columnizerPriority.GetPriority(fileName, loglines);
}

priorityListOfColumnizers.Add(new Tuple<Priority, ILogLineColumnizer>(priority, logLineColumnizer));
priorityListOfColumnizers.Add((priority, logLineColumnizer));
}

ILogLineColumnizer lineColumnizer = priorityListOfColumnizers.OrderByDescending(a => a.Item1).Select(a => a.Item2).First();
ILogLineColumnizer lineColumnizer = priorityListOfColumnizers.OrderByDescending(item => item.priority).Select(item => item.columnizer).First();

return lineColumnizer;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using System.Text.RegularExpressions;

using static LogExpert.Core.Classes.Columnizer.TimeFormatDeterminer;
Expand Down Expand Up @@ -142,13 +143,13 @@ public string[] GetColumnNames ()
var i = 1;
while (columnNames.Count < GetColumnCount())
{
columnNames.Insert(columnNames.Count - 1, "Source" + i++.ToString());
columnNames.Insert(columnNames.Count - 1, $"Source{i++}");
}

return columnNames.ToArray();
}

public IColumnizedLogLine SplitLine (LogExpert.ILogLineColumnizerCallback callback, ILogLine line)
public IColumnizedLogLine SplitLine (ILogLineColumnizerCallback callback, ILogLine line)
{
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
Expand Down
Loading
Loading