Skip to content

Commit 966e414

Browse files
authored
Merge pull request #507 from LogExperts/505-tail-following-stops-working-after-a-while-for-logs-located-on-wsl
fixes missing ApplicationStartup.Path, moved Persister to own Test Pr…
2 parents a16b899 + 795820f commit 966e414

File tree

6 files changed

+729
-34
lines changed

6 files changed

+729
-34
lines changed

src/LogExpert.Core/Classes/Persister/Persister.cs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace LogExpert.Core.Classes.Persister;
1111

12+
//Todo Move Persister to its own assembly LogExpert.Persister
1213
public static class Persister
1314
{
1415
#region Fields
@@ -46,12 +47,13 @@ public static class Persister
4647
/// <param name="preferences">The user preferences that determine the save location and other settings. This parameter cannot be <see
4748
/// langword="null"/>.</param>
4849
/// <returns>The full path of the file where the persistence data was saved.</returns>
49-
public static string SavePersistenceData (string logFileName, PersistenceData persistenceData, Preferences preferences)
50+
public static string SavePersistenceData (string logFileName, PersistenceData persistenceData, Preferences preferences, string applicationStartupPath)
5051
{
5152
ArgumentNullException.ThrowIfNull(preferences);
5253
ArgumentNullException.ThrowIfNull(persistenceData);
54+
ArgumentException.ThrowIfNullOrWhiteSpace(applicationStartupPath);
5355

54-
var fileName = persistenceData.SessionFileName ?? BuildPersisterFileName(logFileName, preferences);
56+
var fileName = persistenceData.SessionFileName ?? BuildPersisterFileName(logFileName, preferences, applicationStartupPath);
5557

5658
if (preferences.SaveLocation == SessionSaveLocation.SameDir)
5759
{
@@ -82,10 +84,12 @@ public static string SavePersistenceDataWithFixedName (string persistenceFileNam
8284
/// <param name="logFileName">The name of the log file to load persistence data from. This value cannot be null.</param>
8385
/// <param name="preferences">The preferences used to determine the file path and loading behaviour. This value cannot be null.</param>
8486
/// <returns>The loaded <see cref="PersistenceData"/> object containing the persistence information.</returns>
85-
public static PersistenceData LoadPersistenceData (string logFileName, Preferences preferences)
87+
public static PersistenceData LoadPersistenceData (string logFileName, Preferences preferences, string applicationStartupPath)
8688
{
8789
ArgumentNullException.ThrowIfNull(preferences);
88-
var fileName = BuildPersisterFileName(logFileName, preferences);
90+
ArgumentNullException.ThrowIfNull(applicationStartupPath);
91+
92+
var fileName = BuildPersisterFileName(logFileName, preferences, applicationStartupPath);
8993
return LoadInternal(fileName);
9094
}
9195

@@ -95,10 +99,12 @@ public static PersistenceData LoadPersistenceData (string logFileName, Preferenc
9599
/// <param name="logFileName">The name of the log file used to determine the persistence data file.</param>
96100
/// <param name="preferences">The preferences that influence the file name generation. Cannot be <see langword="null"/>.</param>
97101
/// <returns>A <see cref="PersistenceData"/> object containing the loaded data.</returns>
98-
public static PersistenceData LoadPersistenceDataOptionsOnly (string logFileName, Preferences preferences)
102+
public static PersistenceData LoadPersistenceDataOptionsOnly (string logFileName, Preferences preferences, string applicationStartupPath)
99103
{
100104
ArgumentNullException.ThrowIfNull(preferences);
101-
var fileName = BuildPersisterFileName(logFileName, preferences);
105+
ArgumentNullException.ThrowIfNull(applicationStartupPath);
106+
107+
var fileName = BuildPersisterFileName(logFileName, preferences, applicationStartupPath);
102108
return LoadInternal(fileName);
103109
}
104110

@@ -149,7 +155,7 @@ public static PersistenceData Load (string fileName)
149155
/// <param name="preferences">The preferences that determine the save location and directory structure for the persister file.</param>
150156
/// <returns>The full file path of the persister file, including the directory and file name, based on the specified log file
151157
/// name and preferences.</returns>
152-
private static string BuildPersisterFileName (string logFileName, Preferences preferences)
158+
private static string BuildPersisterFileName (string logFileName, Preferences preferences, string applicationStartupPath)
153159
{
154160
string dir;
155161
string file;
@@ -180,8 +186,7 @@ private static string BuildPersisterFileName (string logFileName, Preferences pr
180186
}
181187
case SessionSaveLocation.ApplicationStartupDir:
182188
{
183-
//TODO Add Application.StartupPath as Variable
184-
dir = string.Empty;// Application.StartupPath + Path.DirectorySeparatorChar + "sessionfiles";
189+
dir = Path.Join(applicationStartupPath, "sessionFiles");
185190
file = dir + Path.DirectorySeparatorChar + BuildSessionFileNameFromPath(logFileName);
186191
break;
187192
}
@@ -213,12 +218,13 @@ PathTooLongException or
213218
/// underscores, and the file name is appended with the ".lxp" extension.</returns>
214219
private static string BuildSessionFileNameFromPath (string logFileName)
215220
{
216-
var result = logFileName;
217-
result = result.Replace(Path.DirectorySeparatorChar, '_');
218-
result = result.Replace(Path.AltDirectorySeparatorChar, '_');
219-
result = result.Replace(Path.VolumeSeparatorChar, '_');
220-
result += ".lxp";
221-
return result;
221+
var result = new StringBuilder();
222+
_ = result.Append(logFileName);
223+
_ = result.Replace(Path.DirectorySeparatorChar, '_');
224+
_ = result.Replace(Path.AltDirectorySeparatorChar, '_');
225+
_ = result.Replace(Path.VolumeSeparatorChar, '_');
226+
_ = result.Append(".lxp");
227+
return result.ToString();
222228
}
223229

224230
/// <summary>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<IsTestProject>true</IsTestProject>
7+
<AssemblyTitle>LogExpert.Persister.Tests</AssemblyTitle>
8+
<RootNamespace>LogExpert.Persister.Tests</RootNamespace>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Moq" />
13+
<PackageReference Include="NUnit" />
14+
<PackageReference Include="NUnit3TestAdapter" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\LogExpert.Core\LogExpert.Core.csproj" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<Using Include="NUnit.Framework" />
24+
</ItemGroup>
25+
26+
</Project>

0 commit comments

Comments
 (0)