Exemplo n.º 1
0
        public void LoadPluginsTest()
        {
            //Arrange
            var pluginResolver = new PluginResolver();

            PluginManager pluginManager = new PluginManager(pluginResolver);

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

            //Assert
            //we expect 1 plugin
            Assert.Single(pluginResolver.GetPlugins());
            Assert.Equal(typeof(TestPlugin.TestPlugin).FullName, pluginResolver.GetPlugins().First().PluginInstance.GetType().FullName);
        }
Exemplo n.º 2
0
        public void LoadPluginsTest()
        {
            //Arrange
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddScoped <IRepository <Plugin>, Repository <Plugin> >(e => _pluginRepositoryMock.Object);
            serviceCollection.AddScoped <IRepository <Tile>, Repository <Tile> >(e => _tileRepositoryMock.Object);
            serviceCollection.AddScoped <DbContext, AppDashTestContext>();

            _pluginRepositoryMock.SetupRepositoryMock(options =>
                                                      { });

            _tileRepositoryMock.SetupRepositoryMock(options =>
                                                    { });

            var pluginResolver = new PluginResolver();

            PluginLoader pluginLoader = new PluginLoader(pluginResolver, serviceCollection.BuildServiceProvider());

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

            //Assert
            //we expect 1 plugin
            Assert.Single(pluginResolver.GetPlugins());
            //the plugin has 5 tiles
            Assert.Equal(5, pluginResolver.GetPluginTiles().Count());
            //4 of them are type TestTile2
            Assert.Equal(4, pluginResolver.GetPluginTiles().Count(tile => tile.GetType().FullName == typeof(TestTile2).FullName));

            foreach (ITile pluginTile in pluginResolver.GetPluginTiles())
            {
                Assert.NotEmpty(pluginTile.TileKey);
                Assert.NotEmpty(pluginTile.PluginKey);
            }
        }
Exemplo n.º 3
0
        private void Configures_Load(object sender, EventArgs e)
        {
            textBox1.Text    = ConfigurationManager.AppSettings["Destination"];
            label2.BackColor = Color.FromArgb(
                Int16.Parse(ConfigurationManager.AppSettings["UIColorA"]),
                Int16.Parse(ConfigurationManager.AppSettings["UIColorR"]),
                Int16.Parse(ConfigurationManager.AppSettings["UIColorG"]),
                Int16.Parse(ConfigurationManager.AppSettings["UIColorB"]));
            label8.BackColor = Color.FromArgb(
                Int16.Parse(ConfigurationManager.AppSettings["BGColorR"]),
                Int16.Parse(ConfigurationManager.AppSettings["BGColorG"]),
                Int16.Parse(ConfigurationManager.AppSettings["BGColorB"]));
            trackBar1.Value = Int16.Parse(ConfigurationManager.AppSettings["BGOpacity"]) / 10;
            label10.Text    = ConfigurationManager.AppSettings["BGOpacity"] + "%";



            foreach (var p in PluginResolver.GetPlugins())
            {
                Form optionForm = p.OptionsForm;

                if (optionForm != null)
                {
                    var butt = new Button();
                    butt.Text     = p.GetName() + " options";
                    butt.AutoSize = true;

                    butt.Click += delegate
                    {
                        optionForm.ShowDialog();
                    };

                    panel1.Controls.Add(butt);
                }
            }
        }
Exemplo n.º 4
0
 public IEnumerable <Plugin> GetPlugins()
 {
     return(_pluginResolver.GetPlugins());
 }
Exemplo n.º 5
0
        private void InitializeMenu()
        {
            ContextMenu contextMenu = new ContextMenu();

            output = new MenuItem(Resources.Resources.GetString("OutputText"));

            foreach (var plugin in PluginResolver.GetPlugins())
            {
                MenuItem item = new MenuItem();
                item.Text = plugin.GetOutputName();

                item.Click += delegate
                {
                    foreach (var it in output.MenuItems)
                    {
                        if (it != item)
                        {
                            MenuItem i = (MenuItem)it;
                            i.Checked = false;
                        }
                    }

                    item.Checked = true;

                    ConfigResolver.ChangeOutput(plugin.GetHashCode().ToString());
                    label1.Text = plugin.GetOutputName();
                };

                output.MenuItems.Add(item);
            }

            contextMenu.MenuItems.Add(output);
            contextMenu.MenuItems.Add(Resources.Resources.GetString("OptionsText"));
            contextMenu.MenuItems.Add(Resources.Resources.GetString("BrowseText"));
            contextMenu.MenuItems.Add("-");
            contextMenu.MenuItems.Add(Resources.Resources.GetString("HideText"));
            contextMenu.MenuItems.Add("-");
            contextMenu.MenuItems.Add(Resources.Resources.GetString("ExitText"));

            contextMenu.MenuItems[1].Click += delegate
            {
                var OptionsForm = new Configures();
                if (OptionsForm.ShowDialog() == DialogResult.OK)
                {
                    this.Refresh();
                    f2.Refresh();

                    f2.TopMost   = true;
                    this.TopMost = true;
                    f2.TopMost   = false;
                    this.TopMost = false;
                }
            };

            contextMenu.MenuItems[2].Click += delegate
            {
                string windir = Environment.GetEnvironmentVariable("WINDIR");
                System.Diagnostics.Process prc = new System.Diagnostics.Process();
                prc.StartInfo.FileName  = windir + @"\explorer.exe";
                prc.StartInfo.Arguments = ConfigurationManager.AppSettings["Destination"];
                prc.Start();
            };

            contextMenu.MenuItems[4].Click += delegate
            {
                this.WindowState = FormWindowState.Minimized;
            };

            contextMenu.MenuItems[6].Click += delegate { Application.Exit(); };

            this.ContextMenu = contextMenu;
            icon.ContextMenu = contextMenu;
        }