コード例 #1
0
        public void LoadTilesTest()
        {
            //Arrange
            var pluginResolver = new PluginResolver();

            PluginManager pluginManager = new PluginManager(pluginResolver);
            TileManager   tileManager   = new TileManager(pluginResolver, pluginManager, null);

            pluginManager.LoadPlugins(Assembly.GetExecutingAssembly(), new Dictionary <string, string>(new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("TestKey", nameof(TestPlugin.TestPlugin))
            }));

            //Act
            tileManager.LoadTiles(Assembly.GetExecutingAssembly(), new List <Tuple <string, Type> >
            {
                new Tuple <string, Type>("TestTileKey", typeof(TestTileComponent))
            }).ToList();

            //Assert
            var plugin = pluginResolver.GetPlugin("TestKey");

            Assert.Single(plugin.PluginTiles);
            Assert.Equal("TestTileKey", plugin.PluginTiles.First().Key);
            Assert.Null(plugin.PluginTiles.First().Value.Item1);
            Assert.NotNull(plugin.PluginTiles.First().Value.Item2);
        }
コード例 #2
0
        static void ProcessImageThread(object img)
        {
            byte[] image;

            using (MemoryStream ms = new MemoryStream())
            {
                var pic = (Image)img;
                pic.Save(ms, ImageFormat.Png);
                image = ms.ToArray();
            }

            string method = ConfigurationManager.AppSettings["OutputMethod"];

            try
            {
                var plugin = PluginResolver.GetPlugin(method);

                plugin.SaveImage(image);

                Trace.WriteLine(DateTime.Now + " - Image processed");
            }
            catch (Exception e)
            {
                MessageBox.Show(Resources.Resources.GetString("ErrorProcessingImage"), Resources.Resources.GetString("ErrorText"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                Trace.WriteLine(DateTime.Now + " - Error processing image: " + e.ToString());
            }
        }
コード例 #3
0
        public void GetPluginTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");

            //Act
            var plugin      = pluginResolver.GetPlugin(typeof(TestPlugin.TestPlugin));
            var pluginAgain = pluginResolver.GetPlugin("TestKey");

            //Assert
            Assert.Equal(plugin, pluginAgain);

            //make sure the plugin and PluginInstance is not null
            Assert.NotNull(plugin);
            Assert.NotNull(plugin.PluginInstance);
            //make sure the plugin has the right key
            Assert.Equal("TestKey", plugin.PluginInstance.Key);
            Assert.Equal("TestKey", pluginAgain.PluginInstance.Key);
            Assert.Equal("TestKey", plugin.PluginKey);
            Assert.Equal("TestKey", pluginAgain.PluginKey);
        }
コード例 #4
0
        public void LoadPluginSettingsTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");

            //Act
            pluginResolver.LoadPluginSettings(typeof(TestPlugin.TestPlugin));

            //Assert
            var plugin = pluginResolver.GetPlugin(typeof(TestPlugin.TestPlugin));

            Assert.NotNull(plugin.PluginSettings);
        }
コード例 #5
0
        public void LoadPluginSettingsComponentTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");

            //Act
            pluginResolver.LoadPluginSettingsComponent(typeof(TestSettingsComponent), null);

            //Assert
            var plugin = pluginResolver.GetPlugin(typeof(TestPlugin.TestPlugin));

            Assert.NotNull(plugin.PluginSettingsComponent);
            Assert.Equal(typeof(TestSettingsComponent), plugin.PluginSettingsComponent.GetType());
        }
コード例 #6
0
        public void LoadPluginPagesTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");

            //Act
            pluginResolver.LoadPluginPages(typeof(TestPlugin.TestPlugin));

            //Assert
            var plugin = pluginResolver.GetPlugin(typeof(TestPlugin.TestPlugin));

            Assert.Equal(2, plugin.PluginPages.Count);

            //make sure the page instance is not null
            Assert.NotNull(plugin.PluginPages.First().Value.Item1);
            //we only load the IPage so the component SHOULD be null
            Assert.Null(plugin.PluginPages.First().Value.Item2);
            Assert.Equal("TestKey", plugin.PluginPages.First().Value.Item1.PluginKey);
        }
