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
3 changes: 0 additions & 3 deletions src/AutoColumnizer/AutoColumnizer.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using LogExpert;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AutoColumnizer
{
Expand Down
13 changes: 2 additions & 11 deletions src/CsvColumnizer/CsvColumn.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
namespace CsvColumnizer
{
internal class CsvColumn
internal class CsvColumn(string name)
{
#region cTor

public CsvColumn(string name)
{
Name = name;
}

#endregion

#region Properties

public string Name { get; }
public string Name { get; } = name;

#endregion
}
Expand Down
65 changes: 33 additions & 32 deletions src/CsvColumnizer/CsvColumnizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CsvColumnizer : ILogLineColumnizer, IInitColumnizer, IColumnizerCon

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

private readonly IList<CsvColumn> _columnList = new List<CsvColumn>();
private readonly IList<CsvColumn> _columnList = [];
private CsvColumnizerConfig _config;

private ILogLine _firstLine;
Expand All @@ -47,14 +47,12 @@ public string PreProcessLine(string logLine, int lineNum, int realLineNum)

if (_config.MinColumns > 0)
{
using (CsvReader csv = new CsvReader(new StringReader(logLine), _config.ReaderConfiguration))
using CsvReader csv = new(new StringReader(logLine), _config.ReaderConfiguration);
if (csv.Parser.Count < _config.MinColumns)
{
if (csv.Parser.Count < _config.MinColumns)
{
// on invalid CSV don't hide the first line from LogExpert, since the file will be displayed in plain mode
_isValidCsv = false;
return logLine;
}
// on invalid CSV don't hide the first line from LogExpert, since the file will be displayed in plain mode
_isValidCsv = false;
return logLine;
}
}

Expand Down Expand Up @@ -120,9 +118,11 @@ public IColumnizedLogLine SplitLine(ILogLineColumnizerCallback callback, ILogLin

private static ColumnizedLogLine CreateColumnizedLogLine(ILogLine line)
{
ColumnizedLogLine cLogLine = new ColumnizedLogLine();
cLogLine.LogLine = line;
cLogLine.ColumnValues = new IColumn[] { new Column { FullValue = line.FullLine, Parent = cLogLine } };
ColumnizedLogLine cLogLine = new()
{
LogLine = line
};
cLogLine.ColumnValues = [new Column { FullValue = line.FullLine, Parent = cLogLine }];
return cLogLine;
}

Expand Down Expand Up @@ -194,16 +194,17 @@ public void DeSelected(ILogLineColumnizerCallback callback)
public void Configure(ILogLineColumnizerCallback callback, string configDir)
{
string configPath = configDir + "\\" + _configFileName;
FileInfo fileInfo = new FileInfo(configPath);
FileInfo fileInfo = new(configPath);

CsvColumnizerConfigDlg dlg = new(_config);

CsvColumnizerConfigDlg dlg = new CsvColumnizerConfigDlg(_config);
if (dlg.ShowDialog() == DialogResult.OK)
{
_config.VersionBuild = Assembly.GetExecutingAssembly().GetName().Version.Build;

using (StreamWriter sw = new StreamWriter(fileInfo.Create()))
using (StreamWriter sw = new(fileInfo.Create()))
{
JsonSerializer serializer = new JsonSerializer();
JsonSerializer serializer = new();
serializer.Serialize(sw, _config);
}

Expand Down Expand Up @@ -256,31 +257,31 @@ public Priority GetPriority(string fileName, IEnumerable<ILogLine> samples)

private IColumnizedLogLine SplitCsvLine(ILogLine line)
{
ColumnizedLogLine cLogLine = new ColumnizedLogLine();
cLogLine.LogLine = line;

using (CsvReader csv = new CsvReader(new StringReader(line.FullLine), _config.ReaderConfiguration))
ColumnizedLogLine cLogLine = new()
{
csv.Read();
csv.ReadHeader();
LogLine = line
};

//we only read line by line and not the whole file so it is always the header
string[] records = csv.HeaderRecord;
using CsvReader csv = new(new StringReader(line.FullLine), _config.ReaderConfiguration);
csv.Read();
csv.ReadHeader();

if (records != null)
{
List<Column> columns = new List<Column>();
//we only read line by line and not the whole file so it is always the header
string[] records = csv.HeaderRecord;

foreach (string record in records)
{
columns.Add(new Column { FullValue = record, Parent = cLogLine });
}
if (records != null)
{
List<Column> columns = [];

cLogLine.ColumnValues = columns.Select(a => a as IColumn).ToArray();
foreach (string record in records)
{
columns.Add(new Column { FullValue = record, Parent = cLogLine });
}

return cLogLine;
cLogLine.ColumnValues = columns.Select(a => a as IColumn).ToArray();
}

return cLogLine;
}

#endregion
Expand Down
16 changes: 9 additions & 7 deletions src/CsvColumnizer/CsvColumnizerConfig.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Globalization;
using CsvHelper.Configuration;
using CsvHelper.Configuration;

using Newtonsoft.Json;

using System;
using System.Globalization;

namespace CsvColumnizer
{
[Serializable]
Expand All @@ -13,13 +15,13 @@ public class CsvColumnizerConfig
public char CommentChar { get; set; }

public string DelimiterChar { get; set; }

public char EscapeChar { get; set; }

public bool HasFieldNames { get; set; }

public int MinColumns { get; set; }

public char QuoteChar { get; set; }

public int VersionBuild { get; set; }
Expand Down
13 changes: 3 additions & 10 deletions src/CsvColumnizer/CsvLogLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,16 @@

namespace CsvColumnizer
{
public class CsvLogLine : ILogLine
public class CsvLogLine(string fullLine, int lineNumber) : ILogLine
{
public CsvLogLine(string fullLine, int lineNumber)
{
FullLine = fullLine;
LineNumber = lineNumber;
}

#region Properties

public string FullLine { get; set; }
public string FullLine { get; set; } = fullLine;

public int LineNumber { get; set; }
public int LineNumber { get; set; } = lineNumber;

string ITextValue.Text => FullLine;

#endregion
}

}
47 changes: 25 additions & 22 deletions src/DefaultPlugins/Eminus.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System;
using Newtonsoft.Json;

using System;
using System.Collections.Generic;
using System.Xml;
using System.Windows.Forms;
using System.Net.Sockets;
using System.IO;
using System.Net.Sockets;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using System.Runtime.Versioning;
using System.Windows.Forms;
using System.Xml;

[assembly: SupportedOSPlatform("windows")]
namespace LogExpert
Expand All @@ -26,10 +27,7 @@ public class Eminus : IContextMenuEntry, ILogExpertPluginConfigurator

#region Properties

public string Text
{
get { return "eminus"; }
}
public string Text => "eminus";

#endregion

Expand All @@ -49,15 +47,15 @@ private XmlDocument BuildParam(ILogLine line)

pos += "created in ".Length;
int endPos = temp.IndexOf(dot, pos);

if (endPos == -1)
{
return null;
}

string className = temp[pos..endPos];
pos = temp.IndexOf(doubleDot, pos);

if (pos == -1)
{
return null;
Expand All @@ -76,7 +74,7 @@ private XmlDocument BuildParam(ILogLine line)
int pos = str.IndexOf("at ") + 3;
str = str[pos..]; // remove 'at '
int idx = str.IndexOfAny(['(', '$', '<']);

if (idx != -1)
{
if (str[idx] == '$')
Expand All @@ -94,19 +92,19 @@ private XmlDocument BuildParam(ILogLine line)
}

idx = str.LastIndexOf(':');

if (idx == -1)
{
return null;
}

pos = str.IndexOf(')', idx);

if (pos == -1)
{
return null;
}

lineNum = str.Substring(idx + 1, pos - idx - 1);
}
/*
Expand Down Expand Up @@ -230,9 +228,9 @@ public void SaveConfig(string configDir)
FileInfo fileInfo = new(configDir + Path.DirectorySeparatorChar + CFG_FILE_NAME);

dlg?.ApplyChanges();

_config = tmpConfig.Clone();

using StreamWriter sw = new(fileInfo.Create());
JsonSerializer serializer = new();
serializer.Serialize(sw, _config);
Expand All @@ -245,8 +243,10 @@ public bool HasEmbeddedForm()

public void ShowConfigForm(object panel)
{
dlg = new EminusConfigDlg(tmpConfig);
dlg.Parent = (Panel)panel;
dlg = new EminusConfigDlg(tmpConfig)
{
Parent = (Panel)panel
};
dlg.Show();
}

Expand All @@ -257,9 +257,12 @@ public void ShowConfigForm(object panel)
/// <param name="owner"></param>
public void ShowConfigDialog(object owner)
{
dlg = new EminusConfigDlg(tmpConfig);
dlg.TopLevel = true;
dlg.Owner = (Form)owner;
dlg = new EminusConfigDlg(tmpConfig)
{
TopLevel = true,
Owner = (Form)owner
};

dlg.ShowDialog();
dlg.ApplyChanges();
}
Expand Down
10 changes: 6 additions & 4 deletions src/DefaultPlugins/EminusConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ public class EminusConfig

public EminusConfig Clone()
{
EminusConfig config = new();
config.host = host;
config.port = port;
config.password = password;
EminusConfig config = new()
{
host = host,
port = port,
password = password
};
return config;
}

Expand Down
11 changes: 10 additions & 1 deletion src/DefaultPlugins/EminusConfigDlg.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Drawing;
using System.Windows.Forms;

namespace LogExpert
Expand All @@ -13,13 +14,21 @@ public partial class EminusConfigDlg : Form

public EminusConfigDlg(EminusConfig config)
{
SuspendLayout();

AutoScaleDimensions = new SizeF(96F, 96F);
AutoScaleMode = AutoScaleMode.Dpi;

InitializeComponent();

TopLevel = false;
Config = config;

hostTextBox.Text = config.host;
portTextBox.Text = "" + config.port;
portTextBox.Text = string.Empty + config.port;
passwordTextBox.Text = config.password;

ResumeLayout();
}

#endregion
Expand Down
Loading
Loading