From def8012ec107c9a2b8e4aff9d9047badf984b57f Mon Sep 17 00:00:00 2001 From: BlueWall Date: Thu, 26 Apr 2012 22:12:10 -0400 Subject: [PATCH] Changing more methods to work with console and rest --- .../Integration/IntegrationServerHandler.cs | 5 +- .../IntegrationService/IntegrationService.cs | 47 ++++-- .../IntegrationService/PluginManager.cs | 159 +++++++++++++++--- 3 files changed, 176 insertions(+), 35 deletions(-) diff --git a/OpenSim/Server/Handlers/Integration/IntegrationServerHandler.cs b/OpenSim/Server/Handlers/Integration/IntegrationServerHandler.cs index 320b5030c6..7a60ff1034 100644 --- a/OpenSim/Server/Handlers/Integration/IntegrationServerHandler.cs +++ b/OpenSim/Server/Handlers/Integration/IntegrationServerHandler.cs @@ -75,7 +75,7 @@ namespace OpenSim.Server.Handlers.Integration return FailureResult("Error, no command defined!"); } - string command = request["command"].AsString (); + string command = request["command"].AsString(); switch (command) { @@ -85,6 +85,9 @@ namespace OpenSim.Server.Handlers.Integration case "list_available": return HandleListAvailablePlugins(request); + case "show_info": + return HandlePluginInfo(request); + case "install_plugin": return HandleInstallPlugin(request); diff --git a/OpenSim/Services/IntegrationService/IntegrationService.cs b/OpenSim/Services/IntegrationService/IntegrationService.cs index a406299834..20f106d581 100644 --- a/OpenSim/Services/IntegrationService/IntegrationService.cs +++ b/OpenSim/Services/IntegrationService/IntegrationService.cs @@ -135,7 +135,11 @@ namespace OpenSim.Services.IntegrationService // Install plugin from registered repository private void HandleConsoleInstallPlugin(string module, string[] cmd) { - MainConsole.Instance.Output(m_PluginManager.InstallPlugin(cmd)); + if (cmd.Length == 2) + { + int ndx = Convert.ToInt16(cmd[1]); + MainConsole.Instance.Output(m_PluginManager.InstallPlugin(ndx)); + } return; } @@ -144,7 +148,8 @@ namespace OpenSim.Services.IntegrationService { if (cmd.Length == 2) { - m_PluginManager.UnInstall(cmd); + int ndx = Convert.ToInt16(cmd[1]); + m_PluginManager.UnInstall(ndx); } return; } @@ -220,7 +225,7 @@ namespace OpenSim.Services.IntegrationService { if ( cmd.Length == 3) { - m_PluginManager.AddRepository(cmd); + m_PluginManager.AddRepository(cmd[2]); } return; } @@ -271,9 +276,6 @@ namespace OpenSim.Services.IntegrationService enabled == true ? "[ ]" : "[X]", repo["name"], repo["url"]); } - //ArrayList list = m_PluginManager.ListRepositories(); - //foreach (string entry in list) - // MainConsole.Instance.Output(entry); return; } @@ -281,9 +283,22 @@ namespace OpenSim.Services.IntegrationService // Show description information private void HandleConsoleShowAddinInfo(string module, string[] cmd) { - if ( cmd.Length >= 3 ) + if (cmd.Length >= 3) { - m_PluginManager.AddinInfo(cmd); + + Dictionary result = new Dictionary(); + + int ndx = Convert.ToInt16(cmd[2]); + m_PluginManager.AddinInfo(ndx, out result); + + MainConsole.Instance.OutputFormat("Name: {0}\nURL: {1}\n{2}\n{3}", + result["name"], + result["url"], + result["file_name"], + result["author"], + result["category"], + result["description"]); + return; } } @@ -340,9 +355,21 @@ namespace OpenSim.Services.IntegrationService return Ux.DocToBytes(json); } - public byte[] HandleWebPluginInfo (OSDMap request) + public byte[] HandleWebPluginInfo(OSDMap request) { - return Ux.FailureResult("Not Implemented"); + Dictionary result = new Dictionary(); + + if(!String.IsNullOrEmpty(request["index"].ToString())) + { + int ndx = Convert.ToInt16(request["index"].ToString()); + m_PluginManager.AddinInfo(ndx, out result); + string json = LitJson.JsonMapper.ToJson(result); + return Ux.DocToBytes(json); + } + else + { + return Ux.FailureResult("No index supplied"); + } } public byte[] HandleWebListAvailablePlugins(OSDMap request) diff --git a/OpenSim/Services/IntegrationService/PluginManager.cs b/OpenSim/Services/IntegrationService/PluginManager.cs index f1cf1e4ba7..e18aeea700 100644 --- a/OpenSim/Services/IntegrationService/PluginManager.cs +++ b/OpenSim/Services/IntegrationService/PluginManager.cs @@ -44,13 +44,28 @@ namespace OpenSim.Services.IntegrationService { protected AddinRegistry m_Registry; + /// + /// Initializes a new instance of the class. + /// + /// + /// R. + /// internal PluginManager( AddinRegistry r): base (r) { m_Registry = r; m_Registry.Update(); } - public string InstallPlugin(string[] args) + /// + /// Installs the plugin. + /// + /// + /// The plugin. + /// + /// + /// Arguments. + /// + public string InstallPlugin(int ndx) { PackageCollection pack = new PackageCollection(); PackageCollection toUninstall; @@ -58,19 +73,15 @@ namespace OpenSim.Services.IntegrationService IProgressStatus ps = new ConsoleProgressStatus(false); - string name = Addin.GetIdName(args[1]); - string version = Addin.GetIdVersion(args[1]); - AddinRepositoryEntry[] available = GetSortedAvailbleAddins(); - int n = Convert.ToInt16(args[1]); - if (n > (available.Length - 1)) + if (ndx > (available.Length - 1)) { MainConsole.Instance.Output("Selection out of range"); return "Error"; } - AddinRepositoryEntry aentry = available[n]; + AddinRepositoryEntry aentry = available[ndx]; Package p = Package.FromRepository(aentry); pack.Add(p); @@ -93,18 +104,23 @@ namespace OpenSim.Services.IntegrationService } // Remove plugin - public void UnInstall(string[] args) + /// + /// Uns the install. + /// + /// + /// Arguments. + /// + public void UnInstall(int ndx) { Addin[] addins = GetSortedAddinList("IntegrationPlugin"); - int n = Convert.ToInt16(args[1]); - if (n > (addins.Length -1)) + if (ndx > (addins.Length -1)) { MainConsole.Instance.Output("Selection out of range"); return; } - Addin addin = addins[n]; + Addin addin = addins[ndx]; MainConsole.Instance.OutputFormat("Uninstalling plugin {0}", addin.Id); AddinManager.Registry.DisableAddin(addin.Id); addin.Enabled = false; @@ -113,12 +129,23 @@ namespace OpenSim.Services.IntegrationService return; } + /// + /// Checks the installed. + /// + /// + /// The installed. + /// public string CheckInstalled() { return "CheckInstall"; } - // List instaled addins + /// + /// Lists the installed addins. + /// + /// + /// Result. + /// public void ListInstalledAddins(out Dictionary result) { Dictionary res = new Dictionary(); @@ -142,6 +169,12 @@ namespace OpenSim.Services.IntegrationService } // List compatible plugins in registered repositories + /// + /// Lists the available. + /// + /// + /// Result. + /// public void ListAvailable(out Dictionary result) { Dictionary res = new Dictionary(); @@ -164,6 +197,9 @@ namespace OpenSim.Services.IntegrationService } // List available updates ** 1 + /// + /// Lists the updates. + /// public void ListUpdates() { IProgressStatus ps = new ConsoleProgressStatus(true); @@ -180,6 +216,9 @@ namespace OpenSim.Services.IntegrationService } // Sync to repositories + /// + /// Update this instance. + /// public string Update() { IProgressStatus ps = new ConsoleProgressStatus(true); @@ -188,18 +227,36 @@ namespace OpenSim.Services.IntegrationService } // Register a repository - public string AddRepository(string[] args) + /// + /// Register a repository with our server. + /// + /// + /// result of the action + /// + /// + /// The URL of the repository we want to add + /// + public bool AddRepository(string repo) { - Repositories.RegisterRepository(null, args[2].ToString(), true); - return "AddRepository"; + Repositories.RegisterRepository(null, repo, true); + return true; } + /// + /// Gets the repository. + /// public void GetRepository() { Repositories.UpdateAllRepositories(new ConsoleProgressStatus(false)); } // Remove a repository from the list + /// + /// Removes the repository. + /// + /// + /// Arguments. + /// public void RemoveRepository(string[] args) { AddinRepository[] reps = Repositories.GetRepositories(); @@ -223,6 +280,12 @@ namespace OpenSim.Services.IntegrationService } // Enable repository + /// + /// Enables the repository. + /// + /// + /// Arguments. + /// public void EnableRepository(string[] args) { AddinRepository[] reps = Repositories.GetRepositories(); @@ -246,6 +309,12 @@ namespace OpenSim.Services.IntegrationService } // Disable a repository + /// + /// Disables the repository. + /// + /// + /// Arguments. + /// public void DisableRepository(string[] args) { AddinRepository[] reps = Repositories.GetRepositories(); @@ -269,6 +338,12 @@ namespace OpenSim.Services.IntegrationService } // List registered repositories + /// + /// Lists the repositories. + /// + /// + /// Result. + /// public void ListRepositories(out Dictionary result) { Dictionary res = new Dictionary(); @@ -295,32 +370,62 @@ namespace OpenSim.Services.IntegrationService return; } + /// + /// Updates the registry. + /// public void UpdateRegistry() { m_Registry.Update(); } // Show plugin info - public string AddinInfo(string[] args) + /// + /// Addins the info. + /// + /// + /// The info. + /// + /// + /// Arguments. + /// + public bool AddinInfo(int ndx, out Dictionary result) { + Dictionary res = new Dictionary(); + result = res; + Addin[] addins = GetSortedAddinList("IntegrationPlugin"); - int n = Convert.ToInt16(args[2]); - if (n > (addins.Length -1)) + if (ndx > (addins.Length - 1)) { MainConsole.Instance.Output("Selection out of range"); - return "XXX"; + return false; } + // author category description + Addin addin = addins[ndx]; - Addin addin = addins[n]; - MainConsole.Instance.OutputFormat("Name: {0}\nURL: {1}\n{2}", - addin.Name, addin.Description.Url, - addin.Description.FileName); + res["author"] = addin.Description.Author; + res["category"] = addin.Description.Category; + res["description"] = addin.Description.Description; + res["name"] = addin.Name; + res["url"] = addin.Description.Url; + res["file_name"] = addin.Description.FileName; - return "AddinInfo"; +// MainConsole.Instance.OutputFormat("Name: {0}\nURL: {1}\n{2}", +// addin.Name, addin.Description.Url, +// addin.Description.FileName); + + result = res; + + return true; } // Disable a plugin + /// + /// Disables the plugin. + /// + /// + /// Arguments. + /// public void DisablePlugin(string[] args) { Addin[] addins = GetSortedAddinList("IntegrationPlugin"); @@ -339,6 +444,12 @@ namespace OpenSim.Services.IntegrationService } // Enable plugin + /// + /// Enables the plugin. + /// + /// + /// Arguments. + /// public void EnablePlugin(string[] args) { Addin[] addins = GetSortedAddinList("IntegrationPlugin");