Browse Source

Improve code styles.

pull/898/head
Sebastian 3 years ago
parent
commit
4c4a47c305
  1. 2
      backend/extensions/Squidex.Extensions/APM/Otlp/OtlpPlugin.cs
  2. 8
      backend/extensions/Squidex.Extensions/Actions/Comment/CommentActionHandler.cs
  3. 2
      backend/extensions/Squidex.Extensions/Actions/CreateContent/CreateContentActionHandler.cs
  4. 8
      backend/extensions/Squidex.Extensions/Actions/Notification/NotificationActionHandler.cs
  5. 4
      backend/extensions/Squidex.Extensions/Actions/RuleHelper.cs
  6. 2
      backend/extensions/Squidex.Extensions/Assets/Azure/AzureMetadataSource.cs
  7. 6
      backend/extensions/Squidex.Extensions/Text/Azure/AzureIndexDefinition.cs
  8. 2
      backend/extensions/Squidex.Extensions/Text/Azure/CommandFactory.cs
  9. 2
      backend/extensions/Squidex.Extensions/Text/ElasticSearch/ElasticSearchTextIndex.cs
  10. 5
      backend/extensions/Squidex.Extensions/Validation/CompositeUniqueValidator.cs
  11. 4
      backend/src/Migrations/OldEvents/AppPatternUpdated.cs
  12. 2
      backend/src/Migrations/OldEvents/NoopEvent.cs
  13. 4
      backend/src/Squidex.Domain.Apps.Core.Model/Apps/Editor.cs
  14. 9
      backend/src/Squidex.Domain.Apps.Core.Model/Schemas/ComponentFieldProperties.cs
  15. 9
      backend/src/Squidex.Domain.Apps.Core.Model/Schemas/ComponentsFieldProperties.cs
  16. 2
      backend/src/Squidex.Domain.Apps.Core.Model/Schemas/FieldExtensions.cs
  17. 2
      backend/src/Squidex.Domain.Apps.Core.Operations/EventSynchronization/SchemaSynchronizer.cs
  18. 6
      backend/src/Squidex.Domain.Apps.Core.Operations/ExtractReferenceIds/ContentReferencesExtensions.cs
  19. 7
      backend/src/Squidex.Domain.Apps.Core.Operations/ExtractReferenceIds/ReferencesExtractor.cs
  20. 2
      backend/src/Squidex.Domain.Apps.Core.Operations/GenerateFilters/ContentQueryModel.cs
  21. 2
      backend/src/Squidex.Domain.Apps.Core.Operations/HandleRules/Result.cs
  22. 6
      backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/Extensions/StringJintExtension.cs
  23. 2
      backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ScriptExecutionContext.cs
  24. 2
      backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ScriptScope.cs
  25. 4
      backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ScriptingValue.cs
  26. 13
      backend/src/Squidex.Domain.Apps.Core.Operations/ValidateContent/ValidationContext.cs
  27. 4
      backend/src/Squidex.Domain.Apps.Core.Operations/ValidateContent/Validators/AssetsValidator.cs
  28. 2
      backend/src/Squidex.Domain.Apps.Core.Operations/ValidateContent/Validators/CollectionValidator.cs
  29. 5
      backend/src/Squidex.Domain.Apps.Core.Operations/ValidateContent/Validators/ComponentValidator.cs
  30. 4
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/AdaptIdVisitor.cs
  31. 2
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs
  32. 4
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentCollection.cs
  33. 7
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryByQuery.cs
  34. 2
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Text/AtlasTextIndex.cs
  35. 6
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Text/LuceneQueryVisitor.cs
  36. 3
      backend/src/Squidex.Domain.Apps.Entities/Apps/BackupApps.cs
  37. 4
      backend/src/Squidex.Domain.Apps.Entities/Apps/DomainObject/AppDomainObject.cs
  38. 6
      backend/src/Squidex.Domain.Apps.Entities/Apps/DomainObject/Guards/GuardAppClients.cs
  39. 2
      backend/src/Squidex.Domain.Apps.Entities/Apps/Indexes/AppsIndex.cs
  40. 4
      backend/src/Squidex.Domain.Apps.Entities/Apps/RolePermissionsProvider.cs
  41. 4
      backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/Template.cs
  42. 1
      backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/TemplateCommandMiddleware.cs
  43. 2
      backend/src/Squidex.Domain.Apps.Entities/Assets/AssetChangedTriggerHandler.cs
  44. 4
      backend/src/Squidex.Domain.Apps.Entities/Assets/AssetDuplicate.cs
  45. 7
      backend/src/Squidex.Domain.Apps.Entities/Assets/AssetStats.cs
  46. 4
      backend/src/Squidex.Domain.Apps.Entities/Assets/BackupAssets.cs
  47. 2
      backend/src/Squidex.Domain.Apps.Entities/Assets/DomainObject/AssetCommandMiddleware.cs
  48. 2
      backend/src/Squidex.Domain.Apps.Entities/Assets/DomainObject/AssetDomainObject.cs
  49. 2
      backend/src/Squidex.Domain.Apps.Entities/Assets/DomainObject/AssetsBulkUpdateCommandMiddleware.cs
  50. 4
      backend/src/Squidex.Domain.Apps.Entities/Assets/ImageAssetMetadataSource.cs
  51. 2
      backend/src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetLoader.cs
  52. 4
      backend/src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetQueryParser.cs
  53. 4
      backend/src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetQueryService.cs
  54. 8
      backend/src/Squidex.Domain.Apps.Entities/Backup/BackupProcessor.cs
  55. 1
      backend/src/Squidex.Domain.Apps.Entities/Backup/BackupWorker.cs
  56. 4
      backend/src/Squidex.Domain.Apps.Entities/Backup/RestoreProcessor.cs
  57. 5
      backend/src/Squidex.Domain.Apps.Entities/Comments/DomainObject/CommentsStream.cs
  58. 14
      backend/src/Squidex.Domain.Apps.Entities/Contents/ContentChangedTriggerHandler.cs
  59. 4
      backend/src/Squidex.Domain.Apps.Entities/Contents/Counter/CounterJintExtension.cs
  60. 2
      backend/src/Squidex.Domain.Apps.Entities/Contents/DomainObject/ContentCommandMiddleware.cs
  61. 4
      backend/src/Squidex.Domain.Apps.Entities/Contents/DomainObject/ContentDomainObject.cs
  62. 4
      backend/src/Squidex.Domain.Apps.Entities/Contents/DomainObject/ContentsBulkUpdateCommandMiddleware.cs
  63. 2
      backend/src/Squidex.Domain.Apps.Entities/Contents/DomainObject/Guards/ScriptingExtensions.cs
  64. 2
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/DataInputGraphType.cs
  65. 2
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/FieldVisitor.cs
  66. 2
      backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentLoader.cs
  67. 4
      backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentQueryParser.cs
  68. 6
      backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentQueryService.cs
  69. 4
      backend/src/Squidex.Domain.Apps.Entities/Contents/Text/GeoQuery.cs
  70. 3
      backend/src/Squidex.Domain.Apps.Entities/Contents/Text/QueryParser.cs
  71. 4
      backend/src/Squidex.Domain.Apps.Entities/History/NotifoService.cs
  72. 4
      backend/src/Squidex.Domain.Apps.Entities/Rules/DomainObject/Guards/RuleTriggerValidator.cs
  73. 2
      backend/src/Squidex.Domain.Apps.Entities/Rules/Indexes/RulesIndex.cs
  74. 2
      backend/src/Squidex.Domain.Apps.Entities/Rules/RuleCommandMiddleware.cs
  75. 4
      backend/src/Squidex.Domain.Apps.Entities/Rules/UsageTracking/UsageTrackerCommandMiddleware.cs
  76. 6
      backend/src/Squidex.Domain.Apps.Entities/Schemas/DomainObject/Guards/FieldPropertiesValidator.cs
  77. 4
      backend/src/Squidex.Domain.Apps.Entities/Schemas/Indexes/SchemasIndex.cs
  78. 4
      backend/src/Squidex.Domain.Users.MongoDb/MongoUser.cs
  79. 20
      backend/src/Squidex.Domain.Users/DefaultUserService.cs
  80. 2
      backend/src/Squidex.Infrastructure.GetEventStore/EventSourcing/GetEventStore.cs
  81. 2
      backend/src/Squidex.Infrastructure.MongoDb/Migrations/MongoMigrationStatus.cs
  82. 4
      backend/src/Squidex.Infrastructure.MongoDb/MongoDb/BsonJsonReader.cs
  83. 3
      backend/src/Squidex.Infrastructure.MongoDb/MongoDb/DomainIdSerializer.cs
  84. 2
      backend/src/Squidex.Infrastructure.MongoDb/UsageTracking/MongoUsageRepository.cs
  85. 2
      backend/src/Squidex.Infrastructure/Collections/ReadonlyDictionary.cs
  86. 2
      backend/src/Squidex.Infrastructure/Collections/ReadonlyList.cs
  87. 2
      backend/src/Squidex.Infrastructure/Commands/DefaultDomainObjectCache.cs
  88. 4
      backend/src/Squidex.Infrastructure/Commands/DomainObject.cs
  89. 2
      backend/src/Squidex.Infrastructure/Commands/IMigratedStateEvent.cs
  90. 8
      backend/src/Squidex.Infrastructure/DisposableObjectBase.cs
  91. 2
      backend/src/Squidex.Infrastructure/EventSourcing/Consume/BatchSubscriber.cs
  92. 4
      backend/src/Squidex.Infrastructure/EventSourcing/StoredEvent.cs
  93. 2
      backend/src/Squidex.Infrastructure/Guard.cs
  94. 2
      backend/src/Squidex.Infrastructure/IWithId.cs
  95. 10
      backend/src/Squidex.Infrastructure/Json/Objects/JsonValue.cs
  96. 2
      backend/src/Squidex.Infrastructure/States/BatchContext.cs
  97. 2
      backend/src/Squidex.Infrastructure/States/BatchPersistence.cs
  98. 4
      backend/src/Squidex.Infrastructure/Tasks/PartitionedActionBlock.cs
  99. 7
      backend/src/Squidex.Infrastructure/UsageTracking/ApiStats.cs
  100. 4
      backend/src/Squidex.Infrastructure/UsageTracking/ApiStatsSummary.cs

2
backend/extensions/Squidex.Extensions/APM/Otlp/OtlpPlugin.cs

@ -11,7 +11,7 @@ using OpenTelemetry.Trace;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Plugins;
namespace Squidex.Extensions.APM.Datadog
namespace Squidex.Extensions.APM.Otlp
{
public sealed class OtlpPlugin : IPlugin
{

8
backend/extensions/Squidex.Extensions/Actions/Comment/CommentActionHandler.cs

@ -55,18 +55,18 @@ namespace Squidex.Extensions.Actions.Comment
protected override async Task<Result> ExecuteJobAsync(CreateComment job,
CancellationToken ct = default)
{
if (job.CommentsId == default)
var command = job;
if (command.CommentsId == default)
{
return Result.Ignored();
}
var command = job;
command.FromRule = true;
await commandBus.PublishAsync(command, ct);
return Result.Success($"Commented: {job.Text}");
return Result.Success($"Commented: {command.Text}");
}
}
}

2
backend/extensions/Squidex.Extensions/Actions/CreateContent/CreateContentActionHandler.cs

@ -78,7 +78,7 @@ namespace Squidex.Extensions.Actions.CreateContent
await commandBus.PublishAsync(command, ct);
return Result.Success($"Created to: {job.SchemaId.Name}");
return Result.Success($"Created to: {command.SchemaId.Name}");
}
}
}

8
backend/extensions/Squidex.Extensions/Actions/Notification/NotificationActionHandler.cs

@ -74,19 +74,19 @@ namespace Squidex.Extensions.Actions.Notification
protected override async Task<Result> ExecuteJobAsync(CreateComment job,
CancellationToken ct = default)
{
if (job.CommentsId == default)
var command = job;
if (command.CommentsId == default)
{
return Result.Ignored();
}
var command = job;
command.AppId = NoApp;
command.FromRule = true;
await commandBus.PublishAsync(command, ct);
return Result.Success($"Notified: {job.Text}");
return Result.Success($"Notified: {command.Text}");
}
}
}

4
backend/extensions/Squidex.Extensions/Actions/RuleHelper.cs

@ -32,9 +32,7 @@ namespace Squidex.Extensions.Actions
public static bool IsContentDeletion(this EnrichedEvent @event)
{
return @event is EnrichedContentEvent contentEvent &&
(contentEvent.Type == EnrichedContentEventType.Deleted ||
contentEvent.Type == EnrichedContentEventType.Unpublished);
return @event is EnrichedContentEvent { Type: EnrichedContentEventType.Deleted or EnrichedContentEventType.Unpublished };
}
public static bool IsAssetDeletion(this EnrichedEvent @event)

2
backend/extensions/Squidex.Extensions/Assets/Azure/AzureMetadataSource.cs

@ -73,7 +73,7 @@ namespace Squidex.Extensions.Assets.Azure
}
}
var description = result.Description?.Captions?.OrderByDescending(x => x.Confidence)?.FirstOrDefault()?.Text;
var description = result.Description?.Captions.MaxBy(x => x.Confidence)?.Text;
if (description != null)
{

6
backend/extensions/Squidex.Extensions/Text/Azure/AzureIndexDefinition.cs

@ -36,7 +36,7 @@ namespace Squidex.Extensions.Text.Azure
if (indexOfDot > 0)
{
var language = analyzer[0..indexOfDot];
var language = analyzer[..indexOfDot];
var isValidLanguage =
language.Length == 2 ||
@ -78,11 +78,11 @@ namespace Squidex.Extensions.Text.Azure
{
new SimpleField("docId", SearchFieldDataType.String)
{
IsKey = true,
IsKey = true
},
new SimpleField("appId", SearchFieldDataType.String)
{
IsFilterable = true,
IsFilterable = true
},
new SimpleField("appName", SearchFieldDataType.String)
{

2
backend/extensions/Squidex.Extensions/Text/Azure/CommandFactory.cs

@ -96,7 +96,7 @@ namespace Squidex.Extensions.Text.Azure
{
["docId"] = update.DocId.ToBase64(),
["serveAll"] = update.ServeAll,
["servePublished"] = update.ServePublished,
["servePublished"] = update.ServePublished
};
batch.Add(IndexDocumentsAction.MergeOrUpload(document));

2
backend/extensions/Squidex.Extensions/Text/ElasticSearch/ElasticSearchTextIndex.cs

@ -117,7 +117,7 @@ namespace Squidex.Extensions.Text.ElasticSearch
distance = $"{query.Radius}m"
}
}
},
}
}
},
_source = new[]

5
backend/extensions/Squidex.Extensions/Validation/CompositeUniqueValidator.cs

@ -107,10 +107,7 @@ namespace Squidex.Extensions.Validation
return
field.Partitioning == Partitioning.Invariant &&
field.RawProperties.Tags?.Contains(tag) == true &&
(field.RawProperties is BooleanFieldProperties ||
field.RawProperties is NumberFieldProperties ||
field.RawProperties is ReferencesFieldProperties ||
field.RawProperties is StringFieldProperties);
field.RawProperties is BooleanFieldProperties or NumberFieldProperties or ReferencesFieldProperties or StringFieldProperties;
}
}
}

4
backend/src/Migrations/OldEvents/AppPatternUpdated.cs

@ -33,13 +33,13 @@ namespace Migrations.OldEvents
{
var newSettings = new AppSettings
{
Patterns = ReadonlyList.ToReadonlyList(new List<Pattern>(state.Settings.Patterns.Where(x => x.Name != Name || x.Regex != Pattern))
Patterns = new List<Pattern>(state.Settings.Patterns.Where(x => x.Name != Name || x.Regex != Pattern))
{
new Pattern(Name, Pattern)
{
Message = Message
}
}),
}.ToReadonlyList(),
Editors = state.Settings.Editors
};

2
backend/src/Migrations/OldEvents/NoopEvent.cs

