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
43 changes: 18 additions & 25 deletions src/ColumnizerLib/Column.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;

namespace LogExpert;
Expand All @@ -7,8 +7,8 @@
{
#region Fields

private static readonly int _maxLength = 4678 - 3;
private static readonly string _replacement = "...";
private const int MAXLENGTH = 4678 - 3;
private const string REPLACEMENT = "...";

private static readonly IEnumerable<Func<string, string>> _replacements;

Expand All @@ -18,42 +18,35 @@

#region cTor

static Column()
static Column ()

Check warning on line 21 in src/ColumnizerLib/Column.cs

View workflow job for this annotation

GitHub Actions / build

Initialize all static fields in 'Column' when those fields are declared and remove the explicit static constructor (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1810)
{
var replacements = new List<Func<string, string>>(
new Func<string, string>[]
{
[
//replace tab with 3 spaces, from old coding. Needed???
input => input.Replace("\t", " "),
input => input.Replace("\t", " ", StringComparison.Ordinal),

//shorten string if it exceeds maxLength
input =>
{
if (input.Length > _maxLength)
{
return input.Substring(0, _maxLength) + _replacement;
}

return input;
}
});
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", "␀"));
//Replace null char with UTF8 Symbol U+2400 (␀)
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", " "));
replacements.Add(input => input.Replace("\0", " ", StringComparison.Ordinal));
}

_replacements = replacements;

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

#endregion
Expand Down Expand Up @@ -84,30 +77,30 @@

public string DisplayValue { get; private set; }

string ITextValue.Text => DisplayValue;

Check warning on line 80 in src/ColumnizerLib/Column.cs

View workflow job for this annotation

GitHub Actions / build

Make 'Column' sealed (a breaking change if this class has previously shipped), implement the method non-explicitly, or implement a new method that exposes the functionality of 'LogExpert.ITextValue.get_Text' and is visible to derived classes (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1033)

#endregion

#region Public methods

public static Column[] CreateColumns(int count, IColumnizedLogLine parent)
public static Column[] CreateColumns (int count, IColumnizedLogLine parent)
{
return CreateColumns(count, parent, string.Empty);
}

public static Column[] CreateColumns(int count, IColumnizedLogLine parent, string defaultValue)
public static Column[] CreateColumns (int count, IColumnizedLogLine parent, string defaultValue)
{
var output = new Column[count];

for (var i = 0; i < count; i++)
{
output[i] = new Column {FullValue = defaultValue, Parent = parent};
output[i] = new Column { FullValue = defaultValue, Parent = parent };
}

return output;
}

public override string ToString()
public override string ToString ()
{
return DisplayValue ?? string.Empty;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ColumnizerLib/LineEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
/// This struct is used by <see cref="ILogExpertCallback"/>.
/// </summary>
/// <seealso cref="ILogExpertCallback.AddPipedTab"/>
public struct LineEntry

Check warning on line 8 in src/ColumnizerLib/LineEntry.cs

View workflow job for this annotation

GitHub Actions / build

LineEntry should override the equality (==) and inequality (!=) operators (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1815)

Check warning on line 8 in src/ColumnizerLib/LineEntry.cs

View workflow job for this annotation

GitHub Actions / build

LineEntry should override Equals (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1815)
{
/// <summary>
/// The content of the line.
/// </summary>
public ILogLine logLine;
public ILogLine LogLine { get; set; }

/// <summary>
/// The line number. See <see cref="ILogExpertCallback.AddPipedTab"/> for an explanation of the line number.
/// </summary>
public int lineNum;
public int LineNum { get; set; }
}
54 changes: 27 additions & 27 deletions src/CsvColumnizer/CsvColumnizer.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
using CsvHelper;

using LogExpert;

using Newtonsoft.Json;

using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -12,6 +6,12 @@
using System.Runtime.Versioning;
using System.Windows.Forms;

using CsvHelper;

using LogExpert;

using Newtonsoft.Json;

[assembly: SupportedOSPlatform("windows")]
namespace CsvColumnizer;

Expand All @@ -24,7 +24,7 @@ public class CsvColumnizer : ILogLineColumnizer, IInitColumnizer, IColumnizerCon
{
#region Fields

private static readonly string _configFileName = "csvcolumnizer.json";
private const string CONFIGFILENAME = "csvcolumnizer.json";

private readonly IList<CsvColumn> _columnList = [];
private CsvColumnizerConfig _config;
Expand All @@ -38,7 +38,7 @@ public class CsvColumnizer : ILogLineColumnizer, IInitColumnizer, IColumnizerCon

#region Public methods

public string PreProcessLine(string logLine, int lineNum, int realLineNum)
public string PreProcessLine (string logLine, int lineNum, int realLineNum)
{
if (realLineNum == 0)
{
Expand Down Expand Up @@ -72,22 +72,22 @@ public string PreProcessLine(string logLine, int lineNum, int realLineNum)
return logLine;
}

public string GetName()
public string GetName ()
{
return "CSV Columnizer";
}

public string GetDescription()
public string GetDescription ()
{
return "Splits CSV files into columns.\r\n\r\nCredits:\r\nThis Columnizer uses the CsvHelper. https://github.com/JoshClose/CsvHelper. \r\n";
}

public int GetColumnCount()
public int GetColumnCount ()
{
return _isValidCsv ? _columnList.Count : 1;
}

public string[] GetColumnNames()
public string[] GetColumnNames ()
{
var names = new string[GetColumnCount()];
if (_isValidCsv)
Expand All @@ -106,7 +106,7 @@ public string[] GetColumnNames()
return names;
}

public IColumnizedLogLine SplitLine(ILogLineColumnizerCallback callback, ILogLine line)
public IColumnizedLogLine SplitLine (ILogLineColumnizerCallback callback, ILogLine line)
{
if (_isValidCsv)
{
Expand All @@ -116,7 +116,7 @@ public IColumnizedLogLine SplitLine(ILogLineColumnizerCallback callback, ILogLin
return CreateColumnizedLogLine(line);
}

private static ColumnizedLogLine CreateColumnizedLogLine(ILogLine line)
private static ColumnizedLogLine CreateColumnizedLogLine (ILogLine line)
{
ColumnizedLogLine cLogLine = new()
{
Expand All @@ -126,32 +126,32 @@ private static ColumnizedLogLine CreateColumnizedLogLine(ILogLine line)
return cLogLine;
}

public bool IsTimeshiftImplemented()
public bool IsTimeshiftImplemented ()
{
return false;
}

public void SetTimeOffset(int msecOffset)
public void SetTimeOffset (int msecOffset)
{
throw new NotImplementedException();
}

public int GetTimeOffset()
public int GetTimeOffset ()
{
throw new NotImplementedException();
}

public DateTime GetTimestamp(ILogLineColumnizerCallback callback, ILogLine line)
public DateTime GetTimestamp (ILogLineColumnizerCallback callback, ILogLine line)
{
throw new NotImplementedException();
}

public void PushValue(ILogLineColumnizerCallback callback, int column, string value, string oldValue)
public void PushValue (ILogLineColumnizerCallback callback, int column, string value, string oldValue)
{
throw new NotImplementedException();
}

public void Selected(ILogLineColumnizerCallback callback)
public void Selected (ILogLineColumnizerCallback callback)
{
if (_isValidCsv) // see PreProcessLine()
{
Expand Down Expand Up @@ -186,14 +186,14 @@ public void Selected(ILogLineColumnizerCallback callback)
}
}

public void DeSelected(ILogLineColumnizerCallback callback)
public void DeSelected (ILogLineColumnizerCallback callback)
{
// nothing to do
}

public void Configure(ILogLineColumnizerCallback callback, string configDir)
public void Configure (ILogLineColumnizerCallback callback, string configDir)
{
var configPath = configDir + "\\" + _configFileName;
var configPath = configDir + "\\" + CONFIGFILENAME;
FileInfo fileInfo = new(configPath);

CsvColumnizerConfigDlg dlg = new(_config);
Expand All @@ -214,9 +214,9 @@ public void Configure(ILogLineColumnizerCallback callback, string configDir)
}
}

public void LoadConfig(string configDir)
public void LoadConfig (string configDir)
{
var configPath = Path.Combine(configDir, _configFileName);
var configPath = Path.Combine(configDir, CONFIGFILENAME);

if (!File.Exists(configPath))
{
Expand All @@ -239,7 +239,7 @@ public void LoadConfig(string configDir)
}
}

public Priority GetPriority(string fileName, IEnumerable<ILogLine> samples)
public Priority GetPriority (string fileName, IEnumerable<ILogLine> samples)
{
Priority result = Priority.NotSupport;

Expand All @@ -255,7 +255,7 @@ public Priority GetPriority(string fileName, IEnumerable<ILogLine> samples)

#region Private Methods

private IColumnizedLogLine SplitCsvLine(ILogLine line)
private IColumnizedLogLine SplitCsvLine (ILogLine line)
{
ColumnizedLogLine cLogLine = new()
{
Expand Down
13 changes: 7 additions & 6 deletions src/DefaultPlugins/ProcessLauncher.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Diagnostics;

namespace LogExpert;
Expand Down Expand Up @@ -26,7 +27,7 @@ public void Execute (string keyword, string param, ILogExpertCallback callback,
}
else
{
end = param.IndexOf(' ');
end = param.IndexOf(' ', StringComparison.Ordinal);
}

if (end == -1)
Expand All @@ -39,14 +40,14 @@ public void Execute (string keyword, string param, ILogExpertCallback callback,
lock (_callbackLock)
{
var parameters = param[end..].Trim();
parameters = parameters.Replace("%F", callback.GetFileName());
parameters = parameters.Replace("%K", keyword);
parameters = parameters.Replace("%F", callback.GetFileName(), StringComparison.Ordinal);
parameters = parameters.Replace("%K", keyword, StringComparison.Ordinal);

var lineNumber = callback.GetLineNum(); //Line Numbers start at 0, but are displayed (+1)
var logline = callback.GetLogLine(lineNumber).FullLine;
parameters = parameters.Replace("%L", string.Empty + lineNumber);
parameters = parameters.Replace("%T", callback.GetTabTitle());
parameters = parameters.Replace("%C", logline);
parameters = parameters.Replace("%L", string.Empty + lineNumber, System.StringComparison.Ordinal);
parameters = parameters.Replace("%T", callback.GetTabTitle(), StringComparison.Ordinal);
parameters = parameters.Replace("%C", logline, StringComparison.Ordinal);

Process explorer = new();
explorer.StartInfo.FileName = procName;
Expand Down
Loading
Loading