/// <summary>
        /// publis query event
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="eventSource">event source</param>
        /// <param name="datas">datas</param>
        /// <param name="callback">callback</param>
        public static void PublishQuery <T>(Type eventSource, IEnumerable <T> datas, RepositoryEventCallback callback = null)
        {
            if (datas.IsNullOrEmpty())
            {
                return;
            }
            var eventHandlers = GetEventHandlers(eventSource, EventType.QueryData, typeof(T));

            if (eventHandlers.IsNullOrEmpty())
            {
                callback?.Invoke(new QueryEventResult <T>()
                {
                    Datas = datas.ToList()
                });
                return;
            }
            var eventDatas = datas;

            foreach (var handler in eventHandlers)
            {
                QueryEventHandler <T> eventHandler = handler as QueryEventHandler <T>;
                if (eventHandler == null)
                {
                    continue;
                }
                eventDatas = eventHandler.Execute(eventDatas);
            }
            callback?.Invoke(new QueryEventResult <T>()
            {
                Datas = eventDatas.ToList()
            });
        }
Beispiel #2
0
        /// <summary>
        /// Publis query event
        /// </summary>
        /// <typeparam name="TObject">Data type</typeparam>
        /// <param name="eventSource">Event source</param>
        /// <param name="datas">Datas</param>
        /// <param name="query">Query</param>
        /// <param name="callback">Callback</param>
        public static void PublishQuery <TObject>(Type eventSource, IEnumerable <TObject> datas, IQuery query, RepositoryEventCallback callback = null)
        {
            var eventHandlers = GetEventHandlers(eventSource, EventType.QueryData, typeof(TObject));
            var eventDatas    = datas;

            if (!eventHandlers.IsNullOrEmpty())
            {
                foreach (var handler in eventHandlers)
                {
                    QueryEventHandler <TObject> eventHandler = handler as QueryEventHandler <TObject>;
                    if (eventHandler == null)
                    {
                        continue;
                    }
                    eventDatas = eventHandler.Execute(eventDatas);
                }
            }
            callback?.Invoke(new QueryEventResult <TObject>()
            {
                Datas = eventDatas?.ToList() ?? new List <TObject>(0)
            });
        }