Skip to content

Commit d6628de

Browse files
authored
Merge pull request #223 from Hirogen/json-options-read-and-write
Json options read and write
2 parents 9140032 + 1892007 commit d6628de

24 files changed

+1759
-1701
lines changed

build/_build.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="chocolatey" Version="1.0.1" />
14+
<PackageReference Include="chocolatey" Version="1.1.0" />
1515
<PackageReference Include="GitVersion.CommandLine" Version="5.9.0">
1616
<PrivateAssets>all</PrivateAssets>
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

src/ColumnizerLib/IAutoLogLineColumnizerCallback.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
6-
namespace LogExpert
1+
namespace LogExpert
72
{
83
public interface IAutoLogLineColumnizerCallback
94
{

src/LogExpert.Tests/ColumnizerPickerTest.cs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using Moq;
44
using NUnit.Framework;
55
using System;
6-
using System.Collections.Generic;
76
using System.IO;
87

98
namespace LogExpert.Tests

src/LogExpert.Tests/JSONSaveTest.cs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.IO;
2+
using Newtonsoft.Json;
3+
using NUnit.Framework;
4+
5+
namespace LogExpert.Tests
6+
{
7+
[TestFixture]
8+
public class JSONSaveTest
9+
{
10+
[Test(Author = "Hirogen", Description = "Save Options as JSON and Check if the written file can be cast again into the settings object")]
11+
public void SaveOptionsAsJSON()
12+
{
13+
ConfigManager.Settings.alwaysOnTop = true;
14+
ConfigManager.Save(SettingsFlags.All);
15+
string configDir = ConfigManager.ConfigDir;
16+
string settingsFile = configDir + "\\settings.json";
17+
18+
Settings settings = null;
19+
20+
Assert.DoesNotThrow(CastSettings);
21+
Assert.NotNull(settings);
22+
Assert.True(settings.alwaysOnTop);
23+
24+
ConfigManager.Settings.alwaysOnTop = false;
25+
ConfigManager.Save(SettingsFlags.All);
26+
27+
settings = null;
28+
Assert.DoesNotThrow(CastSettings);
29+
Assert.NotNull(settings);
30+
Assert.False(settings.alwaysOnTop);
31+
32+
33+
void CastSettings()
34+
{
35+
settings = JsonConvert.DeserializeObject<Settings>(File.ReadAllText(settingsFile));
36+
}
37+
}
38+
}
39+
}

src/LogExpert.Tests/LogExpert.Tests.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@
5656
<Compile Include="Extensions\EnumerableTests.cs" />
5757
<Compile Include="JsonCompactColumnizerTest.cs" />
5858
<Compile Include="JsonColumnizerTest.cs" />
59+
<Compile Include="JSONSaveTest.cs" />
5960
<Compile Include="LogWindowTest.cs" />
6061
<Compile Include="SquareBracketColumnizerTest.cs" />
6162
<Compile Include="Properties\AssemblyInfo.cs" />
6263
<Compile Include="LogStreamReaderTest.cs" />
6364
</ItemGroup>
6465
<ItemGroup>
6566
<PackageReference Include="Moq">
66-
<Version>4.17.2</Version>
67+
<Version>4.18.1</Version>
6768
</PackageReference>
6869
<PackageReference Include="NUnit">
6970
<Version>3.13.3</Version>

src/LogExpert.Tests/LogStreamReaderTest.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using LogExpert.Classes.Log;
22
using NUnit.Framework;
3-
using System;
43
using System.IO;
54
using System.Text;
65

src/LogExpert.Tests/LogWindowTest.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ public void Instantiate_AnyFile_NotCrash(string fileName)
2727
PluginRegistry.GetInstance().RegisteredColumnizers.Add(new CsvColumnizerType());
2828

2929
LogTabWindow logTabWindow = new LogTabWindow(null, 0, false);
30-
LogWindow logWindow =
31-
new LogWindow(logTabWindow, fileName, false, false);
30+
LogWindow logWindow = new LogWindow(logTabWindow, fileName, false, false);
3231

3332
Assert.True(true);
3433
}

src/LogExpert/Classes/Filter/FilterParams.cs

+19-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Text;
43
using System.Text.RegularExpressions;
54
using System.Collections;
65
using System.Drawing;
@@ -66,28 +65,25 @@ public class FilterParams
6665

6766
public string searchText
6867
{
69-
get { return this._searchText; }
68+
get => _searchText;
7069
set
7170
{
72-
this._searchText = value;
73-
this.lowerSearchText = this._searchText.ToLower();
71+
_searchText = value;
72+
lowerSearchText = _searchText.ToLower();
7473
}
7574
}
7675

7776
public string rangeSearchText
7877
{
79-
get { return this._rangeSearchText; }
78+
get => _rangeSearchText;
8079
set
8180
{
82-
this._rangeSearchText = value;
83-
this.lowerRangeSearchText = this._rangeSearchText.ToLower();
81+
_rangeSearchText = value;
82+
lowerRangeSearchText = _rangeSearchText.ToLower();
8483
}
8584
}
8685

87-
public bool SpreadEnabled
88-
{
89-
get { return this.spreadBefore > 0 || this.spreadBehind > 0; }
90-
}
86+
public bool SpreadEnabled => spreadBefore > 0 || spreadBehind > 0;
9187

9288
#endregion
9389

@@ -99,17 +95,17 @@ public FilterParams CreateCopy2()
9995
newParams.Init();
10096
// removed cloning of columnizer for filtering, because this causes issues with columnizers that hold internal states (like CsvColumnizer)
10197
// newParams.currentColumnizer = Util.CloneColumnizer(this.currentColumnizer);
102-
newParams.currentColumnizer = this.currentColumnizer;
98+
newParams.currentColumnizer = currentColumnizer;
10399
return newParams;
104100
}
105101

