mirror of https://github.com/Squidex/squidex.git
22 changed files with 134 additions and 72 deletions
@ -0,0 +1,46 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using Squidex.Domain.Apps.Core.HandleRules.EnrichedEvents; |
||||
|
using Squidex.Domain.Apps.Core.Rules; |
||||
|
using Squidex.Infrastructure; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Core.HandleRules |
||||
|
{ |
||||
|
public static class RuleRegistry |
||||
|
{ |
||||
|
public static TypeNameRegistry MapRules(this TypeNameRegistry typeNameRegistry) |
||||
|
{ |
||||
|
var eventTypes = typeof(EnrichedEvent).Assembly.GetTypes().Where(x => typeof(EnrichedEvent).IsAssignableFrom(x) && !x.IsAbstract); |
||||
|
|
||||
|
var addedTypes = new HashSet<Type>(); |
||||
|
|
||||
|
foreach (var type in eventTypes) |
||||
|
{ |
||||
|
if (addedTypes.Add(type)) |
||||
|
{ |
||||
|
typeNameRegistry.Map(type, type.Name); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
var triggerTypes = typeof(RuleTrigger).Assembly.GetTypes().Where(x => typeof(RuleTrigger).IsAssignableFrom(x) && !x.IsAbstract); |
||||
|
|
||||
|
foreach (var type in triggerTypes) |
||||
|
{ |
||||
|
if (addedTypes.Add(type)) |
||||
|
{ |
||||
|
typeNameRegistry.Map(type, type.Name); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return typeNameRegistry; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
|
||||
|
namespace Squidex.Infrastructure |
||||
|
{ |
||||
|
public static class TypeNameBuilder |
||||
|
{ |
||||
|
public static string TypeName(this Type type, bool camelCase, params string[] suffixes) |
||||
|
{ |
||||
|
var typeName = type.Name; |
||||
|
|
||||
|
if (suffixes != null) |
||||
|
{ |
||||
|
foreach (var suffix in suffixes) |
||||
|
{ |
||||
|
if (typeName.EndsWith(suffix, StringComparison.Ordinal)) |
||||
|
{ |
||||
|
typeName = typeName.Substring(0, typeName.Length - suffix.Length); |
||||
|
|
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return camelCase ? typeName.ToCamelCase() : typeName; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue