Ejemplo n.º 1
0
        public void Load(IModuleConfiguration config, string[] modulePackagesPaths, string hostBin, string extension,
                         params string[] moduleNames)
        {
            if (modulePackagesPaths == null)
            {
                return;
            }

            // only CSharp module needed - use fast path
            if (moduleNames.Length == 1 && DefaultCSharpModules.ContainsKey(moduleNames[0]) && (string.IsNullOrWhiteSpace(extension) || extension.Equals(DefaultCSharpExtension, StringComparison.InvariantCultureIgnoreCase)))
            {
                _logger.Debug("Only CSharp module is needed - will skip module lookup");
                var csharpModuleAssembly = DefaultCSharpModules[moduleNames[0]];
                var module = _assemblyUtility.LoadFile(Path.Combine(hostBin, csharpModuleAssembly));

                if (module != null)
                {
                    var moduleType = module.GetExportedTypes().FirstOrDefault(f => typeof(IModule).IsAssignableFrom(f));

                    if (moduleType != null)
                    {
                        var moduleInstance = Activator.CreateInstance(moduleType) as IModule;

                        if (moduleInstance != null)
                        {
                            _logger.Debug(String.Format("Initializing module: {0}", module.GetType().FullName));
                            moduleInstance.Initialize(config);
                            return;
                        }
                    }
                }
            }

            _logger.Debug("Loading modules from: " + String.Join(", ", modulePackagesPaths.Select(i => i)));
            var paths = new List <string>();

            AddPaths(modulePackagesPaths, hostBin, paths);

            var catalog   = CreateAggregateCatalog(paths);
            var container = new CompositionContainer(catalog);

            var lazyModules = GetLazyModules(container);

            InitializeModules(config, extension, moduleNames, lazyModules);
        }
Ejemplo n.º 2
0
        internal Assembly AssemblyResolve(object sender, ResolveEventArgs args)
        {
            AssemblyInfo assemblyInfo = null;
            var          name         = new AssemblyName(args.Name);

            if (_assemblyInfoMap.TryGetValue(name.Name, out assemblyInfo))
            {
                lock (assemblyInfo)
                {
                    if (assemblyInfo.Assembly == null)
                    {
                        assemblyInfo.Assembly = _assemblyUtility.LoadFile(assemblyInfo.Path);
                    }
                }
                _logger.DebugFormat("Resolving from: {0} to: {1}", args.Name, assemblyInfo.Assembly.GetName());
                return(assemblyInfo.Assembly);
            }
            return(null);
        }