Browse Source

Cleanup (#411)

* Remove pubsub

* Removed unused code

* Dispatch removed.

* Build fixed.
pull/414/head
Sebastian Stehle 6 years ago
committed by GitHub
parent
commit
a9e2b00a89
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      Squidex.sln
  2. 2
      extensions/Squidex.Extensions/Actions/AzureQueue/AzureQueueAction.cs
  3. 2
      extensions/Squidex.Extensions/Actions/Discourse/DiscourseAction.cs
  4. 2
      extensions/Squidex.Extensions/Actions/ElasticSearch/ElasticSearchAction.cs
  5. 2
      extensions/Squidex.Extensions/Actions/Kafka/KafkaActionHandler.cs
  6. 2
      extensions/Squidex.Extensions/Actions/Kafka/KafkaProducerOptions.cs
  7. 2
      extensions/Squidex.Extensions/Actions/Slack/SlackAction.cs
  8. 1
      src/Squidex.Domain.Apps.Core.Model/Apps/AppImage.cs
  9. 2
      src/Squidex.Domain.Apps.Core.Model/Rules/Json/JsonRule.cs
  10. 2
      src/Squidex.Domain.Apps.Core.Model/Rules/RuleAction.cs
  11. 2
      src/Squidex.Domain.Apps.Core.Model/Schemas/FieldRegistry.cs
  12. 50
      src/Squidex.Domain.Apps.Core.Operations/HandleRules/ClientPool.cs
  13. 2
      src/Squidex.Domain.Apps.Core.Operations/HandleRules/EnrichedEvents/EnrichedContentEventType.cs
  14. 18
      src/Squidex.Domain.Apps.Core.Operations/HandleRules/IContentResolver.cs
  15. 1
      src/Squidex.Domain.Apps.Core.Operations/HandleRules/RuleRegistry.cs
  16. 1
      src/Squidex.Domain.Apps.Core.Operations/HandleRules/RuleService.cs
  17. 1
      src/Squidex.Domain.Apps.Core.Operations/Scripting/JintScriptEngine.cs
  18. 2
      src/Squidex.Domain.Apps.Core.Operations/ValidateContent/ContentValidationExtensions.cs
  19. 1
      src/Squidex.Domain.Apps.Core.Operations/ValidateContent/ContentValidator.cs
  20. 2
      src/Squidex.Domain.Apps.Core.Operations/ValidateContent/JsonValueConverter.cs
  21. 1
      src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs
  22. 16
      src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_EventHandling.cs
  23. 74
      src/Squidex.Domain.Apps.Entities.MongoDb/MongoCollectionExtensions.cs
  24. 1
      src/Squidex.Domain.Apps.Entities/Apps/AppCommandMiddleware.cs
  25. 186
      src/Squidex.Domain.Apps.Entities/Apps/AppHistoryEventsCreator.cs
  26. 1
      src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardApp.cs
  27. 1
      src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppClients.cs
  28. 1
      src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppContributors.cs
  29. 1
      src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppLanguages.cs
  30. 1
      src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppPatterns.cs
  31. 1
      src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppRoles.cs
  32. 1
      src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppWorkflows.cs
  33. 1
      src/Squidex.Domain.Apps.Entities/Apps/Indexes/AppsByNameIndexCommandMiddleware.cs
  34. 2
      src/Squidex.Domain.Apps.Entities/Apps/Invitation/InviteUserCommandMiddleware.cs
  35. 162
      src/Squidex.Domain.Apps.Entities/Apps/State/AppState.cs
  36. 23
      src/Squidex.Domain.Apps.Entities/Assets/AssetUsageTracker_EventHandling.cs
  37. 1
      src/Squidex.Domain.Apps.Entities/Assets/Guards/GuardAsset.cs
  38. 3
      src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetQueryParser.cs
  39. 56
      src/Squidex.Domain.Apps.Entities/Assets/State/AssetState.cs
  40. 5
      src/Squidex.Domain.Apps.Entities/Backup/BackupHandlerWithStore.cs
  41. 1
      src/Squidex.Domain.Apps.Entities/Comments/Guards/GuardComments.cs
  42. 8
      src/Squidex.Domain.Apps.Entities/Contents/ContentHistoryEventsCreator.cs
  43. 11
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/CachingGraphQLService.cs
  44. 12
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/GraphQLModel.cs
  45. 2
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/IGraphModel.cs
  46. 8
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Middlewares.cs
  47. 1
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/NestedGraphType.cs
  48. 2
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/QueryGraphTypeVisitor.cs
  49. 1
      src/Squidex.Domain.Apps.Entities/Contents/Guards/GuardContent.cs
  50. 2
      src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentQueryParser.cs
  51. 2
      src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentQueryService.cs
  52. 62
      src/Squidex.Domain.Apps.Entities/Contents/State/ContentState.cs
  53. 1
      src/Squidex.Domain.Apps.Entities/Contents/Text/TextIndexerGrain.cs
  54. 8
      src/Squidex.Domain.Apps.Entities/EntityMapper.cs
  55. 9
      src/Squidex.Domain.Apps.Entities/History/HistoryEvent.cs
  56. 8
      src/Squidex.Domain.Apps.Entities/History/HistoryEventsCreatorBase.cs
  57. 2
      src/Squidex.Domain.Apps.Entities/History/Notifications/NotificationEmailSender.cs
  58. 1
      src/Squidex.Domain.Apps.Entities/Rules/Guards/GuardRule.cs
  59. 1
      src/Squidex.Domain.Apps.Entities/Rules/Guards/RuleTriggerValidator.cs
  60. 44
      src/Squidex.Domain.Apps.Entities/Rules/State/RuleState.cs
  61. 2
      src/Squidex.Domain.Apps.Entities/Schemas/Guards/FieldPropertiesValidator.cs
  62. 1
      src/Squidex.Domain.Apps.Entities/Schemas/Guards/GuardSchema.cs
  63. 1
      src/Squidex.Domain.Apps.Entities/Schemas/Guards/GuardSchemaField.cs
  64. 6
      src/Squidex.Domain.Apps.Entities/Schemas/SchemaHistoryEventsCreator.cs
  65. 124
      src/Squidex.Domain.Apps.Entities/Schemas/State/SchemaState.cs
  66. 2
      src/Squidex.Domain.Apps.Events/Rules/RuleCreated.cs
  67. 2
      src/Squidex.Domain.Apps.Events/Rules/RuleUpdated.cs
  68. 5
      src/Squidex.Domain.Users.MongoDb/MongoUser.cs
  69. 1
      src/Squidex.Domain.Users/DefaultUserResolver.cs
  70. 1
      src/Squidex.Domain.Users/UserManagerExtensions.cs
  71. 18
      src/Squidex.Infrastructure.MongoDb/MongoDb/MongoRepositoryBase.cs
  72. 1
      src/Squidex.Infrastructure.MongoDb/MongoDb/Queries/FilterBuilder.cs
  73. 2
      src/Squidex.Infrastructure/Assets/FTPAssetStore.cs
  74. 2
      src/Squidex.Infrastructure/Caching/CachingProviderBase.cs
  75. 14
      src/Squidex.Infrastructure/Caching/IInvalidatingCache.cs
  76. 14
      src/Squidex.Infrastructure/Caching/InvalidateMessage.cs
  77. 66
      src/Squidex.Infrastructure/Caching/InvalidatingMemoryCache.cs
  78. 21
      src/Squidex.Infrastructure/Caching/InvalidatingMemoryCacheExtensions.cs
  79. 2
      src/Squidex.Infrastructure/Caching/LRUCache.cs
  80. 2
      src/Squidex.Infrastructure/Collections/ArrayDictionary{TKey,TValue}.cs
  81. 72
      src/Squidex.Infrastructure/Dispatching/ActionContextDispatcher.cs
  82. 72
      src/Squidex.Infrastructure/Dispatching/ActionDispatcher.cs
  83. 80
      src/Squidex.Infrastructure/Dispatching/DispatchExtensions.cs
  84. 61
      src/Squidex.Infrastructure/Dispatching/FuncContextDispatcher.cs
  85. 61
      src/Squidex.Infrastructure/Dispatching/FuncDispatcher.cs
  86. 39
      src/Squidex.Infrastructure/Dispatching/Helper.cs
  87. 2
      src/Squidex.Infrastructure/EventSourcing/DefaultEventDataFormatter.cs
  88. 2
      src/Squidex.Infrastructure/EventSourcing/Grains/EventConsumerGrain.cs
  89. 2
      src/Squidex.Infrastructure/EventSourcing/IEventEnricher.cs
  90. 7
      src/Squidex.Infrastructure/FileExtensions.cs
  91. 1
      src/Squidex.Infrastructure/Guard.cs
  92. 4
      src/Squidex.Infrastructure/Http/DumpFormatter.cs
  93. 18
      src/Squidex.Infrastructure/IPubSub.cs
  94. 41
      src/Squidex.Infrastructure/InMemoryPubSub.cs
  95. 1
      src/Squidex.Infrastructure/Json/Newtonsoft/TypeNameSerializationBinder.cs
  96. 8
      src/Squidex.Infrastructure/Json/Objects/JsonArray.cs
  97. 2
      src/Squidex.Infrastructure/Log/ProfilerSpan.cs
  98. 2
      src/Squidex.Infrastructure/Migrations/IMigrated.cs
  99. 8
      src/Squidex.Infrastructure/Migrations/Migrator.cs
  100. 2
      src/Squidex.Infrastructure/Net/IPAddressComparer.cs

13
Squidex.sln

@ -18,8 +18,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squidex.Domain.Apps.Core.Te
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squidex.Infrastructure.MongoDb", "src\Squidex.Infrastructure.MongoDb\Squidex.Infrastructure.MongoDb.csproj", "{6A811927-3C37-430A-90F4-503E37123956}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squidex.Infrastructure.Redis", "src\Squidex.Infrastructure.Redis\Squidex.Infrastructure.Redis.csproj", "{D7166C56-178A-4457-B56A-C615C7450DEE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squidex.Infrastructure.RabbitMq", "src\Squidex.Infrastructure.RabbitMq\Squidex.Infrastructure.RabbitMq.csproj", "{C1E5BBB6-6B6A-4DE5-B19D-0538304DE343}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squidex.Infrastructure.GoogleCloud", "src\Squidex.Infrastructure.GoogleCloud\Squidex.Infrastructure.GoogleCloud.csproj", "{945871B1-77B8-43FB-B53C-27CF385AB756}"
@ -125,14 +123,6 @@ Global
{6A811927-3C37-430A-90F4-503E37123956}.Release|Any CPU.Build.0 = Release|Any CPU
{6A811927-3C37-430A-90F4-503E37123956}.Release|x64.ActiveCfg = Release|Any CPU
{6A811927-3C37-430A-90F4-503E37123956}.Release|x86.ActiveCfg = Release|Any CPU
{D7166C56-178A-4457-B56A-C615C7450DEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D7166C56-178A-4457-B56A-C615C7450DEE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7166C56-178A-4457-B56A-C615C7450DEE}.Debug|x64.ActiveCfg = Debug|Any CPU
{D7166C56-178A-4457-B56A-C615C7450DEE}.Debug|x86.ActiveCfg = Debug|Any CPU
{D7166C56-178A-4457-B56A-C615C7450DEE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7166C56-178A-4457-B56A-C615C7450DEE}.Release|Any CPU.Build.0 = Release|Any CPU
{D7166C56-178A-4457-B56A-C615C7450DEE}.Release|x64.ActiveCfg = Release|Any CPU
{D7166C56-178A-4457-B56A-C615C7450DEE}.Release|x86.ActiveCfg = Release|Any CPU
{C1E5BBB6-6B6A-4DE5-B19D-0538304DE343}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C1E5BBB6-6B6A-4DE5-B19D-0538304DE343}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C1E5BBB6-6B6A-4DE5-B19D-0538304DE343}.Debug|x64.ActiveCfg = Debug|Any CPU
@ -359,11 +349,10 @@ Global
{7FD0A92B-7862-4BB1-932B-B52A9CACB56B} = {8CF53B92-5EB1-461D-98F8-70DA9B603FBF}
{FD0AFD44-7A93-4F9E-B5ED-72582392E435} = {4C6B06C2-6D77-4E0E-AE32-D7050236433A}
{6A811927-3C37-430A-90F4-503E37123956} = {8CF53B92-5EB1-461D-98F8-70DA9B603FBF}
{D7166C56-178A-4457-B56A-C615C7450DEE} = {8CF53B92-5EB1-461D-98F8-70DA9B603FBF}
{C1E5BBB6-6B6A-4DE5-B19D-0538304DE343} = {8CF53B92-5EB1-461D-98F8-70DA9B603FBF}
{945871B1-77B8-43FB-B53C-27CF385AB756} = {8CF53B92-5EB1-461D-98F8-70DA9B603FBF}
{B51126A8-0D75-4A79-867D-10724EC6AC84} = {94207AA6-4923-4183-A558-E0F8196B8CA3}
{5E75AB7D-6F01-4313-AFF1-7F7128FFD71F} = {8CF53B92-5EB1-461D-98F8-70DA9B603FBF}
{5E75AB7D-6F01-4313-AFF1-7F7128FFD71F} = {7EDE8CF1-B1E4-4005-B154-834B944E0D7A}
{F7771E22-47BD-45C4-A133-FD7F1DE27CA0} = {7EDE8CF1-B1E4-4005-B154-834B944E0D7A}
{27CF800D-890F-4882-BF05-44EC3233537D} = {7EDE8CF1-B1E4-4005-B154-834B944E0D7A}
{42184546-E3CB-4D4F-9495-43979B9C63B9} = {7EDE8CF1-B1E4-4005-B154-834B944E0D7A}

