mirror of https://github.com/Squidex/squidex.git
Browse Source
* Remove pubsub * Removed unused code * Dispatch removed. * Build fixed.pull/414/head
committed by
GitHub
239 changed files with 783 additions and 2105 deletions
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -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,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,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); |
|||
} |
|||
} |
|||
@ -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; } |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue