internal void Init() { if (_eventController == null) { AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; _subRoutes = new Dictionary<sRoute, List<Core>>(); _myRoutes = new List<sRoute>(); _eventController = new EventController(); _loadedAssemblies = new Dictionary<string, Assembly>(); _processEvent = new delProcessEvent(_eventController.ProcessEvent); _processEventInChildren = new delProcessEvent(_ProcessEventInChildren); _logController = new LogController(); _logController.Start(); _messageController = new MessageController(); _messageController.Start(); } }
public void Startup() { List<string> loadedTypes = new List<string>(); AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Type parent = typeof(IStartup); List<IStartup> starts = new List<IStartup>(); foreach (Assembly ass in AppDomain.CurrentDomain.GetAssemblies()) { try { if (ass.GetName().Name != "mscorlib" && !ass.GetName().Name.StartsWith("System.") && ass.GetName().Name != "System" && !ass.GetName().Name.StartsWith("Microsoft")) { foreach (Type t in ass.GetTypes()) { if (!t.IsInterface) { if (new List<Type>(t.GetInterfaces()).Contains(parent)) { if (!loadedTypes.Contains(t.FullName)) { if (t.FullName == typeof(MessageController).FullName) _messageController = (MessageController)Activator.CreateInstance(t); else if (t.FullName == typeof(LogController).FullName) _logController = (LogController)Activator.CreateInstance(t); else starts.Add((IStartup)Activator.CreateInstance(t)); loadedTypes.Add(t.FullName); } } } } } } catch (Exception e) { if (e.Message != "The invoked member is not supported in a dynamic assembly." && e.Message != "Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.") { throw e; } } } if (_logController != null) _logController.Start(); if (_messageController != null) _messageController.Start(); foreach (IStartup start in starts) { try { start.Start(); } catch (Exception e) { System.Error(e); throw e; } } }