Beispiel #1
0
        public Assembly LoadModule(ModuleId moduleId)
        {
            if(serviceManager == null)
                throw new NullReferenceException("Init ModuleManager before loading any module");

            Assembly assembly;
            if (loadedModules.TryGetValue(moduleId, out assembly))
                return assembly;

            assembly = GetLoadedAssembly(moduleId);
            if (assembly == null)
            {
                var stream = ModuleLibrary.GetModuleStream(moduleId);
                assembly = Assembly.Load(stream.ReadAllBytes());
            }

            loadedModules.Add(moduleId, assembly);

            var module = CreateModuleObject(assembly);
            module.OnLoad(serviceManager);
            modules.Add(module);

            CheckGlobalServices(assembly);

            return assembly;
        }
Beispiel #2
0
        public System.IO.Stream GetModuleStream(ModuleId module)
        {
            IModuleLocation location;
            if(!moduleLocations.TryGetValue(module, out location))
                throw new Exception();

            return location.Stream;
        }
Beispiel #3
0
 IContextId IContextLoader.ReadContextId(Message data)
 {
     var moduleId = new ModuleId();
     moduleId.Read(data);
     return moduleId;
 }
Beispiel #4
0
        private static Assembly GetLoadedAssembly(ModuleId moduleId)
        {
            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                var assemblyModuleId = GetModuleId(assembly);
                if (moduleId.Equals(assemblyModuleId))
                    return assembly;
            }

            return null;
        }