示例#1
0
        public async Task Initialize()
        {
            try
            {
                var isScript = await IsScript();

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

                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
        public async Task Initialize()
        {
            try
            {
                var isScript = await IsScript();

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

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

                if (_options.Tags?.Any() == true)
                {
                    assemblyCatalogOptions.TypeFinderOptions = new TypeFinderOptions()
                    {
                        TypeFinderCriterias = new List <TypeFinderCriteria>()
                        {
                            new TypeFinderCriteria()
                            {
                                Query = (context, type) => true,
                                Tags  = _options.Tags
                            }
                        }
                    };
                }

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

                IsInitialized = true;
            }
            catch (Exception e)
            {
                throw new InvalidCodeException($"Failed to initialize catalog with code: {Environment.NewLine}{_code}", e);
            }
        }
        /// <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;
        }
        public async Task Initialize()
        {
            var nuGetDownloader = new NuGetDownloader(_options.LoggerFactory());

            var nugetDownloadResult = await nuGetDownloader.DownloadAsync(PackagesFolder, _packageName, _packageVersion, _includePrerelease, _packageFeed,
                                                                          includeSecondaryRepositories : _options.IncludeSystemFeedsAsSecondary, targetFramework : _options.TargetFramework).ConfigureAwait(false);

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

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

                var downloadedRuntimeDlls = nugetDownloadResult.RunTimeDlls.Where(x => x.IsRecommended).ToList();

                var runtimeAssemblyHints = new List <RuntimeAssemblyHint>();

                foreach (var runTimeDll in downloadedRuntimeDlls)
                {
                    var runtimeAssembly = new RuntimeAssemblyHint(runTimeDll.FileName, runTimeDll.FullFilePath, runTimeDll.IsNative);
                    runtimeAssemblyHints.Add(runtimeAssembly);
                }

                options.PluginLoadContextOptions.RuntimeAssemblyHints = runtimeAssemblyHints;

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

                _pluginCatalogs.Add(assemblyCatalog);
            }

            IsInitialized = true;
        }
        public AssemblyPluginCatalog(string assemblyPath = null, Assembly assembly = null, Predicate <Type> filter = null,
                                     Dictionary <string, Predicate <Type> > taggedFilters = null, Action <TypeFinderCriteriaBuilder> configureFinder = null,
                                     TypeFinderCriteria criteria = null, AssemblyPluginCatalogOptions options = null)
        {
            if (assembly != null)
            {
                _assembly     = assembly;
                _assemblyPath = _assembly.Location;
            }
            else if (!string.IsNullOrWhiteSpace(assemblyPath))
            {
                _assemblyPath = assemblyPath;
            }
            else
            {
                throw new ArgumentNullException($"{nameof(assembly)} or {nameof(assemblyPath)} must be set.");
            }

            _options = options ?? new AssemblyPluginCatalogOptions();

            SetFilters(filter, taggedFilters, criteria, configureFinder);
        }
        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, PluginNameOptions = _options.PluginNameOptions
                };

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

                _pluginCatalogs.Add(assemblyCatalog);
            }

            IsInitialized = true;
        }
 public AssemblyPluginCatalog(Assembly assembly, Dictionary <string, Predicate <Type> > taggedFilters,
                              AssemblyPluginCatalogOptions options = null) : this(null, assembly, null, taggedFilters, null, null, options)
 {
 }
 public AssemblyPluginCatalog(Assembly assembly, Predicate <Type> filter = null, AssemblyPluginCatalogOptions options = null) : this(null, assembly,
                                                                                                                                     filter, null, null, null, options)
 {
 }
 public AssemblyPluginCatalog(string assemblyPath, Predicate <Type> filter = null, AssemblyPluginCatalogOptions options = null) : this(assemblyPath, null,
                                                                                                                                       filter, null, null, null, options)
 {
 }
 public AssemblyPluginCatalog(Assembly assembly, Action <TypeFinderCriteriaBuilder> configureFinder = null,
                              AssemblyPluginCatalogOptions options = null) : this(null,
                                                                                  assembly, null, null, configureFinder, null, options)
 {
 }
 public AssemblyPluginCatalog(string assemblyPath, Action <TypeFinderCriteriaBuilder> configureFinder = null,
                              AssemblyPluginCatalogOptions options = null) : this(assemblyPath,
                                                                                  null, null, null, configureFinder, null, options)
 {
 }
 public AssemblyPluginCatalog(string assemblyPath, TypeFinderCriteria criteria = null, AssemblyPluginCatalogOptions options = null) : this(assemblyPath,
                                                                                                                                           null, null, null,
                                                                                                                                           null, criteria, options)
 {
 }
 public AssemblyPluginCatalog(Assembly assembly, AssemblyPluginCatalogOptions options = null) : this(null, assembly, null, null, null, null, options)
 {
 }
 public AssemblyPluginCatalog(string assemblyPath, AssemblyPluginCatalogOptions options = null) : this(assemblyPath, null, null, null, null, null, options)
 {
 }