public async Task Initialize()
        {
            try
            {
                var isScript = await IsScript();

                if (isScript)
                {
                    var scriptInitializer = new ScriptInitializer(_code, _options);
                    _assembly = await scriptInitializer.CreateAssembly(_options.CustomAssemblyLoadContext);
                }
                else
                {
                    var regularInitializer = new RegularInitializer(_code, _options);
                    _assembly = await regularInitializer.CreateAssembly(_options.CustomAssemblyLoadContext);
                }

                var options = new AssemblyPluginCatalogOptions {
                    PluginNameOptions = _options.PluginNameOptions
                };

                _catalog = new AssemblyPluginCatalog(_assembly, options);
                await _catalog.Initialize();

                IsInitialized = true;
            }
            catch (Exception e)
            {
                throw new InvalidCodeException($"Failed to initialize catalog with code: {Environment.NewLine}{_code}", e);
            }
        }
示例#2
0
        /// <inheritdoc />
        public async Task Initialize()
        {
            var foundFiles = new List <string>();

            foreach (var searchPattern in _options.SearchPatterns)
            {
                var dllFiles = Directory.GetFiles(_folderPath, searchPattern,
                                                  _options.IncludeSubfolders ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);

                foundFiles.AddRange(dllFiles);
            }

            foundFiles = foundFiles.Distinct().ToList();

            foreach (var assemblyPath in foundFiles)
            {
                // Assemblies are treated as readonly as long as possible
                var isPluginAssembly = IsPluginAssembly(assemblyPath);

                if (isPluginAssembly == false)
                {
                    continue;
                }

                var assemblyCatalogOptions = new AssemblyPluginCatalogOptions
                {
                    PluginLoadContextOptions = _options.PluginLoadContextOptions,
                    TypeFinderOptions        = _options.TypeFinderOptions,
                    PluginNameOptions        = _options.PluginNameOptions
                };

                // We are actually just delegating the responsibility from FolderPluginCatalog to AssemblyPluginCatalog.
                var assemblyCatalog = new AssemblyPluginCatalog(assemblyPath, assemblyCatalogOptions);
                await assemblyCatalog.Initialize();

                _catalogs.Add(assemblyCatalog);
            }

            IsInitialized = true;
        }
示例#3
0
        public async Task Initialize()
        {
            var nuGetDownloader         = new NuGetDownloader(_options.LoggerFactory());
            var pluginAssemblyFileNames = await nuGetDownloader.DownloadAsync(PackagesFolder, _packageName, _packageVersion, _includePrerelease, _packageFeed);

            foreach (var f in pluginAssemblyFileNames)
            {
                _pluginAssemblyFilePaths.Add(Path.Combine(PackagesFolder, f));
            }

            foreach (var pluginAssemblyFilePath in _pluginAssemblyFilePaths)
            {
                var options = new AssemblyPluginCatalogOptions {
                    TypeFinderOptions = _options.TypeFinderOptions
                };

                var assemblyCatalog = new AssemblyPluginCatalog(pluginAssemblyFilePath, options);
                await assemblyCatalog.Initialize();

                _pluginCatalogs.Add(assemblyCatalog);
            }

            IsInitialized = true;
        }