AssetService.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 log4net;
  31. using OpenSim.Framework;
  32. using OpenSim.Data;
  33. using OpenSim.Services.Interfaces;
  34. using OpenMetaverse;
  35. namespace OpenSim.Services.AssetService
  36. {
  37. public class AssetService : AssetServiceBase, IAssetService
  38. {
  39. private static readonly ILog m_log =
  40. LogManager.GetLogger(
  41. MethodBase.GetCurrentMethod().DeclaringType);
  42. public AssetService(IConfigSource config) : base(config)
  43. {
  44. if (m_AssetLoader != null)
  45. {
  46. IConfig assetConfig = config.Configs["AssetService"];
  47. if (assetConfig == null)
  48. throw new Exception("No AssetService configuration");
  49. string loaderArgs = assetConfig.GetString("AssetLoaderArgs",
  50. String.Empty);
  51. m_log.InfoFormat("[ASSET]: Loading default asset set from {0}", loaderArgs);
  52. m_AssetLoader.ForEachDefaultXmlAsset(loaderArgs,
  53. delegate(AssetBase a)
  54. {
  55. Store(a);
  56. });
  57. m_log.Info("[ASSET CONNECTOR]: Local asset service enabled");
  58. }
  59. }
  60. public AssetBase Get(string id)
  61. {
  62. //m_log.DebugFormat("[ASSET SERVICE]: Get asset {0}", id);
  63. UUID assetID;
  64. if (!UUID.TryParse(id, out assetID))
  65. return null;
  66. return m_Database.FetchAsset(assetID);
  67. }
  68. public AssetMetadata GetMetadata(string id)
  69. {
  70. UUID assetID;
  71. if (!UUID.TryParse(id, out assetID))
  72. return null;
  73. AssetBase asset = m_Database.FetchAsset(assetID);
  74. return asset.Metadata;
  75. }
  76. public byte[] GetData(string id)
  77. {
  78. UUID assetID;
  79. if (!UUID.TryParse(id, out assetID))
  80. return null;
  81. AssetBase asset = m_Database.FetchAsset(assetID);
  82. return asset.Data;
  83. }
  84. public bool Get(string id, Object sender, AssetRetrieved handler)
  85. {
  86. //m_log.DebugFormat("[AssetService]: Get asset async {0}", id);
  87. UUID assetID;
  88. if (!UUID.TryParse(id, out assetID))
  89. return false;
  90. AssetBase asset = m_Database.FetchAsset(assetID);
  91. //m_log.DebugFormat("[AssetService]: Got asset {0}", asset);
  92. handler(id, sender, asset);
  93. return true;
  94. }
  95. public string Store(AssetBase asset)
  96. {
  97. //m_log.DebugFormat("[ASSET SERVICE]: Store asset {0} {1}", asset.Name, asset.ID);
  98. m_Database.CreateAsset(asset);
  99. return asset.ID;
  100. }
  101. public bool UpdateContent(string id, byte[] data)
  102. {
  103. return false;
  104. }
  105. public bool Delete(string id)
  106. {
  107. return false;
  108. }
  109. }
  110. }