diff --git a/src/Umbraco.Cms.Api.Management/Controllers/PublishedCache/RebuildPublishedCacheController.cs b/src/Umbraco.Cms.Api.Management/Controllers/PublishedCache/RebuildPublishedCacheController.cs index 392c9338db..8f9cd490eb 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/PublishedCache/RebuildPublishedCacheController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/PublishedCache/RebuildPublishedCacheController.cs @@ -15,7 +15,7 @@ public class RebuildPublishedCacheController : PublishedCacheControllerBase [HttpPost("rebuild")] [MapToApiVersion("1.0")] [ProducesResponseType(StatusCodes.Status200OK)] - public async Task Rebuild(CancellationToken cancellationToken) + public Task Rebuild(CancellationToken cancellationToken) { if (_databaseCacheRebuilder.IsRebuilding()) { @@ -27,10 +27,10 @@ public class RebuildPublishedCacheController : PublishedCacheControllerBase Type = "Error", }; - return await Task.FromResult(Conflict(problemDetails)); + return Task.FromResult(Conflict(problemDetails)); } _databaseCacheRebuilder.Rebuild(true); - return await Task.FromResult(Ok()); + return Task.FromResult(Ok()); } } diff --git a/src/Umbraco.Core/Services/ContentTypeEditing/ContentTypeEditingServiceBase.cs b/src/Umbraco.Core/Services/ContentTypeEditing/ContentTypeEditingServiceBase.cs index fdf160ef4f..680d78d5ea 100644 --- a/src/Umbraco.Core/Services/ContentTypeEditing/ContentTypeEditingServiceBase.cs +++ b/src/Umbraco.Core/Services/ContentTypeEditing/ContentTypeEditingServiceBase.cs @@ -50,7 +50,7 @@ internal abstract class ContentTypeEditingServiceBase currentCompositeKeys.Contains(ct.Key)).Select(ct => ct.Alias).ToArray() - : Array.Empty(); + : []; ContentTypeAvailableCompositionsResults availableCompositions = _contentTypeService.GetAvailableCompositeContentTypes( contentType, @@ -142,9 +142,9 @@ internal abstract class ContentTypeEditingServiceBase(ContentTypeOperationStatus.Success, contentType); } - protected virtual async Task AdditionalCreateValidationAsync( + protected virtual Task AdditionalCreateValidationAsync( ContentTypeEditingModelBase model) - => await Task.FromResult(ContentTypeOperationStatus.Success); + => Task.FromResult(ContentTypeOperationStatus.Success); #region Sanitization @@ -346,7 +346,7 @@ internal abstract class ContentTypeEditingServiceBase model, IContentTypeComposition[] allContentTypeCompositions) + private static ContentTypeOperationStatus ValidateProperties(ContentTypeEditingModelBase model, IContentTypeComposition[] allContentTypeCompositions) { // grab all content types used for composition and/or inheritance Guid[] allCompositionKeys = KeysForCompositionTypes(model, CompositionType.Composition, CompositionType.Inheritance); @@ -365,7 +365,7 @@ internal abstract class ContentTypeEditingServiceBase model, IContentTypeComposition[] allContentTypeCompositions) + private static ContentTypeOperationStatus ValidateContainers(ContentTypeEditingModelBase model, IContentTypeComposition[] allContentTypeCompositions) { if (model.Containers.Any(container => Enum.TryParse(container.Type, out _) is false)) { @@ -420,7 +420,7 @@ internal abstract class ContentTypeEditingServiceBase model, IContentTypeComposition[] allContentTypeCompositions) @@ -573,7 +573,7 @@ internal abstract class ContentTypeEditingServiceBase model, IContentTypeComposition[] allContentTypeCompositions) @@ -658,7 +658,7 @@ internal abstract class ContentTypeEditingServiceBase model, IContentTypeComposition[] allContentTypeCompositions) @@ -677,7 +677,7 @@ internal abstract class ContentTypeEditingServiceBase model) + private static Guid[] GetDataTypeKeys(ContentTypeEditingModelBase model) => model.Properties.Select(property => property.DataTypeKey).Distinct().ToArray(); private async Task GetDataTypesAsync(ContentTypeEditingModelBase model) @@ -685,7 +685,7 @@ internal abstract class ContentTypeEditingServiceBase(); + : []; } private int? GetParentId(ContentTypeEditingModelBase model, Guid? containerKey) @@ -711,7 +711,7 @@ internal abstract class ContentTypeEditingServiceBase model, params CompositionType[] compositionTypes) + private static Guid[] KeysForCompositionTypes(ContentTypeEditingModelBase model, params CompositionType[] compositionTypes) => model.Compositions .Where(c => compositionTypes.Contains(c.CompositionType)) .Select(c => c.Key) diff --git a/src/Umbraco.Core/Services/ContentTypeEditing/ElementSwitchValidator.cs b/src/Umbraco.Core/Services/ContentTypeEditing/ElementSwitchValidator.cs index bf02fa6759..4d41e78b1e 100644 --- a/src/Umbraco.Core/Services/ContentTypeEditing/ElementSwitchValidator.cs +++ b/src/Umbraco.Core/Services/ContentTypeEditing/ElementSwitchValidator.cs @@ -20,27 +20,27 @@ public class ElementSwitchValidator : IElementSwitchValidator _dataTypeService = dataTypeService; } - public async Task AncestorsAreAlignedAsync(IContentType contentType) + public Task AncestorsAreAlignedAsync(IContentType contentType) { // this call does not return the system roots var ancestorIds = contentType.AncestorIds(); if (ancestorIds.Length == 0) { // if there are no ancestors, validation passes - return true; + return Task.FromResult(true); } // if there are any ancestors where IsElement is different from the contentType, the validation fails - return await Task.FromResult(_contentTypeService.GetMany(ancestorIds) + return Task.FromResult(_contentTypeService.GetMany(ancestorIds) .Any(ancestor => ancestor.IsElement != contentType.IsElement) is false); } - public async Task DescendantsAreAlignedAsync(IContentType contentType) + public Task DescendantsAreAlignedAsync(IContentType contentType) { IEnumerable descendants = _contentTypeService.GetDescendants(contentType.Id, false); // if there are any descendants where IsElement is different from the contentType, the validation fails - return await Task.FromResult(descendants.Any(descendant => descendant.IsElement != contentType.IsElement) is false); + return Task.FromResult(descendants.Any(descendant => descendant.IsElement != contentType.IsElement) is false); } public async Task ElementToDocumentNotUsedInBlockStructuresAsync(IContentTypeBase contentType) @@ -59,8 +59,8 @@ public class ElementSwitchValidator : IElementSwitchValidator .ConfiguredElementTypeKeys().Contains(contentType.Key)) is false; } - public async Task DocumentToElementHasNoContentAsync(IContentTypeBase contentType) => + public Task DocumentToElementHasNoContentAsync(IContentTypeBase contentType) => // if any content for the content type exists, the validation fails. - await Task.FromResult(_contentTypeService.HasContentNodes(contentType.Id) is false); + Task.FromResult(_contentTypeService.HasContentNodes(contentType.Id) is false); } diff --git a/src/Umbraco.Core/Services/DataTypeService.cs b/src/Umbraco.Core/Services/DataTypeService.cs index 83effe7400..8b1f7f953c 100644 --- a/src/Umbraco.Core/Services/DataTypeService.cs +++ b/src/Umbraco.Core/Services/DataTypeService.cs @@ -355,13 +355,13 @@ namespace Umbraco.Cms.Core.Services.Implement } /// - public async Task> GetByEditorAliasAsync(string[] propertyEditorAlias) + public Task> GetByEditorAliasAsync(string[] propertyEditorAlias) { using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true); IQuery query = Query().Where(x => propertyEditorAlias.Contains(x.EditorAlias)); IEnumerable dataTypes = _dataTypeRepository.Get(query).ToArray(); ConvertMissingEditorsOfDataTypesToLabels(dataTypes); - return await Task.FromResult(dataTypes); + return Task.FromResult(dataTypes); } /// @@ -396,7 +396,7 @@ namespace Umbraco.Cms.Core.Services.Implement return; } - ConvertMissingEditorsOfDataTypesToLabels(new[] { dataType }); + ConvertMissingEditorsOfDataTypesToLabels([dataType]); } private void ConvertMissingEditorsOfDataTypesToLabels(IEnumerable dataTypes) @@ -763,7 +763,7 @@ namespace Umbraco.Cms.Core.Services.Implement var totalItems = combinedUsages.Count; // Create the page of items. - IList<(string PropertyAlias, Udi Udi)> pagedUsages = combinedUsages + List<(string PropertyAlias, Udi Udi)> pagedUsages = combinedUsages .OrderBy(x => x.Udi.EntityType) // Document types first, then media types, then member types. .ThenBy(x => x.PropertyAlias) .Skip(skip) @@ -772,7 +772,7 @@ namespace Umbraco.Cms.Core.Services.Implement // Get the content types for the UDIs referenced in the page of items to construct the response from. // They could be document, media or member types. - IList contentTypes = GetReferencedContentTypes(pagedUsages); + List contentTypes = GetReferencedContentTypes(pagedUsages); IEnumerable relations = pagedUsages .Select(x => @@ -807,7 +807,7 @@ namespace Umbraco.Cms.Core.Services.Implement return Task.FromResult(pagedModel); } - private IList GetReferencedContentTypes(IList<(string PropertyAlias, Udi Udi)> pagedUsages) + private List GetReferencedContentTypes(List<(string PropertyAlias, Udi Udi)> pagedUsages) { IEnumerable documentTypes = GetContentTypes( pagedUsages, @@ -845,10 +845,10 @@ namespace Umbraco.Cms.Core.Services.Implement { IConfigurationEditor? configurationEditor = dataType.Editor?.GetConfigurationEditor(); return configurationEditor == null - ? new[] - { + ? + [ new ValidationResult($"Data type with editor alias {dataType.EditorAlias} does not have a configuration editor") - } + ] : configurationEditor.Validate(dataType.ConfigurationData); } diff --git a/src/Umbraco.Core/Services/EntityTypeContainerService.cs b/src/Umbraco.Core/Services/EntityTypeContainerService.cs index 4a403e0c1f..575ff11f2e 100644 --- a/src/Umbraco.Core/Services/EntityTypeContainerService.cs +++ b/src/Umbraco.Core/Services/EntityTypeContainerService.cs @@ -52,18 +52,18 @@ internal abstract class EntityTypeContainerService - public async Task> GetAsync(string name, int level) + public Task> GetAsync(string name, int level) { using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true); ReadLock(scope); - return await Task.FromResult(_entityContainerRepository.Get(name, level)); + return Task.FromResult(_entityContainerRepository.Get(name, level)); } /// - public async Task> GetAllAsync() + public Task> GetAllAsync() { using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true); ReadLock(scope); - return await Task.FromResult(_entityContainerRepository.GetMany()); + return Task.FromResult(_entityContainerRepository.GetMany()); } /// diff --git a/src/Umbraco.Core/Services/Querying/ContentQueryService.cs b/src/Umbraco.Core/Services/Querying/ContentQueryService.cs index 241236f550..22c4eb40df 100644 --- a/src/Umbraco.Core/Services/Querying/ContentQueryService.cs +++ b/src/Umbraco.Core/Services/Querying/ContentQueryService.cs @@ -23,23 +23,23 @@ public class ContentQueryService : IContentQueryService _coreScopeProvider = coreScopeProvider; } - public async Task> GetWithSchedulesAsync(Guid id) + public Task> GetWithSchedulesAsync(Guid id) { using ICoreScope scope = _coreScopeProvider.CreateCoreScope(autoComplete: true); - IContent? content = await Task.FromResult(_contentService.GetById(id)); + IContent? content = _contentService.GetById(id); if (content == null) { - return Attempt.Fail(ContentQueryOperationStatus - .ContentNotFound); + return Task.FromResult(Attempt.Fail(ContentQueryOperationStatus + .ContentNotFound)); } ContentScheduleCollection schedules = _contentService.GetContentScheduleByContentId(id); - return Attempt + return Task.FromResult(Attempt .Succeed( ContentQueryOperationStatus.Success, - new ContentScheduleQueryResult(content, schedules)); + new ContentScheduleQueryResult(content, schedules))); } } diff --git a/src/Umbraco.Core/Services/RelationService.cs b/src/Umbraco.Core/Services/RelationService.cs index 7dfcb4ae2f..456a3bb8dc 100644 --- a/src/Umbraco.Core/Services/RelationService.cs +++ b/src/Umbraco.Core/Services/RelationService.cs @@ -220,7 +220,7 @@ public class RelationService : RepositoryService, IRelationService } return relationTypeIds.Count == 0 - ? Enumerable.Empty() + ? [] : GetRelationsByListOfTypeIds(relationTypeIds); } @@ -230,8 +230,8 @@ public class RelationService : RepositoryService, IRelationService IRelationType? relationType = GetRelationType(relationTypeAlias); return relationType == null - ? Enumerable.Empty() - : GetRelationsByListOfTypeIds(new[] { relationType.Id }); + ? [] + : GetRelationsByListOfTypeIds([relationType.Id]); } /// @@ -594,7 +594,7 @@ public class RelationService : RepositoryService, IRelationService EventMessages eventMessages = EventMessagesFactory.Get(); var savingNotification = new RelationTypeSavingNotification(relationType, eventMessages); - if (scope.Notifications.PublishCancelable(savingNotification)) + if (await scope.Notifications.PublishCancelableAsync(savingNotification)) { scope.Complete(); return Attempt.FailWithStatus(RelationTypeOperationStatus.CancelledByNotification, relationType); @@ -659,7 +659,7 @@ public class RelationService : RepositoryService, IRelationService EventMessages eventMessages = EventMessagesFactory.Get(); var deletingNotification = new RelationTypeDeletingNotification(relationType, eventMessages); - if (scope.Notifications.PublishCancelable(deletingNotification)) + if (await scope.Notifications.PublishCancelableAsync(deletingNotification)) { scope.Complete(); return Attempt.FailWithStatus(RelationTypeOperationStatus.CancelledByNotification, null); @@ -670,7 +670,7 @@ public class RelationService : RepositoryService, IRelationService Audit(AuditType.Delete, currentUser, relationType.Id, "Deleted relation type"); scope.Notifications.Publish(new RelationTypeDeletedNotification(relationType, eventMessages).WithStateFrom(deletingNotification)); scope.Complete(); - return await Task.FromResult(Attempt.SucceedWithStatus(RelationTypeOperationStatus.Success, relationType)); + return Attempt.SucceedWithStatus(RelationTypeOperationStatus.Success, relationType); } /// @@ -726,7 +726,7 @@ public class RelationService : RepositoryService, IRelationService return _relationTypeRepository.Get(query).FirstOrDefault(); } - private IEnumerable GetRelationsByListOfTypeIds(IEnumerable relationTypeIds) + private List GetRelationsByListOfTypeIds(IEnumerable relationTypeIds) { var relations = new List(); using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) diff --git a/src/Umbraco.Core/Strings/Diff.cs b/src/Umbraco.Core/Strings/Diff.cs index e8a3fdf84c..e8a5cc1324 100644 --- a/src/Umbraco.Core/Strings/Diff.cs +++ b/src/Umbraco.Core/Strings/Diff.cs @@ -13,7 +13,7 @@ namespace Umbraco.Cms.Core.Strings; /// Copyright (c) by Matthias Hertel, http://www.mathertel.de /// This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx /// -internal class Diff +internal sealed class Diff { /// /// Find the difference in 2 texts, comparing by text lines.