/**
         * Gets Main calss associated with Command
         */

        public void ReloadPlugin()
        {
            //Console Commands skip this part becuase Plugins Are not loaded yet
            if (ServerInstance.Instance.PluginManager != null)
            {
                //Search for Plugin
                foreach (PluginInfo pi in ServerInstance.Instance.PluginManager.LoadedPlugins)
                {
                    //Console.WriteLine(pi.MainClass.GetName.ToLower() + "-----" + PluginName.ToLower());
                    if (pi.MainClass.GetName.ToLower() == PluginName.ToLower())
                    {
                        GetPlugin = pi.MainClass;
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
 public bool Execute(VpPluginContext ctx)
 {
     if (IsLoad && ctx.Plugins.ActivePlugins().Find(p => p.Description.Name.ToLower() == PluginName.ToLower()) != null)
     {
         ctx.Cli.WriteLine(ConsoleMessageType.Error, string.Format("Plugin {0} already loaded.", PluginName));
         return(true);
     }
     if (IsLoad)
     {
         var plugin = ctx.Plugins.Instances.Find(p => p.Description.Name.ToLower() == PluginName.ToLower());
         if (plugin == null)
         {
             ctx.Cli.WriteLine(ConsoleMessageType.Error, string.Format("Plugin named {0} not found.", PluginName));
             return(true);
         }
         if (plugin.DependentOn != null)
         {
             foreach (var item in plugin.DependentOn)
             {
                 var dependency = ctx.Plugins.Instances.Find(p => p.Description.Name.ToLower() == item);
                 if (dependency == null)
                 {
                     ctx.Cli.WriteLine(ConsoleMessageType.Error,
                                       string.Format(
                                           "Plugin named {0} can not be initialized as its dependend on plugin {1}, which is not found.",
                                           PluginName, item));
                     return(true);
                 }
                 if (!ctx.Plugins.ActivePlugins().Contains(dependency))
                 {
                     dependency.Console = ctx.Cli;
                     dependency.InitializePlugin(ctx.Vp);
                     ctx.Plugins.Activate(dependency);
                     ctx.Cli.WriteLine(ConsoleMessageType.Information, string.Format("Dependency Plugin {0} initialized.", item));
                 }
             }
         }
         plugin.Console = ctx.Cli;
         plugin.InitializePlugin(ctx.Vp);
         ctx.Plugins.Activate(plugin);
         ctx.Cli.WriteLine(ConsoleMessageType.Information, string.Format("Plugin {0} initialized.", PluginName));
         ctx.Plugins.SaveConfiguration("pluginConfiguration.xml");
         return(true);
     }
     if (!IsLoad && ctx.Plugins.ActivePlugins().Find(p => p.Description.Name.ToLower() == PluginName.ToLower()) == null)
     {
         ctx.Cli.WriteLine(ConsoleMessageType.Error, string.Format("Plugin {0} is not loaded.", PluginName));
         return(true);
     }
     if (!IsLoad)
     {
         var plugin = ctx.Plugins.Instances.Find(p => p.Description.Name.ToLower() == PluginName.ToLower());
         if (plugin == null)
         {
             ctx.Cli.WriteLine(ConsoleMessageType.Error, string.Format("Plugin named {0} not found.", PluginName));
             return(true);
         }
         ctx.Plugins.Deactivate(plugin);
         ctx.Cli.WriteLine(ConsoleMessageType.Information, string.Format("Plugin {0} unloaded.", PluginName));
         ctx.Plugins.SaveConfiguration("pluginConfiguration.xml");
         return(true);
     }
     return(true);
 }