Exemplo n.º 1
0
 private void AddPlugin(IIronPlugin plugin)
 {
     IronPlugins.Plugin.PluginCollection.AddResult result = _pluginManager.AddPlugin(plugin);
     if (result == PluginCollection.AddResult.Added)
     {
         dataGridView1.Rows[
             dataGridView1.Rows.Add(
             plugin.Guid,
             plugin.Source.Path)].Tag = plugin;
     }
     else if (result == PluginCollection.AddResult.OverWrote)
     {
         // Replace the existing row
         foreach (DataGridViewRow row in dataGridView1.Rows)
         {
             if (row.Tag.Equals(plugin))
             {
                 row.Cells[0].Value = plugin.Guid;
                 row.Tag = plugin;
             }
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Remove this manager from the plugin context.
 /// </summary>
 /// <param name="plugin"></param>
 private void RemoveSelfFromPluginContext(IIronPlugin plugin)
 {
     plugin.RemoveContextVariables(new Context.Variable("__mgr__", this));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Run the specified plugin on the current thread, or on the
        /// synchronized context if it was specified.
        /// </summary>
        /// <param name="plugin">The plugin to reload.</param>
        /// <param name="reload">Optionally reload the plugin before running.</param>
        private void RunPlugin(IIronPlugin plugin, bool reload)
        {
            try
            {
                if (_reloadContext == null)
                {
                    Reload(new object[] { plugin, reload, false });
                }
                else
                {
                    _reloadContext.Send(
                        new System.Threading.SendOrPostCallback(Reload),
                        new object[] { plugin, reload, true });
                }
            }
            catch (Exception e)
            {
                if (PluginReloadedError != null)
                {
                    PluginReloadErrorEventArgs args = new PluginReloadErrorEventArgs(plugin, e);
                    if (_reloadContext == null)
                        OnPluginReloadError(args);
                    else
                        _reloadContext.Send(
                                new System.Threading.SendOrPostCallback(delegate(object data)
                        {
                            OnPluginReloadError(args);
                        }), null);

                }
                else throw e;
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Reload the specified plugin.
 /// </summary>
 /// <param name="plugin"></param>
 private void ReloadPlugin(IIronPlugin plugin)
 {
     RunPlugin(plugin, true);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Get the full path for the specified plugin.
 /// </summary>
 /// <param name="plugin"></param>
 /// <returns></returns>
 private string GetPluginFullPath(IIronPlugin plugin)
 {
     string path = plugin.Source.Path;
     if (string.IsNullOrEmpty(path))
         path = ".";
     return Path.GetFullPath(path);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Add this manager to the plugin context.
 /// </summary>
 /// <param name="plugin"></param>
 private void AddSelfToPluginContext(IIronPlugin plugin)
 {
     plugin.AddContextVariables(new Context.Variable("__mgr__", this));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Remove the specified plugin from this manager.
 /// </summary>
 /// <param name="plugin"></param>
 public void RemovePlugin(IIronPlugin plugin)
 {
     if (_plugins.Remove(plugin))
     {
         // If this plugin has a watcher and no other plugins are on the
         // path of this plugins watcher, remove the watcher.
         FileSystemWatcher watcher = GetWatcherForPath(plugin.Source.Path);
         if (watcher != null)
         {
             List<IIronPlugin> pluginsOnPath = GetPluginsForPath(plugin.Source.Path);
             if (pluginsOnPath.Count == 0)
             {
                 _watchers.Remove(Path.GetDirectoryName(plugin.Source.Path));
                 watcher.Dispose();
             }
         }
         RemoveSelfFromPluginContext(plugin);
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Add the specified plugin to this manager.
 /// </summary>
 /// <param name="plugin"></param>
 public PluginCollection.AddResult AddPlugin(IIronPlugin plugin)
 {
     // Initialize the plugin so we have access to the source
     RunPlugin(plugin, false);
     PluginCollection.AddResult result = _plugins.AddPlugin(plugin);
     if (result != PluginCollection.AddResult.NotAdded)
     {
         if (plugin.Source != null)
         {
             if (System.IO.File.Exists(plugin.Source.Path))
             {
                 string dir = Path.GetDirectoryName(plugin.Source.Path);
                 // This creates the watcher on the directory if it doesn't already exist
                 GetWatcherForPath(dir);
             }
         }
     }
     return result;
 }