示例#1
0
        private void RunCombinedTest(ILoggerFactory loggerFactory, bool mustClearCache = false)
        {
            var logger       = loggerFactory.CreateLogger <PluginFinder>();
            var pluginFinder = new PluginFinder(logger);

            if (mustClearCache)
            {
                var fsc = (FileSystemCache <string, string>)pluginFinder.Cache;
                fsc.Clear();
            }

            var plugins = pluginFinder.FindPlugins();

            plugins.InfoByType.Count.Should().BeGreaterOrEqualTo(2);

            // Capabilities extraction
            var testPlugin1Caps = plugins.InfoByType[typeof(TestPlugin1)].Capabilities;

            testPlugin1Caps.Count.Should().Be(0);
            var testPlugin2Caps = plugins.InfoByType[typeof(TestPlugin2)].Capabilities;

            testPlugin2Caps.Count.Should().Be(2);
            testPlugin2Caps.GetValueOrDefault("Client").Should().Be(true);
            testPlugin2Caps.GetValueOrDefault("Server").Should().Be(false);

            // Dependencies extraction
            var testPlugin1Deps = plugins.InfoByType[typeof(TestPlugin1)].Dependencies;

            testPlugin1Deps.Should().BeEquivalentTo((TypeRef)typeof(TestPlugin2));
            var testPlugin1AllDeps = plugins.InfoByType[typeof(TestPlugin1)].AllDependencies;

            testPlugin1AllDeps.Should().Contain((TypeRef)typeof(TestPlugin2));

            var testPlugin2Deps = plugins.InfoByType[typeof(TestPlugin2)].Dependencies;

            testPlugin2Deps.Count.Should().Be(0);

            var host = new PluginHostBuilder()
                       .UsePlugins(plugins)
                       .UsePluginTypes(typeof(ITestPlugin))
                       .Build();

            RunPluginHostTests(host);
        }
