Main.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. */
  28. using System;
  29. using System.Collections.Generic;
  30. using System.IO;
  31. using libsecondlife;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.Console;
  34. using OpenSim.Framework.Servers;
  35. namespace OpenSim.Grid.InventoryServer
  36. {
  37. public class OpenInventory_Main : BaseOpenSimServer, conscmd_callback
  38. {
  39. private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  40. private InventoryManager m_inventoryManager;
  41. private InventoryConfig m_config;
  42. private GridInventoryService m_inventoryService;
  43. public const string LogName = "INVENTORY";
  44. [STAThread]
  45. public static void Main(string[] args)
  46. {
  47. log4net.Config.XmlConfigurator.Configure();
  48. OpenInventory_Main theServer = new OpenInventory_Main();
  49. theServer.Startup();
  50. theServer.Work();
  51. }
  52. public OpenInventory_Main()
  53. {
  54. m_console = new ConsoleBase(LogName, this);
  55. MainConsole.Instance = m_console;
  56. }
  57. public void Startup()
  58. {
  59. m_log.Info("Initialising inventory manager...");
  60. m_config = new InventoryConfig(LogName, (Path.Combine(Util.configDir(), "InventoryServer_Config.xml")));
  61. m_inventoryService = new GridInventoryService();
  62. // m_inventoryManager = new InventoryManager();
  63. m_inventoryService.AddPlugin(m_config.DatabaseProvider);
  64. m_log.Info("[" + LogName + "]: Starting HTTP server ...");
  65. BaseHttpServer httpServer = new BaseHttpServer(m_config.HttpPort);
  66. httpServer.AddStreamHandler(
  67. new RestDeserialisehandler<Guid, InventoryCollection>("POST", "/GetInventory/",
  68. m_inventoryService.GetUserInventory));
  69. httpServer.AddStreamHandler(
  70. new RestDeserialisehandler<Guid, bool>("POST", "/CreateInventory/",
  71. m_inventoryService.CreateUsersInventory));
  72. httpServer.AddStreamHandler(
  73. new RestDeserialisehandler<InventoryFolderBase, bool>("POST", "/NewFolder/",
  74. m_inventoryService.AddInventoryFolder));
  75. httpServer.AddStreamHandler(
  76. new RestDeserialisehandler<InventoryFolderBase, bool>("POST", "/MoveFolder/",
  77. m_inventoryService.MoveInventoryFolder));
  78. httpServer.AddStreamHandler(
  79. new RestDeserialisehandler<InventoryItemBase, bool>("POST", "/NewItem/",
  80. m_inventoryService.AddInventoryItem));
  81. httpServer.AddStreamHandler(
  82. new RestDeserialisehandler<InventoryItemBase, bool>("POST", "/DeleteItem/",
  83. m_inventoryService.DeleteInvItem));
  84. httpServer.AddStreamHandler(
  85. new RestDeserialisehandler<Guid, List<InventoryFolderBase>>("POST", "/RootFolders/",
  86. m_inventoryService.RequestFirstLevelFolders));
  87. // httpServer.AddStreamHandler(new InventoryManager.GetInventory(m_inventoryManager));
  88. httpServer.Start();
  89. m_log.Info("[" + LogName + "]: Started HTTP server");
  90. }
  91. private void Work()
  92. {
  93. m_console.Notice("Enter help for a list of commands\n");
  94. while (true)
  95. {
  96. m_console.Prompt();
  97. }
  98. }
  99. public override void RunCmd(string cmd, string[] cmdparams)
  100. {
  101. base.RunCmd(cmd, cmdparams);
  102. switch (cmd)
  103. {
  104. case "quit":
  105. case "add-user":
  106. m_inventoryService.CreateUsersInventory(LLUUID.Random().UUID);
  107. break;
  108. case "shutdown":
  109. m_console.Close();
  110. Environment.Exit(0);
  111. break;
  112. }
  113. }
  114. }
  115. }