diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/AppDomainObject.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/AppDomainObject.cs index 349669ba1..6f700b17e 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/AppDomainObject.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/AppDomainObject.cs @@ -21,7 +21,6 @@ using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.Log; using Squidex.Infrastructure.Reflection; using Squidex.Infrastructure.States; -using Squidex.Infrastructure.Translations; using Squidex.Shared.Users; namespace Squidex.Domain.Apps.Entities.Apps diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/Builders/ReferencesFieldBuilder.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/Builders/ReferencesFieldBuilder.cs index 9b11fb5a5..f047a7ef3 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/Builders/ReferencesFieldBuilder.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/Builders/ReferencesFieldBuilder.cs @@ -5,7 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using Squidex.Domain.Apps.Core.Schemas; using Squidex.Domain.Apps.Entities.Schemas.Commands; using Squidex.Infrastructure; diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetDomainObject.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetDomainObject.cs index 451d69a6b..ad434c0b6 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetDomainObject.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetDomainObject.cs @@ -20,7 +20,6 @@ using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.Log; using Squidex.Infrastructure.Reflection; using Squidex.Infrastructure.States; -using Squidex.Infrastructure.Translations; namespace Squidex.Domain.Apps.Entities.Assets { diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetFolderDomainObject.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetFolderDomainObject.cs index 77b5c08ea..2db6c6e01 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetFolderDomainObject.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetFolderDomainObject.cs @@ -54,7 +54,6 @@ namespace Squidex.Domain.Apps.Entities.Assets public override Task ExecuteAsync(IAggregateCommand command) { VerifyNotDeleted(); - VerifyCommand(command); switch (command) { @@ -97,24 +96,6 @@ namespace Squidex.Domain.Apps.Entities.Assets } } - private void VerifyCommand(IAggregateCommand command) - { - switch (command) - { - case AssetFolderCommand assetFolderCommand: - if (Version >= 0 && ( - !assetFolderCommand.AssetFolderId.Equals(Snapshot.Id) || - !assetFolderCommand.AppId.Equals(Snapshot.AppId))) - { - throw new InvalidOperationException(); - } - - break; - default: - throw new NotSupportedException(); - } - } - public void Create(CreateAssetFolder command) { RaiseEvent(SimpleMapper.Map(command, new AssetFolderCreated())); diff --git a/backend/src/Squidex.Domain.Apps.Entities/Rules/RuleDomainObject.cs b/backend/src/Squidex.Domain.Apps.Entities/Rules/RuleDomainObject.cs index 46029aaa2..4707495d3 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Rules/RuleDomainObject.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Rules/RuleDomainObject.cs @@ -18,7 +18,6 @@ using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.Log; using Squidex.Infrastructure.Reflection; using Squidex.Infrastructure.States; -using Squidex.Infrastructure.Translations; namespace Squidex.Domain.Apps.Entities.Rules { diff --git a/backend/src/Squidex.Domain.Apps.Entities/Schemas/SchemaDomainObject.cs b/backend/src/Squidex.Domain.Apps.Entities/Schemas/SchemaDomainObject.cs index baea40788..dbb58e00b 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Schemas/SchemaDomainObject.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Schemas/SchemaDomainObject.cs @@ -21,7 +21,6 @@ using Squidex.Infrastructure.Log; using Squidex.Infrastructure.Orleans; using Squidex.Infrastructure.Reflection; using Squidex.Infrastructure.States; -using Squidex.Infrastructure.Translations; namespace Squidex.Domain.Apps.Entities.Schemas { diff --git a/backend/src/Squidex.Infrastructure/Translations/MissingKeys.cs b/backend/src/Squidex.Infrastructure/Translations/MissingKeys.cs new file mode 100644 index 000000000..41d93657f --- /dev/null +++ b/backend/src/Squidex.Infrastructure/Translations/MissingKeys.cs @@ -0,0 +1,44 @@ +// ========================================================================== +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex UG (haftungsbeschraenkt) +// All rights reserved. Licensed under the MIT license. +// ========================================================================== + +using System.Collections.Generic; +using System.IO; + +namespace Squidex.Infrastructure.Translations +{ + public sealed class MissingKeys + { + private const string MissingFileName = "__missing.txt"; + private readonly object lockObject = new object(); + private readonly HashSet missingTranslations; + + public MissingKeys() + { + if (File.Exists(MissingFileName)) + { + var missing = File.ReadAllLines(MissingFileName); + + missingTranslations = new HashSet(missing); + } + else + { + missingTranslations = new HashSet(); + } + } + + public void Log(string key) + { + lock (lockObject) + { + if (!missingTranslations.Add(key)) + { + File.AppendAllLines(MissingFileName, new string[] { key }); + } + } + } + } +} diff --git a/backend/src/Squidex.Infrastructure/Translations/ResourcesLocalizer.cs b/backend/src/Squidex.Infrastructure/Translations/ResourcesLocalizer.cs index 5b4d3c59a..26678662e 100644 --- a/backend/src/Squidex.Infrastructure/Translations/ResourcesLocalizer.cs +++ b/backend/src/Squidex.Infrastructure/Translations/ResourcesLocalizer.cs @@ -6,9 +6,7 @@ // ========================================================================== using System; -using System.Collections.Generic; using System.Globalization; -using System.IO; using System.Resources; using System.Text; @@ -16,29 +14,16 @@ namespace Squidex.Infrastructure.Translations { public sealed class ResourcesLocalizer : ILocalizer { - private const string MissingFileName = "__missing.txt"; - - private static readonly object LockObject = new object(); +#if DEBUG + private static readonly MissingKeys MissingKeys = new MissingKeys(); +#endif private readonly ResourceManager resourceManager; - private readonly HashSet missingTranslations; public ResourcesLocalizer(ResourceManager resourceManager) { Guard.NotNull(resourceManager, nameof(resourceManager)); this.resourceManager = resourceManager; -#if DEBUG - if (File.Exists(MissingFileName)) - { - var missing = File.ReadAllLines(MissingFileName); - - missingTranslations = new HashSet(missing); - } - else - { - missingTranslations = new HashSet(); - } -#endif } public (string Result, bool Found) Get(CultureInfo culture, string key, string fallback, object? args = null) @@ -166,13 +151,7 @@ namespace Squidex.Infrastructure.Translations if (translation == null) { #if DEBUG - lock (LockObject) - { - if (!missingTranslations.Add(key)) - { - File.AppendAllLines(MissingFileName, new string[] { key }); - } - } + MissingKeys.Log(key); #endif } diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetCommandMiddlewareTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetCommandMiddlewareTests.cs index c27b44a1d..9b064e17e 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetCommandMiddlewareTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetCommandMiddlewareTests.cs @@ -7,7 +7,6 @@ using System; using System.Collections.Generic; -using System.IO; using System.Threading; using System.Threading.Tasks; using FakeItEasy; @@ -37,7 +36,6 @@ namespace Squidex.Domain.Apps.Entities.Assets private readonly IServiceProvider serviceProvider = A.Fake(); private readonly ITagService tagService = A.Fake(); private readonly DomainId assetId = DomainId.NewGuid(); - private readonly Stream stream = new MemoryStream(); private readonly AssetDomainObjectGrain asset; private readonly AssetFile file; private readonly Context requestContext = Context.Anonymous(); @@ -281,7 +279,7 @@ namespace Squidex.Domain.Apps.Entities.Assets private Task ExecuteCreateAsync() { - var command = CreateCommand(new CreateAsset { AssetId = Id, File = file }); + var command = CreateCommand(new CreateAsset { AssetId = assetId, File = file }); return asset.ExecuteAsync(CommandRequest.Create(command)); }