Skip to content

Commit

Permalink
Merge pull request #234 from Lombiq/issue/OSOE-751
Browse files Browse the repository at this point in the history
OSOE-751: Upgrade to Orchard Core 1.8
  • Loading branch information
Psichorex authored Feb 21, 2024
2 parents abb5a1e + 63483ff commit 663a91d
Show file tree
Hide file tree
Showing 48 changed files with 162 additions and 154 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Lombiq.HelpfulLibraries.Common.Utilities;
using Lombiq.HelpfulLibraries.Common.Utilities;
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
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
4 changes: 3 additions & 1 deletion Lombiq.HelpfulLibraries.AspNetCore/Mvc/JsonModelBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace Lombiq.HelpfulLibraries.AspNetCore.Mvc;

public class JsonModelBinder : IModelBinder
{
private static readonly JsonSerializerOptions DeSerializeOptions = new(JsonSerializerDefaults.Web);

private readonly ILogger<JsonModelBinder> _logger;
private readonly IObjectModelValidator _validator;

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

if (parsed is null)
{
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;
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
5 changes: 2 additions & 3 deletions Lombiq.HelpfulLibraries.Cli/Helpers/CliWrapHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

namespace Lombiq.HelpfulLibraries.Cli.Helpers;
Expand All @@ -19,7 +18,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.IsWindows() ? "where" : "which";
var result = await CliWrap.Cli.Wrap(appName)
.WithArguments(name)
.WithValidation(CommandResultValidation.None)
Expand All @@ -46,7 +45,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 @@ -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 ?? [];

/// <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
4 changes: 2 additions & 2 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 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,8 +24,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

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;
}
3 changes: 0 additions & 3 deletions Lombiq.HelpfulLibraries.LinqToDb/LinqToDbQueryExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Extensions.Localization;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.Environment.Commands;
using System.Threading.Tasks;

namespace Lombiq.HelpfulLibraries.OrchardCore.Contents;

Expand Down Expand Up @@ -28,6 +29,6 @@ public ContentDefinitionCommands(
" /Part:<contentPartName>" +
"\r\n\t" + "Attaches a content part to a content type.")]
[OrchardSwitches(nameof(Type) + ", " + nameof(Part))]
public void AttachContentPart() =>
_contentDefinitionManager.AlterTypeDefinition(Type, type => type.WithPart(Part));
public Task AttachContentPartAsync() =>
_contentDefinitionManager.AlterTypeDefinitionAsync(Type, type => type.WithPart(Part));
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using OrchardCore.ContentManagement.Metadata.Builders;
using System;
using System.Linq;
using System.Threading.Tasks;

namespace OrchardCore.ContentManagement.Metadata;

Expand All @@ -13,13 +14,13 @@ public static class ContentDefinitionManagerExtensions
/// <param name="contentType">Technical name of the content type.</param>
/// <param name="contentPartName">Technical name of the content part.</param>
/// <returns>Content part settings object.</returns>
public static T GetContentPartSettings<T>(
public static async Task<T> GetContentPartSettingsAsync<T>(
this IContentDefinitionManager contentDefinitionManager,
string contentType,
string contentPartName)
where T : class, new()
{
var contentTypeDefinition = contentDefinitionManager.GetTypeDefinition(contentType);
var contentTypeDefinition = await contentDefinitionManager.GetTypeDefinitionAsync(contentType);
var contentTypePartDefinition = contentTypeDefinition.Parts
.FirstOrDefault(part => part.PartDefinition.Name == contentPartName);

Expand All @@ -30,20 +31,20 @@ public static T GetContentPartSettings<T>(
/// Alters the definition of a content part whose technical name is its model's type name. It uses the typed wrapper
/// <see cref="ContentPartDefinitionBuilder{TPart}"/> for configuration.
/// </summary>
public static string AlterPartDefinition<TPart>(
public static async Task<string> AlterPartDefinitionAsync<TPart>(
this IContentDefinitionManager manager,
Action<ContentPartDefinitionBuilder<TPart>> configure)
where TPart : ContentPart
{
var name = typeof(TPart).Name;
manager.AlterPartDefinition(name, part => configure(part.AsPart<TPart>()));
await manager.AlterPartDefinitionAsync(name, part => configure(part.AsPart<TPart>()));
return name;
}

/// <summary>
/// Prepares a <paramref name="contentType"/> to be used as a Taxonomy by resetting all content type settings to
/// <see langword="false"/> and adding <c>TitlePart</c>.
/// </summary>
public static void AlterTypeDefinitionForTaxonomy(this IContentDefinitionManager manager, string contentType) =>
manager.AlterTypeDefinition(contentType, type => type.NoAbilities().WithTitlePart());
public static Task AlterTypeDefinitionForTaxonomyAsync(this IContentDefinitionManager manager, string contentType) =>
manager.AlterTypeDefinitionAsync(contentType, type => type.NoAbilities().WithTitlePart());
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ public static IContent Merge(this IContent content, object properties, JsonMerge
/// <returns>The status of the <see cref="ContentItem"/>'s publication if any.</returns>
public static PublicationStatus GetPublicationStatus(this IContent content)
{
if (content == null) throw new ArgumentNullException(nameof(content));
ArgumentNullException.ThrowIfNull(content);
if (content.ContentItem == null)
{
throw new ArgumentException($"{nameof(content)}.{nameof(content.ContentItem)} shouldn't be null.");
throw new ArgumentNullException($"{nameof(content)}.{nameof(content.ContentItem)} shouldn't be null.");
}

if (content.ContentItem.Published) return PublicationStatus.Published;
Expand Down Expand Up @@ -118,7 +118,7 @@ public static async Task SanitizeContentItemVersionsAsync(this IContent content,
{
toRemove.Published = false;
toRemove.Latest = false;
session.Save(toRemove);
await session.SaveAsync(toRemove);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static async Task<IEnumerable<ContentItem>> GetOrQueryContentAsync(
// If the published version is already stored, we can return it.
if (contentManagerSession.RecallPublishedItemId(contentItemId, out var contentItem))
{
storedItems ??= new List<ContentItem>();
storedItems ??= [];
storedItems.Add(contentItem);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OrchardCore.Data.Migration;
using System.Threading.Tasks;
using YesSql.Indexes;
using YesSql.Sql;
using YesSql.Sql.Schema;
Expand All @@ -15,11 +16,11 @@ public abstract class IndexDataMigration<TIndex> : DataMigration
{
protected virtual int CreateVersion => 1;

public int Create()
public async Task<int> CreateAsync()
{
SchemaBuilder.CreateMapIndexTable<TIndex>(CreateIndex);
await SchemaBuilder.CreateMapIndexTableAsync<TIndex>(CreateIndex);

SchemaBuilder.CreateDocumentIdIndex<TIndex>();
await SchemaBuilder.CreateDocumentIdIndexAsync<TIndex>();

return CreateVersion;
}
Expand Down
Loading

0 comments on commit 663a91d

Please sign in to comment.