AssetServiceBase.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 OpenSimulator 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. using System;
  28. using System.Reflection;
  29. using Nini.Config;
  30. using OpenSim.Framework;
  31. using OpenSim.Data;
  32. using OpenSim.Services.Interfaces;
  33. using OpenSim.Services.Base;
  34. namespace OpenSim.Services.AssetService
  35. {
  36. public class AssetServiceBase : ServiceBase
  37. {
  38. protected IAssetDataPlugin m_Database = null;
  39. protected IAssetLoader m_AssetLoader = null;
  40. protected string m_ConfigName = "AssetService";
  41. public AssetServiceBase(IConfigSource config)
  42. : this(config, "AssetService")
  43. {
  44. }
  45. public AssetServiceBase(IConfigSource config, string configName) : base(config)
  46. {
  47. if (configName != string.Empty)
  48. m_ConfigName = configName;
  49. string dllName = String.Empty;
  50. string connString = String.Empty;
  51. //
  52. // Try reading the [AssetService] section, if it exists
  53. //
  54. IConfig assetConfig = config.Configs[m_ConfigName];
  55. if (assetConfig != null)
  56. {
  57. dllName = assetConfig.GetString("StorageProvider", dllName);
  58. connString = assetConfig.GetString("ConnectionString", connString);
  59. }
  60. //
  61. // Try reading the [DatabaseService] section, if it exists
  62. //
  63. IConfig dbConfig = config.Configs["DatabaseService"];
  64. if (dbConfig != null)
  65. {
  66. if (dllName == String.Empty)
  67. dllName = dbConfig.GetString("StorageProvider", String.Empty);
  68. if (connString == String.Empty)
  69. connString = dbConfig.GetString("ConnectionString", String.Empty);
  70. }
  71. //
  72. // We tried, but this doesn't exist. We can't proceed.
  73. //
  74. if (dllName.Equals(String.Empty))
  75. throw new Exception("No StorageProvider configured");
  76. m_Database = LoadPlugin<IAssetDataPlugin>(dllName);
  77. if (m_Database == null)
  78. throw new Exception(string.Format("Could not find a storage interface in the module {0}", dllName));
  79. m_Database.Initialise(connString);
  80. string loaderName = assetConfig.GetString("DefaultAssetLoader",
  81. String.Empty);
  82. if (loaderName != String.Empty)
  83. {
  84. m_AssetLoader = LoadPlugin<IAssetLoader>(loaderName);
  85. if (m_AssetLoader == null)
  86. throw new Exception(string.Format("Asset loader could not be loaded from {0}", loaderName));
  87. }
  88. }
  89. }
  90. }