2
extensions/Squidex.Extensions/Actions/AzureQueue/AzureQueueAction.cs

@ -10,7 +10,7 @@ using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
using Squidex.Domain.Apps.Core.HandleRules;
using Squidex.Domain.Apps.Core.Rules;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
namespace Squidex.Extensions.Actions.AzureQueue
{

2
extensions/Squidex.Extensions/Actions/Discourse/DiscourseAction.cs

@ -9,7 +9,7 @@ using System;
using System.ComponentModel.DataAnnotations;
using Squidex.Domain.Apps.Core.HandleRules;
using Squidex.Domain.Apps.Core.Rules;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
namespace Squidex.Extensions.Actions.Discourse
{

2
extensions/Squidex.Extensions/Actions/ElasticSearch/ElasticSearchAction.cs

@ -9,7 +9,7 @@ using System;
using System.ComponentModel.DataAnnotations;
using Squidex.Domain.Apps.Core.HandleRules;
using Squidex.Domain.Apps.Core.Rules;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
namespace Squidex.Extensions.Actions.ElasticSearch
{

2
extensions/Squidex.Extensions/Actions/Kafka/KafkaActionHandler.cs

@ -36,7 +36,7 @@ namespace Squidex.Extensions.Actions.Kafka
return (Description, ruleJob);
}
protected override async Task<Result> ExecuteJobAsync(KafkaJob job, CancellationToken ct)
protected override async Task<Result> ExecuteJobAsync(KafkaJob job, CancellationToken ct = default)
{
try
{

2
extensions/Squidex.Extensions/Actions/Kafka/KafkaProducerOptions.cs

@ -13,7 +13,7 @@ namespace Squidex.Extensions.Actions.Kafka
{
public bool IsProducerConfigured()
{
return !string.IsNullOrWhiteSpace(this.BootstrapServers);
return !string.IsNullOrWhiteSpace(BootstrapServers);
}
}
}

2
extensions/Squidex.Extensions/Actions/Slack/SlackAction.cs

@ -9,7 +9,7 @@ using System;
using System.ComponentModel.DataAnnotations;
using Squidex.Domain.Apps.Core.HandleRules;
using Squidex.Domain.Apps.Core.Rules;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
namespace Squidex.Extensions.Actions.Slack
{

1
src/Squidex.Domain.Apps.Core.Model/Apps/AppImage.cs

@ -5,7 +5,6 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
using Squidex.Infrastructure;
namespace Squidex.Domain.Apps.Core.Apps

2
src/Squidex.Domain.Apps.Core.Model/Rules/Json/JsonRule.cs

@ -6,7 +6,7 @@
// ==========================================================================
using Newtonsoft.Json;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Migrations;
using Squidex.Infrastructure.Reflection;
namespace Squidex.Domain.Apps.Core.Rules.Json

2
src/Squidex.Domain.Apps.Core.Model/Rules/RuleAction.cs

@ -8,7 +8,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Core.Rules
{

2
src/Squidex.Domain.Apps.Core.Model/Schemas/FieldRegistry.cs

@ -8,7 +8,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Reflection;
namespace Squidex.Domain.Apps.Core.Schemas
{

50
src/Squidex.Domain.Apps.Core.Operations/HandleRules/ClientPool.cs

@ -1,50 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
#pragma warning disable RECS0108 // Warns about static fields in generic types
namespace Squidex.Domain.Apps.Core.HandleRules
{
internal sealed class ClientPool<TKey, TClient>
{
private static readonly TimeSpan CacheDuration = TimeSpan.FromMinutes(30);
private readonly MemoryCache memoryCache = new MemoryCache(Options.Create(new MemoryCacheOptions()));
private readonly Func<TKey, Task<TClient>> factory;
public ClientPool(Func<TKey, TClient> factory)
{
this.factory = x => Task.FromResult(factory(x));
}
public ClientPool(Func<TKey, Task<TClient>> factory)
{
this.factory = factory;
}
public TClient GetClient(TKey key)
{
return GetClientAsync(key).Result;
}
public async Task<TClient> GetClientAsync(TKey key)
{
if (!memoryCache.TryGetValue<TClient>(key, out var client))
{
client = await factory(key);
memoryCache.Set(key, client, CacheDuration);
}
return client;
}
}
}

2
src/Squidex.Domain.Apps.Core.Operations/HandleRules/EnrichedEvents/EnrichedContentEventType.cs

@ -14,6 +14,6 @@ namespace Squidex.Domain.Apps.Core.HandleRules.EnrichedEvents
Published,
StatusChanged,
Updated,
Unpublished,
Unpublished
}
}

18
src/Squidex.Domain.Apps.Core.Operations/HandleRules/IContentResolver.cs

@ -1,18 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
using System.Threading.Tasks;
using Squidex.Domain.Apps.Core.Contents;
namespace Squidex.Domain.Apps.Core.HandleRules
{
public interface IContentResolver
{
Task<NamedContentData> GetContentDataAsync(Guid id);
}
}

1
src/Squidex.Domain.Apps.Core.Operations/HandleRules/RuleRegistry.cs

@ -13,6 +13,7 @@ using System.Reflection;
using Squidex.Domain.Apps.Core.HandleRules.EnrichedEvents;
using Squidex.Domain.Apps.Core.Rules;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Reflection;
#pragma warning disable RECS0033 // Convert 'if' to '||' expression

1
src/Squidex.Domain.Apps.Core.Operations/HandleRules/RuleService.cs

@ -18,6 +18,7 @@ using Squidex.Infrastructure;
using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.Json;
using Squidex.Infrastructure.Log;
using Squidex.Infrastructure.Reflection;
using Squidex.Infrastructure.Tasks;
namespace Squidex.Domain.Apps.Core.HandleRules

1
src/Squidex.Domain.Apps.Core.Operations/Scripting/JintScriptEngine.cs

@ -18,6 +18,7 @@ using Jint.Runtime.Interop;
using Squidex.Domain.Apps.Core.Contents;
using Squidex.Domain.Apps.Core.Scripting.ContentWrapper;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Core.Scripting
{

2
src/Squidex.Domain.Apps.Core.Operations/ValidateContent/ContentValidationExtensions.cs

@ -11,7 +11,7 @@ using System.Linq;
using System.Threading.Tasks;
using Squidex.Domain.Apps.Core.Contents;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Core.ValidateContent
{

1
src/Squidex.Domain.Apps.Core.Operations/ValidateContent/ContentValidator.cs

@ -14,6 +14,7 @@ using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Core.ValidateContent.Validators;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Json.Objects;
using Squidex.Infrastructure.Validation;
#pragma warning disable SA1028, IDE0004 // Code must not contain trailing whitespace

2
src/Squidex.Domain.Apps.Core.Operations/ValidateContent/JsonValueConverter.cs

@ -9,8 +9,8 @@ using System;
using System.Collections.Generic;
using NodaTime.Text;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Json.Objects;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Core.ValidateContent
{

1
src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs

@ -23,6 +23,7 @@ using Squidex.Infrastructure;
using Squidex.Infrastructure.Json;
using Squidex.Infrastructure.Log;
using Squidex.Infrastructure.Queries;
using Squidex.Infrastructure.Reflection;
namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
{

16
src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_EventHandling.cs

@ -8,7 +8,6 @@
using System.Threading.Tasks;
using Squidex.Domain.Apps.Events.Assets;
using Squidex.Domain.Apps.Events.Contents;
using Squidex.Infrastructure.Dispatching;
using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.Tasks;
@ -33,17 +32,16 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
public Task On(Envelope<IEvent> @event)
{
return this.DispatchActionAsync(@event.Payload);
}
protected Task On(AssetDeleted @event)
switch (@event.Payload)
{
return contents.CleanupAsync(@event.AssetId);
case AssetDeleted e:
return contents.CleanupAsync(e.AssetId);
case ContentDeleted e:
return contents.CleanupAsync(e.ContentId);
}
protected Task On(ContentDeleted @event)
{
return contents.CleanupAsync(@event.ContentId);
return TaskHelper.Done;
}
Task IEventConsumer.ClearAsync()

74
src/Squidex.Domain.Apps.Entities.MongoDb/MongoCollectionExtensions.cs

@ -1,74 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
using System.Threading.Tasks;
using MongoDB.Driver;
using Squidex.Domain.Apps.Events;
using Squidex.Infrastructure;
using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.MongoDb;
namespace Squidex.Domain.Apps.Entities.MongoDb
{
public static class MongoCollectionExtensions
{
public static Task CreateAsync<T>(this IMongoCollection<T> collection, SquidexEvent @event, EnvelopeHeaders headers, Action<T> updater) where T : class, IEntity, new()
{
var entity = new T().Update(@event, headers, updater);
return collection.InsertOneIfNotExistsAsync(entity);
}
public static async Task UpdateAsync<T>(this IMongoCollection<T> collection, SquidexEvent @event, EnvelopeHeaders headers, Action<T> updater) where T : class, IEntity, new()
{
var entity =
await collection.Find(t => t.Id == headers.AggregateId())
.FirstOrDefaultAsync();
if (entity == null)
{
throw new DomainObjectNotFoundException(headers.AggregateId().ToString(), typeof(T));
}
await collection.UpdateAsync(@event, headers, entity, updater);
}
public static async Task<bool> TryUpdateAsync<T>(this IMongoCollection<T> collection, SquidexEvent @event, EnvelopeHeaders headers, Action<T> updater) where T : class, IEntity, new()
{
var entity =
await collection.Find(t => t.Id == headers.AggregateId())
.FirstOrDefaultAsync();
if (entity != null)
{
if (entity is IEntityWithVersion withVersion)
{
var eventVersion = headers.EventStreamNumber();
if (eventVersion <= withVersion.Version)
{
return false;
}
}
await collection.UpdateAsync(@event, headers, entity, updater);
return true;
}
return false;
}
private static async Task UpdateAsync<T>(this IMongoCollection<T> collection, SquidexEvent @event, EnvelopeHeaders headers, T entity, Action<T> updater) where T : class, IEntity, new()
{
entity.Update(@event, headers, updater);
await collection.ReplaceOneAsync(t => t.Id == entity.Id, entity);
}
}
}

1
src/Squidex.Domain.Apps.Entities/Apps/AppCommandMiddleware.cs

@ -12,6 +12,7 @@ using Squidex.Domain.Apps.Entities.Apps.Commands;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Assets;
using Squidex.Infrastructure.Commands;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Entities.Apps
{

186
src/Squidex.Domain.Apps.Entities/Apps/AppHistoryEventsCreator.cs

@ -5,12 +5,13 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
using System.Threading.Tasks;
using Squidex.Domain.Apps.Entities.History;
using Squidex.Domain.Apps.Events.Apps;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Dispatching;
using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.Reflection;
namespace Squidex.Domain.Apps.Entities.Apps
{
@ -74,166 +75,87 @@ namespace Squidex.Domain.Apps.Entities.Apps
"updated role {[Name]}");
}
protected Task<HistoryEvent> On(AppContributorRemoved @event)
private HistoryEvent CreateEvent(IEvent @event)
{
const string channel = "settings.contributors";
return Task.FromResult(
ForEvent(@event, channel)
.AddParameter("Contributor", @event.ContributorId));
}
protected Task<HistoryEvent> On(AppContributorAssigned @event)
{
const string channel = "settings.contributors";
return Task.FromResult(
ForEvent(@event, channel)
.AddParameter("Contributor", @event.ContributorId).AddParameter("Role", @event.Role));
}
protected Task<HistoryEvent> On(AppClientAttached @event)
{
const string channel = "settings.clients";
return Task.FromResult(
ForEvent(@event, channel)
.AddParameter("Id", @event.Id));
}
protected Task<HistoryEvent> On(AppClientRevoked @event)
{
const string channel = "settings.clients";
return Task.FromResult(
ForEvent(@event, channel)
.AddParameter("Id", @event.Id));
}
protected Task<HistoryEvent> On(AppClientRenamed @event)
{
const string channel = "settings.clients";
return Task.FromResult(
ForEvent(@event, channel)
.AddParameter("Id", @event.Id).AddParameter("Name", ClientName(@event)));
}
protected Task<HistoryEvent> On(AppLanguageAdded @event)
{
const string channel = "settings.languages";
return Task.FromResult(
ForEvent(@event, channel)
.AddParameter("Language", @event.Language));
}
protected Task<HistoryEvent> On(AppLanguageRemoved @event)
{
const string channel = "settings.languages";
return Task.FromResult(
ForEvent(@event, channel)
.AddParameter("Language", @event.Language));
}
protected Task<HistoryEvent> On(AppLanguageUpdated @event)
{
const string channel = "settings.languages";
return Task.FromResult(
ForEvent(@event, channel)
.AddParameter("Language", @event.Language));
}
protected Task<HistoryEvent> On(AppMasterLanguageSet @event)
{
const string channel = "settings.languages";
return Task.FromResult(
ForEvent(@event, channel)
.AddParameter("Language", @event.Language));
}
protected Task<HistoryEvent> On(AppPatternAdded @event)
switch (@event)
{
const string channel = "settings.patterns";
return Task.FromResult(
ForEvent(@event, channel)
.AddParameter("Name", @event.Name));
case AppContributorAssigned e:
return CreateContributorsEvent(e, e.ContributorId, e.Role);
case AppContributorRemoved e:
return CreateContributorsEvent(e, e.ContributorId);
case AppClientAttached e:
return CreateClientsEvent(e, e.Id);
case AppClientRenamed e:
return CreateClientsEvent(e, e.Id, ClientName(e));
case AppClientRevoked e:
return CreateClientsEvent(e, e.Id);
case AppLanguageAdded e:
return CreateLanguagesEvent(e, e.Language);
case AppLanguageUpdated e:
return CreateLanguagesEvent(e, e.Language);
case AppMasterLanguageSet e:
return CreateLanguagesEvent(e, e.Language);
case AppLanguageRemoved e:
return CreateLanguagesEvent(e, e.Language);
case AppPatternAdded e:
return CreatePatternsEvent(e, e.PatternId, e.Name);
case AppPatternUpdated e:
return CreatePatternsEvent(e, e.PatternId, e.Name);
case AppPatternDeleted e:
return CreatePatternsEvent(e, e.PatternId);
case AppRoleAdded e:
return CreateRolesEvent(e, e.Name);
case AppRoleUpdated e:
return CreateRolesEvent(e, e.Name);
case AppRoleDeleted e:
return CreateRolesEvent(e, e.Name);
case AppPlanChanged e:
return CreatePlansEvent(e, e.PlanId);
case AppPlanReset e:
return CreatePlansEvent(e);
}
protected Task<HistoryEvent> On(AppPatternUpdated @event)
{
const string channel = "settings.patterns";
return Task.FromResult(
ForEvent(@event, channel)
.AddParameter("Name", @event.Name));
return null;
}
protected Task<HistoryEvent> On(AppPatternDeleted @event)
private HistoryEvent CreateContributorsEvent(IEvent e, string contributor, string role = null)
{
const string channel = "settings.patterns";
return Task.FromResult(
ForEvent(@event, channel)
.AddParameter("PatternId", @event.PatternId));
return ForEvent(e, "settings.contributors").Param("Contributor", contributor).Param("Role", role);
}
protected Task<HistoryEvent> On(AppRoleAdded @event)
private HistoryEvent CreateLanguagesEvent(IEvent e, Language language)
{
const string channel = "settings.roles";
return Task.FromResult(
ForEvent(@event, channel)
.AddParameter("Name", @event.Name));
return ForEvent(e, "settings.languages").Param("Language", language);
}
protected Task<HistoryEvent> On(AppRoleUpdated @event)
private HistoryEvent CreateRolesEvent(IEvent e, string name)
{
const string channel = "settings.roles";
return Task.FromResult(
ForEvent(@event, channel)
.AddParameter("Name", @event.Name));
return ForEvent(e, "settings.roles").Param("Name", name);
}
protected Task<HistoryEvent> On(AppRoleDeleted @event)
private HistoryEvent CreatePatternsEvent(IEvent e, Guid id, string name = null)
{
const string channel = "settings.roles";
return Task.FromResult(
ForEvent(@event, channel)
.AddParameter("Name", @event.Name));
return ForEvent(e, "settings.patterns").Param("PatternId", id).Param("Name", name);
}
protected Task<HistoryEvent> On(AppPlanChanged @event)
private HistoryEvent CreateClientsEvent(IEvent e, string id, string name = null)
{
const string channel = "settings.plan";
return Task.FromResult(
ForEvent(@event, channel)
.AddParameter("Plan", @event.PlanId));
return ForEvent(e, "settings.clients").Param("Id", id).Param("Name", name);
}
protected Task<HistoryEvent> On(AppPlanReset @event)
private HistoryEvent CreatePlansEvent(IEvent e, string plan = null)
{
const string channel = "settings.plan";
return Task.FromResult(
ForEvent(@event, channel));
return ForEvent(e, "settings.plan").Param("Plan", plan);
}
protected override Task<HistoryEvent> CreateEventCoreAsync(Envelope<IEvent> @event)
{
return this.DispatchFuncAsync(@event.Payload, (HistoryEvent)null);
return Task.FromResult(CreateEvent(@event.Payload));
}
private static string ClientName(AppClientRenamed @event)
private static string ClientName(AppClientRenamed e)
{
return !string.IsNullOrWhiteSpace(@event.Name) ? @event.Name : @event.Id;
return !string.IsNullOrWhiteSpace(e.Name) ? e.Name : e.Id;
}
}
}

1
src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardApp.cs

@ -10,6 +10,7 @@ using Squidex.Domain.Apps.Core.Apps;
using Squidex.Domain.Apps.Entities.Apps.Commands;
using Squidex.Domain.Apps.Entities.Apps.Services;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Entities.Apps.Guards
{

1
src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppClients.cs

@ -8,6 +8,7 @@
using Squidex.Domain.Apps.Core.Apps;
using Squidex.Domain.Apps.Entities.Apps.Commands;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Entities.Apps.Guards
{

1
src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppContributors.cs

@ -12,6 +12,7 @@ using Squidex.Domain.Apps.Core.Apps;
using Squidex.Domain.Apps.Entities.Apps.Commands;
using Squidex.Domain.Apps.Entities.Apps.Services;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
using Squidex.Shared.Users;
namespace Squidex.Domain.Apps.Entities.Apps.Guards

1
src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppLanguages.cs

@ -8,6 +8,7 @@
using Squidex.Domain.Apps.Core.Apps;
using Squidex.Domain.Apps.Entities.Apps.Commands;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Entities.Apps.Guards
{

1
src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppPatterns.cs

@ -9,6 +9,7 @@ using System.Linq;
using Squidex.Domain.Apps.Core.Apps;
using Squidex.Domain.Apps.Entities.Apps.Commands;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Entities.Apps.Guards
{

1
src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppRoles.cs

@ -10,6 +10,7 @@ using System.Linq;
using Squidex.Domain.Apps.Core.Apps;
using Squidex.Domain.Apps.Entities.Apps.Commands;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Entities.Apps.Guards
{

1
src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppWorkflows.cs

@ -9,6 +9,7 @@ using System;
using Squidex.Domain.Apps.Core.Contents;
using Squidex.Domain.Apps.Entities.Apps.Commands;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Entities.Apps.Guards
{

1
src/Squidex.Domain.Apps.Entities/Apps/Indexes/AppsByNameIndexCommandMiddleware.cs

@ -12,6 +12,7 @@ using Squidex.Domain.Apps.Entities.Apps.Commands;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Commands;
using Squidex.Infrastructure.Orleans;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Entities.Apps.Indexes
{

2
src/Squidex.Domain.Apps.Entities/Apps/Invitation/InviteUserCommandMiddleware.cs

@ -44,7 +44,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Invitation
}
}
private bool ShouldInvite(AssignContributor assignContributor)
private static bool ShouldInvite(AssignContributor assignContributor)
{
return assignContributor.Invite && assignContributor.ContributorId.IsEmail();
}

162
src/Squidex.Domain.Apps.Entities/Apps/State/AppState.cs

@ -8,9 +8,7 @@
using System.Runtime.Serialization;
using Squidex.Domain.Apps.Core.Apps;
using Squidex.Domain.Apps.Core.Contents;
using Squidex.Domain.Apps.Events;
using Squidex.Domain.Apps.Events.Apps;
using Squidex.Infrastructure.Dispatching;
using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.Reflection;
using Squidex.Infrastructure.States;
@ -58,145 +56,199 @@ namespace Squidex.Domain.Apps.Entities.Apps.State
[DataMember]
public bool IsArchived { get; set; }
protected void On(AppCreated @event)
public void ApplyEvent(IEvent @event)
{
Roles = Roles.CreateDefaults(@event.Name);
switch (@event)
{
case AppCreated e:
{
Roles = Roles.CreateDefaults(e.Name);
SimpleMapper.Map(@event, this);
SimpleMapper.Map(e, this);
break;
}
protected void On(AppUpdated @event)
case AppUpdated e:
{
SimpleMapper.Map(@event, this);
SimpleMapper.Map(e, this);
break;
}
protected void On(AppImageUploaded @event)
case AppImageUploaded e:
{
Image = @event.Image;
Image = e.Image;
break;
}
protected void On(AppImageRemoved @event)
case AppImageRemoved _:
{
Image = null;
break;
}
protected void On(AppPlanChanged @event)
case AppPlanChanged e:
{
Plan = AppPlan.Build(@event.Actor, @event.PlanId);
Plan = AppPlan.Build(e.Actor, e.PlanId);
break;
}
protected void On(AppPlanReset @event)
case AppPlanReset _:
{
Plan = null;
break;
}
protected void On(AppContributorAssigned @event)
case AppContributorAssigned e:
{
Contributors = Contributors.Assign(@event.ContributorId, @event.Role);
Contributors = Contributors.Assign(e.ContributorId, e.Role);
break;
}
protected void On(AppContributorRemoved @event)
case AppContributorRemoved e:
{
Contributors = Contributors.Remove(@event.ContributorId);
Contributors = Contributors.Remove(e.ContributorId);
break;
}
protected void On(AppClientAttached @event)
case AppClientAttached e:
{
Clients = Clients.Add(@event.Id, @event.Secret);
Clients = Clients.Add(e.Id, e.Secret);
break;
}
protected void On(AppClientUpdated @event)
case AppClientUpdated e:
{
Clients = Clients.Update(@event.Id, @event.Role);
Clients = Clients.Update(e.Id, e.Role);
break;
}
protected void On(AppClientRenamed @event)
case AppClientRenamed e:
{
Clients = Clients.Rename(@event.Id, @event.Name);
Clients = Clients.Rename(e.Id, e.Name);
break;
}
protected void On(AppClientRevoked @event)
case AppClientRevoked e:
{
Clients = Clients.Revoke(@event.Id);
Clients = Clients.Revoke(e.Id);
break;
}
protected void On(AppWorkflowAdded @event)
case AppWorkflowAdded e:
{
Workflows = Workflows.Add(@event.WorkflowId, @event.Name);
Workflows = Workflows.Add(e.WorkflowId, e.Name);
break;
}
protected void On(AppWorkflowUpdated @event)
case AppWorkflowUpdated e:
{
Workflows = Workflows.Update(@event.WorkflowId, @event.Workflow);
Workflows = Workflows.Update(e.WorkflowId, e.Workflow);
break;
}
protected void On(AppWorkflowDeleted @event)
case AppWorkflowDeleted e:
{
Workflows = Workflows.Remove(@event.WorkflowId);
Workflows = Workflows.Remove(e.WorkflowId);
break;
}
protected void On(AppPatternAdded @event)
case AppPatternAdded e:
{
Patterns = Patterns.Add(@event.PatternId, @event.Name, @event.Pattern, @event.Message);
Patterns = Patterns.Add(e.PatternId, e.Name, e.Pattern, e.Message);
break;
}
protected void On(AppPatternDeleted @event)
case AppPatternDeleted e:
{
Patterns = Patterns.Remove(@event.PatternId);
Patterns = Patterns.Remove(e.PatternId);
break;
}
protected void On(AppPatternUpdated @event)
case AppPatternUpdated e:
{
Patterns = Patterns.Update(@event.PatternId, @event.Name, @event.Pattern, @event.Message);
Patterns = Patterns.Update(e.PatternId, e.Name, e.Pattern, e.Message);
break;
}
protected void On(AppRoleAdded @event)
case AppRoleAdded e:
{
Roles = Roles.Add(@event.Name);
Roles = Roles.Add(e.Name);
break;
}
protected void On(AppRoleDeleted @event)
case AppRoleDeleted e:
{
Roles = Roles.Remove(@event.Name);
Roles = Roles.Remove(e.Name);
break;
}
protected void On(AppRoleUpdated @event)
case AppRoleUpdated e:
{
Roles = Roles.Update(@event.Name, @event.Permissions.Prefix(Name));
Roles = Roles.Update(e.Name, e.Permissions.Prefix(Name));
break;
}
protected void On(AppLanguageAdded @event)
case AppLanguageAdded e:
{
LanguagesConfig = LanguagesConfig.Set(@event.Language);
LanguagesConfig = LanguagesConfig.Set(e.Language);
break;
}
protected void On(AppLanguageRemoved @event)
case AppLanguageRemoved e:
{
LanguagesConfig = LanguagesConfig.Remove(@event.Language);
LanguagesConfig = LanguagesConfig.Remove(e.Language);
break;
}
protected void On(AppLanguageUpdated @event)
case AppLanguageUpdated e:
{
LanguagesConfig = LanguagesConfig.Set(@event.Language, @event.IsOptional, @event.Fallback);
LanguagesConfig = LanguagesConfig.Set(e.Language, e.IsOptional, e.Fallback);
if (@event.IsMaster)
if (e.IsMaster)
{
LanguagesConfig = LanguagesConfig.MakeMaster(@event.Language);
LanguagesConfig = LanguagesConfig.MakeMaster(e.Language);
}
break;
}
protected void On(AppArchived @event)
case AppArchived _:
{
Plan = null;
IsArchived = true;
break;
}
}
}
public override AppState Apply(Envelope<IEvent> @event)
{
var payload = (SquidexEvent)@event.Payload;
return Clone().Update(payload, @event.Headers, r => r.DispatchAction(payload));
return Clone().Update(@event, (e, s) => s.ApplyEvent(e));
}
}
}

23
src/Squidex.Domain.Apps.Entities/Assets/AssetUsageTracker_EventHandling.cs

@ -8,7 +8,6 @@
using System;
using System.Threading.Tasks;
using Squidex.Domain.Apps.Events.Assets;
using Squidex.Infrastructure.Dispatching;
using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.Tasks;
using Squidex.Infrastructure.UsageTracking;
@ -39,22 +38,24 @@ namespace Squidex.Domain.Apps.Entities.Assets
public Task On(Envelope<IEvent> @event)
{
return this.DispatchActionAsync(@event.Payload, @event.Headers);
}
protected Task On(AssetCreated @event, EnvelopeHeaders headers)
switch (@event.Payload)
{
return UpdateSizeAsync(@event.AppId.Id, headers.Timestamp().ToDateTimeUtc().Date, @event.FileSize, 1);
case AssetCreated e:
return UpdateSizeAsync(e.AppId.Id, GetDate(@event), e.FileSize, 1);
case AssetUpdated e:
return UpdateSizeAsync(e.AppId.Id, GetDate(@event), e.FileSize, 0);
case AssetDeleted e:
return UpdateSizeAsync(e.AppId.Id, GetDate(@event), e.DeletedSize, -1);
}
protected Task On(AssetUpdated @event, EnvelopeHeaders headers)
{
return UpdateSizeAsync(@event.AppId.Id, headers.Timestamp().ToDateTimeUtc().Date, @event.FileSize, 0);
return TaskHelper.Done;
}
protected Task On(AssetDeleted @event, EnvelopeHeaders headers)
private static DateTime GetDate(Envelope<IEvent> @event)
{
return UpdateSizeAsync(@event.AppId.Id, headers.Timestamp().ToDateTimeUtc().Date, -@event.DeletedSize, -1);
return @event.Headers.Timestamp().ToDateTimeUtc().Date;
}
private Task UpdateSizeAsync(Guid appId, DateTime date, long size, long count)

1
src/Squidex.Domain.Apps.Entities/Assets/Guards/GuardAsset.cs

@ -7,6 +7,7 @@
using Squidex.Domain.Apps.Entities.Assets.Commands;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Entities.Assets.Guards
{

3
src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetQueryParser.cs

@ -18,6 +18,7 @@ using Squidex.Infrastructure.Log;
using Squidex.Infrastructure.Queries;
using Squidex.Infrastructure.Queries.Json;
using Squidex.Infrastructure.Queries.OData;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Entities.Assets.Queries
{
@ -50,7 +51,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries
if (!string.IsNullOrWhiteSpace(q?.JsonQuery))
{
result = ParseJson(q?.JsonQuery);
result = ParseJson(q.JsonQuery);
}
else if (!string.IsNullOrWhiteSpace(q?.ODataQuery))
{

56
src/Squidex.Domain.Apps.Entities/Assets/State/AssetState.cs

@ -9,10 +9,8 @@ using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Squidex.Domain.Apps.Core.ValidateContent;
using Squidex.Domain.Apps.Events;
using Squidex.Domain.Apps.Events.Assets;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Dispatching;
using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.Reflection;
@ -66,59 +64,71 @@ namespace Squidex.Domain.Apps.Entities.Assets.State
get { return Id; }
}
protected void On(AssetCreated @event)
public void ApplyEvent(IEvent @event)
{
SimpleMapper.Map(@event, this);
switch (@event)
{
case AssetCreated e:
{
SimpleMapper.Map(e, this);
FileName = @event.FileName;
FileName = e.FileName;
if (string.IsNullOrWhiteSpace(@event.Slug))
if (string.IsNullOrWhiteSpace(e.Slug))
{
Slug = @event.FileName.ToAssetSlug();
Slug = e.FileName.ToAssetSlug();
}
else
{
Slug = @event.Slug;
Slug = e.Slug;
}
TotalSize += @event.FileSize;
TotalSize += e.FileSize;
break;
}
protected void On(AssetUpdated @event)
case AssetUpdated e:
{
SimpleMapper.Map(@event, this);
SimpleMapper.Map(e, this);
TotalSize += @event.FileSize;
TotalSize += e.FileSize;
break;
}
protected void On(AssetAnnotated @event)
case AssetAnnotated e:
{
if (!string.IsNullOrWhiteSpace(@event.FileName))
if (!string.IsNullOrWhiteSpace(e.FileName))
{
FileName = @event.FileName;
FileName = e.FileName;
}
if (!string.IsNullOrWhiteSpace(@event.Slug))
if (!string.IsNullOrWhiteSpace(e.Slug))
{
Slug = @event.Slug;
Slug = e.Slug;
}
if (@event.Tags != null)
if (e.Tags != null)
{
Tags = @event.Tags;
Tags = e.Tags;
}
break;
}
protected void On(AssetDeleted @event)
case AssetDeleted _:
{
IsDeleted = true;
break;
}
}
}
public override AssetState Apply(Envelope<IEvent> @event)
{
var payload = (SquidexEvent)@event.Payload;
return Clone().Update(payload, @event.Headers, r => r.DispatchAction(payload));
return Clone().Update(@event, (e, s) => s.ApplyEvent(e));
}
}
}

5
src/Squidex.Domain.Apps.Entities/Backup/BackupHandlerWithStore.cs

@ -25,11 +25,6 @@ namespace Squidex.Domain.Apps.Entities.Backup
this.store = store;
}
protected Task RemoveSnapshotAsync<TState>(Guid id)
{
return store.RemoveSnapshotAsync<Guid, TState>(id);
}
protected async Task RebuildManyAsync(IEnumerable<Guid> ids, Func<Guid, Task> action)
{
foreach (var id in ids)

1
src/Squidex.Domain.Apps.Entities/Comments/Guards/GuardComments.cs

@ -11,6 +11,7 @@ using Squidex.Domain.Apps.Entities.Comments.Commands;
using Squidex.Domain.Apps.Events.Comments;
using Squidex.Infrastructure;
using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Entities.Comments.Guards
{

8
src/Squidex.Domain.Apps.Entities/Contents/ContentHistoryEventsCreator.cs

@ -9,8 +9,8 @@ using System.Threading.Tasks;
using Squidex.Domain.Apps.Entities.History;
using Squidex.Domain.Apps.Events;
using Squidex.Domain.Apps.Events.Contents;
using Squidex.Infrastructure;
using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.Reflection;
namespace Squidex.Domain.Apps.Entities.Contents
{
@ -55,17 +55,17 @@ namespace Squidex.Domain.Apps.Entities.Contents
if (@event.Payload is SchemaEvent schemaEvent)
{
result = result.AddParameter("Schema", schemaEvent.SchemaId.Name);
result = result.Param("Schema", schemaEvent.SchemaId.Name);
}
if (@event.Payload is ContentStatusChanged contentStatusChanged)
{
result = result.AddParameter("Status", contentStatusChanged.Status);
result = result.Param("Status", contentStatusChanged.Status);
}
if (@event.Payload is ContentStatusScheduled contentStatusScheduled)
{
result = result.AddParameter("Status", contentStatusScheduled.Status);
result = result.Param("Status", contentStatusScheduled.Status);
}
return Task.FromResult(result);

11
src/Squidex.Domain.Apps.Entities/Contents/GraphQL/CachingGraphQLService.cs

@ -14,6 +14,7 @@ using Microsoft.Extensions.Options;
using Squidex.Domain.Apps.Entities.Apps;
using Squidex.Domain.Apps.Entities.Assets;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Caching;
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
{
@ -58,22 +59,22 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
return result;
}
private async Task<(bool HasError, object Response)> QueryInternalAsync(GraphQLModel model, GraphQLExecutionContext ctx, GraphQLQuery query)
private static async Task<(bool HasError, object Response)> QueryInternalAsync(GraphQLModel model, GraphQLExecutionContext ctx, GraphQLQuery query)
{
if (string.IsNullOrWhiteSpace(query.Query))
{
return (false, new { data = new object() });
}
var result = await model.ExecuteAsync(ctx, query);
var (data, errors) = await model.ExecuteAsync(ctx, query);
if (result.Errors?.Any() == true)
if (errors?.Any() == true)
{
return (false, new { data = result.Data, errors = result.Errors });
return (false, new { data, errors });
}
else
{
return (false, new { data = result.Data });
return (false, new { data });
}
}

12
src/Squidex.Domain.Apps.Entities/Contents/GraphQL/GraphQLModel.cs

@ -145,18 +145,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
return assetType;
}
public IGraphType GetContentDataType(Guid schemaId)
{
var schema = schemasById.GetOrDefault(schemaId);
if (schema == null)
{
return null;
}
return contentDataTypes.GetOrAddNew(schema);
}
public IGraphType GetContentType(Guid schemaId)
{
var schema = schemasById.GetOrDefault(schemaId);

2
src/Squidex.Domain.Apps.Entities/Contents/GraphQL/IGraphModel.cs

@ -33,8 +33,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
IGraphType GetContentType(Guid schemaId);
IGraphType GetContentDataType(Guid schemaId);
(IGraphType ResolveType, ValueResolver Resolver) GetGraphType(ISchemaEntity schema, IField field, string fieldName);
}
}

8
src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Middlewares.cs

@ -19,7 +19,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
{
Guard.NotNull(log, nameof(log));
return new Func<FieldMiddlewareDelegate, FieldMiddlewareDelegate>(next =>
return next =>
{
return async context =>
{
@ -37,12 +37,12 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
throw;
}
};
});
};
}
public static Func<FieldMiddlewareDelegate, FieldMiddlewareDelegate> Errors()
{
return new Func<FieldMiddlewareDelegate, FieldMiddlewareDelegate>(next =>
return next =>
{
return async context =>
{
@ -55,7 +55,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
throw new ExecutionError(ex.Message);
}
};
});
};
}
}
}

1
src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/NestedGraphType.cs

@ -9,7 +9,6 @@ using GraphQL.Resolvers;
using GraphQL.Types;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Entities.Schemas;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Json.Objects;
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types

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

@ -95,7 +95,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
private (IGraphType ResolveType, ValueResolver Resolver) ResolveNested(IArrayField field)
{
var schemaFieldType = new ListGraphType(new NonNullGraphType(new NestedGraphType(model, schema, field, this.fieldName)));
var schemaFieldType = new ListGraphType(new NonNullGraphType(new NestedGraphType(model, schema, field, fieldName)));
return (schemaFieldType, NoopResolver);
}

1
src/Squidex.Domain.Apps.Entities/Contents/Guards/GuardContent.cs

@ -11,6 +11,7 @@ using Squidex.Domain.Apps.Core.Contents;
using Squidex.Domain.Apps.Entities.Contents.Commands;
using Squidex.Domain.Apps.Entities.Schemas;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Entities.Contents.Guards
{

2
src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentQueryParser.cs

@ -19,11 +19,13 @@ using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Entities.Apps;
using Squidex.Domain.Apps.Entities.Schemas;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Caching;
using Squidex.Infrastructure.Json;
using Squidex.Infrastructure.Log;
using Squidex.Infrastructure.Queries;
using Squidex.Infrastructure.Queries.Json;
using Squidex.Infrastructure.Queries.OData;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Entities.Contents.Queries
{

2
src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentQueryService.cs

@ -235,7 +235,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries
var assetUrls = context.AssetUrls();
if (assetUrls.Any() == true)
if (assetUrls.Any())
{
yield return FieldConverters.ResolveAssetUrls(assetUrls.ToList(), assetUrlGenerator);
}

62
src/Squidex.Domain.Apps.Entities/Contents/State/ContentState.cs

@ -8,10 +8,8 @@
using System;
using System.Runtime.Serialization;
using Squidex.Domain.Apps.Core.Contents;
using Squidex.Domain.Apps.Events;
using Squidex.Domain.Apps.Events.Contents;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Dispatching;
using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.Reflection;
@ -45,67 +43,89 @@ namespace Squidex.Domain.Apps.Entities.Contents.State
[DataMember]
public Status Status { get; set; }
protected void On(ContentCreated @event)
public void ApplyEvent(IEvent @event)
{
SimpleMapper.Map(@event, this);
switch (@event)
{
case ContentCreated e:
{
SimpleMapper.Map(e, this);
UpdateData(null, @event.Data, false);
UpdateData(null, e.Data, false);
break;
}
protected void On(ContentChangesPublished @event)
case ContentChangesPublished _:
{
ScheduleJob = null;
UpdateData(DataDraft, null, false);
break;
}
protected void On(ContentStatusChanged @event)
case ContentStatusChanged e:
{
ScheduleJob = null;
SimpleMapper.Map(@event, this);
SimpleMapper.Map(e, this);
if (@event.Status == Status.Published)
if (e.Status == Status.Published)
{
UpdateData(DataDraft, null, false);
}
break;
}
protected void On(ContentUpdated @event)
case ContentUpdated e:
{
UpdateData(@event.Data, @event.Data, false);
UpdateData(e.Data, e.Data, false);
break;
}
protected void On(ContentUpdateProposed @event)
case ContentUpdateProposed e:
{
UpdateData(null, @event.Data, true);
UpdateData(null, e.Data, true);
break;
}
protected void On(ContentChangesDiscarded @event)
case ContentChangesDiscarded _:
{
UpdateData(null, Data, false);
break;
}
protected void On(ContentSchedulingCancelled @event)
case ContentSchedulingCancelled _:
{
ScheduleJob = null;
break;
}
protected void On(ContentStatusScheduled @event)
case ContentStatusScheduled e:
{
ScheduleJob = ScheduleJob.Build(@event.Status, @event.Actor, @event.DueTime);
ScheduleJob = ScheduleJob.Build(e.Status, e.Actor, e.DueTime);
break;
}
protected void On(ContentDeleted @event)
case ContentDeleted _:
{
IsDeleted = true;
break;
}
}
}
public override ContentState Apply(Envelope<IEvent> @event)
{
var payload = (SquidexEvent)@event.Payload;
return Clone().Update(payload, @event.Headers, r => r.DispatchAction(payload));
return Clone().Update(@event, (e, s) => s.ApplyEvent(e));
}
private void UpdateData(NamedContentData data, NamedContentData dataDraft, bool isPending)

1
src/Squidex.Domain.Apps.Entities/Contents/Text/TextIndexerGrain.cs

@ -20,6 +20,7 @@ using Squidex.Domain.Apps.Core;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Assets;
using Squidex.Infrastructure.Orleans;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Entities.Contents.Text
{

8
src/Squidex.Domain.Apps.Entities/EntityMapper.cs

@ -13,8 +13,12 @@ namespace Squidex.Domain.Apps.Entities
{
public static class EntityMapper
{
public static T Update<T>(this T entity, SquidexEvent @event, EnvelopeHeaders headers, Action<T> updater = null) where T : IEntity
public static T Update<T>(this T entity, Envelope<IEvent> envelope, Action<SquidexEvent, T> updater = null) where T : IEntity
{
var @event = (SquidexEvent)envelope.Payload;
var headers = envelope.Headers;
SetId(entity, headers);
SetCreated(entity, headers);
SetCreatedBy(entity, @event);
@ -22,7 +26,7 @@ namespace Squidex.Domain.Apps.Entities
SetLastModifiedBy(entity, @event);
SetVersion(entity, headers);
updater?.Invoke(entity);
updater?.Invoke(@event, entity);
return entity;
}

9
src/Squidex.Domain.Apps.Entities/History/HistoryEvent.cs

@ -18,10 +18,10 @@ namespace Squidex.Domain.Apps.Entities.History
public Guid AppId { get; set; }
public RefToken Actor { get; set; }
public Instant Created { get; set; }
public RefToken Actor { get; set; }
public long Version { get; set; }
public string Channel { get; set; }
@ -44,9 +44,12 @@ namespace Squidex.Domain.Apps.Entities.History
Message = message;
}
public HistoryEvent AddParameter(string key, object value)
public HistoryEvent Param<T>(string key, T value)
{
if (!Equals(value, default(T)))
{
Parameters[key] = value.ToString();
}
return this;
}

8
src/Squidex.Domain.Apps.Entities/History/HistoryEventsCreatorBase.cs

@ -9,6 +9,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using Squidex.Infrastructure;
using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.Reflection;
namespace Squidex.Domain.Apps.Entities.History
{
@ -36,13 +37,6 @@ namespace Squidex.Domain.Apps.Entities.History
texts[typeNameRegistry.GetName<TEvent>()] = message;
}
protected void AddEventMessage(string type, string message)
{
Guard.NotNullOrEmpty(message, nameof(message));
texts[type] = message;
}
protected bool HasEventText(IEvent @event)
{
var message = typeNameRegistry.GetName(@event.GetType());

2
src/Squidex.Domain.Apps.Entities/History/Notifications/NotificationEmailSender.cs

@ -89,7 +89,7 @@ namespace Squidex.Domain.Apps.Entities.History.Notifications
.WriteProperty("reason", reason));
}
private string Format(string text, IUser assigner, IUser assignee, string uiUrl, string appName)
private static string Format(string text, IUser assigner, IUser assignee, string uiUrl, string appName)
{
text = text.Replace("$APP_NAME", appName);

1
src/Squidex.Domain.Apps.Entities/Rules/Guards/GuardRule.cs

@ -10,6 +10,7 @@ using System.Threading.Tasks;
using Squidex.Domain.Apps.Core.Rules;
using Squidex.Domain.Apps.Entities.Rules.Commands;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Entities.Rules.Guards
{

1
src/Squidex.Domain.Apps.Entities/Rules/Guards/RuleTriggerValidator.cs

@ -13,6 +13,7 @@ using Squidex.Domain.Apps.Core.Rules;
using Squidex.Domain.Apps.Core.Rules.Triggers;
using Squidex.Domain.Apps.Entities.Schemas;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Entities.Rules.Guards
{

44
src/Squidex.Domain.Apps.Entities/Rules/State/RuleState.cs

@ -8,10 +8,8 @@
using System;
using System.Runtime.Serialization;
using Squidex.Domain.Apps.Core.Rules;
using Squidex.Domain.Apps.Events;
using Squidex.Domain.Apps.Events.Rules;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Dispatching;
using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.States;
@ -31,46 +29,60 @@ namespace Squidex.Domain.Apps.Entities.Rules.State
[DataMember]
public bool IsDeleted { get; set; }
protected void On(RuleCreated @event)
public void ApplyEvent(IEvent @event)
{
RuleDef = new Rule(@event.Trigger, @event.Action);
switch (@event)
{
case RuleCreated e:
{
RuleDef = new Rule(e.Trigger, e.Action);
AppId = e.AppId;
AppId = @event.AppId;
break;
}
protected void On(RuleUpdated @event)
case RuleUpdated e:
{
if (@event.Trigger != null)
if (e.Trigger != null)
{
RuleDef = RuleDef.Update(@event.Trigger);
RuleDef = RuleDef.Update(e.Trigger);
}
if (@event.Action != null)
if (e.Action != null)
{
RuleDef = RuleDef.Update(@event.Action);
RuleDef = RuleDef.Update(e.Action);
}
break;
}
protected void On(RuleEnabled @event)
case RuleEnabled _:
{
RuleDef = RuleDef.Enable();
break;
}
protected void On(RuleDisabled @event)
case RuleDisabled _:
{
RuleDef = RuleDef.Disable();
break;
}
protected void On(RuleDeleted @event)
case RuleDeleted _:
{
IsDeleted = true;
break;
}
}
}
public override RuleState Apply(Envelope<IEvent> @event)
{
var payload = (SquidexEvent)@event.Payload;
return Clone().Update(payload, @event.Headers, r => r.DispatchAction(payload));
return Clone().Update(@event, (e, s) => s.ApplyEvent(e));
}
}
}

2
src/Squidex.Domain.Apps.Entities/Schemas/Guards/FieldPropertiesValidator.cs

@ -7,7 +7,7 @@
using System.Collections.Generic;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Entities.Schemas.Guards
{

1
src/Squidex.Domain.Apps.Entities/Schemas/Guards/GuardSchema.cs

@ -12,6 +12,7 @@ using Squidex.Domain.Apps.Core;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Entities.Schemas.Commands;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
#pragma warning disable IDE0060 // Remove unused parameter

1
src/Squidex.Domain.Apps.Entities/Schemas/Guards/GuardSchemaField.cs

@ -9,6 +9,7 @@ using Squidex.Domain.Apps.Core;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Entities.Schemas.Commands;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Entities.Schemas.Guards
{

6
src/Squidex.Domain.Apps.Entities/Schemas/SchemaHistoryEventsCreator.cs

@ -9,8 +9,8 @@ using System.Threading.Tasks;
using Squidex.Domain.Apps.Entities.History;
using Squidex.Domain.Apps.Events;
using Squidex.Domain.Apps.Events.Schemas;
using Squidex.Infrastructure;
using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.Reflection;
namespace Squidex.Domain.Apps.Entities.Schemas
{
@ -77,11 +77,11 @@ namespace Squidex.Domain.Apps.Entities.Schemas
{
var channel = $"schemas.{schemaEvent.SchemaId.Name}";
var result = ForEvent(@event.Payload, channel).AddParameter("Name", schemaEvent.SchemaId.Name);
var result = ForEvent(@event.Payload, channel).Param("Name", schemaEvent.SchemaId.Name);
if (schemaEvent is FieldEvent fieldEvent)
{
result.AddParameter("Field", fieldEvent.FieldId.Name);
result.Param("Field", fieldEvent.FieldId.Name);
}
return Task.FromResult(result);

124
src/Squidex.Domain.Apps.Entities/Schemas/State/SchemaState.cs

@ -9,10 +9,8 @@ using System;
using System.Runtime.Serialization;
using Squidex.Domain.Apps.Core;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Events;
using Squidex.Domain.Apps.Events.Schemas;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Dispatching;
using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.States;
@ -35,115 +33,153 @@ namespace Squidex.Domain.Apps.Entities.Schemas.State
[DataMember]
public Schema SchemaDef { get; set; }
protected void On(SchemaCreated @event)
public void ApplyEvent(IEvent @event)
{
SchemaDef = @event.Schema;
SchemaFieldsTotal = @event.Schema.MaxId();
switch (@event)
{
case SchemaCreated e:
{
SchemaDef = e.Schema;
SchemaFieldsTotal = e.Schema.MaxId();
AppId = e.AppId;
AppId = @event.AppId;
break;
}
protected void On(FieldAdded @event)
case FieldAdded e:
{
if (@event.ParentFieldId != null)
if (e.ParentFieldId != null)
{
var field = @event.Properties.CreateNestedField(@event.FieldId.Id, @event.Name);
var field = e.Properties.CreateNestedField(e.FieldId.Id, e.Name);
SchemaDef = SchemaDef.UpdateField(@event.ParentFieldId.Id, x => ((ArrayField)x).AddField(field));
SchemaDef = SchemaDef.UpdateField(e.ParentFieldId.Id, x => ((ArrayField)x).AddField(field));
}
else
{
var partitioning = Partitioning.FromString(@event.Partitioning);
var partitioning = Partitioning.FromString(e.Partitioning);
var field = @event.Properties.CreateRootField(@event.FieldId.Id, @event.Name, partitioning);
var field = e.Properties.CreateRootField(e.FieldId.Id, e.Name, partitioning);
SchemaDef = SchemaDef.DeleteField(@event.FieldId.Id);
SchemaDef = SchemaDef.DeleteField(e.FieldId.Id);
SchemaDef = SchemaDef.AddField(field);
}
SchemaFieldsTotal = Math.Max(SchemaFieldsTotal, @event.FieldId.Id);
SchemaFieldsTotal = Math.Max(SchemaFieldsTotal, e.FieldId.Id);
break;
}
protected void On(SchemaCategoryChanged @event)
case SchemaCategoryChanged e:
{
SchemaDef = SchemaDef.ChangeCategory(@event.Name);
SchemaDef = SchemaDef.ChangeCategory(e.Name);
break;
}
protected void On(SchemaPreviewUrlsConfigured @event)
case SchemaPreviewUrlsConfigured e:
{
SchemaDef = SchemaDef.ConfigurePreviewUrls(@event.PreviewUrls);
SchemaDef = SchemaDef.ConfigurePreviewUrls(e.PreviewUrls);
break;
}
protected void On(SchemaScriptsConfigured @event)
case SchemaScriptsConfigured e:
{
SchemaDef = SchemaDef.ConfigureScripts(@event.Scripts);
SchemaDef = SchemaDef.ConfigureScripts(e.Scripts);
break;
}
protected void On(SchemaPublished @event)
case SchemaPublished _:
{
SchemaDef = SchemaDef.Publish();
break;
}
protected void On(SchemaUnpublished @event)
case SchemaUnpublished _:
{
SchemaDef = SchemaDef.Unpublish();
break;
}
protected void On(SchemaUpdated @event)
case SchemaUpdated e:
{
SchemaDef = SchemaDef.Update(@event.Properties);
SchemaDef = SchemaDef.Update(e.Properties);
break;
}
protected void On(SchemaFieldsReordered @event)
case SchemaFieldsReordered e:
{
SchemaDef = SchemaDef.ReorderFields(@event.FieldIds, @event.ParentFieldId?.Id);
SchemaDef = SchemaDef.ReorderFields(e.FieldIds, e.ParentFieldId?.Id);
break;
}
protected void On(FieldUpdated @event)
case FieldUpdated e:
{
SchemaDef = SchemaDef.UpdateField(@event.FieldId.Id, @event.Properties, @event.ParentFieldId?.Id);
SchemaDef = SchemaDef.UpdateField(e.FieldId.Id, e.Properties, e.ParentFieldId?.Id);
break;
}
protected void On(FieldLocked @event)
case FieldLocked e:
{
SchemaDef = SchemaDef.LockField(@event.FieldId.Id, @event.ParentFieldId?.Id);
SchemaDef = SchemaDef.LockField(e.FieldId.Id, e.ParentFieldId?.Id);
break;
}
protected void On(FieldDisabled @event)
case FieldDisabled e:
{
SchemaDef = SchemaDef.DisableField(@event.FieldId.Id, @event.ParentFieldId?.Id);
SchemaDef = SchemaDef.DisableField(e.FieldId.Id, e.ParentFieldId?.Id);
break;
}
protected void On(FieldEnabled @event)
case FieldEnabled e:
{
SchemaDef = SchemaDef.EnableField(@event.FieldId.Id, @event.ParentFieldId?.Id);
SchemaDef = SchemaDef.EnableField(e.FieldId.Id, e.ParentFieldId?.Id);
break;
}
protected void On(FieldHidden @event)
case FieldHidden e:
{
SchemaDef = SchemaDef.HideField(@event.FieldId.Id, @event.ParentFieldId?.Id);
SchemaDef = SchemaDef.HideField(e.FieldId.Id, e.ParentFieldId?.Id);
break;
}
protected void On(FieldShown @event)
case FieldShown e:
{
SchemaDef = SchemaDef.ShowField(@event.FieldId.Id, @event.ParentFieldId?.Id);
SchemaDef = SchemaDef.ShowField(e.FieldId.Id, e.ParentFieldId?.Id);
break;
}
protected void On(FieldDeleted @event)
case FieldDeleted e:
{
SchemaDef = SchemaDef.DeleteField(@event.FieldId.Id, @event.ParentFieldId?.Id);
SchemaDef = SchemaDef.DeleteField(e.FieldId.Id, e.ParentFieldId?.Id);
break;
}
protected void On(SchemaDeleted @event)
case SchemaDeleted _:
{
IsDeleted = true;
break;
}
}
}
public override SchemaState Apply(Envelope<IEvent> @event)
{
var payload = (SquidexEvent)@event.Payload;
return Clone().Update(payload, @event.Headers, r => r.DispatchAction(payload));
return Clone().Update(@event, (e, s) => s.ApplyEvent(e));
}
}
}

2
src/Squidex.Domain.Apps.Events/Rules/RuleCreated.cs

@ -6,8 +6,8 @@
// ==========================================================================
using Squidex.Domain.Apps.Core.Rules;
using Squidex.Infrastructure;
using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.Migrations;
namespace Squidex.Domain.Apps.Events.Rules
{

2
src/Squidex.Domain.Apps.Events/Rules/RuleUpdated.cs

@ -6,8 +6,8 @@
// ==========================================================================
using Squidex.Domain.Apps.Core.Rules;
using Squidex.Infrastructure;
using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.Migrations;
namespace Squidex.Domain.Apps.Events.Rules
{

5
src/Squidex.Domain.Users.MongoDb/MongoUser.cs

@ -23,11 +23,6 @@ namespace Squidex.Domain.Users.MongoDb
public HashSet<string> Roles { get; set; } = new HashSet<string>();
internal IdentityUserToken<string> FindTokenAsync(string loginProvider, string name)
{
return Tokens.FirstOrDefault(x => x.LoginProvider == loginProvider && x.Name == name);
}
internal void AddLogin(UserLoginInfo login)
{
Logins.Add(new UserLoginInfo(login.LoginProvider, login.ProviderKey, login.ProviderDisplayName));

1
src/Squidex.Domain.Users/DefaultUserResolver.cs

@ -5,7 +5,6 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

1
src/Squidex.Domain.Users/UserManagerExtensions.cs

@ -12,6 +12,7 @@ using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
using Squidex.Shared.Identity;
namespace Squidex.Domain.Users

18
src/Squidex.Infrastructure.MongoDb/MongoDb/MongoRepositoryBase.cs

@ -86,24 +86,6 @@ namespace Squidex.Infrastructure.MongoDb
await SetupCollectionAsync(Collection);
}
public async Task<bool> DropCollectionIfExistsAsync(CancellationToken ct = default)
{
try
{
await mongoDatabase.DropCollectionAsync(CollectionName(), ct);
mongoCollection = CreateCollection();
await SetupCollectionAsync(Collection, ct);
return true;
}
catch
{
return false;
}
}
public async Task InitializeAsync(CancellationToken ct = default)
{
try

1
src/Squidex.Infrastructure.MongoDb/MongoDb/Queries/FilterBuilder.cs

@ -7,6 +7,7 @@
using MongoDB.Driver;
using Squidex.Infrastructure.Queries;
using Squidex.Infrastructure.Validation;
namespace Squidex.Infrastructure.MongoDb.Queries
{

2
src/Squidex.Infrastructure/Assets/FTPAssetStore.cs

@ -129,7 +129,7 @@ namespace Squidex.Infrastructure.Assets
{
if (!IsNotFound(ex))
{
throw ex;
throw;
}
}
}

2
src/Squidex.Infrastructure/CachingProviderBase.cs → src/Squidex.Infrastructure/Caching/CachingProviderBase.cs

@ -7,7 +7,7 @@
using Microsoft.Extensions.Caching.Memory;
namespace Squidex.Infrastructure
namespace Squidex.Infrastructure.Caching
{
public abstract class CachingProviderBase
{

14
src/Squidex.Infrastructure/Caching/IInvalidatingCache.cs

@ -1,14 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
namespace Squidex.Infrastructure.Caching
{
public interface IInvalidatingCache
{
void Invalidate(object key);
}
}

14
src/Squidex.Infrastructure/Caching/InvalidateMessage.cs

@ -1,14 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
namespace Squidex.Infrastructure.Caching
{
public sealed class InvalidateMessage
{
public string CacheKey { get; set; }
}
}

66
src/Squidex.Infrastructure/Caching/InvalidatingMemoryCache.cs

@ -1,66 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
using Microsoft.Extensions.Caching.Memory;
namespace Squidex.Infrastructure.Caching
{
public class InvalidatingMemoryCache : DisposableObjectBase, IMemoryCache, IInvalidatingCache
{
private readonly IMemoryCache inner;
private readonly IDisposable subscription;
private readonly IPubSub invalidator;
public InvalidatingMemoryCache(IMemoryCache inner, IPubSub invalidator)
{
Guard.NotNull(inner, nameof(inner));
Guard.NotNull(invalidator, nameof(invalidator));
this.inner = inner;
this.invalidator = invalidator;
subscription = invalidator.Subscribe<InvalidateMessage>(m =>
{
inner.Remove(m.CacheKey);
});
}
protected override void DisposeObject(bool disposing)
{
if (disposing)
{
subscription.Dispose();
inner.Dispose();
}
}
public ICacheEntry CreateEntry(object key)
{
return inner.CreateEntry(key);
}
public bool TryGetValue(object key, out object value)
{
return inner.TryGetValue(key, out value);
}
public void Remove(object key)
{
inner.Remove(key);
}
public void Invalidate(object key)
{
if (key is string stringKey)
{
invalidator.Publish(new InvalidateMessage { CacheKey = stringKey }, true);
}
}
}
}

21
src/Squidex.Infrastructure/Caching/InvalidatingMemoryCacheExtensions.cs

@ -1,21 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using Microsoft.Extensions.Caching.Memory;
namespace Squidex.Infrastructure.Caching
{
public static class InvalidatingMemoryCacheExtensions
{
public static void Invalidate(this IMemoryCache cache, object key)
{
var invalidatingCache = cache as IInvalidatingCache;
invalidatingCache?.Invalidate(key);
}
}
}

2
src/Squidex.Infrastructure/Caching/LRUCache.cs

@ -23,7 +23,7 @@ namespace Squidex.Infrastructure.Caching
this.capacity = capacity;
this.itemEvicted = itemEvicted ?? new Action<TKey, TValue>((key, value) => { });
this.itemEvicted = itemEvicted ?? ((key, value) => { });
}
public bool Set(TKey key, TValue value)

2
src/Squidex.Infrastructure/Collections/ArrayDictionary{TKey,TValue}.cs

@ -155,7 +155,7 @@ namespace Squidex.Infrastructure.Collections
return items.GetEnumerator();
}
private static IEnumerable<T2> GetEnumerable<T2>(T2[] array)
private static IEnumerable<T2> GetEnumerable<T2>(IEnumerable<T2> array)
{
return array;
}

72
src/Squidex.Infrastructure/Dispatching/ActionContextDispatcher.cs

@ -1,72 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
using System.Linq;
using System.Reflection;
#pragma warning disable IDE0033 // Use explicitly provided tuple name
namespace Squidex.Infrastructure.Dispatching
{
public static class ActionContextDispatcher<TTarget, TIn, TContext>
{
public delegate void ActionContextDelegate<in T>(TTarget target, T input, TContext context) where T : TIn;
public static readonly Func<TTarget, TIn, TContext, bool> On = CreateHandler();
public static Func<TTarget, TIn, TContext, bool> CreateHandler(string methodName = "On")
{
Guard.NotNullOrEmpty(methodName, nameof(methodName));
var handlers =
typeof(TTarget)
.GetMethods(
BindingFlags.Public |
BindingFlags.NonPublic |
BindingFlags.Instance)
.Where(m =>
m.HasMatchingName(methodName) &&
m.HasMatchingParameters<TIn, TContext>() &&
m.HasMatchingReturnType(typeof(void)))
.Select(m =>
{
var inputType = m.GetParameters()[0].ParameterType;
var handler =
typeof(ActionContextDispatcher<TTarget, TIn, TContext>)
.GetMethod(nameof(Factory),
BindingFlags.Static |
BindingFlags.NonPublic)
.MakeGenericMethod(inputType)
.Invoke(null, new object[] { m });
return (inputType, handler);
})
.ToDictionary(m => m.Item1, h => (ActionContextDelegate<TIn>)h.Item2);
return (target, input, context) =>
{
if (handlers.TryGetValue(input.GetType(), out var handler))
{
handler(target, input, context);
return true;
}
return false;
};
}
private static ActionContextDelegate<TIn> Factory<T>(MethodInfo methodInfo) where T : TIn
{
var handler = (ActionContextDelegate<T>)methodInfo.CreateDelegate(typeof(ActionContextDelegate<T>));
return (target, input, context) => handler(target, (T)input, context);
}
}
}

72
src/Squidex.Infrastructure/Dispatching/ActionDispatcher.cs

@ -1,72 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
using System.Linq;
using System.Reflection;
#pragma warning disable IDE0033 // Use explicitly provided tuple name
namespace Squidex.Infrastructure.Dispatching
{
public static class ActionDispatcher<TTarget, TIn>
{
public delegate void ActionDelegate<in T>(TTarget target, T input) where T : TIn;
public static readonly Func<TTarget, TIn, bool> On = CreateHandler();
public static Func<TTarget, TIn, bool> CreateHandler(string methodName = "On")
{
Guard.NotNullOrEmpty(methodName, nameof(methodName));
var handlers =
typeof(TTarget)
.GetMethods(
BindingFlags.Public |
BindingFlags.NonPublic |
BindingFlags.Instance)
.Where(m =>
m.HasMatchingName(methodName) &&
m.HasMatchingParameters<TIn>() &&
m.HasMatchingReturnType(typeof(void)))
.Select(m =>
{
var inputType = m.GetParameters()[0].ParameterType;
var handler =
typeof(ActionDispatcher<TTarget, TIn>)
.GetMethod(nameof(Factory),
BindingFlags.Static |
BindingFlags.NonPublic)
.MakeGenericMethod(inputType)
.Invoke(null, new object[] { m });
return (inputType, handler);
})
.ToDictionary(m => m.Item1, h => (ActionDelegate<TIn>)h.Item2);
return (target, input) =>
{
if (handlers.TryGetValue(input.GetType(), out var handler))
{
handler(target, input);
return true;
}
return false;
};
}
private static ActionDelegate<TIn> Factory<T>(MethodInfo methodInfo) where T : TIn
{
var handler = (ActionDelegate<T>)methodInfo.CreateDelegate(typeof(ActionDelegate<T>));
return (target, input) => handler(target, (T)input);
}
}
}

80
src/Squidex.Infrastructure/Dispatching/DispatchExtensions.cs

@ -1,80 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.Threading.Tasks;
namespace Squidex.Infrastructure.Dispatching
{
public static class DispatchExtensions
{
public static bool DispatchAction<TTarget, TIn>(this TTarget target, TIn input)
{
return ActionDispatcher<TTarget, TIn>.On(target, input);
}
public static bool DispatchAction<TTarget, TIn, TContext>(this TTarget target, TIn input, TContext context)
{
return ActionContextDispatcher<TTarget, TIn, TContext>.On(target, input, context);
}
public static async Task<bool> DispatchActionAsync<TTarget, TIn>(this TTarget target, TIn input)
{
var task = FuncDispatcher<TTarget, TIn, Task>.On(target, input);
if (task == null)
{
return false;
}
await task;
return true;
}
public static async Task<bool> DispatchActionAsync<TTarget, TIn, TContext>(this TTarget target, TIn input, TContext context)
{
var task = FuncContextDispatcher<TTarget, TIn, TContext, Task>.On(target, input, context);
if (task == null)
{
return false;
}
await task;
return true;
}
public static TOut DispatchFunc<TTarget, TIn, TOut>(this TTarget target, TIn input, TOut fallback)
{
var result = FuncDispatcher<TTarget, TIn, TOut>.On(target, input);
return Equals(result, default(TOut)) ? fallback : result;
}
public static TOut DispatchFunc<TTarget, TIn, TContext, TOut>(this TTarget target, TIn input, TContext context, TOut fallback)
{
var result = FuncContextDispatcher<TTarget, TIn, TContext, TOut>.On(target, input, context);
return Equals(result, default(TOut)) ? fallback : result;
}
public static Task<TOut> DispatchFuncAsync<TTarget, TIn, TOut>(this TTarget target, TIn input, TOut fallback)
{
var result = FuncDispatcher<TTarget, TIn, Task<TOut>>.On(target, input);
return result ?? Task.FromResult(fallback);
}
public static Task<TOut> DispatchFuncAsync<TTarget, TIn, TContext, TOut>(this TTarget target, TIn input, TContext context, TOut fallback)
{
var result = FuncContextDispatcher<TTarget, TIn, TContext, Task<TOut>>.On(target, input, context);
return result ?? Task.FromResult(fallback);
}
}
}

61
src/Squidex.Infrastructure/Dispatching/FuncContextDispatcher.cs

@ -1,61 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.Linq;
using System.Reflection;
#pragma warning disable IDE0033 // Use explicitly provided tuple name
namespace Squidex.Infrastructure.Dispatching
{
public static class FuncContextDispatcher<TTarget, TIn, TContext, TOut>
{
public delegate TOut FuncContextDelegate<in T>(TTarget target, T input, TContext context) where T : TIn;
public static readonly FuncContextDelegate<TIn> On = CreateHandler();
public static FuncContextDelegate<TIn> CreateHandler(string methodName = "On")
{
Guard.NotNullOrEmpty(methodName, nameof(methodName));
var handlers =
typeof(TTarget)
.GetMethods(
BindingFlags.Public |
BindingFlags.NonPublic |
BindingFlags.Instance)
.Where(m =>
m.HasMatchingName(methodName) &&
m.HasMatchingParameters<TIn, TContext>() &&
m.HasMatchingReturnType(typeof(TOut)))
.Select(m =>
{
var inputType = m.GetParameters()[0].ParameterType;
var handler =
typeof(FuncContextDispatcher<TTarget, TIn, TContext, TOut>)
.GetMethod(nameof(Factory),
BindingFlags.Static |
BindingFlags.NonPublic)
.MakeGenericMethod(inputType)
.Invoke(null, new object[] { m });
return (inputType, handler);
})
.ToDictionary(m => m.Item1, h => (FuncContextDelegate<TIn>)h.Item2);
return (target, input, context) => handlers.TryGetValue(input.GetType(), out var handler) ? handler(target, input, context) : default;
}
private static FuncContextDelegate<TIn> Factory<T>(MethodInfo methodInfo) where T : TIn
{
var handler = (FuncContextDelegate<T>)methodInfo.CreateDelegate(typeof(FuncContextDelegate<T>));
return (target, input, context) => handler(target, (T)input, context);
}
}
}

61
src/Squidex.Infrastructure/Dispatching/FuncDispatcher.cs

@ -1,61 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.Linq;
using System.Reflection;
#pragma warning disable IDE0033 // Use explicitly provided tuple name
namespace Squidex.Infrastructure.Dispatching
{
public static class FuncDispatcher<TTarget, TIn, TOut>
{
public delegate TOut FuncDelegate<in T>(TTarget target, T input) where T : TIn;
public static readonly FuncDelegate<TIn> On = CreateHandler();
public static FuncDelegate<TIn> CreateHandler(string methodName = "On")
{
Guard.NotNullOrEmpty(methodName, nameof(methodName));
var handlers =
typeof(TTarget)
.GetMethods(
BindingFlags.Public |
BindingFlags.NonPublic |
BindingFlags.Instance)
.Where(m =>
m.HasMatchingName(methodName) &&
m.HasMatchingParameters<TIn>() &&
m.HasMatchingReturnType(typeof(TOut)))
.Select(m =>
{
var inputType = m.GetParameters()[0].ParameterType;
var handler =
typeof(FuncDispatcher<TTarget, TIn, TOut>)
.GetMethod(nameof(Factory),
BindingFlags.Static |
BindingFlags.NonPublic)
.MakeGenericMethod(inputType)
.Invoke(null, new object[] { m });
return (inputType, handler);
})
.ToDictionary(m => m.Item1, h => (FuncDelegate<TIn>)h.Item2);
return (target, input) => handlers.TryGetValue(input.GetType(), out var handler) ? handler(target, input) : default;
}
private static FuncDelegate<TIn> Factory<T>(MethodInfo methodInfo) where T : TIn
{
var handler = (FuncDelegate<T>)methodInfo.CreateDelegate(typeof(FuncDelegate<T>));
return (target, input) => handler(target, (T)input);
}
}
}

39
src/Squidex.Infrastructure/Dispatching/Helper.cs

@ -1,39 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
using System.Reflection;
namespace Squidex.Infrastructure.Dispatching
{
internal static class Helper
{
public static bool HasMatchingName(this MethodInfo method, string name)
{
return string.Equals(method.Name, name, StringComparison.OrdinalIgnoreCase);
}
public static bool HasMatchingReturnType(this MethodInfo method, Type type)
{
return method.ReturnType == type;
}
public static bool HasMatchingParameters<TIn>(this MethodInfo method)
{
var parameters = method.GetParameters();
return parameters.Length == 1 && typeof(TIn).IsAssignableFrom(parameters[0].ParameterType);
}
public static bool HasMatchingParameters<TIn, TContext>(this MethodInfo method)
{
var parameters = method.GetParameters();
return parameters.Length == 2 && typeof(TIn).IsAssignableFrom(parameters[0].ParameterType) && parameters[1].ParameterType == typeof(TContext);
}
}
}

2
src/Squidex.Infrastructure/EventSourcing/DefaultEventDataFormatter.cs

@ -8,6 +8,8 @@
using System;
using System.Diagnostics;
using Squidex.Infrastructure.Json;
using Squidex.Infrastructure.Migrations;
using Squidex.Infrastructure.Reflection;
namespace Squidex.Infrastructure.EventSourcing
{

2
src/Squidex.Infrastructure/EventSourcing/Grains/EventConsumerGrain.cs

@ -12,7 +12,7 @@ using Orleans;
using Orleans.Concurrency;
using Squidex.Infrastructure.Log;
using Squidex.Infrastructure.Orleans;
using Squidex.Infrastructure.States;
using Squidex.Infrastructure.Reflection;
using Squidex.Infrastructure.Tasks;
namespace Squidex.Infrastructure.EventSourcing.Grains

2
src/Squidex.Infrastructure/EventSourcing/IEventEnricher.cs

@ -7,7 +7,7 @@
namespace Squidex.Infrastructure.EventSourcing
{
public interface IEventEnricher<T>
public interface IEventEnricher<in T>
{
void Enrich(Envelope<IEvent> @event, T id);
}

7
src/Squidex.Infrastructure/FileExtensions.cs

@ -64,11 +64,12 @@ namespace Squidex.Infrastructure
var d = (double)value;
var u = 0;
var s = 1024;
while ((d >= s || -d >= s) && u < Extensions.Length - 1)
const int multiplier = 1024;
while ((d >= multiplier || -d >= multiplier) && u < Extensions.Length - 1)
{
d /= s;
d /= multiplier;
u++;
}

1
src/Squidex.Infrastructure/Guard.cs

@ -11,6 +11,7 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using Squidex.Infrastructure.Validation;
namespace Squidex.Infrastructure
{

4
src/Squidex.Infrastructure/Http/DumpFormatter.cs

@ -17,12 +17,12 @@ namespace Squidex.Infrastructure.Http
{
public static string BuildDump(HttpRequestMessage request, HttpResponseMessage response, string responseBody)
{
return BuildDump(request, response, null, responseBody, TimeSpan.Zero, false);
return BuildDump(request, response, null, responseBody, TimeSpan.Zero);
}
public static string BuildDump(HttpRequestMessage request, HttpResponseMessage response, string requestBody, string responseBody)
{
return BuildDump(request, response, requestBody, responseBody, TimeSpan.Zero, false);
return BuildDump(request, response, requestBody, responseBody, TimeSpan.Zero);
}
public static string BuildDump(HttpRequestMessage request, HttpResponseMessage response, string requestBody, string responseBody, TimeSpan elapsed, bool isTimeout = false)

18
src/Squidex.Infrastructure/IPubSub.cs

@ -1,18 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
namespace Squidex.Infrastructure
{
public interface IPubSub
{
void Publish<T>(T value, bool notifySelf);
IDisposable Subscribe<T>(Action<T> handler);
}
}

41
src/Squidex.Infrastructure/InMemoryPubSub.cs

@ -1,41 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
using System.Reactive.Linq;
using System.Reactive.Subjects;
namespace Squidex.Infrastructure
{
public sealed class InMemoryPubSub : IPubSub
{
private readonly Subject<object> subject = new Subject<object>();
private readonly bool publishAlways;
public InMemoryPubSub()
{
}
public InMemoryPubSub(bool publishAlways)
{
this.publishAlways = publishAlways;
}
public void Publish<T>(T value, bool notifySelf)
{
if (notifySelf || publishAlways)
{
subject.OnNext(value);
}
}
public IDisposable Subscribe<T>(Action<T> handler)
{
return subject.Where(x => x is T).OfType<T>().Subscribe(handler);
}
}
}

1
src/Squidex.Infrastructure/Json/Newtonsoft/TypeNameSerializationBinder.cs

@ -7,6 +7,7 @@
using System;
using Newtonsoft.Json.Serialization;
using Squidex.Infrastructure.Reflection;
namespace Squidex.Infrastructure.Json.Newtonsoft
{

8
src/Squidex.Infrastructure/Json/Objects/JsonArray.cs

@ -6,6 +6,7 @@
// ==========================================================================
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
@ -23,10 +24,15 @@ namespace Squidex.Infrastructure.Json.Objects
}
internal JsonArray(params object[] values)
: base(values?.Select(JsonValue.Create).ToList())
: base(ToList(values))
{
}
private static List<IJsonValue> ToList(IEnumerable<object> values)
{
return values?.Select(JsonValue.Create).ToList() ?? new List<IJsonValue>();
}
protected override void InsertItem(int index, IJsonValue item)
{
base.InsertItem(index, item ?? JsonValue.Null);

2
src/Squidex.Infrastructure/Log/ProfilerSpan.cs

@ -12,9 +12,9 @@ namespace Squidex.Infrastructure.Log
{
public sealed class ProfilerSpan : IDisposable
{
private readonly ValueStopwatch watch = ValueStopwatch.StartNew();
private readonly ProfilerSession session;
private readonly string key;
private ValueStopwatch watch = ValueStopwatch.StartNew();
private List<IDisposable> hooks;
public string Key

2
src/Squidex.Infrastructure/IMigrated.cs → src/Squidex.Infrastructure/Migrations/IMigrated.cs

@ -5,7 +5,7 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
namespace Squidex.Infrastructure
namespace Squidex.Infrastructure.Migrations
{
public interface IMigrated<out T>
{

8
src/Squidex.Infrastructure/Migrations/Migrator.cs

@ -51,14 +51,14 @@ namespace Squidex.Infrastructure.Migrations
while (true)
{
var migrationStep = migrationPath.GetNext(version);
var (newVersion, migrations) = migrationPath.GetNext(version);
if (migrationStep.Migrations == null || !migrationStep.Migrations.Any())
if (migrations == null || !migrations.Any())
{
break;
}
foreach (var migration in migrationStep.Migrations)
foreach (var migration in migrations)
{
var name = migration.GetType().ToString();
@ -88,7 +88,7 @@ namespace Squidex.Infrastructure.Migrations
}
}
version = migrationStep.Version;
version = newVersion;
}
}
finally

2
src/Squidex.Infrastructure/IPAddressComparer.cs → src/Squidex.Infrastructure/Net/IPAddressComparer.cs

@ -8,7 +8,7 @@
using System.Collections.Generic;
using System.Net;
namespace Squidex.Infrastructure
namespace Squidex.Infrastructure.Net
{
public sealed class IPAddressComparer : IComparer<IPAddress>
{

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

Loading…
Cancel
Save