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);
            }
        }
Ejemplo n.º 2
0
        public static async Task <List <Type> > CompileScript(string code, RoslynPluginCatalogOptions options = null)
        {
            var catalog  = new ScriptInitializer(code, options);
            var assembly = await catalog.CreateAssembly();

            var result = assembly.GetTypes().Where(x => x.GetCustomAttribute(typeof(CompilerGeneratedAttribute), true) == null).ToList();

            return(result);
        }
Ejemplo n.º 3
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);
            }
        }