mirror of https://github.com/abpframework/abp.git
19 changed files with 208 additions and 49 deletions
@ -0,0 +1,15 @@ |
|||
namespace Volo.Abp.Domain.Entities.Events.Distributed |
|||
{ |
|||
public class AbpDistributedEntityEventOptions |
|||
{ |
|||
public IAutoEntityDistributedEventSelectorList AutoEventSelectors { get; } |
|||
|
|||
public EtoMappingDictionary EtoMappings { get; set; } |
|||
|
|||
public AbpDistributedEntityEventOptions() |
|||
{ |
|||
AutoEventSelectors = new AutoEntityDistributedEventSelectorList(); |
|||
EtoMappings = new EtoMappingDictionary(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.Domain.Entities.Events.Distributed |
|||
{ |
|||
public class AutoEntityDistributedEventSelectorList : List<NamedTypeSelector>, IAutoEntityDistributedEventSelectorList |
|||
{ |
|||
public bool RemoveByName(string name) |
|||
{ |
|||
return RemoveAll(s => s.Name == name) > 0; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,78 @@ |
|||
using System; |
|||
using System.Linq; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.Domain.Entities.Events.Distributed |
|||
{ |
|||
public static class AutoEntityDistributedEventSelectorListExtensions |
|||
{ |
|||
public const string AllEntitiesSelectorName = "All"; |
|||
|
|||
public static void AddNamespace([NotNull] this IAutoEntityDistributedEventSelectorList selectors, [NotNull] string namespaceName) |
|||
{ |
|||
Check.NotNull(selectors, nameof(selectors)); |
|||
|
|||
var selectorName = "Namespace:" + namespaceName; |
|||
if (selectors.Any(s => s.Name == selectorName)) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
selectors.Add( |
|||
new NamedTypeSelector( |
|||
selectorName, |
|||
t => t.FullName?.StartsWith(namespaceName) ?? false |
|||
) |
|||
); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Adds a specific entity type and the types derived from that entity type.
|
|||
/// </summary>
|
|||
/// <typeparam name="TEntity">Type of the entity</typeparam>
|
|||
public static void Add<TEntity>([NotNull] this IAutoEntityDistributedEventSelectorList selectors) |
|||
where TEntity : IEntity |
|||
{ |
|||
Check.NotNull(selectors, nameof(selectors)); |
|||
|
|||
var selectorName = "Entity:" + typeof(TEntity).FullName; |
|||
if (selectors.Any(s => s.Name == selectorName)) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
selectors.Add( |
|||
new NamedTypeSelector( |
|||
selectorName, |
|||
t => typeof(TEntity).IsAssignableFrom(t) |
|||
) |
|||
); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Adds all entity types.
|
|||
/// </summary>
|
|||
public static void AddAll([NotNull] this IAutoEntityDistributedEventSelectorList selectors) |
|||
{ |
|||
Check.NotNull(selectors, nameof(selectors)); |
|||
|
|||
if (selectors.Any(s => s.Name == AllEntitiesSelectorName)) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
selectors.Add( |
|||
new NamedTypeSelector( |
|||
AllEntitiesSelectorName, |
|||
t => typeof(IEntity).IsAssignableFrom(t) |
|||
) |
|||
); |
|||
} |
|||
|
|||
public static bool IsMatch([NotNull] this IAutoEntityDistributedEventSelectorList selectors, Type entityType) |
|||
{ |
|||
Check.NotNull(selectors, nameof(selectors)); |
|||
return selectors.Any(s => s.Predicate(entityType)); |
|||
} |
|||
} |
|||
} |
|||
@ -1,7 +1,8 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
|
|||
namespace Volo.Abp.EventBus.Distributed |
|||
namespace Volo.Abp.Domain.Entities.Events.Distributed |
|||
{ |
|||
public class EtoMappingDictionary : Dictionary<Type, EtoMappingDictionaryItem> |
|||
{ |
|||
@ -1,6 +1,6 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.EventBus.Distributed |
|||
namespace Volo.Abp.Domain.Entities.Events.Distributed |
|||
{ |
|||
public class EtoMappingDictionaryItem |
|||
{ |
|||
@ -0,0 +1,9 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.Domain.Entities.Events.Distributed |
|||
{ |
|||
public interface IAutoEntityDistributedEventSelectorList : IList<NamedTypeSelector> |
|||
{ |
|||
bool RemoveByName(string name); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue