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-751: Upgrade to Orchard Core 1.8 #234

Merged
merged 44 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
25aec62
Adjustments needed for OC 1.8.0.
Psichorex Jan 18, 2024
4db8bd4
Upgrading to .NET 8 and OC 1.8.2.
Psichorex Jan 18, 2024
bad03b4
Merge remote-tracking branch 'origin/dev' into issue/OSOE-751
Psichorex Jan 18, 2024
5d18fdf
Using Append.
Psichorex Jan 18, 2024
57ac665
Updating leftover packages.
Psichorex Jan 18, 2024
1c04ea9
Addressing IDE0290
Psichorex Jan 18, 2024
446e8c6
Addressing warnings.
Psichorex Jan 19, 2024
b5abc48
Addressing warnings.
Psichorex Jan 19, 2024
f2ed7c3
Addressing warnings.
Psichorex Jan 20, 2024
2e30977
Addressing warnings.
Psichorex Jan 20, 2024
8a35be3
Addressing warnings.
Psichorex Jan 20, 2024
109b6b5
Addressing warnings.
Psichorex Jan 20, 2024
44b2009
Addressing warnings.
Psichorex Jan 20, 2024
de1003f
Addressing warnings.
Psichorex Jan 20, 2024
1cdcf85
Removing field.
Psichorex Jan 29, 2024
8e8a009
REmoving fields.
Psichorex Jan 29, 2024
30c92b2
Removing fields.
Psichorex Jan 29, 2024
f2bdd86
Removing fields.
Psichorex Jan 29, 2024
426ca83
Removing field.
Psichorex Jan 29, 2024
7ee991b
Removing field.
Psichorex Jan 29, 2024
aa55837
Keeping T.
Psichorex Jan 29, 2024
3a8bdc0
Keeping T.
Psichorex Jan 29, 2024
968d6de
Keeping T.
Psichorex Jan 29, 2024
afab569
Using better OS determination.
Psichorex Jan 29, 2024
0ddb55d
Removing directive.
Psichorex Jan 29, 2024
3f98d10
Merge remote-tracking branch 'origin/dev' into issue/OSOE-751
Psichorex Jan 30, 2024
9c628b9
Revert "Addressing IDE0290"This reverts commit 1c04ea9d7e524ab95c19da…
Psichorex Jan 30, 2024
48ccf0a
Fix.
Psichorex Jan 30, 2024
dbfd82a
Fixes.
Psichorex Jan 30, 2024
3ae8fb7
Removing space.
Psichorex Jan 31, 2024
416cd1a
Removing ,
Psichorex Jan 31, 2024
f127b12
Some clean-up
Piedone Jan 31, 2024
cff97ea
Warnings.
Psichorex Feb 1, 2024
d31acdb
Update Lombiq.HelpfulLibraries.Tests/UnitTests/Models/TypedRouteTests.cs
Psichorex Feb 1, 2024
382a94c
Minor fixes.
Psichorex Feb 1, 2024
28ed131
Merge branch 'issue/OSOE-751' of https://github.com/Lombiq/Helpful-Li…
Psichorex Feb 1, 2024
1ceef56
Minor fixes.
Psichorex Feb 1, 2024
278d66f
Minor fixing.
Psichorex Feb 1, 2024
116e815
Upgrading from 7.0.0 to 8.0.0 in MS packages.
Psichorex Feb 5, 2024
750436c
Merge remote-tracking branch 'origin/dev' into issue/OSOE-751
Psichorex Feb 5, 2024
ed96315
Fixing TypedRouteTests
Psichorex Feb 5, 2024
8a1aad4
Upgrading MS package.
Psichorex Feb 6, 2024
032a0a5
Using issue branch for publish-nuget.
Psichorex Feb 16, 2024
63483ff
Reverting to dev reference.
Psichorex Feb 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Lombiq.HelpfulLibraries.Common.Utilities;
using Lombiq.HelpfulLibraries.Common.Utilities;
using OrchardCore.Modules;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<DefaultItemExcludes>$(DefaultItemExcludes);.git*</DefaultItemExcludes>
</PropertyGroup>

Expand All @@ -27,6 +27,10 @@
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.Abstractions" Version="1.8.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Lombiq.HelpfulLibraries.Common\Lombiq.HelpfulLibraries.Common.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@

namespace Lombiq.HelpfulLibraries.AspNetCore.Middlewares;

public class DeferredTaskMiddleware
public class DeferredTaskMiddleware(RequestDelegate next)
{
private readonly RequestDelegate _next;

public DeferredTaskMiddleware(RequestDelegate next) => _next = next;

public async Task InvokeAsync(
HttpContext context,
IEnumerable<IDeferredTask> deferredTasks)
Expand All @@ -23,7 +19,7 @@ public async Task InvokeAsync(
await deferredTask.PreProcessAsync(context);
}

await _next(context);
await next(context);

foreach (var deferredTask in deferredTasksList) await deferredTask.PostProcessAsync(context);
}
Expand Down
4 changes: 0 additions & 4 deletions Lombiq.HelpfulLibraries.AspNetCore/Mvc/ActionResultHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ public static FileResult ZipFile(IDictionary<string, Stream> files, string zipFi
var entry = archive.CreateEntry(fileName, CompressionLevel.Optimal);
using var entryStream = entry.Open();
fileStream.CopyTo(entryStream);

// False positive.
#pragma warning disable S3966 // Objects should not be disposed more than once.
fileStream.Dispose();
#pragma warning restore S3966 // Objects should not be disposed more than once.
}
}

Expand Down
19 changes: 6 additions & 13 deletions Lombiq.HelpfulLibraries.AspNetCore/Mvc/JsonModelBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,9 @@

namespace Lombiq.HelpfulLibraries.AspNetCore.Mvc;

public class JsonModelBinder : IModelBinder
public class JsonModelBinder(ILogger<JsonModelBinder> logger, IObjectModelValidator validator) : IModelBinder
{
private readonly ILogger<JsonModelBinder> _logger;
private readonly IObjectModelValidator _validator;

public JsonModelBinder(ILogger<JsonModelBinder> logger, IObjectModelValidator validator)
{
_logger = logger;
_validator = validator;
}
private static readonly JsonSerializerOptions SerializeOptions = new(JsonSerializerDefaults.Web);

public Task BindModelAsync(ModelBindingContext bindingContext)
{
Expand All @@ -28,14 +21,14 @@ public Task BindModelAsync(ModelBindingContext bindingContext)
var parsed = value is null ? null : JsonSerializer.Deserialize(
value,
bindingContext.ModelType,
new JsonSerializerOptions(JsonSerializerDefaults.Web));
SerializeOptions);

if (parsed is null)
{
return Task.CompletedTask;
}

_validator.Validate(
validator.Validate(
bindingContext.ActionContext,
validationState: bindingContext.ValidationState,
prefix: string.Empty,
Expand All @@ -45,15 +38,15 @@ public Task BindModelAsync(ModelBindingContext bindingContext)
}
catch (JsonException jsonException)
{
_logger.LogError(jsonException, "Failed to bind parameter '{FieldName}'", bindingContext.FieldName);
logger.LogError(jsonException, "Failed to bind parameter '{FieldName}'", bindingContext.FieldName);
bindingContext.ActionContext.ModelState.TryAddModelError(
key: jsonException.Path,
exception: jsonException,
bindingContext.ModelMetadata);
}
catch (Exception exception) when (exception is FormatException or OverflowException)
{
_logger.LogError(exception, "Failed to bind parameter '{FieldName}'", bindingContext.FieldName);
logger.LogError(exception, "Failed to bind parameter '{FieldName}'", bindingContext.FieldName);
bindingContext.ActionContext.ModelState.TryAddModelError(
string.Empty,
exception,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Lombiq.HelpfulLibraries.AspNetCore.Security;
using Lombiq.HelpfulLibraries.AspNetCore.Security;
Psichorex marked this conversation as resolved.
Show resolved Hide resolved
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Primitives;
using System;
Expand Down Expand Up @@ -98,7 +99,7 @@ public static IApplicationBuilder UseNosniffContentTypeOptionsHeader(this IAppli

if (!context.Response.Headers.ContainsKey(key))
{
context.Response.Headers.Add(key, "nosniff");
context.Response.Headers.Append(key, "nosniff");
}

await next();
Expand Down Expand Up @@ -129,7 +130,7 @@ static void UpdateIfMissing(ref string cookie, ref bool changed, string test, st
context.Response.OnStarting(() =>
{
var setCookie = context.Response.Headers[setCookieHeader];
if (!setCookie.Any()) return Task.CompletedTask;
if (setCookie.Count == 0) return Task.CompletedTask;

var newCookies = new List<string>(capacity: setCookie.Count);
var changed = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand Down Expand Up @@ -46,19 +46,19 @@ public ValueTask UpdateAsync(IDictionary<string, string> securityPolicies, HttpC
{
var any = false;

if (PermittedStyleSources.Any())
if (!PermittedStyleSources.IsEmpty)
{
any = true;
MergeValues(securityPolicies, StyleSrc, PermittedStyleSources);
}

if (PermittedScriptSources.Any())
if (!PermittedScriptSources.IsEmpty)
{
any = true;
MergeValues(securityPolicies, ScriptSrc, PermittedScriptSources);
}

if (PermittedFontSources.Any())
if (!PermittedFontSources.IsEmpty)
{
any = true;
MergeValues(securityPolicies, FontSrc, PermittedFontSources);
Expand Down
6 changes: 2 additions & 4 deletions Lombiq.HelpfulLibraries.Cli/CliProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@

namespace Lombiq.HelpfulLibraries.Cli;

public class CliProgram
public class CliProgram(string command)
{
public static CliProgram DotNet { get; } = new("dotnet");

private readonly string _command;

public CliProgram(string command) => _command = command + OperatingSystemHelper.GetExecutableExtension();
private readonly string _command = command + OperatingSystemHelper.GetExecutableExtension();

/// <summary>
/// Creates a <see cref="Command"/> object based on the passed <paramref name="arguments"/>.
Expand Down
4 changes: 2 additions & 2 deletions Lombiq.HelpfulLibraries.Cli/Helpers/CliWrapHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class CliWrapHelper
/// <param name="name">The application name you can invoke directly in the command line.</param>
public static async Task<IEnumerable<FileInfo>> WhichAsync(string name)
{
var appName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "where" : "which";
var appName = OperatingSystem.IsOSPlatform(nameof(OSPlatform.Windows)) ? "where" : "which";
Psichorex marked this conversation as resolved.
Show resolved Hide resolved
var result = await CliWrap.Cli.Wrap(appName)
.WithArguments(name)
.WithValidation(CommandResultValidation.None)
Expand All @@ -46,7 +46,7 @@ public static async Task StreamAsync(
Func<Command, Command> configureCommand = null)
{
var command = CliWrap.Cli.Wrap(program);
if (arguments?.Any() == true) command = command.WithArguments(arguments);
if (arguments?.Count != 0) command = command.WithArguments(arguments);
if (configureCommand != null) command = configureCommand(command);

await foreach (var commandEvent in command.ListenAsync()) handler(commandEvent);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ public static class ServiceCollectionExtensions
public static void AddLazyInjectionSupport(this IServiceCollection services) =>
services.TryAddTransient(typeof(Lazy<>), typeof(Lazier<>));

private sealed class Lazier<T> : Lazy<T>
private sealed class Lazier<T>(IServiceProvider provider) : Lazy<T>(provider.GetRequiredService<T>)
where T : class
{
public Lazier(IServiceProvider provider)
: base(provider.GetRequiredService<T>) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public static IEnumerable<T> EmptyIfNull<T>(this IEnumerable<T> collection) =>
/// cref="Array.Empty{TResult}"/>.
/// </summary>
public static IEnumerable<T> EmptyIfNull<T>(this T[] array) =>
array ?? Array.Empty<T>();
array ?? [];
Psichorex marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Maps the provided collection of pairs using a selector with separate arguments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class RandomNumberGeneratorExtensions
/// </remarks>
public static int Next(this RandomNumberGenerator randomNumberGenerator, int minValue, int maxValue)
{
if (minValue > maxValue) throw new ArgumentOutOfRangeException(nameof(minValue));
ArgumentOutOfRangeException.ThrowIfGreaterThan(minValue, maxValue);
if (minValue == maxValue) return minValue;

var diff = (long)maxValue - minValue;
Expand Down
10 changes: 2 additions & 8 deletions Lombiq.HelpfulLibraries.Common/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ public static string MakeFileSystemFriendly(this string text, bool noSpaceOrDot
/// Returns an array by splitting the input along commas and stripping empty entries.
/// </summary>
public static string[] SplitByCommas(this string? text) =>
text?.Split(',', StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>();
text?.Split(',', StringSplitOptions.RemoveEmptyEntries) ?? [];

/// <summary>
/// Returns the input split into lines (using <see cref="Environment.NewLine"/>).
/// </summary>
public static string[] SplitByNewLines(this string? text) =>
text?.Split(Environment.NewLine) ?? Array.Empty<string>();
text?.Split(Environment.NewLine) ?? [];

/// <summary>
/// A shortcut for <c>string.Contains(string, StringComparison.InvariantCultureIgnoreCase)</c>. It also safely
Expand All @@ -99,12 +99,6 @@ public static string[] SplitByNewLines(this string? text) =>
public static bool ContainsLoose(this string? text, string? toFind) =>
text != null && toFind != null && text.Contains(toFind, StringComparison.InvariantCultureIgnoreCase);

/// <summary>
/// A shortcut for <c>string.Equals(string, StringComparison.OrdinalIgnoreCase)</c>.
/// </summary>
public static bool EqualsOrdinalIgnoreCase(this string text, string? value) =>
text.Equals(value, StringComparison.OrdinalIgnoreCase);

Piedone marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// A shortcut for <c>string.Contains(string, StringComparison.OrdinalIgnoreCase)</c>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<DefaultItemExcludes>$(DefaultItemExcludes);.git*</DefaultItemExcludes>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using LinqToDB;
using System.Diagnostics.CodeAnalysis;

namespace Lombiq.HelpfulLibraries.LinqToDb.Extensions;

Expand All @@ -9,16 +8,13 @@ public static class CustomSqlExtensions
// used by the attribute.
[Sql.Expression(ProviderName.SqlServer, "JSON_VALUE({0}, {1})", ServerSideOnly = true, InlineParameters = true)]
[Sql.Expression(ProviderName.SQLite, "json_extract({0}, {1})", ServerSideOnly = true, InlineParameters = true)]
[SuppressMessage("Usage", "CA1801:Review unused parameters", Justification = "Used in the Sql.Expression attribute.")]
public static string JsonValue(object expression, string path) => null;

[Sql.Expression(ProviderName.SqlServer, "JSON_MODIFY({0}, {1}, {2})", ServerSideOnly = true, InlineParameters = true)]
[Sql.Expression(ProviderName.SQLite, "json_replace({0}, {1}, {2})", ServerSideOnly = true, InlineParameters = true)]
[SuppressMessage("Usage", "CA1801:Review unused parameters", Justification = "Used in the Sql.Expression attribute.")]
public static string JsonModify(string json, string path, string newValue) => null;

[Sql.Expression(ProviderName.SqlServer, "JSON_QUERY({0})", ServerSideOnly = true, InlineParameters = true)]
[Sql.Expression(ProviderName.SQLite, "json({0})", ServerSideOnly = true, InlineParameters = true)]
[SuppressMessage("Usage", "CA1801:Review unused parameters", Justification = "Used in the Sql.Expression attribute.")]
public static string JsonQuery(string value) => null;
}
11 changes: 5 additions & 6 deletions Lombiq.HelpfulLibraries.LinqToDb/LinqToDbConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@

namespace Lombiq.HelpfulLibraries.LinqToDb;

public class LinqToDbConnection : DataConnection, ITableAccessor
public class LinqToDbConnection(
IDataProvider dataProvider,
DbTransaction dbTransaction,
string tablePrefix) : DataConnection(dataProvider, dbTransaction), ITableAccessor
{
private readonly string _tablePrefix;

public LinqToDbConnection(IDataProvider dataProvider, DbTransaction dbTransaction, string tablePrefix)
: base(dataProvider, dbTransaction) =>
_tablePrefix = tablePrefix;
private readonly string _tablePrefix = tablePrefix;

/// <summary>
/// For the current query, overrides <see cref="ITable{T}.TableName"/> of the table-like source
Expand Down
2 changes: 0 additions & 2 deletions Lombiq.HelpfulLibraries.LinqToDb/LinqToDbQueryExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ namespace Lombiq.HelpfulLibraries.LinqToDb;
public static class LinqToDbQueryExecutor
{
// We have no control over where these fields are declared.
#pragma warning disable CA1810 // Initialize reference type static fields inline
static LinqToDbQueryExecutor()
#pragma warning restore CA1810 // Initialize reference type static fields inline
{
// Generate aliases for final projection.
Sql.GenerateFinalAliases = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<DefaultItemExcludes>$(DefaultItemExcludes);.git*</DefaultItemExcludes>
</PropertyGroup>

Expand All @@ -24,7 +24,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="linq2db" Version="5.2.2" />
<PackageReference Include="OrchardCore.Data.YesSql" Version="1.7.0" />
<PackageReference Include="linq2db" Version="5.3.2" />
<PackageReference Include="OrchardCore.Data.YesSql" Version="1.8.2" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<DefaultItemExcludes>$(DefaultItemExcludes);.git*</DefaultItemExcludes>
</PropertyGroup>

Expand Down
Loading