diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs index 8055a7e72de..f0fc4e30796 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs @@ -14,7 +14,7 @@ namespace OrchardCore.AdminMenu.Recipes /// /// This recipe step creates a set of admin menus. /// - public class AdminMenuStep : IRecipeStepHandler + public sealed class AdminMenuStep : IRecipeStepHandler { private readonly IAdminMenuService _adminMenuService; private readonly JsonSerializerOptions _serializationOptions; @@ -45,7 +45,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) // When the id is not supplied generate an id, otherwise replace the menu if it exists, or create a new menu. if (string.IsNullOrEmpty(adminMenu.Id)) { - adminMenu.Id = Guid.NewGuid().ToString("n"); + adminMenu.Id = IdGenerator.GenerateId(); } await _adminMenuService.SaveAsync(adminMenu); diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ContentDefinitionStep.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ContentDefinitionStep.cs index 8b9e2eac856..81e64f830b8 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ContentDefinitionStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ContentDefinitionStep.cs @@ -13,11 +13,11 @@ namespace OrchardCore.ContentTypes.RecipeSteps /// /// This recipe step creates content definitions. /// - public class ContentDefinitionStep : IRecipeStepHandler + public sealed class ContentDefinitionStep : IRecipeStepHandler { private readonly IContentDefinitionManager _contentDefinitionManager; - protected readonly IStringLocalizer S; + internal readonly IStringLocalizer S; public ContentDefinitionStep( IContentDefinitionManager contentDefinitionManager, diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/DeleteContentDefinitionStep.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/DeleteContentDefinitionStep.cs index cf37538caab..5c892321d5c 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/DeleteContentDefinitionStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/DeleteContentDefinitionStep.cs @@ -10,7 +10,7 @@ namespace OrchardCore.ContentTypes.RecipeSteps /// /// This recipe step deletes content definition records. /// - public class DeleteContentDefinitionStep : IRecipeStepHandler + public sealed class DeleteContentDefinitionStep : IRecipeStepHandler { private readonly IContentDefinitionManager _contentDefinitionManager; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ReplaceContentDefinitionStep.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ReplaceContentDefinitionStep.cs index 93704b92a6f..c4fad2a735d 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ReplaceContentDefinitionStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ReplaceContentDefinitionStep.cs @@ -11,7 +11,7 @@ namespace OrchardCore.ContentTypes.RecipeSteps /// /// This recipe step replaces content definition records. /// - public class ReplaceContentDefinitionStep : IRecipeStepHandler + public sealed class ReplaceContentDefinitionStep : IRecipeStepHandler { private readonly IContentDefinitionManager _contentDefinitionManager; diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Recipes/ContentStep.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Recipes/ContentStep.cs index 7791ffb436d..220196b15a9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Recipes/ContentStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Recipes/ContentStep.cs @@ -12,7 +12,7 @@ namespace OrchardCore.Contents.Recipes /// /// This recipe step creates a set of content items. /// - public class ContentStep : IRecipeStepHandler + public sealed class ContentStep : IRecipeStepHandler { public Task ExecuteAsync(RecipeExecutionContext context) { @@ -43,7 +43,7 @@ public Task ExecuteAsync(RecipeExecutionContext context) } } - public class ContentStepModel + public sealed class ContentStepModel { public JsonArray Data { get; set; } } diff --git a/src/OrchardCore.Modules/OrchardCore.CustomSettings/Recipes/CustomSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.CustomSettings/Recipes/CustomSettingsStep.cs index 11f2d281b53..e00e7ad6699 100644 --- a/src/OrchardCore.Modules/OrchardCore.CustomSettings/Recipes/CustomSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.CustomSettings/Recipes/CustomSettingsStep.cs @@ -9,7 +9,7 @@ namespace OrchardCore.CustomSettings.Recipes /// /// This recipe step updates the site settings. /// - public class CustomSettingsStep : IRecipeStepHandler + public sealed class CustomSettingsStep : IRecipeStepHandler { private readonly ISiteService _siteService; diff --git a/src/OrchardCore.Modules/OrchardCore.Deployment/Recipes/DeploymentPlansRecipeStep.cs b/src/OrchardCore.Modules/OrchardCore.Deployment/Recipes/DeploymentPlansRecipeStep.cs index 678d091fe4a..1b2551ad69d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Deployment/Recipes/DeploymentPlansRecipeStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Deployment/Recipes/DeploymentPlansRecipeStep.cs @@ -5,6 +5,7 @@ using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; using OrchardCore.Json; using OrchardCore.Recipes.Models; @@ -15,20 +16,24 @@ namespace OrchardCore.Deployment.Recipes /// /// This recipe step creates a deployment plan. /// - public class DeploymentPlansRecipeStep : IRecipeStepHandler + public sealed class DeploymentPlansRecipeStep : IRecipeStepHandler { private readonly IServiceProvider _serviceProvider; private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly IDeploymentPlanService _deploymentPlanService; + internal readonly IStringLocalizer S; + public DeploymentPlansRecipeStep( IServiceProvider serviceProvider, IOptions jsonSerializerOptions, - IDeploymentPlanService deploymentPlanService) + IDeploymentPlanService deploymentPlanService, + IStringLocalizer stringLocalizer) { _serviceProvider = serviceProvider; _jsonSerializerOptions = jsonSerializerOptions.Value.SerializerOptions; _deploymentPlanService = deploymentPlanService; + S = stringLocalizer; } public Task ExecuteAsync(RecipeExecutionContext context) @@ -71,10 +76,11 @@ public Task ExecuteAsync(RecipeExecutionContext context) if (unknownTypes.Count != 0) { - var prefix = "No changes have been made. The following types of deployment plans cannot be added:"; - var suffix = "Please ensure that the related features are enabled to add these types of deployment plans."; + context.Errors.Add( + S["No changes have been made. The following types of deployment plans cannot be added: {0}. Please ensure that the related features are enabled to add these types of deployment plans.", + string.Join(", ", unknownTypes)]); - throw new InvalidOperationException($"{prefix} {string.Join(", ", unknownTypes)}. {suffix}"); + return Task.CompletedTask; } return _deploymentPlanService.CreateOrUpdateDeploymentPlansAsync(deploymentPlans); diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Recipes/FacebookLoginSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Recipes/FacebookLoginSettingsStep.cs index 46e45966562..7bdbdd6a5a3 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Recipes/FacebookLoginSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Recipes/FacebookLoginSettingsStep.cs @@ -11,7 +11,7 @@ namespace OrchardCore.Facebook.Login.Recipes /// /// This recipe step sets general Facebook Login settings. /// - public class FacebookLoginSettingsStep : IRecipeStepHandler + public sealed class FacebookLoginSettingsStep : IRecipeStepHandler { private readonly IFacebookLoginService _loginService; @@ -36,7 +36,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) } } - public class FacebookLoginSettingsStepModel + public sealed class FacebookLoginSettingsStepModel { public string CallbackPath { get; set; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Recipes/FacebookSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/Recipes/FacebookSettingsStep.cs index 4ddaec0e112..53d5bf3eb8a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Recipes/FacebookSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Recipes/FacebookSettingsStep.cs @@ -10,7 +10,7 @@ namespace OrchardCore.Facebook.Recipes /// /// This recipe step sets general Facebook Login settings. /// - public class FacebookSettingsStep : IRecipeStepHandler + public sealed class FacebookSettingsStep : IRecipeStepHandler { private readonly IFacebookService _facebookService; @@ -40,7 +40,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) } } - public class FacebookCoreSettingsStepModel + public sealed class FacebookCoreSettingsStepModel { public string AppId { get; set; } public string AppSecret { get; set; } diff --git a/src/OrchardCore.Modules/OrchardCore.Features/Recipes/Executors/FeatureStep.cs b/src/OrchardCore.Modules/OrchardCore.Features/Recipes/Executors/FeatureStep.cs index ba7c463b7cf..71531374ba5 100644 --- a/src/OrchardCore.Modules/OrchardCore.Features/Recipes/Executors/FeatureStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Features/Recipes/Executors/FeatureStep.cs @@ -11,12 +11,11 @@ namespace OrchardCore.Features.Recipes.Executors /// /// This recipe step enables or disables a set of features. /// - public class FeatureStep : IRecipeStepHandler + public sealed class FeatureStep : IRecipeStepHandler { private readonly IShellFeaturesManager _shellFeaturesManager; - public FeatureStep( - IShellFeaturesManager shellFeaturesManager) + public FeatureStep(IShellFeaturesManager shellFeaturesManager) { _shellFeaturesManager = shellFeaturesManager; } diff --git a/src/OrchardCore.Modules/OrchardCore.GitHub/Recipes/GithubAuthenticationSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.GitHub/Recipes/GithubAuthenticationSettingsStep.cs index 4ed64ade22f..b04d385ee91 100644 --- a/src/OrchardCore.Modules/OrchardCore.GitHub/Recipes/GithubAuthenticationSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.GitHub/Recipes/GithubAuthenticationSettingsStep.cs @@ -11,7 +11,7 @@ namespace OrchardCore.GitHub.Recipes /// /// This recipe step sets GitHub Account settings. /// - public class GitHubAuthenticationSettingsStep : IRecipeStepHandler + public sealed class GitHubAuthenticationSettingsStep : IRecipeStepHandler { private readonly IGitHubAuthenticationService _githubAuthenticationService; @@ -26,6 +26,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) { return; } + var model = context.Step.ToObject(); var settings = await _githubAuthenticationService.LoadSettingsAsync(); @@ -37,7 +38,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) } } - public class GitHubLoginSettingsStepModel + public sealed class GitHubLoginSettingsStepModel { public string ConsumerKey { get; set; } public string ConsumerSecret { get; set; } diff --git a/src/OrchardCore.Modules/OrchardCore.Layers/Recipes/LayerStep.cs b/src/OrchardCore.Modules/OrchardCore.Layers/Recipes/LayerStep.cs index af6fe1bd439..bd84fa077fb 100644 --- a/src/OrchardCore.Modules/OrchardCore.Layers/Recipes/LayerStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Layers/Recipes/LayerStep.cs @@ -19,14 +19,14 @@ namespace OrchardCore.Layers.Recipes /// /// This recipe step creates or updates a layer. /// - public class LayerStep : IRecipeStepHandler + public sealed class LayerStep : IRecipeStepHandler { private readonly ILayerService _layerService; private readonly IConditionIdGenerator _conditionIdGenerator; private readonly IEnumerable _factories; private readonly JsonSerializerOptions _serializationOptions; - protected readonly IStringLocalizer S; + internal readonly IStringLocalizer S; public LayerStep( ILayerService layerService, diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Recipes/MediaProfileStep.cs b/src/OrchardCore.Modules/OrchardCore.Media/Recipes/MediaProfileStep.cs index cf0de970f68..883d89e33ed 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Recipes/MediaProfileStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Recipes/MediaProfileStep.cs @@ -12,7 +12,7 @@ namespace OrchardCore.Media.Recipes /// /// This recipe step creates or updates a media profile. /// - public class MediaProfileStep : IRecipeStepHandler + public sealed class MediaProfileStep : IRecipeStepHandler { private readonly MediaProfilesManager _mediaProfilesManager; @@ -37,7 +37,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) } } - public class MediaProfileStepModel + public sealed class MediaProfileStepModel { public Dictionary MediaProfiles { get; set; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Recipes/MediaStep.cs b/src/OrchardCore.Modules/OrchardCore.Media/Recipes/MediaStep.cs index dc276494929..02b829b1d15 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Recipes/MediaStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Recipes/MediaStep.cs @@ -6,7 +6,7 @@ using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.FileProviders; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; @@ -16,23 +16,24 @@ namespace OrchardCore.Media.Recipes /// /// This recipe step creates a set of queries. /// - public class MediaStep : IRecipeStepHandler + public sealed class MediaStep : IRecipeStepHandler { private readonly IMediaFileStore _mediaFileStore; private readonly HashSet _allowedFileExtensions; private readonly IHttpClientFactory _httpClientFactory; - private readonly ILogger _logger; + + internal readonly IStringLocalizer S; public MediaStep( IMediaFileStore mediaFileStore, IOptions options, IHttpClientFactory httpClientFactory, - ILogger logger) + IStringLocalizer stringLocalizer) { _mediaFileStore = mediaFileStore; _allowedFileExtensions = options.Value.AllowedFileExtensions; _httpClientFactory = httpClientFactory; - _logger = logger; + S = stringLocalizer; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -48,7 +49,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) { if (!_allowedFileExtensions.Contains(Path.GetExtension(file.TargetPath), StringComparer.OrdinalIgnoreCase)) { - _logger.LogWarning("File extension not allowed: '{Path}'", file.TargetPath); + context.Errors.Add(S["File extension not allowed: '{0}'", file.TargetPath]); continue; } diff --git a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Recipes/AzureADSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Recipes/AzureADSettingsStep.cs index 30a56777d61..10b0e2956e9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Recipes/AzureADSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Recipes/AzureADSettingsStep.cs @@ -11,7 +11,7 @@ namespace OrchardCore.Microsoft.Authentication.Recipes /// /// This recipe step sets general Microsoft Entra ID settings. /// - public class AzureADSettingsStep : IRecipeStepHandler + public sealed class AzureADSettingsStep : IRecipeStepHandler { private readonly IAzureADService _azureADService; @@ -39,7 +39,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) } } - public class AzureADSettingsStepModel + public sealed class AzureADSettingsStepModel { public string DisplayName { get; set; } public string AppId { get; set; } diff --git a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Recipes/MicrosoftAccountSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Recipes/MicrosoftAccountSettingsStep.cs index 642dce35fed..e62b0cb0099 100644 --- a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Recipes/MicrosoftAccountSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Recipes/MicrosoftAccountSettingsStep.cs @@ -11,7 +11,7 @@ namespace OrchardCore.Microsoft.Authentication.Recipes /// /// This recipe step sets Microsoft Account settings. /// - public class MicrosoftAccountSettingsStep : IRecipeStepHandler + public sealed class MicrosoftAccountSettingsStep : IRecipeStepHandler { private readonly IMicrosoftAccountService _microsoftAccountService; @@ -38,7 +38,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) } } - public class MicrosoftAccountSettingsStepModel + public sealed class MicrosoftAccountSettingsStepModel { public string AppId { get; set; } public string AppSecret { get; set; } diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdApplicationStep.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdApplicationStep.cs index 999d3682993..ccc2bae111f 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdApplicationStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdApplicationStep.cs @@ -8,7 +8,7 @@ namespace OrchardCore.OpenId.Recipes { - public class OpenIdApplicationStep : IRecipeStepHandler + public sealed class OpenIdApplicationStep : IRecipeStepHandler { private readonly IOpenIdApplicationManager _applicationManager; diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdClientSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdClientSettingsStep.cs index 942b245aaeb..6a1a0d19ee9 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdClientSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdClientSettingsStep.cs @@ -11,7 +11,7 @@ namespace OrchardCore.OpenId.Recipes /// /// This recipe step sets general OpenID Connect Client settings. /// - public class OpenIdClientSettingsStep : IRecipeStepHandler + public sealed class OpenIdClientSettingsStep : IRecipeStepHandler { private readonly IOpenIdClientService _clientService; @@ -47,7 +47,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) } } - public class OpenIdClientSettingsStepModel + public sealed class OpenIdClientSettingsStepModel { public string DisplayName { get; set; } diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdScopeStep.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdScopeStep.cs index 7974664825c..4402739198c 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdScopeStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdScopeStep.cs @@ -8,7 +8,7 @@ namespace OrchardCore.OpenId.Recipes { - public class OpenIdScopeStep : IRecipeStepHandler + public sealed class OpenIdScopeStep : IRecipeStepHandler { private readonly IOpenIdScopeManager _scopeManager; @@ -46,8 +46,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) { descriptor.Resources.Clear(); descriptor.Resources.UnionWith( - model.Resources - .Split(' ', StringSplitOptions.RemoveEmptyEntries)); + model.Resources.Split(' ', StringSplitOptions.RemoveEmptyEntries)); } if (isNew) diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdServerSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdServerSettingsStep.cs index 91f5c8b8d4a..f79794e085a 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdServerSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdServerSettingsStep.cs @@ -12,7 +12,7 @@ namespace OrchardCore.OpenId.Recipes /// /// This recipe step sets general OpenID Connect settings. /// - public class OpenIdServerSettingsStep : IRecipeStepHandler + public sealed class OpenIdServerSettingsStep : IRecipeStepHandler { private readonly IOpenIdServerService _serverService; diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdValidationSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdValidationSettingsStep.cs index fbf75ec3595..f33be3eeb69 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdValidationSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdValidationSettingsStep.cs @@ -11,12 +11,11 @@ namespace OrchardCore.OpenId.Recipes /// /// This recipe step sets Token Validation OpenID Connect settings. /// - public class OpenIdValidationSettingsStep : IRecipeStepHandler + public sealed class OpenIdValidationSettingsStep : IRecipeStepHandler { private readonly IOpenIdValidationService _validationService; - public OpenIdValidationSettingsStep( - IOpenIdValidationService validationService) + public OpenIdValidationSettingsStep(IOpenIdValidationService validationService) { _validationService = validationService; } diff --git a/src/OrchardCore.Modules/OrchardCore.Placements/Recipes/PlacementStep.cs b/src/OrchardCore.Modules/OrchardCore.Placements/Recipes/PlacementStep.cs index a07894ada91..dd340b6af72 100644 --- a/src/OrchardCore.Modules/OrchardCore.Placements/Recipes/PlacementStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Placements/Recipes/PlacementStep.cs @@ -11,7 +11,7 @@ namespace OrchardCore.Placements.Recipes /// /// This recipe step creates a set of placements. /// - public class PlacementStep : IRecipeStepHandler + public sealed class PlacementStep : IRecipeStepHandler { private readonly PlacementsManager _placementsManager; diff --git a/src/OrchardCore.Modules/OrchardCore.Queries/Recipes/QueryStep.cs b/src/OrchardCore.Modules/OrchardCore.Queries/Recipes/QueryStep.cs index dc86d0fcd3f..4bd19af3493 100644 --- a/src/OrchardCore.Modules/OrchardCore.Queries/Recipes/QueryStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Queries/Recipes/QueryStep.cs @@ -92,7 +92,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) } } - public class QueryStepModel + public sealed class QueryStepModel { public JsonArray Queries { get; set; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Recipes/RecipeSteps/CommandStep.cs b/src/OrchardCore.Modules/OrchardCore.Recipes/RecipeSteps/CommandStep.cs index 356133e8387..2e260ecce5a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Recipes/RecipeSteps/CommandStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Recipes/RecipeSteps/CommandStep.cs @@ -13,7 +13,7 @@ namespace OrchardCore.Recipes.RecipeSteps /// /// This recipe step executes a set of commands. /// - public class CommandStep : IRecipeStepHandler + public sealed class CommandStep : IRecipeStepHandler { private readonly ICommandManager _commandManager; private readonly ICommandParser _commandParser; @@ -42,14 +42,17 @@ public async Task ExecuteAsync(RecipeExecutionContext context) foreach (var command in step.Commands) { - using (var output = new ZStringWriter()) + await using (var output = new ZStringWriter()) { _logger.LogInformation("Executing command: {Command}", command); + var commandParameters = _commandParameterParser.Parse(_commandParser.Parse(command)); commandParameters.Output = output; await _commandManager.ExecuteAsync(commandParameters); + _logger.LogInformation("Command executed with output: {CommandOutput}", output); } + _logger.LogInformation("Executed command: {Command}", command); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Recipes/RecipeSteps/RecipesStep.cs b/src/OrchardCore.Modules/OrchardCore.Recipes/RecipeSteps/RecipesStep.cs index 4e1919b4000..dce986da558 100644 --- a/src/OrchardCore.Modules/OrchardCore.Recipes/RecipeSteps/RecipesStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Recipes/RecipeSteps/RecipesStep.cs @@ -12,11 +12,11 @@ namespace OrchardCore.Recipes.RecipeSteps /// /// This recipe step executes a set of external recipes. /// - public class RecipesStep : IRecipeStepHandler + public sealed class RecipesStep : IRecipeStepHandler { private readonly IEnumerable _recipeHarvesters; - protected readonly IStringLocalizer S; + internal readonly IStringLocalizer S; public RecipesStep( IEnumerable recipeHarvesters, diff --git a/src/OrchardCore.Modules/OrchardCore.Roles/Recipes/RolesStep.cs b/src/OrchardCore.Modules/OrchardCore.Roles/Recipes/RolesStep.cs index 133d4bcb525..8488e4fc0d5 100644 --- a/src/OrchardCore.Modules/OrchardCore.Roles/Recipes/RolesStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Roles/Recipes/RolesStep.cs @@ -13,7 +13,7 @@ namespace OrchardCore.Roles.Recipes /// /// This recipe step creates a set of roles. /// - public class RolesStep : IRecipeStepHandler + public sealed class RolesStep : IRecipeStepHandler { private readonly RoleManager _roleManager; @@ -43,12 +43,19 @@ public async Task ExecuteAsync(RecipeExecutionContext context) if (isNewRole) { - role = new Role { RoleName = importedRole.Name }; + role = new Role + { + RoleName = importedRole.Name + }; } role.RoleDescription = importedRole.Description; role.RoleClaims.RemoveAll(c => c.ClaimType == Permission.ClaimType); - role.RoleClaims.AddRange(importedRole.Permissions.Select(p => new RoleClaim { ClaimType = Permission.ClaimType, ClaimValue = p })); + role.RoleClaims.AddRange(importedRole.Permissions.Select(p => new RoleClaim + { + ClaimType = Permission.ClaimType, + ClaimValue = p, + })); if (isNewRole) { @@ -60,14 +67,14 @@ public async Task ExecuteAsync(RecipeExecutionContext context) } } } + } - public class RolesStepModel - { - public RolesStepRoleModel[] Roles { get; set; } - } + public sealed class RolesStepModel + { + public RolesStepRoleModel[] Roles { get; set; } } - public class RolesStepRoleModel + public sealed class RolesStepRoleModel { public string Name { get; set; } public string Description { get; set; } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexRebuildStep.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexRebuildStep.cs index 1ce1bdf5632..0bd2542d876 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexRebuildStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexRebuildStep.cs @@ -1,10 +1,8 @@ using System; using System.Linq; -using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; using OrchardCore.BackgroundJobs; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; @@ -14,7 +12,7 @@ namespace OrchardCore.Search.Lucene.Recipes /// /// This recipe step rebuilds a Lucene index. /// - public class LuceneIndexRebuildStep : IRecipeStepHandler + public sealed class LuceneIndexRebuildStep : IRecipeStepHandler { public async Task ExecuteAsync(RecipeExecutionContext context) { @@ -32,7 +30,9 @@ await HttpBackgroundJob.ExecuteAfterEndOfRequestAsync("lucene-index-rebuild", as var luceneIndexSettingsService = scope.ServiceProvider.GetRequiredService(); var luceneIndexingService = scope.ServiceProvider.GetRequiredService(); - var indices = model.IncludeAll ? (await luceneIndexSettingsService.GetSettingsAsync()).Select(x => x.IndexName).ToArray() : model.Indices; + var indices = model.IncludeAll + ? (await luceneIndexSettingsService.GetSettingsAsync()).Select(x => x.IndexName).ToArray() + : model.Indices; foreach (var indexName in indices) { diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexResetStep.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexResetStep.cs index abdde7696eb..89e4b359ce6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexResetStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexResetStep.cs @@ -12,7 +12,7 @@ namespace OrchardCore.Search.Lucene.Recipes /// /// This recipe step resets a lucene index. /// - public class LuceneIndexResetStep : IRecipeStepHandler + public sealed class LuceneIndexResetStep : IRecipeStepHandler { public async Task ExecuteAsync(RecipeExecutionContext context) { @@ -31,7 +31,9 @@ await HttpBackgroundJob.ExecuteAfterEndOfRequestAsync("lucene-index-reset", asyn var luceneIndexingService = scope.ServiceProvider.GetRequiredService(); var luceneIndexManager = scope.ServiceProvider.GetRequiredService(); - var indices = model.IncludeAll ? (await luceneIndexSettingsService.GetSettingsAsync()).Select(x => x.IndexName).ToArray() : model.Indices; + var indices = model.IncludeAll + ? (await luceneIndexSettingsService.GetSettingsAsync()).Select(x => x.IndexName).ToArray() + : model.Indices; foreach (var indexName in indices) { diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexStep.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexStep.cs index 0dd0611145c..e1e6b1acc30 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexStep.cs @@ -12,7 +12,7 @@ namespace OrchardCore.Search.Lucene.Recipes /// /// This recipe step creates a lucene index. /// - public class LuceneIndexStep : IRecipeStepHandler + public sealed class LuceneIndexStep : IRecipeStepHandler { private readonly LuceneIndexingService _luceneIndexingService; private readonly LuceneIndexManager _luceneIndexManager; @@ -33,24 +33,25 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var indices = context.Step["Indices"]; - if (indices is JsonArray jsonArray) + if (context.Step["Indices"] is not JsonArray jsonArray) { - foreach (var index in jsonArray) - { - var luceneIndexSettings = index.ToObject>().FirstOrDefault(); + return; + } - if (!_luceneIndexManager.Exists(luceneIndexSettings.Key)) - { - luceneIndexSettings.Value.IndexName = luceneIndexSettings.Key; - await _luceneIndexingService.CreateIndexAsync(luceneIndexSettings.Value); - } + foreach (var index in jsonArray) + { + var luceneIndexSettings = index.ToObject>().FirstOrDefault(); + + if (!_luceneIndexManager.Exists(luceneIndexSettings.Key)) + { + luceneIndexSettings.Value.IndexName = luceneIndexSettings.Key; + await _luceneIndexingService.CreateIndexAsync(luceneIndexSettings.Value); } } } } - public class ContentStepModel + public sealed class ContentStepModel { public JsonObject Data { get; set; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Settings/Recipes/SettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.Settings/Recipes/SettingsStep.cs index 4af28a27e2c..94c8240f571 100644 --- a/src/OrchardCore.Modules/OrchardCore.Settings/Recipes/SettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Settings/Recipes/SettingsStep.cs @@ -10,7 +10,7 @@ namespace OrchardCore.Settings.Recipes /// /// This recipe step updates the site settings. /// - public class SettingsStep : IRecipeStepHandler + public sealed class SettingsStep : IRecipeStepHandler { private readonly ISiteService _siteService; diff --git a/src/OrchardCore.Modules/OrchardCore.Shortcodes/Recipes/ShortcodeTemplateStep.cs b/src/OrchardCore.Modules/OrchardCore.Shortcodes/Recipes/ShortcodeTemplateStep.cs index 35540d8bd48..e622011d772 100644 --- a/src/OrchardCore.Modules/OrchardCore.Shortcodes/Recipes/ShortcodeTemplateStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Shortcodes/Recipes/ShortcodeTemplateStep.cs @@ -11,7 +11,7 @@ namespace OrchardCore.Shortcodes.Recipes /// /// This recipe step creates a set of shortcodes. /// - public class ShortcodeTemplateStep : IRecipeStepHandler + public sealed class ShortcodeTemplateStep : IRecipeStepHandler { private readonly ShortcodeTemplatesManager _templatesManager; diff --git a/src/OrchardCore.Modules/OrchardCore.Templates/Recipes/AdminTemplateStep.cs b/src/OrchardCore.Modules/OrchardCore.Templates/Recipes/AdminTemplateStep.cs index 21709373b7e..9c434b8f83a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Templates/Recipes/AdminTemplateStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Templates/Recipes/AdminTemplateStep.cs @@ -11,7 +11,7 @@ namespace OrchardCore.Templates.Recipes /// /// This recipe step creates a set of templates. /// - public class AdminTemplateStep : IRecipeStepHandler + public sealed class AdminTemplateStep : IRecipeStepHandler { private readonly AdminTemplatesManager _adminTemplatesManager; diff --git a/src/OrchardCore.Modules/OrchardCore.Templates/Recipes/TemplateStep.cs b/src/OrchardCore.Modules/OrchardCore.Templates/Recipes/TemplateStep.cs index 0bfbc887fff..f87b7c06433 100644 --- a/src/OrchardCore.Modules/OrchardCore.Templates/Recipes/TemplateStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Templates/Recipes/TemplateStep.cs @@ -11,7 +11,7 @@ namespace OrchardCore.Templates.Recipes /// /// This recipe step creates a set of templates. /// - public class TemplateStep : IRecipeStepHandler + public sealed class TemplateStep : IRecipeStepHandler { private readonly TemplatesManager _templatesManager; diff --git a/src/OrchardCore.Modules/OrchardCore.Tenants/Recipes/FeatureProfilesStep.cs b/src/OrchardCore.Modules/OrchardCore.Tenants/Recipes/FeatureProfilesStep.cs index 05d4a7ef8e8..45879d3599d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Tenants/Recipes/FeatureProfilesStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Tenants/Recipes/FeatureProfilesStep.cs @@ -11,7 +11,7 @@ namespace OrchardCore.Tenants.Recipes /// /// This recipe step creates a set of feature profiles. /// - public class FeatureProfilesStep : IRecipeStepHandler + public sealed class FeatureProfilesStep : IRecipeStepHandler { private readonly FeatureProfilesManager _featureProfilesManager; diff --git a/src/OrchardCore.Modules/OrchardCore.Themes/Recipes/ThemesStep.cs b/src/OrchardCore.Modules/OrchardCore.Themes/Recipes/ThemesStep.cs index 0b258a10dd9..81c2bd6e71f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Themes/Recipes/ThemesStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Themes/Recipes/ThemesStep.cs @@ -11,7 +11,7 @@ namespace OrchardCore.Themes.Recipes /// /// This recipe step defines the site and admin current themes. /// - public class ThemesStep : IRecipeStepHandler + public sealed class ThemesStep : IRecipeStepHandler { private readonly ISiteThemeService _siteThemeService; private readonly IAdminThemeService _adminThemeService; @@ -45,7 +45,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) } } - public class ThemeStepModel + public sealed class ThemeStepModel { public string Site { get; set; } public string Admin { get; set; } diff --git a/src/OrchardCore.Modules/OrchardCore.Twitter/Recipes/TwitterSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.Twitter/Recipes/TwitterSettingsStep.cs index a3a62c52e59..eeb094c07b4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Twitter/Recipes/TwitterSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Twitter/Recipes/TwitterSettingsStep.cs @@ -11,7 +11,7 @@ namespace OrchardCore.Twitter.Recipes /// /// This recipe step sets Microsoft Account settings. /// - public class TwitterSettingsStep : IRecipeStepHandler + public sealed class TwitterSettingsStep : IRecipeStepHandler { private readonly ITwitterSettingsService _twitterService; @@ -39,7 +39,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) } } - public class TwitterSettingsStepModel + public sealed class TwitterSettingsStepModel { public string ConsumerKey { get; set; } public string ConsumerSecret { get; set; } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs index 39f4d76b580..a95dad4f47c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs @@ -13,7 +13,7 @@ namespace OrchardCore.Users.Recipes; /// /// This recipe step updates the custom user settings. /// -public class CustomUserSettingsStep : IRecipeStepHandler +public sealed class CustomUserSettingsStep : IRecipeStepHandler { private readonly ISession _session; diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs index a52a8cae6e8..87072e47b47 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs @@ -9,7 +9,7 @@ namespace OrchardCore.Users.Recipes; -public class UsersStep : IRecipeStepHandler +public sealed class UsersStep : IRecipeStepHandler { private readonly UserManager _userManager; private readonly ISession _session; @@ -42,7 +42,10 @@ public async Task ExecuteAsync(RecipeExecutionContext context) if (iUser is not User user) { - user = new User { UserId = importedUser.UserId }; + user = new User + { + UserId = importedUser.UserId + }; } user.Email = importedUser.Email; diff --git a/src/OrchardCore.Modules/OrchardCore.Workflows/Recipes/WorkflowTypeStep.cs b/src/OrchardCore.Modules/OrchardCore.Workflows/Recipes/WorkflowTypeStep.cs index 2b1ba0c6838..b4386a07b73 100644 --- a/src/OrchardCore.Modules/OrchardCore.Workflows/Recipes/WorkflowTypeStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Workflows/Recipes/WorkflowTypeStep.cs @@ -18,7 +18,7 @@ namespace OrchardCore.Workflows.Recipes { - public class WorkflowTypeStep : IRecipeStepHandler + public sealed class WorkflowTypeStep : IRecipeStepHandler { private readonly IWorkflowTypeStore _workflowTypeStore; private readonly ISecurityTokenService _securityTokenService; @@ -103,7 +103,7 @@ private string ReGenerateHttpRequestEventUrl(IUrlHelper urlHelper, WorkflowType } } - public class WorkflowStepModel + public sealed class WorkflowStepModel { public JsonArray Data { get; set; } } diff --git a/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeExecutor.cs b/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeExecutor.cs index 5d1ba0eca83..a58cca59d2d 100644 --- a/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeExecutor.cs +++ b/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeExecutor.cs @@ -176,10 +176,7 @@ await shellScope.UsingAsync(async scope => // Substitutes the script elements by their actual values. EvaluateJsonTree(scriptingManager, recipeStep, recipeStep.Step); - if (_logger.IsEnabled(LogLevel.Information)) - { - _logger.LogInformation("Executing recipe step '{RecipeName}'.", recipeStep.Name); - } + _logger.LogInformation("Executing recipe step '{RecipeName}'.", recipeStep.Name); await _recipeEventHandlers.InvokeAsync((handler, recipeStep) => handler.RecipeStepExecutingAsync(recipeStep), recipeStep, _logger); @@ -190,10 +187,7 @@ await shellScope.UsingAsync(async scope => await _recipeEventHandlers.InvokeAsync((handler, recipeStep) => handler.RecipeStepExecutedAsync(recipeStep), recipeStep, _logger); - if (_logger.IsEnabled(LogLevel.Information)) - { - _logger.LogInformation("Finished executing recipe step '{RecipeName}'.", recipeStep.Name); - } + _logger.LogInformation("Finished executing recipe step '{RecipeName}'.", recipeStep.Name); }); } diff --git a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Recipes/AzureAISearchIndexRebuildStep.cs b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Recipes/AzureAISearchIndexRebuildStep.cs index b8ab6c4df78..775733ee4ae 100644 --- a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Recipes/AzureAISearchIndexRebuildStep.cs +++ b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Recipes/AzureAISearchIndexRebuildStep.cs @@ -11,7 +11,7 @@ namespace OrchardCore.Search.AzureAI.Recipes; -public class AzureAISearchIndexRebuildStep : IRecipeStepHandler +public sealed class AzureAISearchIndexRebuildStep : IRecipeStepHandler { public async Task ExecuteAsync(RecipeExecutionContext context) { diff --git a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Recipes/AzureAISearchIndexResetStep.cs b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Recipes/AzureAISearchIndexResetStep.cs index d56ef676eea..e57f51582c7 100644 --- a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Recipes/AzureAISearchIndexResetStep.cs +++ b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Recipes/AzureAISearchIndexResetStep.cs @@ -11,7 +11,7 @@ namespace OrchardCore.Search.AzureAI.Recipes; -public class AzureAISearchIndexResetStep : IRecipeStepHandler +public sealed class AzureAISearchIndexResetStep : IRecipeStepHandler { public async Task ExecuteAsync(RecipeExecutionContext context) { diff --git a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Recipes/AzureAISearchIndexSettingsStep.cs b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Recipes/AzureAISearchIndexSettingsStep.cs index 6e4167b6614..e3f930515e3 100644 --- a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Recipes/AzureAISearchIndexSettingsStep.cs +++ b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Recipes/AzureAISearchIndexSettingsStep.cs @@ -3,7 +3,7 @@ using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Localization; using OrchardCore.BackgroundJobs; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; @@ -14,25 +14,26 @@ namespace OrchardCore.Search.AzureAI.Recipes; -public class AzureAISearchIndexSettingsStep : IRecipeStepHandler +public sealed class AzureAISearchIndexSettingsStep : IRecipeStepHandler { public const string Name = "azureai-index-create"; private readonly AzureAISearchIndexManager _indexManager; private readonly AzureAIIndexDocumentManager _azureAIIndexDocumentManager; private readonly AzureAISearchIndexSettingsService _azureAISearchIndexSettingsService; - private readonly ILogger _logger; + + internal readonly IStringLocalizer S; public AzureAISearchIndexSettingsStep( AzureAISearchIndexManager indexManager, AzureAIIndexDocumentManager azureAIIndexDocumentManager, AzureAISearchIndexSettingsService azureAISearchIndexSettingsService, - ILogger logger) + IStringLocalizer stringLocalizer) { _indexManager = indexManager; _azureAIIndexDocumentManager = azureAIIndexDocumentManager; _azureAISearchIndexSettingsService = azureAISearchIndexSettingsService; - _logger = logger; + S = stringLocalizer; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -55,21 +56,21 @@ public async Task ExecuteAsync(RecipeExecutionContext context) if (string.IsNullOrWhiteSpace(indexInfo.IndexName)) { - _logger.LogError("No index name was provided in the '{Name}' recipe step.", Name); + context.Errors.Add(S["No index name was provided in the '{0}' recipe step.", Name]); continue; } if (!AzureAISearchIndexNamingHelper.TryGetSafeIndexName(indexInfo.IndexName, out var indexName)) { - _logger.LogError("Invalid index name was provided in the recipe step. IndexName: {IndexName}.", indexInfo.IndexName); + context.Errors.Add(S["Invalid index name was provided in the recipe step. IndexName: {0}.", indexInfo.IndexName]); continue; } if (indexInfo.IndexedContentTypes?.Length == 0) { - _logger.LogError("No {IndexedContentTypes} were provided in the recipe step. IndexName: {IndexName}.", nameof(indexInfo.IndexedContentTypes), indexInfo.IndexName); + context.Errors.Add(S["No {0} were provided in the recipe step. IndexName: {1}.", nameof(indexInfo.IndexedContentTypes), indexInfo.IndexName]); continue; } diff --git a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Recipes/ElasticIndexRebuildStep.cs b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Recipes/ElasticIndexRebuildStep.cs index 2dc3571eee9..c66764efd78 100644 --- a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Recipes/ElasticIndexRebuildStep.cs +++ b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Recipes/ElasticIndexRebuildStep.cs @@ -14,7 +14,7 @@ namespace OrchardCore.Search.Elasticsearch.Core.Recipes /// /// This recipe step rebuilds an Elasticsearch index. /// - public class ElasticIndexRebuildStep : IRecipeStepHandler + public sealed class ElasticIndexRebuildStep : IRecipeStepHandler { public async Task ExecuteAsync(RecipeExecutionContext context) { @@ -33,7 +33,9 @@ await HttpBackgroundJob.ExecuteAfterEndOfRequestAsync("elastic-index-rebuild", a var elasticIndexSettingsService = scope.ServiceProvider.GetService(); var elasticIndexManager = scope.ServiceProvider.GetRequiredService(); - var indexNames = model.IncludeAll ? (await elasticIndexSettingsService.GetSettingsAsync()).Select(x => x.IndexName).ToArray() : model.Indices; + var indexNames = model.IncludeAll + ? (await elasticIndexSettingsService.GetSettingsAsync()).Select(x => x.IndexName).ToArray() + : model.Indices; foreach (var indexName in indexNames) { diff --git a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Recipes/ElasticIndexResetStep.cs b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Recipes/ElasticIndexResetStep.cs index 0501bdce407..ffc79ebde8e 100644 --- a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Recipes/ElasticIndexResetStep.cs +++ b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Recipes/ElasticIndexResetStep.cs @@ -14,7 +14,7 @@ namespace OrchardCore.Search.Elasticsearch.Core.Recipes /// /// This recipe step resets an Elasticsearch index. /// - public class ElasticIndexResetStep : IRecipeStepHandler + public sealed class ElasticIndexResetStep : IRecipeStepHandler { public async Task ExecuteAsync(RecipeExecutionContext context) { @@ -33,7 +33,9 @@ await HttpBackgroundJob.ExecuteAfterEndOfRequestAsync("elastic-index-reset", asy var elasticIndexSettingsService = scope.ServiceProvider.GetService(); var elasticIndexManager = scope.ServiceProvider.GetRequiredService(); - var indexNames = model.IncludeAll ? (await elasticIndexSettingsService.GetSettingsAsync()).Select(x => x.IndexName).ToArray() : model.Indices; + var indexNames = model.IncludeAll + ? (await elasticIndexSettingsService.GetSettingsAsync()).Select(x => x.IndexName).ToArray() + : model.Indices; foreach (var indexName in indexNames) { diff --git a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Recipes/ElasticIndexStep.cs b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Recipes/ElasticIndexStep.cs index fecfc4c96ce..2cbbb5fc556 100644 --- a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Recipes/ElasticIndexStep.cs +++ b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Recipes/ElasticIndexStep.cs @@ -13,7 +13,7 @@ namespace OrchardCore.Search.Elasticsearch.Core.Recipes /// /// This recipe step creates a Elasticsearch index. /// - public class ElasticIndexStep : IRecipeStepHandler + public sealed class ElasticIndexStep : IRecipeStepHandler { private readonly ElasticIndexingService _elasticIndexingService; private readonly ElasticIndexManager _elasticIndexManager; @@ -34,18 +34,19 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var indices = context.Step["Indices"]; - if (indices is JsonArray jsonArray) + if (context.Step["Indices"] is not JsonArray jsonArray) { - foreach (var index in jsonArray) - { - var elasticIndexSettings = index.ToObject>().FirstOrDefault(); + return; + } - if (!await _elasticIndexManager.ExistsAsync(elasticIndexSettings.Key)) - { - elasticIndexSettings.Value.IndexName = elasticIndexSettings.Key; - await _elasticIndexingService.CreateIndexAsync(elasticIndexSettings.Value); - } + foreach (var index in jsonArray) + { + var elasticIndexSettings = index.ToObject>().FirstOrDefault(); + + if (!await _elasticIndexManager.ExistsAsync(elasticIndexSettings.Key)) + { + elasticIndexSettings.Value.IndexName = elasticIndexSettings.Key; + await _elasticIndexingService.CreateIndexAsync(elasticIndexSettings.Value); } } } diff --git a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Recipes/ElasticSettingsStep.cs b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Recipes/ElasticSettingsStep.cs index a8fbae7c427..36b3c37ed72 100644 --- a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Recipes/ElasticSettingsStep.cs +++ b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Recipes/ElasticSettingsStep.cs @@ -9,7 +9,7 @@ namespace OrchardCore.Search.Elasticsearch.Core.Recipes /// /// This recipe step is used to sync Elasticsearch and Lucene settings. /// - public class ElasticSettingsStep : IRecipeStepHandler + public sealed class ElasticSettingsStep : IRecipeStepHandler { private readonly ElasticIndexingService _elasticIndexingService; diff --git a/src/docs/releases/2.0.0.md b/src/docs/releases/2.0.0.md index 0a3ad60c65c..a85e9a8865c 100644 --- a/src/docs/releases/2.0.0.md +++ b/src/docs/releases/2.0.0.md @@ -622,4 +622,11 @@ A new filter named `supported_cultures` was added to allow you to get a list of ### Sealing Types -Many configuration classes commonly used by modules can be `sealed`, which improves runtime performance. We've implemented this enhancement in [this pull request](https://github.com/OrchardCMS/OrchardCore/pull/16253) and [this one](https://github.com/OrchardCMS/OrchardCore/pull/16238). While it's not mandatory, we recommend that you consider applying this improvement to your own extensions as well. +Many type commonly used by modules can be `sealed`, which improves runtime performance. While it's not mandatory, we recommend that you consider applying this improvement to your own extensions as well. We've implemented this enhancement in the following pull-requests: + +- [16253](https://github.com/OrchardCMS/OrchardCore/pull/16253) +- [16238](https://github.com/OrchardCMS/OrchardCore/pull/16238) +- [16464](https://github.com/OrchardCMS/OrchardCore/pull/16464) + +!!! note + Do not seal classes that are used to create shapes like view-models. Sealing these classes can break your code at runtime, as these classes need to be unsealed to allow for proxy creation.