Skip to content

Commit 36df022

Browse files
authored
Merge pull request #331 from RandallFlagg/CodeImprovement
Code improvement
2 parents 1b1b009 + 2f5f1f6 commit 36df022

Some content is hidden

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

54 files changed

+2444
-2614
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ Nuke.build Requirements
5858
# FAQ / HELP / Informations / Examples
5959
Please checkout the wiki for FAQ / HELP / Informations / Examples
6060

61+
# High DPI
62+
- dont use AutoScaleMode for single GUI controls like Buttons etc.
63+
- dont use AutoScaleDimensions for single GUI controls like Buttons etc.
64+
6165
https://github.com/zarunbal/LogExpert/wiki
6266

6367
# Discord Server

src/ColumnizerLib/ColumnizerLib.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net8.0-windows</TargetFramework>
4-
<EnableWindowsTargeting>true</EnableWindowsTargeting>
3+
<TargetFramework>net8.0</TargetFramework>
54
<OutputType>Library</OutputType>
65
<AppDesignerFolder>Properties</AppDesignerFolder>
76
<RootNamespace>LogExpert</RootNamespace>
87
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
9-
<UseWindowsForms>true</UseWindowsForms>
108
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
119
<DocumentationFile>$(SolutionDir)..\bin\Docs\ColumnizerLib.xml</DocumentationFile>
1210
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>

src/ColumnizerLib/ILogExpertPluginConfigurator.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Text;
4-
using System.Windows.Forms;
54

65
namespace LogExpert
76
{
@@ -46,7 +45,7 @@ public interface ILogExpertPluginConfigurator
4645
/// </summary>
4746
/// <seealso cref="HasEmbeddedForm"/>
4847
/// <param name="parentPanel">Set this panel as the parent for you config dialog.</param>
49-
void ShowConfigForm(Panel parentPanel);
48+
void ShowConfigForm(object parentPanel);
5049

5150
/// <summary>
5251
/// Implement this function if your plugin uses an own top level dialog for the configuration (modal config dialog).
@@ -60,7 +59,7 @@ public interface ILogExpertPluginConfigurator
6059
/// </summary>
6160
/// <seealso cref="HasEmbeddedForm"/>
6261
/// <param name="owner">Set the given Form as the owner of your dialog.</param>
63-
void ShowConfigDialog(Form owner);
62+
void ShowConfigDialog(object owner);
6463

6564
/// <summary>
6665
/// This function is called when the user selects another plugin in the list. You should retrieve

src/DefaultPlugins/Eminus.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ public bool HasEmbeddedForm()
241241
return true;
242242
}
243243

244-
public void ShowConfigForm(Panel panel)
244+
public void ShowConfigForm(object panel)
245245
{
246246
dlg = new EminusConfigDlg(tmpConfig);
247-
dlg.Parent = panel;
247+
dlg.Parent = (Panel)panel;
248248
dlg.Show();
249249
}
250250

@@ -253,11 +253,11 @@ public void ShowConfigForm(Panel panel)
253253
/// is pressed (HasEmbeddedForm() must return false for this).
254254
/// </summary>
255255
/// <param name="owner"></param>
256-
public void ShowConfigDialog(Form owner)
256+
public void ShowConfigDialog(object owner)
257257
{
258258
dlg = new EminusConfigDlg(tmpConfig);
259259
dlg.TopLevel = true;
260-
dlg.Owner = owner;
260+
dlg.Owner = (Form)owner;
261261
dlg.ShowDialog();
262262
dlg.ApplyChanges();
263263
}

src/FlashIconHighlighter/FlashIconPlugin.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ public string Text
1717

1818
#endregion
1919

20-
private delegate void FlashWindowFx(Form form);
21-
2220
#region IKeywordAction Member
2321

2422
public void Execute(string keyword, string param, ILogExpertCallback callback, ILogLineColumnizer columnizer)
@@ -28,8 +26,7 @@ public void Execute(string keyword, string param, ILogExpertCallback callback, I
2826
{
2927
if (form.TopLevel && form.Name.Equals("LogTabWindow") && form.Text.Contains(callback.GetFileName()))
3028
{
31-
FlashWindowFx fx = FlashWindow;
32-
form.BeginInvoke(fx, [form]);
29+
form.BeginInvoke(FlashWindow, [form]);
3330
}
3431
}
3532
}

src/LogExpert.Tests/ColumnizerPickerTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void FindReplacementForAutoColumnizer_ValidTextFile_ReturnCorrectColumniz
7474
autoColumnizer.Setup(a => a.GetName()).Returns("Auto Columnizer");
7575

7676
// TODO: When DI container is ready, we can mock this set up.
77-
PluginRegistry.GetInstance().RegisteredColumnizers.Add(new JsonCompactColumnizer());
77+
PluginRegistry.Instance.RegisteredColumnizers.Add(new JsonCompactColumnizer());
7878
var result = ColumnizerPicker.FindReplacementForAutoColumnizer(fileName, reader, autoColumnizer.Object);
7979

