Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 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
6 changes: 3 additions & 3 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ dotnet_style_parentheses_in_other_operators = never_if_unnecessary:warning
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning

# Modifier preferences
dotnet_style_require_accessibility_modifiers = always:warning
dotnet_style_require_accessibility_modifiers = for_non_interface_members

# Expression-level preferences
dotnet_prefer_system_hash_code = true
Expand Down Expand Up @@ -89,7 +89,7 @@ dotnet_style_allow_statement_immediately_after_block_experimental = false:warnin
#### C# Coding Conventions ####

# var preferences
csharp_style_var_elsewhere = false:suggestion
csharp_style_var_elsewhere = true:suggestion
csharp_style_var_for_built_in_types = true:warning
csharp_style_var_when_type_is_apparent = true:warning

Expand Down Expand Up @@ -277,7 +277,7 @@ dotnet_diagnostic.IDE0003.severity = warning
dotnet_diagnostic.IDE0004.severity = warning

# IDE0005: Remove unnecessary import
dotnet_diagnostic.IDE0005.severity = warning
dotnet_diagnostic.IDE0005.severity = none

# IDE0005_gen: Remove unnecessary import (NotConfigurable)
#dotnet_diagnostic.IDE0005_gen.severity = silent
Expand Down
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
8 changes: 5 additions & 3 deletions src/LogExpert.Core/Classes/Bookmark/BookmarkExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ public static class BookmarkExporter

#region Public methods

public static void ExportBookmarkList (SortedList<int, Entities.Bookmark> bookmarkList, string logfileName,
string fileName)
//TOOD: check if the callers are checking for null before calling
public static void ExportBookmarkList (SortedList<int, Entities.Bookmark> bookmarkList, string logfileName, string fileName)
{
ArgumentNullException.ThrowIfNull(bookmarkList, nameof(bookmarkList));
FileStream fs = new(fileName, FileMode.Create, FileAccess.Write);
StreamWriter writer = new(fs);
writer.WriteLine("Log file name;Line number;Comment");
foreach (Entities.Bookmark bookmark in bookmarkList.Values)
foreach (var bookmark in bookmarkList.Values)
{
var line = $"{logfileName};{bookmark.LineNum};{bookmark.Text.Replace(replacementForNewLine, @"\" + replacementForNewLine, StringComparison.OrdinalIgnoreCase).Replace("\r\n", replacementForNewLine, StringComparison.OrdinalIgnoreCase)}";
writer.WriteLine(line);
}

writer.Close();
fs.Close();
}
Expand Down
Loading
Loading