Пример #1
0
        public Event CreateEvent(EventInformation eventInfo)
        {
            ISpecificEventFactory specificFactory = null;
            XmlElement            eventData       = null;

            if (eventInfo.Type == EventType.FunctionCall)
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(eventInfo.RawData);
                eventData = doc.DocumentElement;

                string fullFunctionName = eventData.SelectSingleNode("/event/name").InnerText.Trim();
                string functionName     = fullFunctionName.Split(new string[] { "::" }, StringSplitOptions.None)[1];
                m_funcCallFactories.TryGetValue(functionName, out specificFactory);
            }

            if (specificFactory != null)
            {
                return(specificFactory.CreateEvent(eventInfo, eventData));
            }
            else
            {
                return(new Event(eventInfo));
            }
        }
Пример #2
0
        public EventFactory()
        {
            Assembly asm = Assembly.GetExecutingAssembly();

            foreach (Type t in asm.GetTypes())
            {
                object[] attrs = t.GetCustomAttributes(typeof(FunctionCallEventFactoryAttribute), true);
                if (attrs.Length == 0)
                {
                    continue;
                }
                FunctionCallEventFactoryAttribute attr = attrs[0] as FunctionCallEventFactoryAttribute;
                ConstructorInfo[]     ctors            = t.GetConstructors();
                ISpecificEventFactory eventFactory     = ctors[0].Invoke(new object[] { }) as ISpecificEventFactory;
                m_funcCallFactories[attr.FunctionName] = eventFactory;
            }
        }