/* * Loops through all MethodInfo objects given, and adds them to the associated dictionary with type as key, * if they have Active Event attributes declared */ private void AddActiveEventsForType( Type type, MethodInfo[] methods, ActiveEventTypes activeEventTypes) { // Looping through all MethodInfo from type we currently are iterating foreach (var idxMethod in methods) { // Checking to see if current MethodInfo has our Active Event attribute, and if it does, we check if it has // the right signature, before we add it to our list of Active Event sinks var atrs = idxMethod.GetCustomAttributes(typeof(ActiveEventAttribute), true) as ActiveEventAttribute[]; if (atrs != null && atrs.Length > 0) { // Checking if Active Event has a valid signature VerifyActiveEventSignature(idxMethod); // Looping through each Active Event attribute for method foreach (var idxAtr in atrs) { // Adding currently iterated Active Event attribute activeEventTypes.AddActiveEvent(type, idxAtr, idxMethod); } } } }
/* * Creates a new application context. * This must be done through the Loader class, hence the constructor is internal. */ internal ApplicationContext(ActiveEventTypes instanceHandlerTypes, ActiveEventTypes staticHandlerTypes, ContextTicket ticket) { _ticket = ticket; // Each type that can handle instance Active Events neds to be stored, such that we can later register instance listeners, // according to their type. _instanceHandlerTypes = instanceHandlerTypes; // However, the static event handlers, are processed when we create our application context, and not stored for later. // Which means, you can register instance listeners on the ApplicationContext object, but if you register new assemblies through // your Loader singletone instance, these will not affect existing ApplicationContext instances. // While registering listener instances for a single ApplicationContext instance, will only affect that single context, and not // any other contexts. InitializeApplicationContext(staticHandlerTypes); }
/* * Initializes our ApplicationContext instance. */ void InitializeApplicationContext(ActiveEventTypes staticEventTypes) { // Looping through each Type in Active Events given. foreach (var idxType in staticEventTypes.Keys) { // Looping through each ActiveEvent in Type. foreach (var idxAVTypeEvent in staticEventTypes[idxType]) { // Registering Active Event as a static Active Event handler. _registeredActiveEvents.AddEventMethod(idxAVTypeEvent.Item1, idxAVTypeEvent.Item2); } } // Raising "initialize" Application Context Active Event, in case there are any listeners being interested in such things. RaiseEvent(".p5.core.initialize-application-context"); }