public void EmptyPluginsCollectionAtStart() { var col = new PluginsCollection(); var startCount = col.Count(); Assert.Equal(startCount, 0); }
public SlackController(PluginsCollection plugins, IConfigurationProvider config, SessionFactory sessionFactory) { _postMessageUrl = "https://slack.com/api/chat.postMessage"; _queue = new ProducerConsumerQueue <dynamic>(1, callback: Send); _sessionFactory = sessionFactory; _config = config; }
public void LoadTestPluginByAssemblyAndName() { var col = new PluginsCollection(); var plug = col.LoadPlugin(TEST_PLUGIN1_ASSEMBLY, TEST_PLUGIN1_FULLNAME); Assert.Equal(col.Count(), 1); Assert.NotNull(plug); }
public void LoadTestPluginByAssemblyWithoutExtension() { var col = new PluginsCollection(); var plug = col.LoadPlugin(TEST_PLUGIN1_ASSEMBLY_WITHOUT_EXTENSION); Assert.Equal(plug.Count(), 1); Assert.Equal(col.Count(), 1); }
public void LoadAndSelectPlugin() { var col = new PluginsCollection(); var plug1 = col.LoadPlugin(TEST_PLUGIN1_ASSEMBLY, TEST_PLUGIN1_FULLNAME); var plug2 = col[TEST_PLUGIN1_FULLNAME].FirstOrDefault(); Assert.Equal(plug1, plug2); Assert.Equal(plug1, plug2); }
public void LoadTestPluginByAssembly() { var col = new PluginsCollection(); var plug = col.LoadPlugin(TEST_PLUGIN1_ASSEMBLY); var count = plug.Count(); Assert.Equal(count, 1); Assert.Equal(col.Count(), 1); }
public SearchController( PluginsCollection plugins, IConfigurationProvider config, IStringModel tokenizer, SessionFactory sessionFactory) : base(config, sessionFactory) { _plugins = plugins; _model = tokenizer; }
public void LoadAndCheckContainsPlugin() { var col = new PluginsCollection(); col.LoadPlugin(TEST_PLUGIN1_ASSEMBLY, TEST_PLUGIN1_FULLNAME); Assert.True(col.Contains(TEST_PLUGIN1_FULLNAME)); Assert.False(col.Contains("fsefsefse")); }
public QueryParserController( PluginsCollection plugins, IQueryFormatter queryFormatter, IConfigurationProvider config, IStringModel tokenizer, SessionFactory sessionFactory) : base(config, sessionFactory) { _queryFormatter = queryFormatter; _plugins = plugins; _model = tokenizer; }
public void LoadAndRemoveAllPlugins() { var col = new PluginsCollection(); var plug = col.LoadPlugin(TEST_PLUGIN1_ASSEMBLY, TEST_PLUGIN1_FULLNAME); Assert.NotNull(plug); Assert.True(col.Any()); col.StopAndRemoveAll(); Assert.Equal(col.Count(), 0); }
public WriteController( PluginsCollection plugins, IStringModel tokenizer, ILogger <WriteController> logger, IConfigurationProvider config) { _plugins = plugins; _model = tokenizer; _logger = logger; _config = config; }
public void LoadTwoSamePlugins() { var col = new PluginsCollection(); var plug1 = col.LoadPlugin(TEST_PLUGIN1_ASSEMBLY, TEST_PLUGIN1_FULLNAME); var plug2 = col.LoadPlugin(TEST_PLUGIN1_ASSEMBLY, TEST_PLUGIN1_FULLNAME); Assert.NotNull(plug1); Assert.NotNull(plug2); Assert.NotEqual(plug1.GetHashCode(), plug2.GetHashCode()); Assert.NotEqual(plug1.GetHashCode(), plug2.GetHashCode()); Assert.Equal(col.Count(), 2); }
public void LoadedPluginNotInCurrentAppDomain() { var col = new PluginsCollection(); var plug1 = col.LoadPlugin(TEST_PLUGIN1_ASSEMBLY, TEST_PLUGIN1_FULLNAME); var currentAssemblies = AppDomain.CurrentDomain.GetAssemblies(); var foundAssembly = currentAssemblies.Where( x => x.FullName == plug1.ToString() || x.GetType().FullName == plug1.TypeFullName); Assert.NotNull(plug1); Assert.Equal(foundAssembly.Count(), 0); }
public void LoadAndRemovePluginAndGCCollect() { var col = new PluginsCollection(); var plug = col.LoadPlugin(TEST_PLUGIN1_ASSEMBLY, TEST_PLUGIN1_FULLNAME); Assert.NotNull(plug); Assert.True(col.Any()); col.RemovePlugin(plug); Assert.Equal(col.Count(), 0); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); Assert.Throws<AppDomainUnloadedException>(() => plug.GetFields()); Assert.Throws<AppDomainUnloadedException>(() => plug.Close()); }
public void LoadAndRemovePluginAndGCCollect() { var col = new PluginsCollection(); var plug = col.LoadPlugin(TEST_PLUGIN1_ASSEMBLY, TEST_PLUGIN1_FULLNAME); Assert.NotNull(plug); Assert.True(col.Any()); col.RemovePlugin(plug); Assert.Equal(col.Count(), 0); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); Assert.Throws <AppDomainUnloadedException>(() => plug.GetFields()); Assert.Throws <AppDomainUnloadedException>(() => plug.Close()); }
public void LoadAndUsingPluginsWithGCCollect() { var col = new PluginsCollection(); var plug1 = col.LoadPlugin(TEST_PLUGIN1_ASSEMBLY, TEST_PLUGIN1_FULLNAME); var plug2 = col.LoadPlugin(TEST_PLUGIN1_ASSEMBLY, TEST_PLUGIN1_FULLNAME); Assert.NotNull(plug1); Assert.NotNull(plug2); Assert.Equal(col.Count(), 2); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); Assert.DoesNotThrow(() => plug1.GetFields()); Assert.DoesNotThrow(plug1.Close); Assert.DoesNotThrow(() => plug2.GetFields()); Assert.DoesNotThrow(plug2.Close); }
public void LoadPluginByBadAsmAndName() { var col = new PluginsCollection(); Assert.Throws<PluginsException>(() => col.LoadPlugin("Sosososbad", TEST_PLUGIN1_FULLNAME)); }
public void LoadPluginByBadAssembly() { var col = new PluginsCollection(); Assert.Throws<PluginsException>(() => col.LoadPlugin("badAsm")); }
public void LoadPluginByBadAsmAndName() { var col = new PluginsCollection(); Assert.Throws <PluginsException>(() => col.LoadPlugin("Sosososbad", TEST_PLUGIN1_FULLNAME)); }
public IOController(PluginsCollection plugins) { _plugins = plugins; }
public AddController(PluginsCollection plugins) { _plugins = plugins; _htmlParser = new HtmlWeb(); }
public void LoadPluginByAsmAndBadName() { var col = new PluginsCollection(); Assert.Throws <TypeLoadException>(() => col.LoadPlugin(TEST_PLUGIN1_ASSEMBLY, "badfullname")); }
public static void RegisterComponents(IServiceCollection services, PluginsCollection plugins, IServiceProvider container) { var sessionFactory = container.GetService <SessionFactory>(); services.Add(new ServiceDescriptor(typeof(CrawlQueue), new CrawlQueue(sessionFactory))); }
public void LoadPluginByMissingAsmAndName() { var col = new PluginsCollection(); Assert.Throws<PluginsException>(() => col.LoadPlugin(null, TEST_PLUGIN1_FULLNAME)); }
public void LoadPluginByAsmAndBadName() { var col = new PluginsCollection(); Assert.Throws<TypeLoadException>(() => col.LoadPlugin(TEST_PLUGIN1_ASSEMBLY, "badfullname")); }
public void LoadPluginByAsmAndMissingName() { var col = new PluginsCollection(); Assert.Throws <PluginsException>(() => col.LoadPlugin(TEST_PLUGIN1_ASSEMBLY, null)); }
public void LoadPluginByMissingAsmAndName() { var col = new PluginsCollection(); Assert.Throws <PluginsException>(() => col.LoadPlugin(null, TEST_PLUGIN1_FULLNAME)); }
public void InitializePluginsCollection() { var col = new PluginsCollection(); }
public void LoadPluginByAsmAndMissingName() { var col = new PluginsCollection(); Assert.Throws<PluginsException>(() => col.LoadPlugin(TEST_PLUGIN1_ASSEMBLY, null)); }
public void Inited_With_Collection_Collection_Counts_Equal() { var plugins = new List<DummyPlugin> { plugin }; var ctorColl = new PluginsCollection<DummyPlugin>(manager, plugins); Assert.Equal(plugins.Count, ctorColl.Count); }
public IOController(PluginsCollection plugins, LocalStorageSessionFactory sessionFactory) { _plugins = plugins; _sessionFactory = sessionFactory; _log = Logging.CreateLogWriter("iocontroller"); }
public PluginsCollectionTests() { plugin = new Mock<DummyPlugin>(); manager = new Mock<IAsyncMethodManager<DummyPlugin>>(); collection = new PluginsCollection<DummyPlugin>(manager.Object) { plugin.Object }; }
public SearchController(PluginsCollection plugins, IConfigurationService config) : base(config) { _plugins = plugins; }
public static IServiceProvider Configure(IServiceCollection services) { // register config services.Add(new ServiceDescriptor(typeof(IConfigurationProvider), new IniConfiguration(Path.Combine(Directory.GetCurrentDirectory(), "sir.ini")))); // register plugins var assemblyPath = Directory.GetCurrentDirectory(); #if DEBUG assemblyPath = Path.Combine(Directory.GetCurrentDirectory(), "bin\\Debug\\netcoreapp2.1"); #endif var files = Directory.GetFiles(assemblyPath, "*.plugin.dll"); foreach (var assembly in files.Select(file => AssemblyLoadContext.Default.LoadFromAssemblyPath(file))) { foreach (var type in assembly.GetTypes()) { // search for concrete implementations if (!type.IsInterface) { var interfaces = type.GetInterfaces(); if (interfaces.Contains(typeof(IPluginStop)) || interfaces.Contains(typeof(IPluginStart)) || interfaces.Contains(typeof(IPlugin))) { // register plugins, startup and teardown services foreach (var contract in interfaces.Where(t => t != typeof(IDisposable))) { services.Add(new ServiceDescriptor( contract, type, ServiceLifetime.Singleton)); } } } } } var plugins = new PluginsCollection(); services.Add(new ServiceDescriptor(typeof(PluginsCollection), plugins)); var serviceProvider = services.BuildServiceProvider(); // initiate plugins foreach (var service in serviceProvider.GetServices <IPluginStart>()) { service.OnApplicationStartup(services, serviceProvider); } // Create one instances each of all plugins and register them with the PluginCollection, // so that they can be fetched at runtime by Content-Type and System.Type. foreach (var service in services.BuildServiceProvider().GetServices <IWriter>()) { plugins.Add(service.ContentType, service); } foreach (var service in services.BuildServiceProvider().GetServices <IReader>()) { plugins.Add(service.ContentType, service); } return(services.BuildServiceProvider()); }
public static void RegisterComponents( IServiceCollection services, PluginsCollection plugins, IServiceProvider container) { services.AddSingleton(typeof(JobQueue)); services.AddSingleton(typeof(SaveAsJobQueue)); }
public void LoadPluginByBadAssembly() { var col = new PluginsCollection(); Assert.Throws <PluginsException>(() => col.LoadPlugin("badAsm")); }
public PluginsCollectionTests() { plugin = MockRepository.GenerateMock<DummyPlugin>(); manager = MockRepository.GenerateMock<IAsyncMethodManager<DummyPlugin>>(); collection = new PluginsCollection<DummyPlugin>(manager) { plugin }; }
public static IServiceProvider Configure(IServiceCollection services) { var assemblyPath = Directory.GetCurrentDirectory(); var config = new KeyValueConfiguration(Path.Combine(assemblyPath, "sir.ini")); // register config services.Add(new ServiceDescriptor(typeof(IConfigurationProvider), config)); // register plugin startup and teardown handlers #if DEBUG var frameworkVersion = AppContext.TargetFrameworkName.Substring(AppContext.TargetFrameworkName.IndexOf("=v") + 2); assemblyPath = Path.Combine(assemblyPath, "bin", "Debug", $"netcoreapp{frameworkVersion}"); #endif var files = Directory.GetFiles(assemblyPath, "*.plugin.dll"); foreach (var assembly in files.Select(file => AssemblyLoadContext.Default.LoadFromAssemblyPath(file))) { foreach (var type in assembly.GetTypes()) { // search for concrete types if (!type.IsInterface) { var interfaces = type.GetInterfaces(); if (interfaces.Contains(typeof(IPluginStop))) { services.Add(new ServiceDescriptor(typeof(IPluginStop), type, ServiceLifetime.Singleton)); } else if (interfaces.Contains(typeof(IPluginStart))) { services.Add(new ServiceDescriptor(typeof(IPluginStart), type, ServiceLifetime.Singleton)); } } } } var plugins = new PluginsCollection(); services.Add(new ServiceDescriptor(typeof(PluginsCollection), plugins)); var serviceProvider = services.BuildServiceProvider(); // raise startup event foreach (var service in serviceProvider.GetServices <IPluginStart>()) { service.OnApplicationStartup(services, serviceProvider, config); } // Fetch one instance each of all plugins and register them with the PluginCollection // so that they can be fetched at runtime by Content-Type and System.Type. foreach (var service in services.BuildServiceProvider().GetServices <IHttpWriter>()) { plugins.Add(service.ContentType, service); } foreach (var service in services.BuildServiceProvider().GetServices <IHttpReader>()) { plugins.Add(service.ContentType, service); } RegisterComponents(services, plugins, services.BuildServiceProvider()); return(services.BuildServiceProvider()); }
public AddController(PluginsCollection plugins, CrawlQueue crawlQueue, IConfigurationService config) : base(config) { _plugins = plugins; _htmlParser = new HtmlWeb(); _crawlQueue = crawlQueue; }