8080
Assert.That(columnizerType, Is.EqualTo(result.GetType()));
@@ -87,9 +87,9 @@ public void DecideColumnizerByName_WhenReaderIsNotReady_ReturnCorrectColumnizer(
8787
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
8888

8989
// TODO: When DI container is ready, we can mock this set up.
90-
PluginRegistry.GetInstance().RegisteredColumnizers.Add(new JsonCompactColumnizer());
90+
PluginRegistry.Instance.RegisteredColumnizers.Add(new JsonCompactColumnizer());
9191
var result = ColumnizerPicker.DecideColumnizerByName(fileName,
92-
PluginRegistry.GetInstance().RegisteredColumnizers);
92+
PluginRegistry.Instance.RegisteredColumnizers);
9393

9494
Assert.That(columnizerType, Is.EqualTo(result.GetType()));
9595
}
@@ -102,10 +102,10 @@ public void DecideColumnizerByName_ValidTextFile_ReturnCorrectColumnizer(
102102
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, columnizerName);
103103

104104
// TODO: When DI container is ready, we can mock this set up.
105-
PluginRegistry.GetInstance().RegisteredColumnizers.Add(new JsonColumnizer.JsonColumnizer());
105+
PluginRegistry.Instance.RegisteredColumnizers.Add(new JsonColumnizer.JsonColumnizer());
106106

107107
var result = ColumnizerPicker.DecideColumnizerByName(columnizerName,
108-
PluginRegistry.GetInstance().RegisteredColumnizers);
108+
PluginRegistry.Instance.RegisteredColumnizers);
109109

110110
Assert.That(columnizerType, Is.EqualTo(result.GetType()));
111111
}

src/LogExpert.Tests/JSONSaveTest.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using LogExpert.Config;
2-
32
using Newtonsoft.Json;
4-
53
using NUnit.Framework;
6-
74
using System.IO;
85

96
namespace LogExpert.Tests
@@ -20,14 +17,14 @@ public void SaveOptionsAsJSON()
2017
string settingsFile = configDir + "\\settings.json";
2118

2219
Settings settings = null;
23-
20+
2421
Assert.DoesNotThrow(CastSettings);
2522
Assert.That(settings, Is.Not.Null);
2623
Assert.That(settings.alwaysOnTop, Is.True);
2724

2825
ConfigManager.Settings.alwaysOnTop = false;
2926
ConfigManager.Save(SettingsFlags.All);
30-
27+
3128
settings = null;
3229
Assert.DoesNotThrow(CastSettings);
3330

src/LogExpert/Classes/CmdLine.cs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/*
55
* Taken from https://cmdline.codeplex.com/
6-
*
6+
*
77
*/
88

99
namespace LogExpert.Classes
@@ -15,19 +15,23 @@ public class CmdLineException : Exception
1515
{
1616
#region cTor
1717

18-
public CmdLineException(string parameter, string message) : base($"Syntax error of parameter -{parameter}: {message}")
18+
public CmdLineException(string parameter, string message)
19+
:
20+
base(string.Format("Syntax error of parameter -{0}: {1}", parameter, message))
1921
{
2022
}
2123

22-
public CmdLineException(string message) : base(message)
24+
public CmdLineException(string message)
25+
:
26+
base(message)
2327
{
2428
}
2529

2630
#endregion
2731
}
2832

2933
/// <summary>
30-
/// Represents a command line parameter.
34+
/// Represents a command line parameter.
3135
/// Parameters are words in the command line beginning with a hyphen (-).
3236
/// The value of the parameter is the next word in
3337
/// </summary>
@@ -99,7 +103,7 @@ public virtual void SetValue(string value)
99103
}
100104

