Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSOE-606: Fixing new C# 11 analyzer violations #38

Merged
merged 8 commits into from
Jun 6, 2023
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Lombiq.HelpfulLibraries.OrchardCore.DependencyInjection;
using Lombiq.HelpfulLibraries.OrchardCore.DependencyInjection;
using Lombiq.Hosting.MediaTheme.Bridge.Constants;
using Lombiq.Hosting.MediaTheme.Bridge.Services;
using Lombiq.Hosting.MediaTheme.Bridge.ViewModels;
Expand Down Expand Up @@ -74,7 +74,7 @@ public async Task<ActionResult> IndexPost(MediaThemeSettingsViewModel viewModel)
var availableThemes = (await _mediaThemeManager.GetAvailableBaseThemesAsync()).ToList();
viewModel.AvailableBaseThemes = availableThemes;
if (!string.IsNullOrEmpty(viewModel.BaseThemeId) &&
availableThemes.All(theme => theme.Id != viewModel.BaseThemeId))
availableThemes.TrueForAll(theme => theme.Id != viewModel.BaseThemeId))
{
_updateModelAccessor.ModelUpdater.ModelState.AddModelError(
nameof(viewModel.BaseThemeId),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Lombiq.Hosting.MediaTheme.Bridge.Constants;
using OrchardCore.Environment.Extensions;
using OrchardCore.Environment.Extensions.Features;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -30,7 +31,7 @@ public IEnumerable<IFeatureInfo> GetFeatureDependencies(string featureId)
if (string.IsNullOrEmpty(baseThemeId)) return dependencies;

var allFeatures = GetFeatures().ToArray();
var baseTheme = allFeatures.FirstOrDefault(feature => feature.Id == baseThemeId);
var baseTheme = allFeatures.Find(feature => feature.Id == baseThemeId);
dependencies.Add(baseTheme);

// The base theme has to be the last dependency, see ThemeFeatureBuilderEvents in Orchard's source.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Lombiq.Hosting.MediaTheme.Bridge.Services;
/// to translate /mediatheme URLs.
/// </para>
/// </remarks>
internal class FileVersionProviderDecorator : IFileVersionProvider
internal sealed class FileVersionProviderDecorator : IFileVersionProvider
{
private readonly IFileVersionProvider _decorated;
private readonly IMediaFileStore _mediaFileStore;
Expand Down
15 changes: 3 additions & 12 deletions Lombiq.Hosting.MediaTheme.Bridge/Services/MediaThemeManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Lombiq.Hosting.MediaTheme.Bridge.Constants;
using Lombiq.Hosting.MediaTheme.Bridge.Constants;
using Lombiq.Hosting.MediaTheme.Bridge.Models;
using Microsoft.Extensions.Caching.Memory;
using OrchardCore.DisplayManagement.Extensions;
Expand All @@ -9,7 +9,6 @@
using OrchardCore.Themes.Services;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -38,23 +37,15 @@ public MediaThemeManager(
_siteThemeService = siteThemeService;
}

[SuppressMessage(
"Major Code Smell",
"S4457:Parameter validation in \"async\"/\"await\" methods should be wrapped",
Justification = "Part of the validation needs to call async code.")]
public async Task UpdateBaseThemeAsync(string baseThemeId)
{
ThrowIfBaseThemeIdIsInvalid(baseThemeId);

if (!string.IsNullOrEmpty(baseThemeId))
{
var baseThemeFeature = (await _shellFeaturesManager.GetAvailableFeaturesAsync())
.FirstOrDefault(feature => feature.IsTheme() && feature.Id == baseThemeId);
if (baseThemeFeature == null)
{
throw new ArgumentException($"Theme with the given ID ({baseThemeId}) doesn't exist.", nameof(baseThemeId));
}

.FirstOrDefault(feature => feature.IsTheme() && feature.Id == baseThemeId)
?? throw new ArgumentException($"Theme with the given ID ({baseThemeId}) doesn't exist.", nameof(baseThemeId));
await _shellFeaturesManager.EnableFeaturesAsync(new[] { baseThemeFeature }, force: true);
}

Expand Down
9 changes: 2 additions & 7 deletions Lombiq.Hosting.MediaTheme.Deployer/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using CommandLine;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO.Compression;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -72,7 +71,7 @@ internal static class Program
public static Task Main(string[] args) =>
Parser.Default.ParseArguments<CommandLineOptions>(args)
.WithNotParsed(HandleParseError)
.WithParsedAsync(options => RunOptionsAsync(options));
.WithParsedAsync(RunOptionsAsync);

private static void HandleParseError(IEnumerable<Error> errors)
{
Expand Down Expand Up @@ -103,10 +102,6 @@ private static async Task RunOptionsAsync(CommandLineOptions options)
}
}

[SuppressMessage(
"Major Code Smell",
"S4457:Parameter validation in \"sync\"/\"await\" methods should be wrapped",
Justification = "RunOptionsAsync() needs to use await as well to be able to set the exit code on exception.")]
private static async Task RunOptionsInnerAsync(CommandLineOptions options)
{
// Creating directory for the deployment.
Expand Down Expand Up @@ -181,7 +176,7 @@ private static async Task RunOptionsInnerAsync(CommandLineOptions options)
void AddFile(string rootPath, string filePath)
{
// These need to use forward slashes on every platform due to Orchard's import logic.
var importPath = Path.Combine(rootPath, filePath).Replace("\\", "/");
var importPath = Path.Combine(rootPath, filePath).Replace('\\', '/');
var templateJObject = JObject.FromObject(new
{
SourcePath = importPath,
Expand Down