示例#2
0
        public void LoadPlugins()
        {
            this.Log.Info("Entered LoadPlugins");

            var types = PluginFinder.FindPlugins();

            this.Log.Info("Loading Plugins");

            foreach (var type in types)
            {
                this.Log.Debug("type.TypeName: " + type.TypeName);
                this.Log.Debug("type.AssemblyName: " + type.AssemblyName);

                var domain = Common.CreateSandboxDomain("Sandbox Domain", type.Location, SecurityZone.Internet, typeof(ClientService));

                plugins.Add(new Plugin(type.AssemblyName, type.TypeName, domain, type.Location));
            }

            this.Log.Info("Found " + plugins.Count.ToString() + " plugins");

            foreach (Plugin plugin in plugins)
            {
                try
                {
                    this.Log.Info("---------------------------------------");
                    this.Log.Info("plugin name: " + plugin.PluginName);
                    this.Log.Info("plugin type: " + plugin.PluginType);

                    if (plugin.PluginName != string.Empty)
                    {
                        OSAEObject obj = OSAEObjectManager.GetObjectByName(plugin.PluginName);

                        this.Log.Info("setting found: " + obj.Name + " - " + obj.Enabled.ToString());
                        bool isSystemPlugin = false;
                        foreach (OSAEObjectProperty p in obj.Properties)
                        {
                            if (p.Name == "System Plugin")
                            {
                                if (p.Value == "TRUE")
                                {
                                    isSystemPlugin = true;
                                }
                                break;
                            }
                        }
                        this.Log.Info("isSystemPlugin?: " + isSystemPlugin.ToString());
                        if (!isSystemPlugin)
                        {
                            if (obj.Enabled == 1)
                            {
                                try
                                {
                                    enablePlugin(plugin);
                                }
                                catch (Exception ex)
                                {
                                    this.Log.Error("Error activating plugin (" + plugin.PluginName + ")", ex);
                                }
                            }
                            else
                            {
                                plugin.Enabled = false;
                            }

                            this.Log.Info("status: " + plugin.Enabled.ToString());
                            this.Log.Info("PluginName: " + plugin.PluginName);
                            this.Log.Info("PluginVersion: " + plugin.PluginVersion);

                            NetworkComms.SendObject("Plugin", Common.WcfServer, 10051, plugin.PluginName + "|" + plugin.Status + "|" + plugin.PluginVersion + "|" + plugin.Enabled);
                        }
                    }
                    else
                    {
                        //add code to create the object.  We need the plugin to specify the type though
                        this.Log.Info("Plugin object doesn't exist");
                        DataSet dataset = OSAESql.RunSQL("SELECT * FROM osae_object_type_property p inner join osae_object_type t on p.object_type_id = t.object_type_id WHERE object_type='" + plugin.PluginType + "' AND property_name='Computer Name'");
                        this.Log.Info("dataset count: " + dataset.Tables[0].Rows.Count.ToString());

                        // if object type has a property called 'Computer Name' we know it is not a System Plugin
                        if (dataset.Tables[0].Rows.Count > 0)
                        {
                            plugin.PluginName = plugin.PluginType + "-" + Common.ComputerName;

                            this.Log.Info("Plugin object does not exist in DB: " + plugin.PluginName);
                            OSAEObjectManager.ObjectAdd(plugin.PluginName, plugin.PluginName, plugin.PluginType, "", "System", false);
                            OSAEObjectPropertyManager.ObjectPropertySet(plugin.PluginName, "Computer Name", Common.ComputerName, "Client Service");

                            this.Log.Info("Plugin added to DB: " + plugin.PluginName);
                            NetworkComms.SendObject("Plugin", Common.WcfServer, 10051, plugin.PluginName + "|" + plugin.Status
                                                    + "|" + plugin.PluginVersion + "|" + plugin.Enabled);
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.Log.Error("Error loading plugin", ex);
                }
            }
            this.Log.Info("Done loading plugins");
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        public void LoadPlugins(string serviceName)
        {
            Log = new General.OSAELog(serviceName);
            Log.Info("Loading Plugins...");

            OSAEPluginCollection newPlugins = new OSAEPluginCollection();
            var pluginAssemblies            = new List <OSAEPluginBase>();
            var types = PluginFinder.FindPlugins();

            foreach (var type in types)
            {
                Log.Debug("TypeName: " + type.TypeName + ", AssemblyName: " + type.AssemblyName);

                var domain = Common.CreateSandboxDomain("Sandbox Domain", type.Location, SecurityZone.Internet, typeof(OSAEService));
                domain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledPluginExceptions);

                Plugin p = new Plugin(type.AssemblyName, type.TypeName, domain, type.Location);
                if (!pluginLoaded(p.PluginType))
                {
                    newPlugins.Add(p);
                }
            }

            Log.Info("Found " + newPlugins.Count.ToString() + " Assemblies");
            MySqlConnection connection = new MySqlConnection(Common.ConnectionString);

            foreach (Plugin plugin in newPlugins)
            {
                try
                {
                    Log.Info("----------------------------------------------------");
                    if (plugin.PluginName != "")
                    {
                        OSAEObject obj = OSAEObjectManager.GetObjectByName(plugin.PluginName);
                        if (obj == null)
                        {
                            bool found = OSAEObjectTypeManager.ObjectTypeExists(plugin.PluginType);
                            if (found)
                            {
                                OSAEObjectManager.ObjectAdd(plugin.PluginName, "", plugin.PluginName + " plugin's Object", plugin.PluginType, "", serviceName, 50, false);

                                obj = OSAEObjectManager.GetObjectByName(plugin.PluginName);
                                if (obj == null)
                                {
                                    Log.Info(plugin.PluginName + ":  I failed to create the Plugin Object!");
                                }
                                else
                                {
                                    Log.Info(obj.Name + ":  Plugin Object was Not found, so I created a new Plugin Object.");
                                }
                            }
                            else
                            {
                                Log.Info(":  Plugin Object Type Not found for: " + plugin.PluginType + ".  Plugin Object Cannot be Created.");
                            }
                        }

                        if (obj != null)
                        {
                            Log.Info(obj.Name + ":  Plugin Object found.  Plugin Object Enabled = " + obj.Enabled.ToString());
                            //No idea why the following line would run
                            //OSAEObjectManager.ObjectUpdate(plugin.PluginName,plugin.PluginName, "", plugin.PluginName + " plugin's Object", plugin.PluginType, "", serviceName, 50, true);
                            if (obj.Enabled == true)
                            {
                                plugin.Enabled = true;
                                startPlugin(serviceObject, plugin);
                            }
                            else
                            {
                                plugin.Enabled = false;
                                OSAEObjectStateManager.ObjectStateSet(obj.Name, "OFF", serviceObject);
                            }

                            Log.Info(obj.Name + ":  Plugin Enabled = " + plugin.Enabled.ToString());
                            Log.Info(obj.Name + ":  Plugin Version = " + plugin.PluginVersion);
                            OSAEObjectManager.ObjectUpdate(plugin.PluginName, plugin.PluginName, "", plugin.PluginName + " plugin's Object", plugin.PluginType, obj.Address, serviceName, 50, plugin.Enabled);
                            OSAEObjectPropertyManager.ObjectPropertySet(obj.Name, "Version", plugin.PluginVersion, serviceName);
                            OSAEObjectPropertyManager.ObjectPropertySet(obj.Name, "Author", plugin.PluginAuthor, serviceName);
                        }
                    }
                    else
                    {
                        bool found = OSAEObjectTypeManager.ObjectTypeExists(plugin.PluginType);
                        if (found)
                        {
                            plugin.PluginName = plugin.PluginType;
                            Log.Info(plugin.PluginName + ":  Plugin object does not exist in DB!");
                            OSAEObjectManager.ObjectAdd(plugin.PluginName, "", plugin.PluginName, plugin.PluginType, "", "System", 50, false);
                            OSAEObjectPropertyManager.ObjectPropertySet(plugin.PluginName, "Version", plugin.PluginVersion, serviceName);
                            OSAEObjectPropertyManager.ObjectPropertySet(plugin.PluginName, "Author", plugin.PluginAuthor, serviceName);
                            Log.Info(plugin.PluginName + ":  Plugin added to DB.");
                            //Uh, this still looks wrong below.   I don't think it is needed, besides, any new plugin is disabled...
                            //UDPConnection.SendObject("Plugin", plugin.PluginName + " | " + plugin.Enabled.ToString() + " | " + plugin.PluginVersion + " | Stopped | " + plugin.LatestAvailableVersion + " | " + plugin.PluginType + " | " + Common.ComputerName, new IPEndPoint(IPAddress.Broadcast, 10051));
                        }
                        else
                        {
                            Log.Info(":  Plugin Object Type Not found for: " + plugin.PluginType + ".  Plugin Object Cannot be Created!");
                        }
                    }
                    plugins.Add(plugin);
                    masterPlugins.Add(plugin);
                }
                catch (Exception ex)
                { Log.Error("Error loading plugin: " + ex.Message, ex); }
            }
            OSAEObjectStateManager.ObjectStateSet(serviceObject, "ON", serviceObject);
        }
示例#4
0
        /// <summary>
        ///
        /// </summary>
        public void LoadPlugins()
        {
            this.Log.Info("Loading Plugins...");

            OSAEPluginCollection newPlugins = new OSAEPluginCollection();
            var pluginAssemblies            = new List <OSAEPluginBase>();
            var types = PluginFinder.FindPlugins();

            foreach (var type in types)
            {
                this.Log.Debug("type.TypeName: " + type.TypeName);
                this.Log.Debug("type.AssemblyName: " + type.AssemblyName);

                var domain = Common.CreateSandboxDomain("Sandbox Domain", type.Location, SecurityZone.Internet, typeof(OSAEService));
                domain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledPluginExceptions);

                Plugin p = new Plugin(type.AssemblyName, type.TypeName, domain, type.Location);
                if (!pluginLoaded(p.PluginType))
                {
                    newPlugins.Add(p);
                }
            }

            this.Log.Info("Found " + newPlugins.Count.ToString() + " Assemblies");
            MySqlConnection connection = new MySqlConnection(Common.ConnectionString);

            foreach (Plugin plugin in newPlugins)
            {
                try
                {
                    if (plugin.PluginName != "")
                    {
                        this.Log.Info("----------------------------------------------------");
                        if (!goodConnection)
                        {
                            try
                            {
                                connection.Open();
                                goodConnection = true;
                            }
                            catch
                            {
                            }
                        }
                        this.Log.Info(plugin.PluginName + ":  Connection Passed (" + goodConnection + ")");
                        if (goodConnection)
                        {
                            if (plugin.PluginName != "")
                            {
                                OSAEObject obj = OSAEObjectManager.GetObjectByName(plugin.PluginName);

                                if (obj == null)
                                {
                                    OSAEObjectManager.ObjectAdd(plugin.PluginName, plugin.PluginName, plugin.PluginName + " plugin's Object", plugin.PluginType, "", "", true);
                                    obj = OSAEObjectManager.GetObjectByName(plugin.PluginName);
                                }

                                if (obj != null)
                                {
                                    this.Log.Info(obj.Name + ":  Plugin Object found.  Plugin Object Enabled = " + obj.Enabled.ToString());
                                    if (obj.Enabled == 1)
                                    {
                                        enablePlugin(plugin);
                                    }
                                    else
                                    {
                                        plugin.Enabled = false;
                                    }

                                    this.Log.Info(obj.Name + ":  Plugin Enabled =  " + plugin.Enabled.ToString());
                                    this.Log.Info(obj.Name + ":  Plugin Version = " + plugin.PluginVersion);
                                }
                            }
                            else
                            {
                                //add code to create the object.  We need the plugin to specify the type though

                                MySqlDataAdapter adapter;
                                DataSet          dataset  = new DataSet();
                                DataSet          dataset2 = new DataSet();
                                MySqlCommand     command  = new MySqlCommand();

                                command.Connection  = connection;
                                command.CommandText = "SELECT * FROM osae_object_type_property p inner join osae_object_type t on p.object_type_id = t.object_type_id WHERE object_type=@type AND property_name='Computer Name'";
                                command.Parameters.AddWithValue("@type", plugin.PluginType);
                                adapter = new MySqlDataAdapter(command);
                                adapter.Fill(dataset);

                                command.CommandText = "SELECT * FROM osae_v_object WHERE object_type=@type";
                                command.Parameters.AddWithValue("@type", plugin.PluginType);
                                adapter = new MySqlDataAdapter(command);
                                adapter.Fill(dataset2);

                                if (dataset.Tables[0].Rows.Count > 0 && dataset2.Tables[0].Rows.Count > 0)
                                {
                                    plugin.PluginName = plugin.PluginType + "-" + Common.ComputerName;
                                }
                                else
                                {
                                    plugin.PluginName = plugin.PluginType;
                                }

                                this.Log.Info(plugin.PluginName + ":  Plugin object does not exist in DB!");
                                OSAEObjectManager.ObjectAdd(plugin.PluginName, plugin.PluginName, plugin.PluginName, plugin.PluginType, "", "System", false);
                                OSAEObjectPropertyManager.ObjectPropertySet(plugin.PluginName, "Computer Name", Common.ComputerName, sourceName);
                                this.Log.Info(plugin.PluginName + ":  Plugin added to DB.");
                                UDPConnection.SendObject("Plugin", plugin.PluginName + " | " + plugin.Enabled.ToString() + " | " + plugin.PluginVersion + " | Stopped | " + plugin.LatestAvailableVersion + " | " + plugin.PluginType + " | " + Common.ComputerName, new IPEndPoint(IPAddress.Broadcast, 10051));
                            }
                            plugins.Add(plugin);
                            masterPlugins.Add(plugin);
                        }
                    }
                    else
                    {
                        this.Log.Info(plugin.PluginType + " Skipped! (Not Loaded due to missing Object or other issue)");
                    }
                }
                catch (Exception ex)
                {
                    this.Log.Error("Error loading plugin: " + ex.Message, ex);
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        public void LoadPlugins()
        {
            OSAEPluginCollection newPlugins = new OSAEPluginCollection();
            var pluginAssemblies            = new List <OSAEPluginBase>();
            var types = PluginFinder.FindPlugins();

            logging.AddToLog("Loading Plugins", true);

            foreach (var type in types)
            {
                logging.AddToLog("type.TypeName: " + type.TypeName, false);
                logging.AddToLog("type.AssemblyName: " + type.AssemblyName, false);

                var domain = Common.CreateSandboxDomain("Sandbox Domain", type.Location, SecurityZone.Internet, typeof(OSAEService));
                domain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledPluginExceptions);

                Plugin p = new Plugin(type.AssemblyName, type.TypeName, domain, type.Location);
                if (!pluginLoaded(p.PluginType))
                {
                    newPlugins.Add(p);
                }
            }

            logging.AddToLog("Found " + plugins.Count.ToString() + " plugins", true);
            MySqlConnection connection = new MySqlConnection(Common.ConnectionString);

            foreach (Plugin plugin in newPlugins)
            {
                try
                {
                    logging.AddToLog("---------------------------------------", true);
                    logging.AddToLog("Plugin name: " + plugin.PluginName, true);
                    logging.AddToLog("Testing connection", true);
                    if (!goodConnection)
                    {
                        try
                        {
                            connection.Open();
                            goodConnection = true;
                        }
                        catch
                        {
                        }
                    }

                    if (goodConnection)
                    {
                        if (plugin.PluginName != "")
                        {
                            OSAEObject obj = OSAEObjectManager.GetObjectByName(plugin.PluginName);

                            if (obj != null)
                            {
                                logging.AddToLog("Plugin Object found: " + obj.Name + " - Enabled: " + obj.Enabled.ToString(), true);
                                if (obj.Enabled == 1)
                                {
                                    enablePlugin(plugin);
                                }
                                else
                                {
                                    plugin.Enabled = false;
                                }

                                logging.AddToLog("Status: " + plugin.Enabled.ToString(), true);
                                logging.AddToLog("PluginVersion: " + plugin.PluginVersion, true);
                            }
                        }
                        else
                        {
                            //add code to create the object.  We need the plugin to specify the type though

                            MySqlDataAdapter adapter;
                            DataSet          dataset = new DataSet();
                            MySqlCommand     command = new MySqlCommand();

                            command.Connection  = connection;
                            command.CommandText = "SELECT * FROM osae_object_type_property p inner join osae_object_type t on p.object_type_id = t.object_type_id WHERE object_type=@type AND property_name='Computer Name'";
                            command.Parameters.AddWithValue("@type", plugin.PluginType);
                            adapter = new MySqlDataAdapter(command);
                            adapter.Fill(dataset);

                            if (dataset.Tables[0].Rows.Count > 0)
                            {
                                plugin.PluginName = plugin.PluginType + "-" + Common.ComputerName;
                            }
                            else
                            {
                                plugin.PluginName = plugin.PluginType;
                            }

                            logging.AddToLog("Plugin object does not exist in DB: " + plugin.PluginName, true);
                            OSAEObjectManager.ObjectAdd(plugin.PluginName, plugin.PluginName, plugin.PluginType, "", "System", false);
                            OSAEObjectPropertyManager.ObjectPropertySet(plugin.PluginName, "Computer Name", Common.ComputerName, sourceName);

                            logging.AddToLog("Plugin added to DB: " + plugin.PluginName, true);
                            sendMessageToClients(WCF.OSAEWCFMessageType.PLUGIN, plugin.PluginName + " | " + plugin.Enabled.ToString() + " | " + plugin.PluginVersion + " | Stopped | " + plugin.LatestAvailableVersion + " | " + plugin.PluginType + " | " + Common.ComputerName);
                        }
                        plugins.Add(plugin);
                        masterPlugins.Add(plugin);
                    }
                }
                catch (Exception ex)
                {
                    logging.AddToLog("Error loading plugin: " + ex.Message, true);
                }
            }
        }
        public void LoadPlugins(string name)
        {
            //Log.Info("Entered LoadPlugins");
            var types = PluginFinder.FindPlugins();

            Log.Info("Loading Plugins");

            foreach (var type in types)
            {
                Log.Debug("type.TypeName: " + type.TypeName);
                Log.Debug("type.AssemblyName: " + type.AssemblyName);

                var domain = Common.CreateSandboxDomain("Sandbox Domain", type.Location, SecurityZone.Internet, typeof(ClientService));

                plugins.Add(new Plugin(type.AssemblyName, type.TypeName, domain, type.Location, Common.ComputerName));
            }

            Log.Info("Found " + plugins.Count.ToString() + " plugins");

            foreach (Plugin plugin in plugins)
            {
                try
                {
                    Log.Info("---------------------------------------");
                    Log.Info("plugin name: " + plugin.PluginName);
                    Log.Info("plugin type: " + plugin.PluginType);

                    if (plugin.PluginName != "")
                    {
                        OSAEObject obj = OSAEObjectManager.GetObjectByName(plugin.PluginName);

                        if (obj == null)
                        {
                            OSAEObjectManager.ObjectAdd(plugin.PluginName, "", plugin.PluginName + " plugin's Object", plugin.PluginType, "", name, 50, true);
                            Log.Info(obj.Name + ":  Plugin Object Not found.  Plugin Object Created.");
                            obj = OSAEObjectManager.GetObjectByName(plugin.PluginName);
                            if (obj == null)
                            {
                                Log.Info(obj.Name + ":  I failed to create the Plugin Object!");
                            }
                        }

                        if (obj != null)
                        {
                            Log.Info("Plugin Object found: " + plugin.PluginName);
                            bool isSystemPlugin = false;
                            foreach (OSAEObjectProperty p in obj.Properties)
                            {
                                if (p.Name == "System Plugin")
                                {
                                    if (p.Value == "TRUE")
                                    {
                                        isSystemPlugin = true;
                                    }
                                    break;
                                }
                            }
                            Log.Info("isSystemPlugin?: " + isSystemPlugin.ToString());
                            if (!isSystemPlugin)
                            {
                                if (obj.Enabled == true)
                                {
                                    try
                                    {
                                        startPlugin(plugin);
                                    }
                                    catch (Exception ex)
                                    { Log.Error("Error activating plugin (" + plugin.PluginName + ")", ex); }
                                }
                                else
                                {
                                    plugin.Enabled = false;
                                }

                                Log.Info("status: " + plugin.Enabled.ToString());
                                Log.Info("PluginName: " + plugin.PluginName);
                                Log.Info("PluginVersion: " + plugin.PluginVersion);
                                OSAEObjectPropertyManager.ObjectPropertySet(obj.Name, "Version", plugin.PluginVersion, name);
                                OSAEObjectPropertyManager.ObjectPropertySet(obj.Name, "Author", plugin.PluginAuthor, name);

                                //NetworkComms.SendObject("Plugin", Common.WcfServer, 10051, plugin.PluginName + "|" + plugin.Status + "|" + plugin.PluginVersion + "|" + plugin.Enabled);
                                UDPConnection.SendObject("Plugin", plugin.PluginName + " | " + plugin.Enabled.ToString() + " | " + plugin.PluginVersion + " | Stopped | " + plugin.LatestAvailableVersion + " | " + plugin.PluginType + " | " + Common.ComputerName, new IPEndPoint(IPAddress.Broadcast, 10051));
                            }
                        }
                    }
                    else
                    {
                        Log.Info("Plugin object does not exist in DB: " + plugin.PluginName);
                        OSAEObjectManager.ObjectAdd(plugin.PluginName, "", plugin.PluginName, plugin.PluginType, "", "System", 50, true);
                        Log.Info("Plugin added to DB: " + plugin.PluginName);
                        UDPConnection.SendObject("Plugin", plugin.PluginName + " | ON | " + plugin.PluginVersion + " | Started | " + plugin.LatestAvailableVersion + " | " + plugin.PluginType + " | " + Common.ComputerName, new IPEndPoint(IPAddress.Broadcast, 10051));
                    }
                }
                catch (Exception ex)
                { Log.Error("Error loading plugin!", ex); }
            }
            Log.Info("Done loading plugins");
        }