Skip to content

Commit e430d67

Browse files
authored
Merge pull request #324 from Hirogen/issue321
Issue321: Highlights are now there own .json file
2 parents 0f5c3f4 + 337e6e7 commit e430d67

27 files changed

Lines changed: 528 additions & 478 deletions

src/LogExpert/Classes/CmdLine.cs

Lines changed: 25 additions & 26 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,23 +15,19 @@ public class CmdLineException : Exception
1515
{
1616
#region cTor
1717

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

24-
public CmdLineException(string message)
25-
:
26-
base(message)
22+
public CmdLineException(string message) : base(message)
2723
{
2824
}
2925

3026
#endregion
3127
}
3228

3329
/// <summary>
34-
/// Represents a command line parameter.
30+
/// Represents a command line parameter.
3531
/// Parameters are words in the command line beginning with a hyphen (-).
3632
/// The value of the parameter is the next word in
3733
/// </summary>
@@ -103,7 +99,7 @@ public virtual void SetValue(string value)
10399
}
104100

105101
/// <summary>
106-
/// Represents an integer command line parameter.
102+
/// Represents an integer command line parameter.
107103
/// </summary>
108104
public class CmdLineInt : CmdLineParameter
109105
{
@@ -162,22 +158,25 @@ public CmdLineInt(string name, bool required, string helpMessage, int min, int m
162158
public override void SetValue(string value)
163159
{
164160
base.SetValue(value);
165-
int i = 0;
161+
int i;
162+
166163
try
167164
{
168165
i = Convert.ToInt32(value);
169166
}
170167
catch (Exception)
171168
{
172-
throw new CmdLineException(base.Name, "Value is not an integer.");
169+
throw new CmdLineException(Name, "Value is not an integer.");
173170
}
171+
174172
if (i < _min)
175173
{
176-
throw new CmdLineException(base.Name, string.Format("Value must be greather or equal to {0}.", _min));
174+
throw new CmdLineException(Name, $"Value must be greather or equal to {_min}.");
177175
}
176+
178177
if (i > _max)
179178
{
180-
throw new CmdLineException(base.Name, string.Format("Value must be less or equal to {0}.", _max));
179+
throw new CmdLineException(Name, $"Value must be less or equal to {_max}.");
181180
}
182181
Value = i;
183182
}
@@ -253,11 +252,11 @@ public CmdLineParameter this[string name]
253252
{
254253
get
255254
{
256-
if (!parameters.ContainsKey(name))
255+
if (!parameters.TryGetValue(name, out CmdLineParameter value))
257256
{
258257
throw new CmdLineException(name, "Not a registered parameter.");
259258
}
260-
return parameters[name];
259+
return value;
261260
}
262261
}
263262

@@ -307,8 +306,8 @@ public string[] Parse(string[] args)
307306
if (args[i].Length > 1 && args[i][0] == '-')
308307
{
309308
// The current string is a parameter name
310-
string key = args[i].Substring(1, args[i].Length - 1).ToLower();
311-
string value = "";
309+
string key = args[i][1..].ToLower();
310+
string value = string.Empty;
312311
i++;
313312
if (i < args.Length)
314313
{
@@ -323,17 +322,17 @@ public string[] Parse(string[] args)
323322
i++;
324323
}
325324
}
326-
if (!parameters.ContainsKey(key))
325+
if (!parameters.TryGetValue(key, out CmdLineParameter cmdLineParameter))
327326
{
328327
throw new CmdLineException(key, "Parameter is not allowed.");
329328
}
330329

331-
if (parameters[key].Exists)
330+
if (cmdLineParameter.Exists)
332331
{
333332
throw new CmdLineException(key, "Parameter is specified more than once.");
334333
}
335334

336-
parameters[key].SetValue(value);
335+
cmdLineParameter.SetValue(value);
337336
}
338337
else
339338
{
@@ -343,7 +342,7 @@ public string[] Parse(string[] args)
343342
}
344343

345344

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

395394
public ConsoleCmdLine()
396395
{
397-
base.RegisterParameter(new CmdLineString("help", false, "Prints the help screen."));
396+
RegisterParameter(new CmdLineString("help", false, "Prints the help screen."));
398397
}
399398

400399
#endregion
@@ -404,7 +403,7 @@ public ConsoleCmdLine()
404403
public new string[] Parse(string[] args)
405404
{
406405
string[] ret = null;
407-
string error = "";
406+
string error = string.Empty;
408407
try
409408
{
410409
ret = base.Parse(args);
@@ -418,15 +417,15 @@ public ConsoleCmdLine()
418417
{
419418
//foreach(string s in base.HelpScreen().Split('\n'))
420419
// Console.WriteLine(s);
421-
Console.WriteLine(base.HelpScreen());
422-
System.Environment.Exit(0);
420+
Console.WriteLine(HelpScreen());
421+
Environment.Exit(0);
423422
}
424423

425424
if (error != "")
426425
{
427426
Console.WriteLine(error);
428427
Console.WriteLine("Use -help for more information.");
429-
System.Environment.Exit(1);
428+
Environment.Exit(1);
430429
}
431430
return ret;
432431
}

src/LogExpert/Classes/Columnizer/ColumnizerPicker.cs

Lines changed: 1 addition & 1 deletion
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
}
Lines changed: 107 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,108 @@
1-
using Newtonsoft.Json;
2-
3-
using System;
4-
using System.Drawing;
5-
using System.Text.RegularExpressions;
6-
7-
namespace LogExpert.Classes.Highlight
8-
{
9-
[Serializable]
10-
[method: JsonConstructor]
11-
public class HilightEntry() : ICloneable
12-
{
13-
#region Fields
14-
15-
[NonSerialized] private Regex regex = null;
16-
17-
private string _searchText = string.Empty;
18-
19-
#endregion Fields
20-
21-
#region Properties
22-
23-
public bool IsStopTail { get; set; }
24-
25-
public bool IsSetBookmark { get; set; }
26-
27-
public bool IsRegEx { get; set; }
28-
29-
public bool IsCaseSensitive { get; set; }
30-
31-
public Color ForegroundColor { get; set; }
32-
33-
public Color BackgroundColor { get; set; }
34-
35-
public string SearchText
36-
{
37-
get => _searchText;
38-
set
39-
{
40-
_searchText = value;
41-
regex = null;
42-
}
43-
}
44-
45-
public bool IsLedSwitch { get; set; }
46-
47-
public ActionEntry ActionEntry { get; set; }
48-
49-
public bool IsActionEntry { get; set; }
50-
51-
public string BookmarkComment { get; set; }
52-
53-
public Regex Regex
54-
{
55-
get
56-
{
57-
if (regex == null)
58-
{
59-
if (IsRegEx)
60-
{
61-
regex = new Regex(SearchText, IsCaseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase);
62-
}
63-
else
64-
{
65-
regex = new Regex(Regex.Escape(SearchText), IsCaseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase);
66-
}
67-
}
68-
return regex;
69-
}
70-
}
71-
72-
public bool IsWordMatch { get; set; }
73-
74-
// highlightes search result
75-
[field: NonSerialized]
76-
public bool IsSearchHit { get; set; }
77-
78-
public bool IsBold { get; set; }
79-
80-
public bool NoBackground { get; set; }
81-
82-
public object Clone()
83-
{
84-
var highLightEntry = new HilightEntry
85-
{
86-
SearchText = SearchText,
87-
ForegroundColor = ForegroundColor,
88-
BackgroundColor = BackgroundColor,
89-
IsRegEx = IsRegEx,
90-
IsCaseSensitive = IsCaseSensitive,
91-
IsLedSwitch = IsLedSwitch,
92-
IsStopTail = IsStopTail,
93-
IsSetBookmark = IsSetBookmark,
94-
IsActionEntry = IsActionEntry,
95-
ActionEntry = ActionEntry != null ? (ActionEntry)ActionEntry.Clone() : null,
96-
IsWordMatch = IsWordMatch,
97-
IsBold = IsBold,
98-
BookmarkComment = BookmarkComment,
99-
NoBackground = NoBackground,
100-
IsSearchHit = IsSearchHit
101-
};
102-
103-
return highLightEntry;
104-
}
105-
106-
#endregion Properties
107-
}
1+
using Newtonsoft.Json;
2+
3+
using System;
4+
using System.Drawing;
5+
using System.Text.RegularExpressions;
6+
7+
namespace LogExpert.Classes.Highlight
8+
{
9+
[Serializable]
10+
[method: JsonConstructor]
11+
public class HighlightEntry() : ICloneable
12+
{
13+
#region Fields
14+
15+
[NonSerialized] private Regex regex = null;
16+
17+
private string _searchText = string.Empty;
18+
19+
#endregion Fields
20+
21+
#region Properties
22+
23+
public bool IsStopTail { get; set; }
24+
25+
public bool IsSetBookmark { get; set; }
26+
27+
public bool IsRegEx { get; set; }
28+
29+
public bool IsCaseSensitive { get; set; }
30+
31+
public Color ForegroundColor { get; set; }
32+
33+
public Color BackgroundColor { get; set; }
34+
35+
public string SearchText
36+
{
37+
get => _searchText;
38+
set
39+
{
40+
_searchText = value;
41+
regex = null;
42+
}
43+
}
44+
45+
public bool IsLedSwitch { get; set; }
46+
47+
public ActionEntry ActionEntry { get; set; }
48+
49+
public bool IsActionEntry { get; set; }
50+
51+
public string BookmarkComment { get; set; }
52+
53+
public Regex Regex
54+
{
55+
get
56+
{
57+
if (regex == null)
58+
{
59+
if (IsRegEx)
60+
{
61+
regex = new Regex(SearchText, IsCaseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase);
62+
}
63+
else
64+
{
65+
regex = new Regex(Regex.Escape(SearchText), IsCaseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase);
66+
}
67+
}
68+
return regex;
69+
}
70+
}
71+
72+
public bool IsWordMatch { get; set; }
73+
74+
// highlightes search result
75+
[field: NonSerialized]
76+
public bool IsSearchHit { get; set; }
77+
78+
public bool IsBold { get; set; }
79+
80+
public bool NoBackground { get; set; }
81+
82+
public object Clone()
83+
{
84+
var highLightEntry = new HighlightEntry
85+
{
86+
SearchText = SearchText,
87+
ForegroundColor = ForegroundColor,
88+
BackgroundColor = BackgroundColor,
89+
IsRegEx = IsRegEx,
90+
IsCaseSensitive = IsCaseSensitive,
91+
IsLedSwitch = IsLedSwitch,
92+
IsStopTail = IsStopTail,
93+
IsSetBookmark = IsSetBookmark,
94+
IsActionEntry = IsActionEntry,
95+
ActionEntry = ActionEntry != null ? (ActionEntry)ActionEntry.Clone() : null,
96+
IsWordMatch = IsWordMatch,
97+
IsBold = IsBold,
98+
BookmarkComment = BookmarkComment,
99+
NoBackground = NoBackground,
100+
IsSearchHit = IsSearchHit
101+
};
102+
103+
return highLightEntry;
104+
}
105+
106+
#endregion Properties
107+
}
108108
}

0 commit comments

Comments
 (0)