Skip to content

Commit 93d2c87

Browse files
authored
Merge pull request #378 from LogExperts/decouple_ui_businesslogic
Decouple UI businesslogic
2 parents fe25a88 + 4b697b5 commit 93d2c87

172 files changed

Lines changed: 7651 additions & 7630 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/AutoColumnizer/AutoColumnizer.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using LogExpert;
22

33
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
6-
using System.Text;
74

85
namespace AutoColumnizer
96
{

src/CsvColumnizer/CsvColumn.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
namespace CsvColumnizer
22
{
3-
internal class CsvColumn
3+
internal class CsvColumn(string name)
44
{
5-
#region cTor
6-
7-
public CsvColumn(string name)
8-
{
9-
Name = name;
10-
}
11-
12-
#endregion
13-
145
#region Properties
156

16-
public string Name { get; }
7+
public string Name { get; } = name;
178

189
#endregion
1910
}

src/CsvColumnizer/CsvColumnizer.cs

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class CsvColumnizer : ILogLineColumnizer, IInitColumnizer, IColumnizerCon
2626

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

29-
private readonly IList<CsvColumn> _columnList = new List<CsvColumn>();
29+
private readonly IList<CsvColumn> _columnList = [];
3030
private CsvColumnizerConfig _config;
3131

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

4848
if (_config.MinColumns > 0)
4949
{
50-
using (CsvReader csv = new CsvReader(new StringReader(logLine), _config.ReaderConfiguration))
50+
using CsvReader csv = new(new StringReader(logLine), _config.ReaderConfiguration);
51+
if (csv.Parser.Count < _config.MinColumns)
5152
{
52-
if (csv.Parser.Count < _config.MinColumns)
53-
{
54-
// on invalid CSV don't hide the first line from LogExpert, since the file will be displayed in plain mode
55-
_isValidCsv = false;
56-
return logLine;
57-
}
53+
// on invalid CSV don't hide the first line from LogExpert, since the file will be displayed in plain mode
54+
_isValidCsv = false;
55+
return logLine;
5856
}
5957
}
6058

@@ -120,9 +118,11 @@ public IColumnizedLogLine SplitLine(ILogLineColumnizerCallback callback, ILogLin
120118

121119
private static ColumnizedLogLine CreateColumnizedLogLine(ILogLine line)
122120
{
123-
ColumnizedLogLine cLogLine = new ColumnizedLogLine();
124-
cLogLine.LogLine = line;
125-
cLogLine.ColumnValues = new IColumn[] { new Column { FullValue = line.FullLine, Parent = cLogLine } };
121+
ColumnizedLogLine cLogLine = new()
122+
{
123+
LogLine = line
124+
};
125+
cLogLine.ColumnValues = [new Column { FullValue = line.FullLine, Parent = cLogLine }];
126126
return cLogLine;
127127
}
128128

@@ -194,16 +194,17 @@ public void DeSelected(ILogLineColumnizerCallback callback)
194194
public void Configure(ILogLineColumnizerCallback callback, string configDir)
195195
{
196196
string configPath = configDir + "\\" + _configFileName;
197-
FileInfo fileInfo = new FileInfo(configPath);
197+
FileInfo fileInfo = new(configPath);
198+
199+
CsvColumnizerConfigDlg dlg = new(_config);
198200

199-
CsvColumnizerConfigDlg dlg = new CsvColumnizerConfigDlg(_config);
200201
if (dlg.ShowDialog() == DialogResult.OK)
201202
{
202203
_config.VersionBuild = Assembly.GetExecutingAssembly().GetName().Version.Build;
203204

204-
using (StreamWriter sw = new StreamWriter(fileInfo.Create()))
205+
using (StreamWriter sw = new(fileInfo.Create()))
205206
{
206-
JsonSerializer serializer = new JsonSerializer();
207+
JsonSerializer serializer = new();
207208
serializer.Serialize(sw, _config);
208209
}
209210

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

257258
private IColumnizedLogLine SplitCsvLine(ILogLine line)
258259
{
259-
ColumnizedLogLine cLogLine = new ColumnizedLogLine();
260-
cLogLine.LogLine = line;
261-
262-
using (CsvReader csv = new CsvReader(new StringReader(line.FullLine), _config.ReaderConfiguration))
260+
ColumnizedLogLine cLogLine = new()
263261
{
264-
csv.Read();
265-
csv.ReadHeader();
262+
LogLine = line
263+
};
266264

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

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

274-
foreach (string record in records)
275-
{
276-
columns.Add(new Column { FullValue = record, Parent = cLogLine });
277-
}
272+
if (records != null)
273+
{
274+
List<Column> columns = [];
278275

279-
cLogLine.ColumnValues = columns.Select(a => a as IColumn).ToArray();
276+
foreach (string record in records)
277+
{
278+
columns.Add(new Column { FullValue = record, Parent = cLogLine });
280279
}
281280

282-
return cLogLine;
281+
cLogLine.ColumnValues = columns.Select(a => a as IColumn).ToArray();
283282
}
283+
284+
return cLogLine;
284285
}
285286

286287
#endregion

src/CsvColumnizer/CsvColumnizerConfig.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
using System;
2-
using System.Globalization;
3-
using CsvHelper.Configuration;
1+
using CsvHelper.Configuration;
2+
43
using Newtonsoft.Json;
54

5+
using System;
6+
using System.Globalization;
7+
68
namespace CsvColumnizer
79
{
810
[Serializable]
@@ -13,13 +15,13 @@ public class CsvColumnizerConfig
1315
public char CommentChar { get; set; }
1416

1517
public string DelimiterChar { get; set; }
16-
18+
1719
public char EscapeChar { get; set; }
18-
20+
1921
public bool HasFieldNames { get; set; }
20-
22+
2123
public int MinColumns { get; set; }
22-
24+
2325
public char QuoteChar { get; set; }
2426

2527
public int VersionBuild { get; set; }

src/CsvColumnizer/CsvLogLine.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,16 @@
22

33
namespace CsvColumnizer
44
{
5-
public class CsvLogLine : ILogLine
5+
public class CsvLogLine(string fullLine, int lineNumber) : ILogLine
66
{
7-
public CsvLogLine(string fullLine, int lineNumber)
8-
{
9-
FullLine = fullLine;
10-
LineNumber = lineNumber;
11-
}
12-
137
#region Properties
148

15-
public string FullLine { get; set; }
9+
public string FullLine { get; set; } = fullLine;
1610

17-
public int LineNumber { get; set; }
11+
public int LineNumber { get; set; } = lineNumber;
1812

1913
string ITextValue.Text => FullLine;
2014

2115
#endregion
2216
}
23-
2417
}

src/DefaultPlugins/Eminus.cs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
using System;
1+
using Newtonsoft.Json;
2+
3+
using System;
24
using System.Collections.Generic;
3-
using System.Xml;
4-
using System.Windows.Forms;
5-
using System.Net.Sockets;
65
using System.IO;
6+
using System.Net.Sockets;
77
using System.Runtime.Serialization;
8-
using Newtonsoft.Json;
98
using System.Runtime.Versioning;
9+
using System.Windows.Forms;
10+
using System.Xml;
1011

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

2728
#region Properties
2829

29-
public string Text
30-
{
31-
get { return "eminus"; }
32-
}
30+
public string Text => "eminus";
3331

3432
#endregion
3533

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

5048
pos += "created in ".Length;
5149
int endPos = temp.IndexOf(dot, pos);
52-
50+
5351
if (endPos == -1)
5452
{
5553
return null;
5654
}
5755

5856
string className = temp[pos..endPos];
5957
pos = temp.IndexOf(doubleDot, pos);
60-
58+
6159
if (pos == -1)
6260
{
6361
return null;
@@ -76,7 +74,7 @@ private XmlDocument BuildParam(ILogLine line)
7674
int pos = str.IndexOf("at ") + 3;
7775
str = str[pos..]; // remove 'at '
7876
int idx = str.IndexOfAny(['(', '$', '<']);
79-
77+
8078
if (idx != -1)
8179
{
8280
if (str[idx] == '$')
@@ -94,19 +92,19 @@ private XmlDocument BuildParam(ILogLine line)
9492
}
9593

9694
idx = str.LastIndexOf(':');
97-
95+
9896
if (idx == -1)
9997
{
10098
return null;
10199
}
102100

103101
pos = str.IndexOf(')', idx);
104-
102+
105103
if (pos == -1)
106104
{
107105
return null;
108106
}
109-
107+
110108
lineNum = str.Substring(idx + 1, pos - idx - 1);
111109
}
112110
/*
@@ -230,9 +228,9 @@ public void SaveConfig(string configDir)
230228
FileInfo fileInfo = new(configDir + Path.DirectorySeparatorChar + CFG_FILE_NAME);
231229

232230
dlg?.ApplyChanges();
233-
231+
234232
_config = tmpConfig.Clone();
235-
233+
236234
using StreamWriter sw = new(fileInfo.Create());
237235
JsonSerializer serializer = new();
238236
serializer.Serialize(sw, _config);
@@ -245,8 +243,10 @@ public bool HasEmbeddedForm()
245243

246244
public void ShowConfigForm(object panel)
247245
{
248-
dlg = new EminusConfigDlg(tmpConfig);
249-
dlg.Parent = (Panel)panel;
246+
dlg = new EminusConfigDlg(tmpConfig)
247+
{
248+
Parent = (Panel)panel
249+
};
250250
dlg.Show();
251251
}
252252

@@ -257,9 +257,12 @@ public void ShowConfigForm(object panel)
257257
/// <param name="owner"></param>
258258
public void ShowConfigDialog(object owner)
259259
{
260-
dlg = new EminusConfigDlg(tmpConfig);
261-
dlg.TopLevel = true;
262-
dlg.Owner = (Form)owner;
260+
dlg = new EminusConfigDlg(tmpConfig)
261+
{
262+
TopLevel = true,
263+
Owner = (Form)owner
264+
};
265+
263266
dlg.ShowDialog();
264267
dlg.ApplyChanges();
265268
}

src/DefaultPlugins/EminusConfig.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ public class EminusConfig
1717

1818
public EminusConfig Clone()
1919
{
20-
EminusConfig config = new();
21-
config.host = host;
22-
config.port = port;
23-
config.password = password;
20+
EminusConfig config = new()
21+
{
22+
host = host,
23+
port = port,
24+
password = password
25+
};
2426
return config;
2527
}
2628

src/DefaultPlugins/EminusConfigDlg.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Drawing;
23
using System.Windows.Forms;
34

45
namespace LogExpert
@@ -13,13 +14,21 @@ public partial class EminusConfigDlg : Form
1314

1415
public EminusConfigDlg(EminusConfig config)
1516
{
17+
SuspendLayout();
18+
19+
AutoScaleDimensions = new SizeF(96F, 96F);
20+
AutoScaleMode = AutoScaleMode.Dpi;
21+
1622
InitializeComponent();
23+
1724
TopLevel = false;
1825
Config = config;
1926

2027
hostTextBox.Text = config.host;
21-
portTextBox.Text = "" + config.port;
28+
portTextBox.Text = string.Empty + config.port;
2229
passwordTextBox.Text = config.password;
30+
31+
ResumeLayout();
2332
}
2433

2534
#endregion

0 commit comments

Comments
 (0)