106102
// call after deserialization!
107103
public void Init()
108104
{
109-
this.lastNonEmptyCols = new Hashtable();
110-
this.lowerRangeSearchText = this._rangeSearchText.ToLower();
111-
this.lowerSearchText = this._searchText.ToLower();
112-
this.lastLine = "";
105+
lastNonEmptyCols = new Hashtable();
106+
lowerRangeSearchText = _rangeSearchText.ToLower();
107+
lowerSearchText = _searchText.ToLower();
108+
lastLine = "";
113109
}
114110

115111
// Reset before a new search
@@ -121,21 +117,21 @@ public void Reset()
121117

122118
public void CreateRegex()
123119
{
124-
if (this._searchText != null)
120+
if (_searchText != null)
125121
{
126-
this.rex = new Regex(this._searchText,
127-
this.isCaseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase);
122+
rex = new Regex(_searchText,
123+
isCaseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase);
128124
}
129-
if (this._rangeSearchText != null && this.isRangeSearch)
125+
if (_rangeSearchText != null && isRangeSearch)
130126
{
131-
this.rangeRex = new Regex(this._rangeSearchText,
132-
this.isCaseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase);
127+
rangeRex = new Regex(_rangeSearchText,
128+
isCaseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase);
133129
}
134130
}
135131

136132
public FilterParams CreateCopy()
137133
{
138-
return (FilterParams) this.MemberwiseClone();
134+
return (FilterParams) MemberwiseClone();
139135
}
140136

141137
#endregion

src/LogExpert/Classes/Highlight/HilightEntry.cs

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Text;
55
using System.Drawing;
66
using System.Text.RegularExpressions;
7+
using Newtonsoft.Json;
78

89
namespace LogExpert
910
{
@@ -37,6 +38,12 @@ public class HilightEntry
3738

3839
#region cTor
3940

41+
[JsonConstructor]
42+
public HilightEntry()
43+
{
44+
45+
}
46+
4047
public HilightEntry(string searchText, Color fgColor, Color bgColor, bool isWordMatch)
4148
{
4249
this.searchText = searchText;

src/LogExpert/Config/ColorEntry.cs

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
1+
#region
2+
13
using System;
24
using System.Drawing;
35

6+
#endregion
7+
48
namespace LogExpert
59
{
610
[Serializable]
711
public class ColorEntry
812
{
9-
#region Fields
10-
11-
public Color color;
12-
public string fileName;
13-
14-
#endregion
15-
1613
#region cTor
1714

1815
public ColorEntry(string fileName, Color color)
1916
{
20-
this.fileName = fileName;
21-
this.color = color;
17+
FileName = fileName;
18+
Color = color;
2219
}
2320

2421
#endregion
22+
23+
public Color Color { get; }
24+
25+
public string FileName { get; }
26+
27+
#region Fields
28+
29+
#endregion
2530
}
2631
}
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1+
#region
2+
13
using System;
24

5+
#endregion
6+
37
namespace LogExpert
48
{
59
[Serializable]
610
public class ColumnizerHistoryEntry
711
{
8-
#region Fields
9-
10-
public string columnizerName;
11-
public string fileName;
12-
13-
#endregion
14-
1512
#region cTor
1613

1714
public ColumnizerHistoryEntry(string fileName, string columnizerName)
1815
{
19-
this.fileName = fileName;
20-
this.columnizerName = columnizerName;
16+
FileName = fileName;
17+
ColumnizerName = columnizerName;
2118
}
2219

2320
#endregion
21+
22+
#region Fields
23+
24+
public string FileName { get; }
25+
26+
#endregion
27+
28+
public string ColumnizerName { get; }
2429
}
2530
}

0 commit comments

Comments
 (0)