Пример #1
0
        /// <summary>
        /// Called by infrastructure to automatically build filters from attributes on content types
        /// </summary>
        /// <param name="ehd">Event data when called via an event being raised after the repository is built</param>
        /// <returns>Returns null (needed to have signature of an event processor)</returns>
        public object BuildFilters(EventHubData ehd)
        {
            // Get filters on summary types
            foreach (Type t in ContentTypeHierarchy.SummaryBaseTypes.Keys.Concat(typeof(Summary)))
            {
                foreach (PropertyInfo pi in t.GetProperties(BindingFlags.DeclaredOnly |
                                                            BindingFlags.Public |
                                                            BindingFlags.Instance)) // just the properties declared in this class, not any base class
                {
                    var lfa = pi.GetCustomAttribute <FieldFilterAttribute>();
                    if (lfa != null)
                    {
                        Filters.Add(FieldFilter.Create(lfa, pi));
                    }
                }
            }

            // Get filters on container types
            foreach (Type t in ContentTypeHierarchy.AllContentTypes.Select(ct => Collator.Instance.ContainerType(ct)).Distinct())
            {
                foreach (PropertyInfo pi in t.GetProperties())
                {
                    var lfa = pi.GetCustomAttribute <FieldFilterAttribute>();
                    if (lfa != null)
                    {
                        Filters.Add(FieldFilter.Create(lfa, pi));
                    }
                }
            }

            // Get filters on container extension types
            foreach (Type extT in CompositeTypeManager.Instance.ExtensionTypes)
            {
                Type baseT = extT.BaseType;
                foreach (PropertyInfo pi in extT.GetProperties(BindingFlags.DeclaredOnly |
                                                               BindingFlags.Public |
                                                               BindingFlags.Instance))
                {
                    var lfa = pi.GetCustomAttribute <FieldFilterAttribute>();
                    if (lfa != null)
                    {
                        PropertyInfo mappedPi = CompositeTypeManager.Instance.ExtendedTypes[baseT]
                                                .GetProperty(pi.Name);
                        Filters.Add(FieldFilter.Create(lfa, mappedPi));
                    }
                }
            }

            return(null);
        }
Пример #2
0
        /// <summary>
        /// Raise an event with event data for processing
        /// </summary>
        /// <typeparam name="TEventData">The type of the event data</typeparam>
        /// <param name="eventName">The name of the event being raised</param>
        /// <param name="sender">The sender of the event</param>
        /// <param name="eventData">The data which will be processed by all relevant processors</param>
        /// <returns>The event data after all processing</returns>
        public EventHubData ProcessEvent(string eventName, object sender, object eventData)
        {
            EventHubData data = new EventHubData
            {
                EventName = eventName,
                Sender    = sender,
                Data      = eventData
            };

            string leastSuperEvent = LeastSuperEvent(data.EventName);

            if (leastSuperEvent == null)
            {
                return(data);
            }

            foreach (var proc in Processors[leastSuperEvent])
            {
                data.Data = proc.Processor(data);
            }

            return(data);
        }