|
@@ -1,4 +1,5 @@
|
|
|
-using Comal.Classes;
|
|
|
+using com.sun.jmx.mbeanserver;
|
|
|
+using Comal.Classes;
|
|
|
using Expressive;
|
|
|
using InABox.Core;
|
|
|
using InABox.Database;
|
|
@@ -87,53 +88,44 @@ public static class EventUtils
|
|
|
|
|
|
#region Event Types
|
|
|
|
|
|
- private static Dictionary<string, Type>? _eventTypes;
|
|
|
- private static Dictionary<string, Type>? _triggerTypes;
|
|
|
- private static Dictionary<string, Type>? _actionTypes;
|
|
|
-
|
|
|
private static Dictionary<Type, List<Type>>? _eventTriggerTypes;
|
|
|
private static Dictionary<Type, List<Type>>? _eventActionTypes;
|
|
|
+ private static List<Type>? _standardEventActionTypes;
|
|
|
|
|
|
- [MemberNotNullWhen(true, nameof(_eventTypes), nameof(_triggerTypes), nameof(_actionTypes), nameof(_eventTriggerTypes), nameof(_eventActionTypes))]
|
|
|
+ [MemberNotNullWhen(true, nameof(_eventTriggerTypes), nameof(_eventActionTypes), nameof(_standardEventActionTypes))]
|
|
|
private static bool _loadedTypes { get; set; }
|
|
|
|
|
|
- [MemberNotNull(nameof(_eventTypes), nameof(_triggerTypes), nameof(_actionTypes), nameof(_eventTriggerTypes), nameof(_eventActionTypes))]
|
|
|
+ [MemberNotNull(nameof(_eventTriggerTypes), nameof(_eventActionTypes), nameof(_standardEventActionTypes))]
|
|
|
private static void LoadTypes()
|
|
|
{
|
|
|
if (_loadedTypes) return;
|
|
|
|
|
|
_loadedTypes = true;
|
|
|
- _eventTypes = new();
|
|
|
- _triggerTypes = new();
|
|
|
- _actionTypes = new();
|
|
|
_eventTriggerTypes = new();
|
|
|
_eventActionTypes = new();
|
|
|
+ _standardEventActionTypes = new();
|
|
|
foreach(var type in CoreUtils.TypeList(x => true))
|
|
|
{
|
|
|
- if (type.HasInterface(typeof(IEvent<>)))
|
|
|
+ if (type.GetInterfaceDefinition(typeof(IEventTrigger<,>)) is Type eventTriggerInterface)
|
|
|
{
|
|
|
if (type.GetConstructor([]) is not null)
|
|
|
{
|
|
|
- _eventTypes[type.Name] = type;
|
|
|
+ var eventType = eventTriggerInterface.GenericTypeArguments[0];
|
|
|
+ eventType = eventType.IsGenericType ? eventType.GetGenericTypeDefinition() : eventType;
|
|
|
+ _eventTriggerTypes.GetValueOrAdd(eventType).Add(type);
|
|
|
}
|
|
|
}
|
|
|
- else if (type.GetInterfaceDefinition(typeof(IEventTrigger<,>)) is Type eventTriggerInterface)
|
|
|
+ else if(type.GetInterfaceDefinition(typeof(IStandardEventAction<>)) is Type standardEventAction)
|
|
|
{
|
|
|
if (type.GetConstructor([]) is not null)
|
|
|
{
|
|
|
- _triggerTypes[type.Name] = type;
|
|
|
-
|
|
|
- var eventType = eventTriggerInterface.GenericTypeArguments[0];
|
|
|
- eventType = eventType.IsGenericType ? eventType.GetGenericTypeDefinition() : eventType;
|
|
|
- _eventTriggerTypes.GetValueOrAdd(eventType).Add(type);
|
|
|
+ _standardEventActionTypes.Add(type);
|
|
|
}
|
|
|
}
|
|
|
else if (type.GetInterfaceDefinition(typeof(IEventAction<>)) is Type eventActionInterface)
|
|
|
{
|
|
|
if (type.GetConstructor([]) is not null)
|
|
|
{
|
|
|
- _actionTypes[type.Name] = type;
|
|
|
-
|
|
|
var eventType = eventActionInterface.GenericTypeArguments[0];
|
|
|
eventType = eventType.IsGenericType ? eventType.GetGenericTypeDefinition() : eventType;
|
|
|
_eventActionTypes.GetValueOrAdd(eventType).Add(type);
|
|
@@ -155,23 +147,10 @@ public static class EventUtils
|
|
|
eventType = eventType.IsGenericType ? eventType.GetGenericTypeDefinition() : eventType;
|
|
|
return _eventActionTypes.GetValueOrDefault(eventType) ?? Enumerable.Empty<Type>();
|
|
|
}
|
|
|
-
|
|
|
- public static Type GetEventType(string type)
|
|
|
- {
|
|
|
- LoadTypes();
|
|
|
- return _eventTypes[type]; // Force exception if not a valid type name.
|
|
|
- }
|
|
|
-
|
|
|
- public static Type GetTriggerType(string type)
|
|
|
- {
|
|
|
- LoadTypes();
|
|
|
- return _triggerTypes[type]; // Force exception if not a valid type name.
|
|
|
- }
|
|
|
-
|
|
|
- public static Type GetActionType(string type)
|
|
|
+ public static IEnumerable<Type> GetStandardEventActionTypes()
|
|
|
{
|
|
|
LoadTypes();
|
|
|
- return _actionTypes[type]; // Force exception if not a valid type name.
|
|
|
+ return _standardEventActionTypes;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
@@ -814,3 +793,11 @@ public interface IEventAction<TEvent> : IEventAction
|
|
|
where TEvent : IEvent
|
|
|
{
|
|
|
}
|
|
|
+
|
|
|
+/// <summary>
|
|
|
+/// Marks this event action as being applicable to any event type.
|
|
|
+/// </summary>
|
|
|
+public interface IStandardEventAction<TEvent> : IEventAction<TEvent>
|
|
|
+ where TEvent : IEvent
|
|
|
+{
|
|
|
+}
|