@ -8,7 +8,7 @@
using Squidex.Domain.Apps.Events;
using Squidex.Infrastructure.Reflection;
namespace Squidex.Infrastructure.EventSourcing
namespace Migrations.OldEvents
{
[TypeName(nameof(NoopEvent))]
public sealed class NoopEvent : SquidexEvent

4
backend/src/Squidex.Domain.Apps.Core.Model/Apps/Editor.cs

@ -9,7 +9,5 @@
namespace Squidex.Domain.Apps.Core.Apps
{
public sealed record Editor(string Name, string Url)
{
}
public sealed record Editor(string Name, string Url);
}

9
backend/src/Squidex.Domain.Apps.Core.Model/Schemas/ComponentFieldProperties.cs

@ -16,14 +16,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
init
{
if (value != default)
{
SchemaIds = ReadonlyList.Create(value);
}
else
{
SchemaIds = null;
}
SchemaIds = value != default ? ReadonlyList.Create(value) : null;
}
get
{

9
backend/src/Squidex.Domain.Apps.Core.Model/Schemas/ComponentsFieldProperties.cs

@ -22,14 +22,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
init
{
if (value != default)
{
SchemaIds = ReadonlyList.Create(value);
}
else
{
SchemaIds = null;
}
SchemaIds = value != default ? ReadonlyList.Create(value) : null;
}
get
{

2
backend/src/Squidex.Domain.Apps.Core.Model/Schemas/FieldExtensions.cs

@ -29,7 +29,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
public static bool IsComponentLike<T>(this T field) where T : IField
{
return field.RawProperties is ComponentFieldProperties || field.RawProperties is ComponentsFieldProperties;
return field.RawProperties is ComponentFieldProperties or ComponentsFieldProperties;
}
public static bool IsUI<T>(this T field) where T : IField

2
backend/src/Squidex.Domain.Apps.Core.Operations/EventSynchronization/SchemaSynchronizer.cs

@ -175,7 +175,7 @@ namespace Squidex.Domain.Apps.Core.EventSynchronization
new FieldEnabled { FieldId = id };
}
if ((sourceField == null || sourceField is IArrayField) && targetField is IArrayField targetArrayField)
if (sourceField is null or IArrayField && targetField is IArrayField targetArrayField)
{
var fields = (sourceField as IArrayField)?.FieldCollection ?? FieldCollection<NestedField>.Empty;

6
backend/src/Squidex.Domain.Apps.Core.Operations/ExtractReferenceIds/ContentReferencesExtensions.cs

@ -22,7 +22,7 @@ namespace Squidex.Domain.Apps.Core.ExtractReferenceIds
return false;
}
static bool CanHaveReference(JsonValue value)
static bool CanValueHaveReference(JsonValue value)
{
if (value.Value is JsonArray)
{
@ -33,7 +33,7 @@ namespace Squidex.Domain.Apps.Core.ExtractReferenceIds
{
foreach (var (_, nested) in o)
{
if (CanHaveReference(nested))
if (CanValueHaveReference(nested))
{
return true;
}
@ -49,7 +49,7 @@ namespace Squidex.Domain.Apps.Core.ExtractReferenceIds
{
foreach (var (_, value) in field)
{
if (CanHaveReference(value))
if (CanValueHaveReference(value))
{
return true;
}

7
backend/src/Squidex.Domain.Apps.Core.Operations/ExtractReferenceIds/ReferencesExtractor.cs

@ -126,12 +126,7 @@ namespace Squidex.Domain.Apps.Core.ExtractReferenceIds
private static bool CanHaveReferences(FieldProperties properties)
{
return
properties is ArrayFieldProperties ||
properties is ReferencesFieldProperties ||
properties is AssetsFieldProperties ||
properties is ComponentFieldProperties ||
properties is ComponentsFieldProperties;
return properties is ArrayFieldProperties or ReferencesFieldProperties or AssetsFieldProperties or ComponentFieldProperties or ComponentsFieldProperties;
}
private static void AddIds(ref Args args)

2
backend/src/Squidex.Domain.Apps.Core.Operations/GenerateFilters/ContentQueryModel.cs

@ -47,7 +47,7 @@ namespace Squidex.Domain.Apps.Core.GenerateFilters
},
new FilterField(SharedSchemas.Status, "status")
{
Description = FieldDescriptions.ContentStatus,
Description = FieldDescriptions.ContentStatus
},
new FilterField(SharedSchemas.Status, "newStatus", IsNullable: true)
{

2
backend/src/Squidex.Domain.Apps.Core.Operations/HandleRules/Result.cs

@ -88,7 +88,7 @@ namespace Squidex.Domain.Apps.Core.HandleRules
{
var result = new Result { Exception = ex, Dump = dump ?? ex?.Message };
if (ex is OperationCanceledException || ex is TimeoutException)
if (ex is OperationCanceledException or TimeoutException)
{
result.Status = RuleResult.Timeout;
}

6
backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/Extensions/StringJintExtension.cs

@ -17,7 +17,7 @@ namespace Squidex.Domain.Apps.Core.Scripting.Extensions
{
private delegate JsValue StringSlugifyDelegate(string text, bool single = false);
private readonly Func<string, JsValue> sha256 = (text) =>
private readonly Func<string, JsValue> sha256 = text =>
{
try
{
@ -29,7 +29,7 @@ namespace Squidex.Domain.Apps.Core.Scripting.Extensions
}
};
private readonly Func<string, JsValue> sha512 = (text) =>
private readonly Func<string, JsValue> sha512 = text =>
{
try
{
@ -41,7 +41,7 @@ namespace Squidex.Domain.Apps.Core.Scripting.Extensions
}
};
private readonly Func<string, JsValue> md5 = (text) =>
private readonly Func<string, JsValue> md5 = text =>
{
try
{

2
backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ScriptExecutionContext.cs

@ -40,7 +40,7 @@ namespace Squidex.Domain.Apps.Core.Scripting
public bool IsCompleted
{
get => tcs.Task.Status == TaskStatus.RanToCompletion || tcs.Task.Status == TaskStatus.Faulted;
get => tcs.Task.Status is TaskStatus.RanToCompletion or TaskStatus.Faulted;
}
internal ScriptExecutionContext(Engine engine, CancellationToken cancellationToken)

2
backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ScriptScope.cs

@ -19,6 +19,6 @@ namespace Squidex.Domain.Apps.Core.Scripting
ContentTrigger = 32,
SchemaTrigger = 128,
Transform = 256,
UsageTrigger = 512,
UsageTrigger = 512
}
}

4
backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ScriptingValue.cs

@ -9,7 +9,5 @@
namespace Squidex.Domain.Apps.Core.Scripting
{
public sealed record ScriptingValue(string Path, JsonType Type, string? Description)
{
}
public sealed record ScriptingValue(string Path, JsonType Type, string? Description);
}

13
backend/src/Squidex.Domain.Apps.Core.Operations/ValidateContent/ValidationContext.cs

@ -7,25 +7,20 @@
using System.Collections.Immutable;
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
namespace Squidex.Domain.Apps.Core.ValidateContent
{
public sealed record ValidationContext
public sealed record ValidationContext(RootContext Root)
{
public ImmutableQueue<string> Path { get; private set; } = ImmutableQueue<string>.Empty;
public ImmutableQueue<string> Path { get; init; } = ImmutableQueue<string>.Empty;
public bool IsOptional { get; init; }
public RootContext Root { get; }
public ValidationMode Mode { get; init; }
public ValidationAction Action { get; init; }
public ValidationContext(RootContext rootContext)
{
Root = rootContext;
}
public void AddError(IEnumerable<string> path, string message)
{
Root.AddError(path, message);

4
backend/src/Squidex.Domain.Apps.Core.Operations/ValidateContent/Validators/AssetsValidator.cs

@ -130,9 +130,7 @@ namespace Squidex.Domain.Apps.Core.ValidateContent.Validators
context.AddError(path, T.Get("contents.validation.maximumSize", new { size = asset.FileSize.ToReadableSize(), max }));
}
if (properties.AllowedExtensions != null &&
properties.AllowedExtensions.Count > 0 &&
!properties.AllowedExtensions.Any(x => asset.FileName.EndsWith("." + x, StringComparison.OrdinalIgnoreCase)))
if (properties.AllowedExtensions is { Count: > 0 } && !properties.AllowedExtensions.Any(x => asset.FileName.EndsWith("." + x, StringComparison.OrdinalIgnoreCase)))
{
context.AddError(path, T.Get("contents.validation.extension"));
}

2
backend/src/Squidex.Domain.Apps.Core.Operations/ValidateContent/Validators/CollectionValidator.cs

@ -19,7 +19,7 @@ namespace Squidex.Domain.Apps.Core.ValidateContent.Validators
public CollectionValidator(bool isRequired, int? minItems = null, int? maxItems = null)
{
if (minItems != null && minItems > maxItems)
if (minItems > maxItems)
{
ThrowHelper.ArgumentException("Min length must be greater than max length.", nameof(minItems));
}

5
backend/src/Squidex.Domain.Apps.Core.Operations/ValidateContent/Validators/ComponentValidator.cs

@ -25,10 +25,7 @@ namespace Squidex.Domain.Apps.Core.ValidateContent.Validators
{
var validator = validatorFactory(component.Schema);
if (validator != null)
{
validator.Validate(component.Data, context);
}
validator?.Validate(component.Data, context);
}
}
}

4
backend/src/Squidex.Domain.Apps.Entities.MongoDb/AdaptIdVisitor.cs

@ -32,8 +32,6 @@ namespace Squidex.Domain.Apps.Entities.MongoDb
public override FilterNode<ClrValue> Visit(CompareFilter<ClrValue> nodeIn, Args args)
{
var result = nodeIn;
var (path, _, value) = nodeIn;
var clrValue = value.Value;
@ -77,7 +75,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb
}
}
return result with { Path = path, Value = value };
return nodeIn with { Path = path, Value = value };
}
}
}

2
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs

@ -89,7 +89,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets
{
try
{
if (q.Ids != null && q.Ids.Count > 0)
if (q.Ids is { Count: > 0 })
{
var filter = BuildFilter(appId, q.Ids.ToHashSet());

4
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentCollection.cs

@ -119,7 +119,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
{
using (Telemetry.Activities.StartActivity("MongoContentCollection/QueryAsync"))
{
if (q.Ids != null && q.Ids.Count > 0)
if (q.Ids is { Count: > 0 })
{
return await queryByIds.QueryAsync(app.Id, schemas, q, ct);
}
@ -148,7 +148,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
{
using (Telemetry.Activities.StartActivity("MongoContentCollection/QueryAsync"))
{
if (q.Ids != null && q.Ids.Count > 0)
if (q.Ids is { Count: > 0 })
{
return await queryByIds.QueryAsync(app.Id, new List<ISchemaEntity> { schema }, q, ct);
}

7
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryByQuery.cs

@ -216,12 +216,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations
private static bool IsSatisfiedByIndex(ClrQuery query)
{
return query.Sort != null &&
query.Sort.Count == 2 &&
query.Sort[0].Path.ToString() == "mt" &&
query.Sort[0].Order == SortOrder.Descending &&
query.Sort[1].Path.ToString() == "id" &&
query.Sort[1].Order == SortOrder.Ascending;
return query.Sort is { Count: 2 } && query.Sort[0].Path.ToString() == "mt" && query.Sort[0].Order == SortOrder.Descending && query.Sort[1].Path.ToString() == "id" && query.Sort[1].Order == SortOrder.Ascending;
}
private static FilterDefinition<MongoContentEntity> BuildFilter(DomainId appId, DomainId schemaId, FilterNode<ClrValue>? filter)

2
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Text/AtlasTextIndex.cs

@ -139,7 +139,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Text
var searchQuery = new BsonDocument
{
["compound"] = compound,
["compound"] = compound
};
if (index != null)

6
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Text/LuceneQueryVisitor.cs

@ -111,7 +111,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Text
{
var fuzzy = new BsonDocument
{
["maxEdits"] = fuzzyQuery.MaxEdits,
["maxEdits"] = fuzzyQuery.MaxEdits
};
if (fuzzyQuery.PrefixLength > 0)
@ -154,7 +154,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Text
var doc = new BsonDocument
{
["path"] = GetPath(terms[0].Field),
["path"] = GetPath(terms[0].Field)
};
if (terms.Length == 1)
@ -304,7 +304,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Text
if (number == integer)
{
if (integer <= int.MaxValue && integer >= int.MinValue)
if (integer is <= int.MaxValue and >= int.MinValue)
{
result = (int)integer;
}

3
backend/src/Squidex.Domain.Apps.Entities/Apps/BackupApps.cs

@ -25,7 +25,6 @@ namespace Squidex.Domain.Apps.Entities.Apps
private readonly IAppImageStore appImageStore;
private readonly IAppsIndex appsIndex;
private readonly IAppUISettings appUISettings;
private readonly HashSet<string> contributors = new HashSet<string>();
private string? appReservation;
public string Name { get; } = "Apps";
@ -91,7 +90,6 @@ namespace Squidex.Domain.Apps.Entities.Apps
}
contributorAssigned.ContributorId = user.Identifier;
contributors.Add(contributorAssigned.ContributorId);
break;
}
@ -103,7 +101,6 @@ namespace Squidex.Domain.Apps.Entities.Apps
}
contributorRemoved.ContributorId = user.Identifier;
contributors.Remove(contributorRemoved.ContributorId);
break;
}
}

4
backend/src/Squidex.Domain.Apps.Entities/Apps/DomainObject/AppDomainObject.cs

@ -268,7 +268,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject
}
else
{
var result = await AppPlanBillingManager().ChangePlanAsync(c.Actor.Identifier, Snapshot.NamedId(), c.PlanId, c.Referer);
var result = await AppPlanBillingManager().ChangePlanAsync(c.Actor.Identifier, Snapshot.NamedId(), c.PlanId, c.Referer, default);
switch (result)
{
@ -284,7 +284,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject
case DeleteApp delete:
return UpdateAsync(delete, async (c, ct) =>
{
await AppPlanBillingManager().ChangePlanAsync(c.Actor.Identifier, Snapshot.NamedId(), null, null);
await AppPlanBillingManager().ChangePlanAsync(c.Actor.Identifier, Snapshot.NamedId(), null, null, ct);
DeleteApp(c);
}, ct);

6
backend/src/Squidex.Domain.Apps.Entities/Apps/DomainObject/Guards/GuardAppClients.cs

@ -1,4 +1,4 @@
// ==========================================================================
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
@ -67,12 +67,12 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject.Guards
e(Not.Valid(nameof(command.Role)), nameof(command.Role));
}
if (command.ApiCallsLimit != null && command.ApiCallsLimit < 0)
if (command.ApiCallsLimit is < 0)
{
e(Not.GreaterEqualsThan(nameof(command.ApiCallsLimit), "0"), nameof(command.ApiCallsLimit));
}
if (command.ApiTrafficLimit != null && command.ApiTrafficLimit < 0)
if (command.ApiTrafficLimit is < 0)
{
e(Not.GreaterEqualsThan(nameof(command.ApiTrafficLimit), "0"), nameof(command.ApiTrafficLimit));
}

2
backend/src/Squidex.Domain.Apps.Entities/Apps/Indexes/AppsIndex.cs

@ -212,7 +212,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Indexes
private static bool IsValid(IAppEntity? app)
{
return app != null && app.Version > EtagVersion.Empty && !app.IsDeleted;
return app is { Version: > EtagVersion.Empty, IsDeleted: false };
}
private Task InvalidateItAsync(DomainId id, string name)

4
backend/src/Squidex.Domain.Apps.Entities/Apps/RolePermissionsProvider.cs

@ -17,10 +17,6 @@ namespace Squidex.Domain.Apps.Entities.Apps
private readonly List<string> forAppWithoutSchemas = new List<string>();
private readonly IAppProvider appProvider;
static RolePermissionsProvider()
{
}
public RolePermissionsProvider(IAppProvider appProvider)
{
this.appProvider = appProvider;

4
backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/Template.cs

@ -9,7 +9,5 @@
namespace Squidex.Domain.Apps.Entities.Apps.Templates
{
public sealed record Template(string Name, string Title, string Description, bool IsStarter)
{
}
public sealed record Template(string Name, string Title, string Description, bool IsStarter);
}

1
backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/TemplateCommandMiddleware.cs

@ -5,7 +5,6 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Squidex.CLI.Commands.Implementation;
using Squidex.CLI.Commands.Implementation.FileSystem;

2
backend/src/Squidex.Domain.Apps.Entities/Assets/AssetChangedTriggerHandler.cs

@ -40,7 +40,7 @@ namespace Squidex.Domain.Apps.Entities.Assets
public bool Handles(AppEvent @event)
{
return @event is AssetEvent && @event is not AssetMoved;
return @event is AssetEvent and not AssetMoved;
}
public async IAsyncEnumerable<EnrichedEvent> CreateSnapshotEventsAsync(RuleContext context,

4
backend/src/Squidex.Domain.Apps.Entities/Assets/AssetDuplicate.cs

@ -9,7 +9,5 @@
namespace Squidex.Domain.Apps.Entities.Assets
{
public sealed record AssetDuplicate(IEnrichedAssetEntity Asset)
{
}
public sealed record AssetDuplicate(IEnrichedAssetEntity Asset);
}

7
backend/src/Squidex.Domain.Apps.Entities/Assets/AssetStats.cs

@ -9,10 +9,5 @@
namespace Squidex.Domain.Apps.Entities.Assets
{
public sealed record AssetStats(
DateTime Date,
long TotalCount,
long TotalSize)
{
}
public sealed record AssetStats(DateTime Date, long TotalCount, long TotalSize);
}

4
backend/src/Squidex.Domain.Apps.Entities/Assets/BackupAssets.cs

@ -137,13 +137,13 @@ namespace Squidex.Domain.Apps.Entities.Assets
var export = new TagsExport { Tags = tags, Alias = alias };
await tagService.RebuildTagsAsync(context.AppId, TagGroups.Assets, export);
await tagService.RebuildTagsAsync(context.AppId, TagGroups.Assets, export, ct);
}
private async Task BackupTagsAsync(BackupContext context,
CancellationToken ct)
{
var tags = await tagService.GetExportableTagsAsync(context.AppId, TagGroups.Assets);
var tags = await tagService.GetExportableTagsAsync(context.AppId, TagGroups.Assets, ct);
if (tags.Tags != null)
{

2
backend/src/Squidex.Domain.Apps.Entities/Assets/DomainObject/AssetCommandMiddleware.cs

@ -159,7 +159,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject
{
await using (var uploadStream = command.File.OpenRead())
{
using (var hashStream = new HasherStream(uploadStream, HashAlgorithmName.SHA256))
await using (var hashStream = new HasherStream(uploadStream, HashAlgorithmName.SHA256))
{
await assetFileStore.UploadAsync(tempFile, hashStream, ct);

2
backend/src/Squidex.Domain.Apps.Entities/Assets/DomainObject/AssetDomainObject.cs

@ -130,7 +130,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject
return Snapshot;
}, ct);
case DeleteAsset delete when delete.Permanent:
case DeleteAsset { Permanent: true } delete:
return DeletePermanentAsync(delete, async (c, ct) =>
{
var operation = await AssetOperation.CreateAsync(serviceProvider, c, () => Snapshot);

2
backend/src/Squidex.Domain.Apps.Entities/Assets/DomainObject/AssetsBulkUpdateCommandMiddleware.cs

@ -105,7 +105,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject
results,
ct);
if (!await createCommandsBlock.SendAsync(task))
if (!await createCommandsBlock.SendAsync(task, ct))
{
break;
}

4
backend/src/Squidex.Domain.Apps.Entities/Assets/ImageAssetMetadataSource.cs

@ -23,11 +23,11 @@ namespace Squidex.Domain.Apps.Entities.Assets
public async Task EnhanceAsync(UploadAssetCommand command,
CancellationToken ct)
{
if (command.Type == AssetType.Unknown || command.Type == AssetType.Image)
if (command.Type is not AssetType.Unknown or AssetType.Image)
{
var mimeType = command.File.MimeType;
ImageInfo? imageInfo = null;
ImageInfo? imageInfo;
await using (var uploadStream = command.File.OpenRead())
{

2
backend/src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetLoader.cs

@ -34,7 +34,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries
asset = await GetAsync(uniqueId, version, ct);
}
if (asset == null || asset.Version <= EtagVersion.Empty || (version > EtagVersion.Any && asset.Version != version))
if (asset is not { Version: > EtagVersion.Empty } || (version > EtagVersion.Any && asset.Version != version))
{
return null;
}

4
backend/src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetQueryParser.cs

@ -85,9 +85,9 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries
private void WithPaging(ClrQuery query, Q q)
{
if (query.Take <= 0 || query.Take == long.MaxValue)
if (query.Take is <= 0 or long.MaxValue)
{
if (q.Ids != null && q.Ids.Count > 0)
if (q.Ids is { Count: > 0 })
{
query.Take = q.Ids.Count;
}

4
backend/src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetQueryService.cs

@ -150,7 +150,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries
if (version > EtagVersion.Empty)
{
asset = await assetLoader.GetAsync(context.App.Id, id, version);
asset = await assetLoader.GetAsync(context.App.Id, id, version, ct);
}
else
{
@ -182,7 +182,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries
var assets = await QueryCoreAsync(context, parentId, q, ct);
if (q.Ids != null && q.Ids.Count > 0)
if (q.Ids is { Count: > 0 })
{
assets = assets.SortSet(x => x.Id, q.Ids);
}

8
backend/src/Squidex.Domain.Apps.Entities/Backup/BackupProcessor.cs

@ -119,7 +119,7 @@ namespace Squidex.Domain.Apps.Entities.Backup
await backupArchiveStore.DeleteAsync(backup.Id, default);
}
await state.ClearAsync();
await state.ClearAsync(default);
});
}
@ -161,7 +161,7 @@ namespace Squidex.Domain.Apps.Entities.Backup
currentRun.Dispose();
currentRun = null;
}
});
}, ct);
}
private async Task ProcessAsync(Run run,
@ -183,7 +183,7 @@ namespace Squidex.Domain.Apps.Entities.Backup
{
var @event = eventFormatter.Parse(storedEvent);
if (@event.Payload is SquidexEvent squidexEvent && squidexEvent.Actor != null)
if (@event.Payload is SquidexEvent { Actor: { } } squidexEvent)
{
backupUsers.Backup(squidexEvent.Actor);
}
@ -241,7 +241,7 @@ namespace Squidex.Domain.Apps.Entities.Backup
{
run.Job.Stopped = Clock.GetCurrentInstant();
await state.WriteAsync();
await state.WriteAsync(default);
}
}

1
backend/src/Squidex.Domain.Apps.Entities/Backup/BackupWorker.cs

@ -5,7 +5,6 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.Collections.Concurrent;
using Microsoft.Extensions.DependencyInjection;
using Squidex.Hosting;
using Squidex.Infrastructure;

4
backend/src/Squidex.Domain.Apps.Entities/Backup/RestoreProcessor.cs

@ -381,7 +381,7 @@ namespace Squidex.Domain.Apps.Entities.Backup
if (newStream != null)
{
if (!await batchBlock.SendAsync((newStream, job.Event)))
if (!await batchBlock.SendAsync((newStream, job.Event), ct))
{
break;
}
@ -416,7 +416,7 @@ namespace Squidex.Domain.Apps.Entities.Backup
run.StreamMapper = new StreamMapper(run.Context);
}
if (@event.Payload is SquidexEvent squidexEvent && squidexEvent.Actor != null)
if (@event.Payload is SquidexEvent { Actor: { } } squidexEvent)
{
if (run.Context.UserMapping.TryMap(squidexEvent.Actor, out var newUser))
{

5
backend/src/Squidex.Domain.Apps.Entities/Comments/DomainObject/CommentsStream.cs

@ -27,10 +27,7 @@ namespace Squidex.Domain.Apps.Entities.Comments.DomainObject
private long version = EtagVersion.Empty;
private string streamName;
private long Version
{
get => version;
}
private long Version => version;
public CommentsStream(
DomainId key,

14
backend/src/Squidex.Domain.Apps.Entities/Contents/ContentChangedTriggerHandler.cs

@ -19,6 +19,8 @@ using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.Reflection;
using Squidex.Text;
#pragma warning disable SA1013 // Closing braces should be spaced correctly
namespace Squidex.Domain.Apps.Entities.Contents
{
public sealed class ContentChangedTriggerHandler : IRuleTriggerHandler
@ -99,13 +101,13 @@ namespace Squidex.Domain.Apps.Entities.Contents
case ContentDeleted:
result.Type = EnrichedContentEventType.Deleted;
break;
case ContentStatusChanged e when e.Change == StatusChange.Published:
case ContentStatusChanged { Change: StatusChange.Published }:
result.Type = EnrichedContentEventType.Published;
break;
case ContentStatusChanged e when e.Change == StatusChange.Unpublished:
case ContentStatusChanged { Change: StatusChange.Unpublished }:
result.Type = EnrichedContentEventType.Unpublished;
break;
case ContentStatusChanged e when e.Change == StatusChange.Change:
case ContentStatusChanged { Change: StatusChange.Change }:
result.Type = EnrichedContentEventType.StatusChanged;
break;
case ContentUpdated:
@ -142,11 +144,11 @@ namespace Squidex.Domain.Apps.Entities.Contents
return $"{e.SchemaId.Name.ToPascalCase()}Created";
case ContentDeleted e:
return $"{e.SchemaId.Name.ToPascalCase()}Deleted";
case ContentStatusChanged e when e.Change == StatusChange.Published:
case ContentStatusChanged { Change: StatusChange.Published } e:
return $"{e.SchemaId.Name.ToPascalCase()}Published";
case ContentStatusChanged e when e.Change == StatusChange.Unpublished:
case ContentStatusChanged { Change: StatusChange.Unpublished } e:
return $"{e.SchemaId.Name.ToPascalCase()}Unpublished";
case ContentStatusChanged e when e.Change == StatusChange.Change:
case ContentStatusChanged { Change: StatusChange.Change } e:
return $"{e.SchemaId.Name.ToPascalCase()}StatusChanged";
case ContentUpdated e:
return $"{e.SchemaId.Name.ToPascalCase()}Updated";

4
backend/src/Squidex.Domain.Apps.Entities/Contents/Counter/CounterJintExtension.cs

@ -92,7 +92,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Counter
{
context.Schedule(async (scheduler, ct) =>
{
var result = await counterService.IncrementAsync(appId, name);
var result = await counterService.IncrementAsync(appId, name, ct);
if (callback != null)
{
@ -110,7 +110,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Counter
{
context.Schedule(async (scheduler, ct) =>
{
var result = await counterService.ResetAsync(appId, name, value);
var result = await counterService.ResetAsync(appId, name, value, ct);
if (callback != null)
{

2
backend/src/Squidex.Domain.Apps.Entities/Contents/DomainObject/ContentCommandMiddleware.cs

@ -32,7 +32,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject
{
var payload = await base.EnrichResultAsync(context, result, ct);
if (payload is IContentEntity content && payload is not IEnrichedContentEntity)
if (payload is IContentEntity content and not IEnrichedContentEntity)
{
payload = await contentEnricher.EnrichAsync(content, true, contextProvider.Context, ct);
}

4
backend/src/Squidex.Domain.Apps.Entities/Contents/DomainObject/ContentDomainObject.cs

@ -42,7 +42,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject
protected override bool CanAcceptCreation(ICommand command)
{
return command is CreateContent || command is UpsertContent;
return command is CreateContent or UpsertContent;
}
protected override bool CanRecreate()
@ -204,7 +204,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject
return Snapshot;
}, ct);
case DeleteContent deleteContent when deleteContent.Permanent:
case DeleteContent { Permanent: true } deleteContent:
return DeletePermanentAsync(deleteContent, async (c, ct) =>
{
var operation = await ContentOperation.CreateAsync(serviceProvider, c, () => Snapshot);

4
backend/src/Squidex.Domain.Apps.Entities/Contents/DomainObject/ContentsBulkUpdateCommandMiddleware.cs

@ -113,7 +113,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject
results,
ct);
if (!await createCommandsBlock.SendAsync(task))
if (!await createCommandsBlock.SendAsync(task, ct))
{
break;
}
@ -313,7 +313,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject
return existing.Select(x => x.Id).ToArray();
}
if (task.CommandJob.Type == BulkUpdateContentType.Create || task.CommandJob.Type == BulkUpdateContentType.Upsert)
if (task.CommandJob.Type is BulkUpdateContentType.Create or BulkUpdateContentType.Upsert)
{
return new[] { DomainId.NewGuid() };
}

2
backend/src/Squidex.Domain.Apps.Entities/Contents/DomainObject/Guards/ScriptingExtensions.cs

@ -61,7 +61,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject.Guards
OldStatus = operation.Snapshot.Status,
Operation = "Update",
Status = operation.Snapshot.EditingStatus(),
StatusOld = default,
StatusOld = default
});
return TransformAsync(operation, script, vars);

2
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/DataInputGraphType.cs

@ -78,7 +78,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents
foreach (var item in list)
{
if (item is JsonValue nested && nested.Value is JsonObject)
if (item is JsonValue { Value: JsonObject } nested)
{
array.Add(nested);
}

2
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/FieldVisitor.cs

@ -17,7 +17,7 @@ using Squidex.Infrastructure.Json.Objects;
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents
{
public delegate T ValueResolver<T>(JsonValue value, IResolveFieldContext fieldContext, GraphQLExecutionContext context);
public delegate T ValueResolver<out T>(JsonValue value, IResolveFieldContext fieldContext, GraphQLExecutionContext context);
public delegate Task<T> AsyncValueResolver<T>(JsonValue value, IResolveFieldContext fieldContext, GraphQLExecutionContext context);

2
backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentLoader.cs

@ -34,7 +34,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries
content = await GetAsync(uniqueId, version, ct);
}
if (content == null || content.Version <= EtagVersion.Empty || (version > EtagVersion.Any && content.Version != version))
if (content is not { Version: > EtagVersion.Empty } || (version > EtagVersion.Any && content.Version != version))
{
return null;
}

4
backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentQueryParser.cs

@ -156,9 +156,9 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries
private void WithPaging(ClrQuery query, Q q)
{
if (query.Take <= 0 || query.Take == long.MaxValue)
if (query.Take is <= 0 or long.MaxValue)
{
if (q.Ids != null && q.Ids.Count > 0)
if (q.Ids is { Count: > 0 })
{
query.Take = q.Ids.Count;
}

6
backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentQueryService.cs

@ -60,7 +60,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries
if (version > EtagVersion.Empty)
{
content = await contentLoader.GetAsync(context.App.Id, id, version);
content = await contentLoader.GetAsync(context.App.Id, id, version, ct);
}
else
{
@ -99,7 +99,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries
var contents = await QueryCoreAsync(context, q, schema, ct);
if (q.Ids != null && q.Ids.Count > 0)
if (q.Ids is { Count: > 0 })
{
contents = contents.SortSet(x => x.Id, q.Ids);
}
@ -131,7 +131,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries
var contents = await QueryCoreAsync(context, q, schemas, ct);
if (q.Ids != null && q.Ids.Count > 0)
if (q.Ids is { Count: > 0 })
{
contents = contents.SortSet(x => x.Id, q.Ids);
}

4
backend/src/Squidex.Domain.Apps.Entities/Contents/Text/GeoQuery.cs

@ -11,7 +11,5 @@ using Squidex.Infrastructure;
namespace Squidex.Domain.Apps.Entities.Contents.Text
{
public sealed record GeoQuery(DomainId SchemaId, string Field, double Latitude, double Longitude, double Radius, int Take)
{
}
public sealed record GeoQuery(DomainId SchemaId, string Field, double Latitude, double Longitude, double Radius, int Take);
}

3
backend/src/Squidex.Domain.Apps.Entities/Contents/Text/QueryParser.cs

@ -51,8 +51,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Text
{
lastIndexOfColon = indexOfColon;
var i = 0;
int i;
for (i = indexOfColon - 1; i >= position; i--)
{
var c = query[i];

4
backend/src/Squidex.Domain.Apps.Entities/History/NotifoService.cs

@ -240,7 +240,7 @@ namespace Squidex.Domain.Apps.Entities.History
private IEnumerable<PublishDto> CreateRequests(Envelope<AppEvent> appEvent, HistoryEvent? historyEvent)
{
if (appEvent.Payload is CommentCreated comment && comment.Mentions?.Length > 0)
if (appEvent.Payload is CommentCreated { Mentions.Length: > 0 } comment)
{
foreach (var userId in comment.Mentions)
{
@ -267,7 +267,7 @@ namespace Squidex.Domain.Apps.Entities.History
publishRequest.Properties["SquidexApp"] = payload.AppId.Name;
if (payload is ContentEvent @event && payload is not ContentDeleted)
if (payload is ContentEvent @event and not ContentDeleted)
{
var url = urlGenerator.ContentUI(@event.AppId, @event.SchemaId, @event.ContentId);

4
backend/src/Squidex.Domain.Apps.Entities/Rules/DomainObject/Guards/RuleTriggerValidator.cs

@ -1,4 +1,4 @@
// ==========================================================================
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
@ -57,7 +57,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.DomainObject.Guards
{
var errors = new List<ValidationError>();
if (trigger.NumDays != null && (trigger.NumDays < 1 || trigger.NumDays > 30))
if (trigger.NumDays is < 1 or > 30)
{
errors.Add(new ValidationError(Not.Between(nameof(trigger.NumDays), 1, 30), nameof(trigger.NumDays)));
}

2
backend/src/Squidex.Domain.Apps.Entities/Rules/Indexes/RulesIndex.cs

@ -32,7 +32,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Indexes
private static bool IsValid(IRuleEntity? rule)
{
return rule != null && rule.Version > EtagVersion.Empty && !rule.IsDeleted;
return rule is { Version: > EtagVersion.Empty, IsDeleted: false };
}
}
}

2
backend/src/Squidex.Domain.Apps.Entities/Rules/RuleCommandMiddleware.cs

@ -29,7 +29,7 @@ namespace Squidex.Domain.Apps.Entities.Rules
{
var payload = await base.EnrichResultAsync(context, result, ct);
if (payload is IRuleEntity rule && payload is not IEnrichedRuleEntity)
if (payload is IRuleEntity rule and not IEnrichedRuleEntity)
{
payload = await ruleEnricher.EnrichAsync(rule, contextProvider.Context, ct);
}

4
backend/src/Squidex.Domain.Apps.Entities/Rules/UsageTracking/UsageTrackerCommandMiddleware.cs

@ -29,10 +29,10 @@ namespace Squidex.Domain.Apps.Entities.Rules.UsageTracking
case DeleteRule deleteRule:
await messaging.PublishAsync(new UsageTrackingRemove(deleteRule.RuleId), ct: default);
break;
case CreateRule createRule when createRule.Trigger is UsageTrigger usage:
case CreateRule { Trigger: UsageTrigger usage } createRule:
await messaging.PublishAsync(new UsageTrackingAdd(createRule.RuleId, createRule.AppId, usage.Limit, usage.NumDays), ct: default);
break;
case UpdateRule ruleUpdated when ruleUpdated.Trigger is UsageTrigger usage:
case UpdateRule { Trigger: UsageTrigger usage } ruleUpdated:
await messaging.PublishAsync(new UsageTrackingUpdate(ruleUpdated.RuleId, usage.Limit, usage.NumDays), ct: default);
break;
}

6
backend/src/Squidex.Domain.Apps.Entities/Schemas/DomainObject/Guards/FieldPropertiesValidator.cs

@ -157,7 +157,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.DomainObject.Guards
nameof(properties.Editor));
}
if ((properties.Editor == NumberFieldEditor.Radio || properties.Editor == NumberFieldEditor.Dropdown) && properties.AllowedValues?.Any() != true)
if (properties.Editor is NumberFieldEditor.Radio or NumberFieldEditor.Dropdown && properties.AllowedValues?.Any() != true)
{
yield return new ValidationError(T.Get("schemas.stringEditorsNeedAllowedValuesError"),
nameof(properties.AllowedValues));
@ -215,7 +215,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.DomainObject.Guards
nameof(properties.ContentType));
}
if ((properties.Editor == StringFieldEditor.Radio || properties.Editor == StringFieldEditor.Dropdown) && properties.AllowedValues?.Any() != true)
if (properties.Editor is StringFieldEditor.Radio or StringFieldEditor.Dropdown && properties.AllowedValues?.Any() != true)
{
yield return new ValidationError(T.Get("schemas.stringEditorsNeedAllowedValuesError"),
nameof(properties.AllowedValues));
@ -264,7 +264,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.DomainObject.Guards
nameof(properties.Editor));
}
if ((properties.Editor == TagsFieldEditor.Checkboxes || properties.Editor == TagsFieldEditor.Dropdown) && properties.AllowedValues?.Any() != true)
if (properties.Editor is TagsFieldEditor.Checkboxes or TagsFieldEditor.Dropdown && properties.AllowedValues?.Any() != true)
{
yield return new ValidationError(T.Get("schemas.tags.editorNeedsAllowedValues"),
nameof(properties.AllowedValues));

4
backend/src/Squidex.Domain.Apps.Entities/Schemas/Indexes/SchemasIndex.cs

@ -171,7 +171,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Indexes
{
var existing = await schemaRepository.FindAsync(command.AppId.Id, command.Name, ct);
if (existing != null && !existing.IsDeleted)
if (existing is { IsDeleted: false })
{
throw new ValidationException(T.Get("schemas.nameAlreadyExists"));
}
@ -208,7 +208,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Indexes
private static bool IsValid(ISchemaEntity? schema)
{
return schema != null && schema.Version > EtagVersion.Empty && !schema.IsDeleted;
return schema is { Version: > EtagVersion.Empty, IsDeleted: false };
}
private Task InvalidateItAsync(DomainId appId, DomainId id, string name)

4
backend/src/Squidex.Domain.Users.MongoDb/MongoUser.cs

@ -54,7 +54,7 @@ namespace Squidex.Domain.Users.MongoDb
internal void AddClaims(IEnumerable<Claim> claims)
{
claims.Foreach(x => AddClaim(x));
claims.Foreach(AddClaim);
}
internal void AddToken(string provider, string name, string value)
@ -84,7 +84,7 @@ namespace Squidex.Domain.Users.MongoDb
internal void RemoveClaims(IEnumerable<Claim> claims)
{
claims.Foreach(x => RemoveClaim(x));
claims.Foreach(RemoveClaim);
}
internal void ReplaceClaim(Claim existingClaim, Claim newClaim)

20
backend/src/Squidex.Domain.Users/DefaultUserService.cs

@ -215,16 +215,16 @@ namespace Squidex.Domain.Users
var resolved = await ResolveAsync(user);
foreach (var @events in userEvents)
foreach (var events in userEvents)
{
await @events.OnUserRegisteredAsync(resolved);
await events.OnUserRegisteredAsync(resolved);
}
if (HasConsentGiven(values, null!))
{
foreach (var @events in userEvents)
foreach (var events in userEvents)
{
await @events.OnConsentGivenAsync(resolved);
await events.OnConsentGivenAsync(resolved);
}
}
@ -281,16 +281,16 @@ namespace Squidex.Domain.Users
if (!silent)
{
foreach (var @events in userEvents)
foreach (var events in userEvents)
{
await @events.OnUserUpdatedAsync(resolved, oldUser);
await events.OnUserUpdatedAsync(resolved, oldUser);
}
if (HasConsentGiven(values, oldUser))
{
foreach (var @events in userEvents)
foreach (var events in userEvents)
{
await @events.OnConsentGivenAsync(resolved);
await events.OnConsentGivenAsync(resolved);
}
}
}
@ -341,9 +341,9 @@ namespace Squidex.Domain.Users
await userManager.DeleteAsync(user).Throw(log);
foreach (var @events in userEvents)
foreach (var events in userEvents)
{
await @events.OnUserDeletedAsync(resolved);
await events.OnUserDeletedAsync(resolved);
}
}

2
backend/src/Squidex.Infrastructure.GetEventStore/EventSourcing/GetEventStore.cs

@ -83,7 +83,7 @@ namespace Squidex.Infrastructure.EventSourcing
var stream = QueryReverseAsync(streamName, StreamPosition.End, take, ct);
await foreach (var storedEvent in stream.IgnoreNotFound(ct).TakeWhile(x => x.Data.Headers.Timestamp() >= timestamp))
await foreach (var storedEvent in stream.IgnoreNotFound(ct).TakeWhile(x => x.Data.Headers.Timestamp() >= timestamp).WithCancellation(ct))
{
yield return storedEvent;
}

2
backend/src/Squidex.Infrastructure.MongoDb/Migrations/MongoMigrationStatus.cs

@ -44,7 +44,7 @@ namespace Squidex.Infrastructure.Migrations
UpsertFind,
ct);
return entity == null || !entity.IsLocked;
return entity is not { IsLocked: true };
}
public Task CompleteAsync(int newVersion,

4
backend/src/Squidex.Infrastructure.MongoDb/MongoDb/BsonJsonReader.cs

@ -25,9 +25,7 @@ namespace Squidex.Infrastructure.MongoDb
public override bool Read()
{
if (bsonReader.State == BsonReaderState.Initial ||
bsonReader.State == BsonReaderState.ScopeDocument ||
bsonReader.State == BsonReaderState.Type)
if (bsonReader.State is BsonReaderState.Initial or BsonReaderState.ScopeDocument or BsonReaderState.Type)
{
bsonReader.ReadBsonType();
}

3
backend/src/Squidex.Infrastructure.MongoDb/MongoDb/DomainIdSerializer.cs

@ -41,8 +41,7 @@ namespace Squidex.Infrastructure.MongoDb
case BsonType.Binary:
var binary = context.Reader.ReadBinaryData();
if (binary.SubType == BsonBinarySubType.UuidLegacy ||
binary.SubType == BsonBinarySubType.UuidStandard)
if (binary.SubType is BsonBinarySubType.UuidLegacy or BsonBinarySubType.UuidStandard)
{
return DomainId.Create(binary.ToGuid());
}

2
backend/src/Squidex.Infrastructure.MongoDb/UsageTracking/MongoUsageRepository.cs

@ -31,7 +31,7 @@ namespace Squidex.Infrastructure.UsageTracking
.Ascending(x => x.Key)
.Ascending(x => x.Category)
.Ascending(x => x.Date)),
cancellationToken: ct = default);
cancellationToken: ct);
}
public Task DeleteAsync(string key,

2
backend/src/Squidex.Infrastructure/Collections/ReadonlyDictionary.cs

@ -12,7 +12,7 @@ namespace Squidex.Infrastructure.Collections
private static class Empties<TKey, TValue> where TKey : notnull
{
#pragma warning disable SA1401 // Fields should be private
public static ReadonlyDictionary<TKey, TValue> Instance = new ReadonlyDictionary<TKey, TValue>();
public static readonly ReadonlyDictionary<TKey, TValue> Instance = new ReadonlyDictionary<TKey, TValue>();
#pragma warning restore SA1401 // Fields should be private
}

2
backend/src/Squidex.Infrastructure/Collections/ReadonlyList.cs

@ -12,7 +12,7 @@ namespace Squidex.Infrastructure.Collections
private static class Empties<T>
{
#pragma warning disable SA1401 // Fields should be private
public static ReadonlyList<T> Instance = new ReadonlyList<T>();
public static readonly ReadonlyList<T> Instance = new ReadonlyList<T>();
#pragma warning restore SA1401 // Fields should be private
}

2
backend/src/Squidex.Infrastructure/Commands/DefaultDomainObjectCache.cs

@ -73,7 +73,7 @@ namespace Squidex.Infrastructure.Commands
{
using (var stream = DefaultPools.MemoryStream.GetStream())
{
serializer.Serialize<T>(snapshot, stream, true);
serializer.Serialize(snapshot, stream, true);
await distributedCache.SetAsync(cacheKey, stream.ToArray(), CacheOptions, ct);
}

4
backend/src/Squidex.Infrastructure/Commands/DomainObject.cs

@ -127,9 +127,7 @@ namespace Squidex.Infrastructure.Commands
{
try
{
#pragma warning disable MA0040 // Flow the cancellation token
await persistence.WriteSnapshotAsync(Snapshot);
#pragma warning restore MA0040 // Flow the cancellation token
await persistence.WriteSnapshotAsync(Snapshot, default);
}
catch (Exception ex)
{

2
backend/src/Squidex.Infrastructure/Commands/IMigratedStateEvent.cs

@ -9,7 +9,7 @@ using Squidex.Infrastructure.EventSourcing;
namespace Squidex.Infrastructure.Commands
{
public interface IMigratedStateEvent<T>
public interface IMigratedStateEvent<in T>
{
IEvent Migrate(T state);
}

8
backend/src/Squidex.Infrastructure/DisposableObjectBase.cs

@ -12,13 +12,7 @@ namespace Squidex.Infrastructure
private readonly object disposeLock = new object();
private bool isDisposed;
public bool IsDisposed
{
get
{
return isDisposed;
}
}
public bool IsDisposed => isDisposed;
public void Dispose()
{

2
backend/src/Squidex.Infrastructure/EventSourcing/Consume/BatchSubscriber.cs

@ -95,7 +95,7 @@ namespace Squidex.Infrastructure.EventSourcing.Consume
{
switch (task)
{
case ErrorJob error when error.Exception is not OperationCanceledException:
case ErrorJob { Exception: not OperationCanceledException } error:
{
await processor.OnErrorAsync(this, error.Exception);
break;

4
backend/src/Squidex.Infrastructure/EventSourcing/StoredEvent.cs

@ -9,7 +9,5 @@
namespace Squidex.Infrastructure.EventSourcing
{
public sealed record StoredEvent(string StreamName, string EventPosition, long EventStreamNumber, EventData Data)
{
}
public sealed record StoredEvent(string StreamName, string EventPosition, long EventStreamNumber, EventData Data);
}

2
backend/src/Squidex.Infrastructure/Guard.cs

@ -193,7 +193,7 @@ namespace Squidex.Infrastructure
{
NotNull(target, parameterName);
if (target != null && target.Count == 0)
if (target is { Count: 0 })
{
ThrowHelper.ArgumentException("Collection does not contain an item.", parameterName);
return default!;

2
backend/src/Squidex.Infrastructure/IWithId.cs

@ -7,7 +7,7 @@
namespace Squidex.Infrastructure
{
public interface IWithId<T>
public interface IWithId<out T>
{
T Id { get; }
}

10
backend/src/Squidex.Infrastructure/Json/Objects/JsonValue.cs

@ -121,27 +121,27 @@ namespace Squidex.Infrastructure.Json.Objects
{
Guard.ValidNumber(value);
this.Value = value;
Value = value;
}
public JsonValue(bool value)
{
this.Value = value;
Value = value;
}
public JsonValue(string? value)
{
this.Value = value;
Value = value;
}
public JsonValue(JsonArray? value)
{
this.Value = value;
Value = value;
}
public JsonValue(JsonObject? value)
{
this.Value = value;
Value = value;
}
public static JsonValue Create<T>(IReadOnlyDictionary<string, T>? values)

2
backend/src/Squidex.Infrastructure/States/BatchContext.cs

@ -19,7 +19,7 @@ namespace Squidex.Infrastructure.States
private readonly IEventStore eventStore;
private readonly IEventStreamNames eventStreamNames;
private readonly ISnapshotStore<T> snapshotStore;
private readonly Dictionary<DomainId, (long, List<Envelope<IEvent>>)> @events = new Dictionary<DomainId, (long, List<Envelope<IEvent>>)>();
private readonly Dictionary<DomainId, (long, List<Envelope<IEvent>>)> events = new Dictionary<DomainId, (long, List<Envelope<IEvent>>)>();
private Dictionary<DomainId, SnapshotWriteJob<T>>? snapshots;
public ISnapshotStore<T> Snapshots => snapshotStore;

2
backend/src/Squidex.Infrastructure/States/BatchPersistence.cs

@ -20,7 +20,7 @@ namespace Squidex.Infrastructure.States
public bool IsSnapshotStale => false;
internal BatchPersistence(DomainId ownerKey, BatchContext<T> context, long version, IReadOnlyList<Envelope<IEvent>> @events,
internal BatchPersistence(DomainId ownerKey, BatchContext<T> context, long version, IReadOnlyList<Envelope<IEvent>> events,
HandleEvent? applyEvent)
{
this.ownerKey = ownerKey;

4
backend/src/Squidex.Infrastructure/Tasks/PartitionedActionBlock.cs

@ -35,13 +35,13 @@ namespace Squidex.Infrastructure.Tasks
for (var i = 0; i < dataflowBlockOptions.MaxDegreeOfParallelism; i++)
{
workers[i] = new ActionBlock<TInput>(action, new ExecutionDataflowBlockOptions()
workers[i] = new ActionBlock<TInput>(action, new ExecutionDataflowBlockOptions
{
BoundedCapacity = dataflowBlockOptions.BoundedCapacity,
CancellationToken = dataflowBlockOptions.CancellationToken,
MaxDegreeOfParallelism = 1,
MaxMessagesPerTask = 1,
TaskScheduler = dataflowBlockOptions.TaskScheduler,
TaskScheduler = dataflowBlockOptions.TaskScheduler
});
}

7
backend/src/Squidex.Infrastructure/UsageTracking/ApiStats.cs

@ -9,10 +9,5 @@
namespace Squidex.Infrastructure.UsageTracking
{
public sealed record ApiStats(
DateTime Date,
long TotalCalls, double AverageElapsedMs,
long TotalBytes)
{
}
public sealed record ApiStats(DateTime Date, long TotalCalls, double AverageElapsedMs, long TotalBytes);
}

4
backend/src/Squidex.Infrastructure/UsageTracking/ApiStatsSummary.cs

@ -14,7 +14,5 @@ namespace Squidex.Infrastructure.UsageTracking
long TotalCalls,
long TotalBytes,
long MonthCalls,
long MonthBytes)
{
}
long MonthBytes);
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save