コード例 #7
0
        public void LoadPluginPageComponentTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");

            //Act
            pluginResolver.LoadPluginPageComponent(typeof(TestPageComponent));

            //Assert
            var plugin = pluginResolver.GetPlugin(typeof(TestPlugin.TestPlugin));

            Assert.Single(plugin.PluginPages);
            Assert.True(plugin.PluginPages.ContainsKey("/test"));

            //make sure the page component is not null
            Assert.NotNull(plugin.PluginPages["/test"].Item2);
            //we only load the component so the IPage SHOULD be null
            Assert.Null(plugin.PluginPages["/test"].Item1);
            Assert.Equal("TestKey", plugin.PluginPages["/test"].Item2.PluginKey);
        }
コード例 #8
0
        public void LoadSettingsTest()
        {
            //Arrange
            var pluginResolver = new PluginResolver();

            PluginManager   pluginManager   = new PluginManager(pluginResolver);
            SettingsManager settingsManager = new SettingsManager(pluginManager, null, pluginResolver, null);

            pluginManager.LoadPlugins(Assembly.GetExecutingAssembly(), new Dictionary <string, string>(new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("TestKey", nameof(TestPlugin.TestPlugin))
            }));

            //Act
            settingsManager.LoadSettings(Assembly.GetExecutingAssembly()).ToList();

            //Assert
            var plugin = pluginResolver.GetPlugin("TestKey");

            Assert.NotNull(plugin.PluginSettingsComponent);
            Assert.Equal("TestKey", plugin.PluginSettingsComponent.PluginKey);
        }
コード例 #9
0
        public void LoadPagesTest()
        {
            //Arrange
            var pluginResolver = new PluginResolver();

            PluginManager pluginManager = new PluginManager(pluginResolver);
            PageManager   pageManager   = new PageManager(pluginResolver);

            pluginManager.LoadPlugins(Assembly.GetExecutingAssembly(), new Dictionary <string, string>(new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("TestKey", nameof(TestPlugin.TestPlugin))
            }));

            //Act
            pageManager.LoadPages(Assembly.GetExecutingAssembly()).ToList();

            //Assert
            var plugin = pluginResolver.GetPlugin("TestKey");

            Assert.Equal(2, plugin.PluginPages.Count);
            Assert.Equal("TestKey", plugin.PluginPages.First().Value.Item2.PluginKey);
        }
コード例 #10
0
        public void LoadPluginTileTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");

            //Act
            pluginResolver.LoadPluginTile(typeof(TestPlugin.TestPlugin), typeof(TestTile), "TestTileKey");

            //Assert
            var plugin = pluginResolver.GetPlugin(typeof(TestPlugin.TestPlugin));

            Assert.Single(plugin.PluginTiles);
            Assert.True(plugin.PluginTiles.ContainsKey("TestTileKey"));

            //make sure the tile instance is not null
            Assert.NotNull(plugin.PluginTiles["TestTileKey"].Item1);
            //we only load the ITile so the component SHOULD be null
            Assert.Null(plugin.PluginTiles["TestTileKey"].Item2);
            Assert.Equal("TestTileKey", plugin.PluginTiles["TestTileKey"].Item1.TileKey);
            Assert.Equal("TestKey", plugin.PluginTiles["TestTileKey"].Item1.PluginKey);
        }
