Skip to content

Commit

Permalink
Quality and dependency updates (#28)
Browse files Browse the repository at this point in the history
* Upgrade application dependencies

* Update installer dependencies

* Fix typos

* Improve argument checking

* Use primary constructors
  • Loading branch information
elzik authored Feb 22, 2024
1 parent c760d48 commit 09a3163
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="WixToolset.Sdk/4.0.0">
<Project Sdk="WixToolset.Sdk/4.0.4">
<PropertyGroup>
<UpdateAssemblyInfo>false</UpdateAssemblyInfo>
<GenerateGitVersionInformation>false</GenerateGitVersionInformation>
Expand All @@ -11,7 +11,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="WixToolset.UI.wixext" Version="4.0.3" />
<PackageReference Include="WixToolset.UI.wixext" Version="4.0.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Elzik.FmSync.Console\Elzik.FmSync.Console.csproj" />
Expand Down
4 changes: 2 additions & 2 deletions src/Elzik.FmSync.Application/Elzik.FmSync.Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="Polly.Core" Version="8.3.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.19.0.84025">
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.20.0.85982">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
20 changes: 8 additions & 12 deletions src/Elzik.FmSync.Application/FrontMatterFileSynchroniser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@

namespace Elzik.FmSync.Application;

public class FrontMatterFileSynchroniser : IFrontMatterFileSynchroniser
public class FrontMatterFileSynchroniser(ILogger<FrontMatterFileSynchroniser> logger,
IMarkdownFrontMatter markdownFrontMatter, IFile file) : IFrontMatterFileSynchroniser
{
private readonly ILogger<FrontMatterFileSynchroniser> _logger;
private readonly IMarkdownFrontMatter _markdownFrontMatter;
private readonly IFile _file;

public FrontMatterFileSynchroniser(ILogger<FrontMatterFileSynchroniser> logger,
IMarkdownFrontMatter markdownFrontMatter, IFile file)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_markdownFrontMatter = markdownFrontMatter ?? throw new ArgumentNullException(nameof(markdownFrontMatter));
_file = file ?? throw new ArgumentNullException(nameof(file));
}
private readonly ILogger<FrontMatterFileSynchroniser> _logger = logger
?? throw new ArgumentNullException(nameof(logger));
private readonly IMarkdownFrontMatter _markdownFrontMatter = markdownFrontMatter
?? throw new ArgumentNullException(nameof(markdownFrontMatter));
private readonly IFile _file = file
?? throw new ArgumentNullException(nameof(file));

public virtual SyncResult SyncCreationDate(string markDownFilePath)
{
Expand Down
38 changes: 20 additions & 18 deletions src/Elzik.FmSync.Application/FrontMatterFolderSynchroniser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,26 @@

namespace Elzik.FmSync.Application;

public class FrontMatterFolderSynchroniser : IFrontMatterFolderSynchroniser
public class FrontMatterFolderSynchroniser(
ILogger<FrontMatterFolderSynchroniser> logger,
IDirectory directory,
IFrontMatterFileSynchroniser frontMatterFileSynchroniser,
IOptions<FileSystemOptions> options) : IFrontMatterFolderSynchroniser
{
private readonly ILogger<FrontMatterFolderSynchroniser> _logger;
private readonly IDirectory _directory;
private readonly IFrontMatterFileSynchroniser _frontMatterFileSynchroniser;
private readonly FileSystemOptions _options;

public FrontMatterFolderSynchroniser(ILogger<FrontMatterFolderSynchroniser> logger, IDirectory directory,
IFrontMatterFileSynchroniser frontMatterFileSynchroniser, IOptions<FileSystemOptions> options)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_directory = directory ?? throw new ArgumentNullException(nameof(directory));
_frontMatterFileSynchroniser = frontMatterFileSynchroniser
?? throw new ArgumentNullException(nameof(frontMatterFileSynchroniser));
_options = options.Value;
}
private readonly ILogger<FrontMatterFolderSynchroniser> _logger = logger
?? throw new ArgumentNullException(nameof(logger));
private readonly IDirectory _directory = directory
?? throw new ArgumentNullException(nameof(directory));
private readonly IFrontMatterFileSynchroniser _frontMatterFileSynchroniser = frontMatterFileSynchroniser
?? throw new ArgumentNullException(nameof(frontMatterFileSynchroniser));
private readonly FileSystemOptions _options = options.Value;

public void SyncCreationDates(string directoryPath)
{
var loggingInfo = (StartTime: Stopwatch.GetTimestamp(), EditedCount: 0, ErrorCount: 0, TotalCount: 0);

_logger.LogDebug("Synchronising {FilenamePattern} files in {DirectoryPath}", _options.FilenamePattern, directoryPath);
_logger.LogDebug("Synchronising {FilenamePattern} files in {DirectoryPath}",
_options.FilenamePattern, directoryPath);

var markdownFiles = _directory.EnumerateFiles(directoryPath, _options.FilenamePattern ?? string.Empty,
new EnumerationOptions
Expand Down Expand Up @@ -66,7 +64,11 @@ public void SyncCreationDates(string directoryPath)
errorsMessage = $" and failed {loggingInfo.ErrorCount}";
}

_logger.LogInformation("Synchronised {EditedFileCount}{ErrorsMessage} files out of a total {TotalFileCount} in {TimeTaken}.",
loggingInfo.EditedCount, errorsMessage, loggingInfo.TotalCount, Stopwatch.GetElapsedTime(loggingInfo.StartTime));
_logger.LogInformation("Synchronised {EditedFileCount}{ErrorsMessage} files out " +
"of a total {TotalFileCount} in {TimeTaken}.",
loggingInfo.EditedCount,
errorsMessage,
loggingInfo.TotalCount,
Stopwatch.GetElapsedTime(loggingInfo.StartTime));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@

namespace Elzik.FmSync.Application
{
public class ResilientFrontMatterFileSynchroniser : IResilientFrontMatterFileSynchroniser
public class ResilientFrontMatterFileSynchroniser(
IFrontMatterFileSynchroniser frontMatterFileSynchroniser,
ResiliencePipelineProvider<string> resiliencePipelineProvider) : IResilientFrontMatterFileSynchroniser
{
private readonly ResiliencePipeline _fileWriteResiliencePipeline;
private readonly IFrontMatterFileSynchroniser _frontMatterFileSynchroniser;

public ResilientFrontMatterFileSynchroniser(IFrontMatterFileSynchroniser frontMatterFileSynchroniser,
ResiliencePipelineProvider<string> resiliencePipelineProvider)
{
_fileWriteResiliencePipeline = resiliencePipelineProvider.GetPipeline(Retry5TimesPipelineBuilder.StrategyName);
_frontMatterFileSynchroniser = frontMatterFileSynchroniser;
}
private readonly ResiliencePipeline _fileWriteResiliencePipeline
= resiliencePipelineProvider.GetPipeline(Retry5TimesPipelineBuilder.StrategyName);
private readonly IFrontMatterFileSynchroniser _frontMatterFileSynchroniser
= frontMatterFileSynchroniser;

public SyncResult SyncCreationDate(string markDownFilePath)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Elzik.FmSync.Domain/Elzik.FmSync.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.19.0.84025">
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.20.0.85982">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.1" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.19.0.84025">
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.20.0.85982">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
12 changes: 3 additions & 9 deletions src/Elzik.FmSync.Worker/FmSyncWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,12 @@ public FmSyncWorker(ILogger<FmSyncWorker> logger, IOptions<WatcherOptions> watch
IResilientFrontMatterFileSynchroniser fileSynchroniser, IOptions<FileSystemOptions> fileSystemOptions)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
if (watcherOptions == null)
{
throw new ArgumentNullException(nameof(watcherOptions));
}
if (fileSystemOptions == null)
{
throw new ArgumentNullException(nameof(fileSystemOptions));
}
ArgumentNullException.ThrowIfNull(watcherOptions);
ArgumentNullException.ThrowIfNull(fileSystemOptions);
_fileSystemOptions = fileSystemOptions.Value;
_watcherOptions = watcherOptions.Value;
_fileSynchroniser = fileSynchroniser ?? throw new ArgumentNullException(nameof(fileSynchroniser));
_folderWatchers = new List<FileSystemWatcher>();
_folderWatchers = [];
}

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

<ItemGroup>
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="coverlet.collector" Version="6.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<PackageReference Include="coverlet.msbuild" Version="6.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="coverlet.collector" Version="6.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<PackageReference Include="coverlet.msbuild" Version="6.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ public sealed class MarkdownFrontMatterTests : IDisposable
{
[Theory]
[InlineData("./TestFiles/YamlContainsOnlyCreatedDate.md", "GMT Standard Time", null, "2023-01-07 14:28:22",
"because the current timezone is GMT")]
"because the current time zone is GMT")]
[InlineData("./TestFiles/YamlContainsOnlyCreatedDateWithPrecedingNewLines.md", "GMT Standard Time", null, "2023-01-07 14:28:22",
"because the current timezone is GMT")]
"because the current time zone is GMT")]
[InlineData("./TestFiles/YamlContainsCreatedDateAndOtherValue.md", "GMT Standard Time", null, "2022-03-31 13:52:15",
"because the current timezone is GMT at BST")]
"because the current time zone is GMT at BST")]
[InlineData("./TestFiles/YamlContainsOnlyCreatedDate.md", "AUS Eastern Standard Time", null, "2023-01-07 03:28:22",
"because the current timezone is AUS")]
"because the current time zone is AUS")]
[InlineData("./TestFiles/YamlContainsCreatedDateAndOtherValue.md", "AUS Eastern Standard Time", null, "2022-03-31 03:52:15",
"because the current timezone is AUS")]
"because the current time zone is AUS")]
[InlineData("./TestFiles/YamlContainsOnlyCreatedDateWithPrecedingNewLines.md", "AUS Eastern Standard Time", null, "2023-01-07 03:28:22",
"because the current timezone is AUS")]
"because the current time zone is AUS")]
[InlineData("./TestFiles/YamlContainsOnlyCreatedDate.md", "GMT Standard Time", "AUS Eastern Standard Time", "2023-01-07 03:28:22",
"because even though the current timezone is GMT the YAML is configured for AUS")]
"because even though the current time zone is GMT the YAML is configured for AUS")]
[InlineData("./TestFiles/YamlContainsCreatedDateAndOtherValue.md", "GMT Standard Time", "AUS Eastern Standard Time", "2022-03-31 03:52:15",
"because even though the current timezone is GMT the YAML is configured for AUS")]
"because even though the current time zone is GMT the YAML is configured for AUS")]
[InlineData("./TestFiles/YamlContainsOnlyCreatedDateWithPrecedingNewLines.md", "GMT Standard Time", "AUS Eastern Standard Time", "2023-01-07 03:28:22",
"because even though the current timezone is GMT the YAML is configured for AUS")]
"because even though the current time zone is GMT the YAML is configured for AUS")]
[InlineData("./TestFiles/YamlContainsOnlyDateWithOffset.md", "GMT Standard Time", null, "2023-02-14 13:20:32",
"because even though our current timezone is GMT it is ignored because a time offset was supplied in the Front Matter data")]
"because even though our current time zone is GMT it is ignored because a time offset was supplied in the Front Matter data")]
[InlineData("./TestFiles/YamlContainsOnlyDateWithOffset.md", "GMT Standard Time", "AUS Eastern Standard Time", "2023-02-14 13:20:32",
"because even though our current timezone is GMT and the Front Matter is configured for AUS they are both ignored because a time offset was supplied in the Front Matter data")]
"because even though our current time zone is GMT and the Front Matter is configured for AUS they are both ignored because a time offset was supplied in the Front Matter data")]
public void GetCreatedDate_YamlContainsCreatedDate_ReturnsCreatedDate(string testFilePath, string localTimeZone,
string configuredTimeZone, string expectedUtcDateString, string because)
string? configuredTimeZone, string expectedUtcDateString, string because)
{
// Arrange
SetTimeZone(localTimeZone);
Expand Down

0 comments on commit 09a3163

Please sign in to comment.