Beispiel #1
0
        public void EmptyPluginsCollectionAtStart()
        {
            var col        = new PluginsCollection();
            var startCount = col.Count();

            Assert.Equal(startCount, 0);
        }
Beispiel #2
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;
 }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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 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);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
 public SearchController(
     PluginsCollection plugins,
     IConfigurationProvider config,
     IStringModel tokenizer,
     SessionFactory sessionFactory) : base(config, sessionFactory)
 {
     _plugins = plugins;
     _model   = tokenizer;
 }
        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);
        }
Beispiel #11
0
        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"));
        }
Beispiel #12
0
 public QueryParserController(
     PluginsCollection plugins,
     IQueryFormatter queryFormatter,
     IConfigurationProvider config,
     IStringModel tokenizer,
     SessionFactory sessionFactory) : base(config, sessionFactory)
 {
     _queryFormatter = queryFormatter;
     _plugins        = plugins;
     _model          = tokenizer;
 }
Beispiel #13
0
        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 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);
        }
Beispiel #15
0
 public WriteController(
     PluginsCollection plugins,
     IStringModel tokenizer,
     ILogger <WriteController> logger,
     IConfigurationProvider config)
 {
     _plugins = plugins;
     _model   = tokenizer;
     _logger  = logger;
     _config  = config;
 }
Beispiel #16
0
        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);
        }
Beispiel #17
0
        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());
        }
Beispiel #19
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());
        }
Beispiel #20
0
        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 EmptyPluginsCollectionAtStart()
 {
     var col = new PluginsCollection();
     var startCount = col.Count();
     Assert.Equal(startCount, 0);
 }
 public void LoadPluginByBadAssembly()
 {
     var col = new PluginsCollection();
     Assert.Throws<PluginsException>(() => col.LoadPlugin("badAsm"));
 }
        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"));
        }
Beispiel #25
0
        public void LoadPluginByBadAsmAndName()
        {
            var col = new PluginsCollection();

            Assert.Throws <PluginsException>(() => col.LoadPlugin("Sosososbad", TEST_PLUGIN1_FULLNAME));
        }
Beispiel #26
0
 public IOController(PluginsCollection plugins)
 {
     _plugins = plugins;
 }
Beispiel #27
0
 public AddController(PluginsCollection plugins)
 {
     _plugins    = plugins;
     _htmlParser = new HtmlWeb();
 }
Beispiel #28
0
        public void LoadPluginByAsmAndBadName()
        {
            var col = new PluginsCollection();

            Assert.Throws <TypeLoadException>(() => col.LoadPlugin(TEST_PLUGIN1_ASSEMBLY, "badfullname"));
        }
Beispiel #29
0
        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"));
 }
Beispiel #32
0
        public void LoadPluginByAsmAndMissingName()
        {
            var col = new PluginsCollection();

            Assert.Throws <PluginsException>(() => col.LoadPlugin(TEST_PLUGIN1_ASSEMBLY, null));
        }
Beispiel #33
0
        public void LoadPluginByMissingAsmAndName()
        {
            var col = new PluginsCollection();

            Assert.Throws <PluginsException>(() => col.LoadPlugin(null, TEST_PLUGIN1_FULLNAME));
        }
Beispiel #34
0
 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);
 }
Beispiel #37
0
 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 };
 }
Beispiel #39
0
 public SearchController(PluginsCollection plugins, IConfigurationService config) : base(config)
 {
     _plugins = plugins;
 }
        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 InitializePluginsCollection()
 {
     var col = new PluginsCollection();
 }
        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);
        }
Beispiel #43
0
        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 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);
 }
Beispiel #45
0
 public static void RegisterComponents(
     IServiceCollection services, PluginsCollection plugins, IServiceProvider container)
 {
     services.AddSingleton(typeof(JobQueue));
     services.AddSingleton(typeof(SaveAsJobQueue));
 }
Beispiel #46
0
        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 };
 }
Beispiel #48
0
        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());
        }
Beispiel #49
0
 public AddController(PluginsCollection plugins, CrawlQueue crawlQueue, IConfigurationService config) : base(config)
 {
     _plugins    = plugins;
     _htmlParser = new HtmlWeb();
     _crawlQueue = crawlQueue;
 }
        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);
        }