101105
/// <summary>
102-
/// Represents an integer command line parameter.
106+
/// Represents an integer command line parameter.
103107
/// </summary>
104108
public class CmdLineInt : CmdLineParameter
105109
{
@@ -158,25 +162,22 @@ public CmdLineInt(string name, bool required, string helpMessage, int min, int m
158162
public override void SetValue(string value)
159163
{
160164
base.SetValue(value);
161-
int i;
162-
165+
int i = 0;
163166
try
164167
{
165168
i = Convert.ToInt32(value);
166169
}
167170
catch (Exception)
168171
{
169-
throw new CmdLineException(Name, "Value is not an integer.");
172+
throw new CmdLineException(base.Name, "Value is not an integer.");
170173
}
171-
172174
if (i < _min)
173175
{
174-
throw new CmdLineException(Name, $"Value must be greather or equal to {_min}.");
176+
throw new CmdLineException(base.Name, string.Format("Value must be greather or equal to {0}.", _min));
175177
}
176-
177178
if (i > _max)
178179
{
179-
throw new CmdLineException(Name, $"Value must be less or equal to {_max}.");
180+
throw new CmdLineException(base.Name, string.Format("Value must be less or equal to {0}.", _max));
180181
}
181182
Value = i;
182183
}
@@ -252,11 +253,11 @@ public CmdLineParameter this[string name]
252253
{
253254
get
254255
{
255-
if (!parameters.TryGetValue(name, out CmdLineParameter value))
256+
if (!parameters.ContainsKey(name))
256257
{
257258
throw new CmdLineException(name, "Not a registered parameter.");
258259
}
259-
return value;
260+
return parameters[name];
260261
}
261262
}
262263

@@ -306,8 +307,8 @@ public string[] Parse(string[] args)
306307
if (args[i].Length > 1 && args[i][0] == '-')
307308
{
308309
// The current string is a parameter name
309-
string key = args[i][1..].ToLower();
310-
string value = string.Empty;
310+
string key = args[i].Substring(1, args[i].Length - 1).ToLower();
311+
string value = "";
311312
i++;
312313
if (i < args.Length)
313314
{
@@ -322,17 +323,17 @@ public string[] Parse(string[] args)
322323
i++;
323324
}
324325
}
325-
if (!parameters.TryGetValue(key, out CmdLineParameter cmdLineParameter))
326+
if (!parameters.ContainsKey(key))
326327
{
327328
throw new CmdLineException(key, "Parameter is not allowed.");
328329
}
329330

330-
if (cmdLineParameter.Exists)
331+
if (parameters[key].Exists)
331332
{
332333
throw new CmdLineException(key, "Parameter is specified more than once.");
333334
}
334335

335-
cmdLineParameter.SetValue(value);
336+
parameters[key].SetValue(value);
336337
}
337338
else
338339
{
@@ -342,7 +343,7 @@ public string[] Parse(string[] args)
342343
}
343344

344345

345-
// Check that required parameters are present in the command line.
346+
// Check that required parameters are present in the command line.
346347
foreach (string key in parameters.Keys)
347348
{
348349
if (parameters[key].Required && !parameters[key].Exists)
@@ -393,7 +394,7 @@ public class ConsoleCmdLine : CmdLine
393394

394395
public ConsoleCmdLine()
395396
{
396-
RegisterParameter(new CmdLineString("help", false, "Prints the help screen."));
397+
base.RegisterParameter(new CmdLineString("help", false, "Prints the help screen."));
397398
}
398399

399400
#endregion
@@ -403,7 +404,7 @@ public ConsoleCmdLine()
403404
public new string[] Parse(string[] args)
404405
{
405406
string[] ret = null;
406-
string error = string.Empty;
407+
string error = "";
407408
try
408409
{
409410
ret = base.Parse(args);
@@ -417,15 +418,15 @@ public ConsoleCmdLine()
417418
{
418419
//foreach(string s in base.HelpScreen().Split('\n'))
419420
// Console.WriteLine(s);
420-
Console.WriteLine(HelpScreen());
421-
Environment.Exit(0);
421+
Console.WriteLine(base.HelpScreen());
422+
System.Environment.Exit(0);
422423
}
423424

424425
if (error != "")
425426
{
426427
Console.WriteLine(error);
427428
Console.WriteLine("Use -help for more information.");
428-
Environment.Exit(1);
429+
System.Environment.Exit(1);
429430
}
430431
return ret;
431432
}

src/LogExpert/Classes/Columnizer/ColumnizerPicker.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static ILogLineColumnizer CloneColumnizer(ILogLineColumnizer columnizer)
4848
object o = cti.Invoke(new object[] { });
4949
if (o is IColumnizerConfigurator configurator)
5050
{
51-
configurator.LoadConfig(ConfigManager.Settings.Preferences.PortableMode ? ConfigManager.PortableModeDir : ConfigManager.ConfigDir);
51+
configurator.LoadConfig(ConfigManager.Settings.preferences.PortableMode ? ConfigManager.PortableModeDir : ConfigManager.ConfigDir);
5252
}
5353
return (ILogLineColumnizer)o;
5454
}
@@ -120,13 +120,13 @@ public static ILogLineColumnizer FindColumnizer(string fileName, IAutoLogLineCol
120120
];
121121
}
122122

123-
var registeredColumnizer = PluginRegistry.GetInstance().RegisteredColumnizers;
123+
var registeredColumnizer = PluginRegistry.Instance.RegisteredColumnizers;
124124

125125
List<Tuple<Priority, ILogLineColumnizer>> priorityListOfColumnizers = [];
126126

127127
foreach (ILogLineColumnizer logLineColumnizer in registeredColumnizer)
128128
{
129-
Priority priority = default(Priority);
129+
Priority priority = default;
130130
if (logLineColumnizer is IColumnizerPriority columnizerPriority)
131131
{
132132
priority = columnizerPriority.GetPriority(fileName, loglines);

src/LogExpert/Classes/Filter/Filter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace LogExpert.Classes.Filter
1010
{
1111
internal delegate void FilterFx(FilterParams filterParams, List<int> filterResultLines, List<int> lastFilterResultLines, List<int> filterHitList);
1212

13-
public class Filter
13+
internal class Filter
1414
{
1515
#region Fields
1616

src/LogExpert/Classes/Filter/FilterPipe.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace LogExpert.Classes.Filter
99
{
10-
public class FilterPipe
10+
internal class FilterPipe
1111
{
1212
#region Fields
1313

0 commit comments

Comments
 (0)