예제 #1
0
        /// <summary>
        /// Attempt to load a plugin
        /// </summary>
        /// <param name="info"></param>
        public void LoadPlugin(PluginInfo info)
        {
            Func<PluginLoader> wrapperFactory;
            var extension = Path.GetExtension(info.File);
            if (_pluginLoaderFactory.TryGetValue(extension, out wrapperFactory)) {
                // load the plugin via the wrapper
                var wrapper = _pluginLoaderFactory[extension]();
                var plugin = wrapper.Load(info.File);
                // setup the plugin instance
                plugin.RootDir = info.Directory;
                plugin.AppCommands = _appCommands.Value;
                plugin.Logger = new RemoteLogger("fix_me");
                // this needs to be removed, and be consistent with the python plugins
                plugin.Setup();
                info.Instance = plugin;

                // all done
                lock (LoadedPlugins) {
                    // make plugin available
                    LoadedPlugins.Add(plugin);
                }

                _logger.Debug("Loaded Plugin [{0}]: {1}", plugin.PluginLanguage, plugin.Name);
            }
        }
예제 #2
0
 public void UnloadPlugin(PluginInfo info)
 {
     var plugin = info.Instance;
     var pluginLanguage = plugin.PluginLanguage;
     var pluginName = plugin.Name;
     lock (LoadedPlugins) {
         LoadedPlugins.Remove(plugin);
     }
     try {
         plugin.Unload();
     }
     catch (AppDomainUnloadedException) {
     }
     finally {
         info.Instance = null;
         _logger.Debug("Unloaded Plugin [{0}]: {1}", pluginLanguage, pluginName);
     }
 }
예제 #3
0
 /// <summary>
 /// Load or Unload the plugin defined by <paramref name="info"/>, if Enabled is true the plugin will be loaded.
 /// This method is thread safe.
 /// </summary>
 /// <param name="info"></param>
 public void LoadOrUnload(PluginInfo info)
 {
     lock (info.LoadLock) {
         try {
             if (info.Instance == null && info.Enabled) {
                 // load
                 LoadPlugin(info);
             }
             else if (info.Instance != null && !info.Enabled) {
                 // unload
                 UnloadPlugin(info);
             }
             // update user configuration
             lock (_settings) {
                 if (info.Enabled) {
                     _settings.User.EnabledPlugins.Add(info.guid);
                 }
                 else {
                     _settings.User.EnabledPlugins.Remove(info.guid);
                 }
                 _settings.Save();
             }
         }
         catch (Exception e) {
             _logger.Warn(e, "An error occurred while loading or unloading a plugin");
         }
     }
 }