/// <summary>
        ///     Creates a type as a specified plugin.
        /// </summary>
        /// <typeparam name="T">The type of plugin to load it as.</typeparam>
        /// <param name="type">The type to load.</param>
        /// <param name="loadData">The data to load into the plugin.</param>
        /// <param name="backupLoadData">The backup load data to try for backwards compatability.</param>
        /// <returns>The new plugin.</returns>
        internal T Create<T>(Type type, PluginBaseLoadData loadData, PluginLoadData backupLoadData = null) where T : PluginBase
        {
            //Create an instance of the plugin
            T plugin;
            try
            {
                plugin = (T)Activator.CreateInstance(type, loadData);
            }
            catch (MissingMethodException)
            {
                //Failed, perhaps using backup PluginLoadData would help?
                if (backupLoadData != null)
                {
                    plugin = (T)Activator.CreateInstance(type, backupLoadData);
                    logger.Warning($"Plugin {type.Name} was loaded using a PluginLoadData object instead of the desired {loadData.GetType().Name}. Consider replacing the constructor with one accepting a " + loadData.GetType().Name + " object instead.");
                }
                else
                {
                    throw;
                }
            }

            //Log creation
            if (!plugin.Hidden)
                logger.Trace($"Created plugin '{type.Name}'.");
            
            return plugin;
        }
        /// <summary>
        ///     Load the plugin given.
        /// </summary>
        /// <param name="name">The name of the plugin instance.</param>
        /// <param name="type">The plugin type to load.</param>
        /// <param name="pluginLoadData">The data for this plugin.</param>
        /// <param name="backupLoadData">The data for this plugin if the first fails.</param>
        /// <param name="createResourceDirectory">Whether to create a resource directory or not.</param>
        protected override T LoadPlugin(string name, string type, PluginBaseLoadData pluginLoadData, PluginLoadData backupLoadData, bool createResourceDirectory)
        {
            T plugin = base.LoadPlugin(name, type, pluginLoadData, backupLoadData, createResourceDirectory);

            HandleThreadSafe(plugin);

            HandleInstallUpgrade(plugin);

            return(plugin);
        }
 /// <summary>
 ///     Creates a named type as a specified plugin.
 /// </summary>
 /// <typeparam name="T">The type of plugin to load it as.</typeparam>
 /// <param name="type">The name of the type to load.</param>
 /// <param name="loadData">The data to load into the plugin.</param>
 /// <param name="backupLoadData">The backup load data to try for backwards compatablity.</param>
 /// <returns>The new plugin.</returns>
 internal T Create<T>(string type, PluginBaseLoadData loadData, PluginLoadData backupLoadData = null) where T : PluginBase
 {
     try
     {
         return Create<T>(types[type], loadData, backupLoadData);
     }
     catch (KeyNotFoundException e)
     {
         throw new KeyNotFoundException($"No plugin of type {type} is available to load. Check the plugin is in the plugin search paths, you can see the plugins that are found by setting startup log levels to show trace level logs.", e);
     }
 }
        /// <summary>
        ///     Creates a new plugin base using the given plugin load data.
        /// </summary>
        /// <param name="pluginLoadData"></param>
        public PluginBase(PluginBaseLoadData pluginLoadData)
        {
            this.Name = pluginLoadData.Name;
#pragma warning disable CS0618 // Type or member is obsolete
            this.DatabaseManager = pluginLoadData.DatabaseManager;
#pragma warning restore CS0618 // Type or member is obsolete
            this.Dispatcher   = pluginLoadData.Dispatcher;
            this.ServerInfo   = pluginLoadData.ServerInfo;
            this.ThreadHelper = pluginLoadData.ThreadHelper;
            this.LogManager   = pluginLoadData.LogManager;
            this.Logger       = pluginLoadData.Logger;
            this.Server       = pluginLoadData.Server;
        }
Exemple #5
0
        /// <summary>
        ///     Load the plugin given.
        /// </summary>
        /// <param name="name">The name of the plugin instance.</param>
        /// <param name="type">The plugin type to load.</param>
        /// <param name="pluginLoadData">The data for this plugin.</param>
        /// <param name="backupLoadData">The data for this plugin if the first fails.</param>
        /// <param name="createResourceDirectory">Whether to create a resource directory or not.</param>
        protected virtual T LoadPlugin(string name, string type, PluginBaseLoadData pluginLoadData, PluginLoadData backupLoadData, bool createResourceDirectory)
        {
            //Ensure the resource directory is present
            if (createResourceDirectory)
            {
                dataManager.CreateResourceDirectory(type);
            }

            T plugin = pluginFactory.Create <T>(type, pluginLoadData);

            plugins.Add(name, plugin);

            return(plugin);
        }