/// <summary> /// Subscribe event /// </summary> /// <param name="eventSource">Event source</param> /// <param name="repositoryEventHandler">Event handler</param> public static void Subscribe(Type eventSource, IRepositoryEventHandler repositoryEventHandler) { if (eventSource == null || repositoryEventHandler == null || repositoryEventHandler.ObjectType == null || repositoryEventHandler.HandlerRepositoryType == null) { return; } var eventSourceId = eventSource.GUID; var objectId = repositoryEventHandler.ObjectType.GUID; if (!EventWarehouses.TryGetValue(eventSourceId, out var sourceEvents) || sourceEvents.IsNullOrEmpty()) { sourceEvents = new Dictionary <Guid, Dictionary <EventType, List <IRepositoryEventHandler> > >(); EventWarehouses[eventSourceId] = sourceEvents; } if (!sourceEvents.TryGetValue(objectId, out var eventDict) || eventDict.IsNullOrEmpty()) { eventDict = new Dictionary <EventType, List <IRepositoryEventHandler> >(); sourceEvents[objectId] = eventDict; } if (!eventDict.TryGetValue(repositoryEventHandler.EventType, out var dataEvents) || dataEvents.IsNullOrEmpty()) { dataEvents = new List <IRepositoryEventHandler>(); eventDict[repositoryEventHandler.EventType] = dataEvents; } if (!dataEvents.Exists(c => c.HandlerRepositoryType == repositoryEventHandler.HandlerRepositoryType)) { dataEvents.Add(repositoryEventHandler); } }
/// <summary> /// subscribe event /// </summary> /// <param name="repositoryEventHandler">event handler</param> public static void Subscribe(Type eventSource, IRepositoryEventHandler repositoryEventHandler) { if (eventSource == null || repositoryEventHandler == null || repositoryEventHandler.ObjectType == null || repositoryEventHandler.HandlerRepositoryType == null) { return; } var eventSourceId = eventSource.GUID; var objectId = repositoryEventHandler.ObjectType.GUID; var sourceEvents = eventWarehouse.GetOrAdd(eventSourceId, new ConcurrentDictionary <Guid, ConcurrentDictionary <EventType, List <IRepositoryEventHandler> > >()); var eventDict = sourceEvents.GetOrAdd(objectId, new ConcurrentDictionary <EventType, List <IRepositoryEventHandler> >()); var dataEvents = eventDict.GetOrAdd(repositoryEventHandler.EventType, new List <IRepositoryEventHandler>()); if (!dataEvents.Exists(c => c.HandlerRepositoryType == repositoryEventHandler.HandlerRepositoryType)) { dataEvents.Add(repositoryEventHandler); } }