コード例 #11
0
        private void Form1_Load(object sender, EventArgs e)
        {
            string outputmethod = ConfigurationManager.AppSettings["OutputMethod"];

            var plugin = PluginResolver.GetPlugin(outputmethod);

            if (plugin != null)
            {
                label1.Text      = plugin.GetOutputName();
                label1.BackColor = Color.FromArgb(
                    Int16.Parse(ConfigurationManager.AppSettings["UIColorR"]),
                    Int16.Parse(ConfigurationManager.AppSettings["UIColorG"]),
                    Int16.Parse(ConfigurationManager.AppSettings["UIColorB"]));
            }
            else
            {
                label1.Text      = "-";
                label1.BackColor = Color.FromArgb(
                    Int16.Parse(ConfigurationManager.AppSettings["UIColorR"]),
                    Int16.Parse(ConfigurationManager.AppSettings["UIColorG"]),
                    Int16.Parse(ConfigurationManager.AppSettings["UIColorB"]));
            }
        }
コード例 #12
0
        public void InitializePluginsTest()
        {
            //Arrange
            AppDashTestContext dbContext = new AppDashTestContext();

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <IRepository <Plugin>, Repository <Plugin> >(e => _pluginRepositoryMock.Object);
            serviceCollection.AddSingleton <IRepository <Tile>, Repository <Tile> >(e => _tileRepositoryMock.Object);
            serviceCollection.AddSingleton <IRepository <PluginSettings>, Repository <PluginSettings> >(e => _pluginSettingsRepositoryMock.Object);
            serviceCollection.AddSingleton <DbContext, AppDashTestContext>(e => dbContext);

            _pluginRepositoryMock.SetupRepositoryMock(dbContext, options =>
            {
                options.InsertNoTracking(new Plugin
                {
                    UniqueIdentifier = typeof(TestPlugin.TestPlugin).FullName,
                    Key  = "TestKey",
                    Name = "TestName"
                });
            });

            _tileRepositoryMock.SetupRepositoryMock(dbContext, options =>
                                                    { });

            _pluginSettingsRepositoryMock.SetupRepositoryMock(dbContext, options =>
            {
                options.InsertNoTracking(new PluginSettings
                {
                    PluginKey = "TestKey",
                    Data      = JsonConvert.SerializeObject(new PluginData
                    {
                        Data = new Dictionary <string, Tuple <Type, object> >(new List <KeyValuePair <string, Tuple <Type, object> > >
                        {
                            new KeyValuePair <string, Tuple <Type, object> >("TestData", new Tuple <Type, object>(typeof(string), "TestValue")),
                            new KeyValuePair <string, Tuple <Type, object> >("TestData2", new Tuple <Type, object>(typeof(string), "TestValue2"))
                        })
                    })
                });
            });

            var serviceProvider = serviceCollection.BuildServiceProvider();

            var pluginResolver        = new PluginResolver();
            var pluginSettingsManager = new PluginSettingsManager(serviceProvider);

            PluginLoader pluginLoader = new PluginLoader(pluginResolver, serviceProvider);

            PluginInitializer pluginInitializer = new PluginInitializer(pluginResolver, pluginSettingsManager, serviceProvider);

            //Act
            pluginLoader.LoadPlugins(Path.Combine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), "plugins"));

            pluginInitializer.InitializePlugins();

            //Assert
            var plugin = pluginResolver.GetPlugin("TestKey");

            //make sure the plugin exists
            Assert.NotNull(plugin);
            //make sure the plugin has the right key
            Assert.Equal("TestKey", plugin.PluginInstance.Key);
            Assert.Equal("TestKey", plugin.PluginKey);

            foreach (ITile pluginTile in pluginResolver.GetPluginTiles())
            {
                //make sure tiles have correct data
                Assert.Equal("TestKey", pluginTile.PluginKey);
                Assert.NotEmpty(pluginTile.TileKey);
                Assert.NotNull(pluginTile.PluginSettings);
                Assert.NotNull(pluginTile.PluginSettings.GetData <string>("TestData"));
                Assert.NotNull(pluginTile.PluginSettings.GetData <string>("TestData2"));
                Assert.Throws <InvalidCastException>(() =>
                {
                    //make sure this throws an InvalidCastException since it should be a string
                    int data = pluginTile.PluginSettings.GetData <int>("TestData");
                });
            }
        }