mirror of https://github.com/Squidex/squidex.git
committed by
GitHub
154 changed files with 1417 additions and 1112 deletions
@ -0,0 +1,26 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Microsoft.Extensions.DependencyInjection; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Backup |
|||
{ |
|||
public sealed class DefaultBackupHandlerFactory : IBackupHandlerFactory |
|||
{ |
|||
private readonly IServiceProvider serviceProvider; |
|||
|
|||
public DefaultBackupHandlerFactory(IServiceProvider serviceProvider) |
|||
{ |
|||
this.serviceProvider = serviceProvider; |
|||
} |
|||
|
|||
public IEnumerable<IBackupHandler> CreateMany() |
|||
{ |
|||
return serviceProvider.GetRequiredService<IEnumerable<IBackupHandler>>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Backup |
|||
{ |
|||
public interface IBackupHandlerFactory |
|||
{ |
|||
IEnumerable<IBackupHandler> CreateMany(); |
|||
} |
|||
} |
|||
@ -0,0 +1,56 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Squidex.Infrastructure.States; |
|||
|
|||
#pragma warning disable RECS0108 // Warns about static fields in generic types
|
|||
|
|||
namespace Squidex.Infrastructure.Commands |
|||
{ |
|||
public sealed class DefaultDomainObjectFactory : IDomainObjectFactory |
|||
{ |
|||
private readonly IServiceProvider serviceProvider; |
|||
|
|||
private static class DefaultFactory<T> |
|||
{ |
|||
private static readonly ObjectFactory ObjectFactory = |
|||
ActivatorUtilities.CreateFactory(typeof(T), new[] { typeof(DomainId) }); |
|||
|
|||
public static T Create(IServiceProvider serviceProvider, DomainId id) |
|||
{ |
|||
return (T)ObjectFactory(serviceProvider, new object[] { id }); |
|||
} |
|||
} |
|||
|
|||
private static class PersistenceFactory<T, TState> |
|||
{ |
|||
private static readonly ObjectFactory ObjectFactory = |
|||
ActivatorUtilities.CreateFactory(typeof(T), new[] { typeof(DomainId), typeof(IPersistenceFactory<TState>) }); |
|||
|
|||
public static T Create(IServiceProvider serviceProvider, DomainId id, IPersistenceFactory<TState> persistenceFactory) |
|||
{ |
|||
return (T)ObjectFactory(serviceProvider, new object[] { id, persistenceFactory }); |
|||
} |
|||
} |
|||
|
|||
public DefaultDomainObjectFactory(IServiceProvider serviceProvider) |
|||
{ |
|||
this.serviceProvider = serviceProvider; |
|||
} |
|||
|
|||
public T Create<T>(DomainId id) |
|||
{ |
|||
return DefaultFactory<T>.Create(serviceProvider, id); |
|||
} |
|||
|
|||
public T Create<T, TState>(DomainId id, IPersistenceFactory<TState> factory) |
|||
{ |
|||
return PersistenceFactory<T, TState>.Create(serviceProvider, id, factory); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Squidex.Infrastructure.States; |
|||
|
|||
namespace Squidex.Infrastructure.Commands |
|||
{ |
|||
public interface IDomainObjectFactory |
|||
{ |
|||
T Create<T>(DomainId id); |
|||
|
|||
T Create<T, TState>(DomainId id, IPersistenceFactory<TState> factory); |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
namespace Squidex.Infrastructure.EventSourcing |
|||
{ |
|||
public sealed class DefaultEventConsumerFactory : IEventConsumerFactory |
|||
{ |
|||
private readonly Dictionary<string, IEventConsumer> eventConsumers; |
|||
|
|||
public DefaultEventConsumerFactory(IEnumerable<IEventConsumer> eventConsumers) |
|||
{ |
|||
this.eventConsumers = eventConsumers.ToDictionary(x => x.Name); |
|||
} |
|||
|
|||
public IEventConsumer Create(string name) |
|||
{ |
|||
Guard.NotNullOrEmpty(name); |
|||
|
|||
if (!eventConsumers.TryGetValue(name, out var eventConsumer)) |
|||
{ |
|||
throw new ArgumentException($"Cannot find event consuemr with name '{name}'", nameof(name)); |
|||
} |
|||
|
|||
return eventConsumer; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
namespace Squidex.Infrastructure.EventSourcing |
|||
{ |
|||
public interface IEventConsumerFactory |
|||
{ |
|||
IEventConsumer Create(string name); |
|||
} |
|||
} |
|||
@ -1,50 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Orleans; |
|||
using Orleans.Core; |
|||
using Orleans.Runtime; |
|||
|
|||
namespace Squidex.Infrastructure.Orleans |
|||
{ |
|||
public abstract class GrainOfString : GrainBase |
|||
{ |
|||
public string Key { get; private set; } |
|||
|
|||
protected GrainOfString() |
|||
{ |
|||
} |
|||
|
|||
protected GrainOfString(IGrainIdentity identity, IGrainRuntime runtime) |
|||
: base(identity, runtime) |
|||
{ |
|||
} |
|||
|
|||
public sealed override Task OnActivateAsync() |
|||
{ |
|||
return ActivateAsync(this.GetPrimaryKeyString()); |
|||
} |
|||
|
|||
public async Task ActivateAsync(string key) |
|||
{ |
|||
Key = key; |
|||
|
|||
await OnLoadAsync(key); |
|||
await OnActivateAsync(key); |
|||
} |
|||
|
|||
protected virtual Task OnLoadAsync(string key) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
protected virtual Task OnActivateAsync(string key) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
} |
|||
@ -1,34 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Squidex.Infrastructure.Json; |
|||
|
|||
#pragma warning disable SA1401 // Fields must be private
|
|||
#pragma warning disable CA2211 // Non-constant fields should not be visible
|
|||
|
|||
namespace Squidex.Infrastructure.Orleans |
|||
{ |
|||
public static class J |
|||
{ |
|||
public static IJsonSerializer DefaultSerializer; |
|||
|
|||
public static J<T> AsJ<T>(this T value) |
|||
{ |
|||
return new J<T>(value); |
|||
} |
|||
|
|||
public static J<T> Of<T>(T value) |
|||
{ |
|||
return value; |
|||
} |
|||
|
|||
public static Task<J<T>> AsTask<T>(T value) |
|||
{ |
|||
return Task.FromResult<J<T>>(value); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Orleans.Serialization; |
|||
using Squidex.Infrastructure.Json; |
|||
|
|||
namespace Squidex.Infrastructure.Orleans |
|||
{ |
|||
public sealed class JsonSerializer : IExternalSerializer |
|||
{ |
|||
private readonly IJsonSerializer jsonSerializer; |
|||
|
|||
public JsonSerializer(IJsonSerializer jsonSerializer) |
|||
{ |
|||
this.jsonSerializer = jsonSerializer; |
|||
} |
|||
|
|||
public bool IsSupportedType(Type itemType) |
|||
{ |
|||
return itemType.Namespace?.StartsWith("Squidex", StringComparison.OrdinalIgnoreCase) == true; |
|||
} |
|||
|
|||
public object DeepCopy(object source, ICopyContext context) |
|||
{ |
|||
return source; |
|||
} |
|||
|
|||
public object Deserialize(Type expectedType, IDeserializationContext context) |
|||
{ |
|||
var stream = new StreamReaderWrapper(context.StreamReader); |
|||
|
|||
return jsonSerializer.Deserialize<object>(stream, expectedType); |
|||
} |
|||
|
|||
public void Serialize(object item, ISerializationContext context, Type expectedType) |
|||
{ |
|||
var stream = new StreamWriterWrapper(context.StreamWriter); |
|||
|
|||
jsonSerializer.Serialize(item, stream); |
|||
} |
|||
} |
|||
} |
|||
@ -1,82 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Orleans.CodeGeneration; |
|||
using Orleans.Concurrency; |
|||
using Orleans.Serialization; |
|||
using Squidex.Infrastructure.Json; |
|||
|
|||
#pragma warning disable IDE0060 // Remove unused parameter
|
|||
|
|||
namespace Squidex.Infrastructure.Orleans |
|||
{ |
|||
[Immutable] |
|||
public readonly struct J<T> |
|||
{ |
|||
public T Value { get; } |
|||
|
|||
public J(T value) |
|||
{ |
|||
Value = value; |
|||
} |
|||
|
|||
public static implicit operator T(J<T> value) |
|||
{ |
|||
return value.Value; |
|||
} |
|||
|
|||
public static implicit operator J<T>(T d) |
|||
{ |
|||
return new J<T>(d); |
|||
} |
|||
|
|||
public override string ToString() |
|||
{ |
|||
return Value?.ToString() ?? string.Empty; |
|||
} |
|||
|
|||
public static Task<J<T>> AsTask(T value) |
|||
{ |
|||
return Task.FromResult<J<T>>(value); |
|||
} |
|||
|
|||
[CopierMethod] |
|||
public static object? Copy(object? input, ICopyContext? context) |
|||
{ |
|||
return input; |
|||
} |
|||
|
|||
[SerializerMethod] |
|||
public static void Serialize(object? input, ISerializationContext context, Type? expected) |
|||
{ |
|||
var stream = new StreamWriterWrapper(context.StreamWriter); |
|||
|
|||
GetSerializer(context).Serialize(input, stream); |
|||
} |
|||
|
|||
[DeserializerMethod] |
|||
public static object? Deserialize(Type expected, IDeserializationContext context) |
|||
{ |
|||
var stream = new StreamReaderWrapper(context.StreamReader); |
|||
|
|||
return GetSerializer(context).Deserialize<object>(stream, expected); |
|||
} |
|||
|
|||
private static IJsonSerializer GetSerializer(ISerializerContext context) |
|||
{ |
|||
try |
|||
{ |
|||
return context?.ServiceProvider?.GetRequiredService<IJsonSerializer>() ?? J.DefaultSerializer; |
|||
} |
|||
catch |
|||
{ |
|||
return J.DefaultSerializer; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue