29 using System.Collections.Generic;
31 using System.Reflection;
34 using OpenSim.Framework;
36 using OpenSim.Services.Interfaces;
39 namespace OpenSim.Services.AssetService
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 public XAssetService(IConfigSource config) : this(config,
"AssetService") {}
53 public XAssetService(IConfigSource config,
string configName) : base(config, configName)
55 if (m_RootInstance == null)
57 m_RootInstance =
this;
59 if (m_AssetLoader != null)
61 IConfig assetConfig = config.Configs[configName];
62 if (assetConfig == null)
63 throw new Exception(
"No AssetService configuration");
65 string loaderArgs = assetConfig.GetString(
"AssetLoaderArgs", String.Empty);
67 bool assetLoaderEnabled = assetConfig.GetBoolean(
"AssetLoaderEnabled",
true);
69 if (assetLoaderEnabled && !HasChainedAssetService)
71 m_log.DebugFormat(
"[XASSET SERVICE]: Loading default asset set from {0}", loaderArgs);
73 m_AssetLoader.ForEachDefaultXmlAsset(
80 if (existingAsset == null || Util.SHA1Hash(existingAsset.
Data) != Util.SHA1Hash(a.Data))
88 m_log.Debug(
"[XASSET SERVICE]: Local asset service enabled");
89 m_log.Error(
"[XASSET SERVICE]: THIS ASSET SERVICE HAS BEEN MARKED OBSOLETE. PLEASE USE FSAssetService");
100 if (!UUID.TryParse(
id, out assetID))
102 m_log.WarnFormat(
"[XASSET SERVICE]: Could not parse requested asset id {0}", id);
108 AssetBase asset = m_Database.GetAsset(assetID);
114 else if (HasChainedAssetService)
116 asset = m_ChainedAssetService.Get(id);
119 MigrateFromChainedService(asset);
128 m_log.ErrorFormat(
"[XASSET SERVICE]: Exception getting asset {0} {1}", assetID, e);
145 return asset.Metadata;
168 if (!UUID.TryParse(
id, out assetID))
175 handler(
id, sender, asset);
182 UUID[] uuid = Array.ConvertAll(ids,
id => UUID.Parse(id));
183 return m_Database.AssetsExist(uuid);
188 bool exists = m_Database.AssetsExist(
new[] { asset.FullID })[0];
193 m_Database.StoreAsset(asset);
214 if (!UUID.TryParse(
id, out assetID))
217 if (HasChainedAssetService)
218 m_ChainedAssetService.Delete(id);
220 return m_Database.Delete(id);
223 private void MigrateFromChainedService(
AssetBase asset)
226 m_ChainedAssetService.Delete(asset.ID);
virtual bool Get(string id, Object sender, AssetRetrieved handler)
Get an asset synchronously or asynchronously (depending on whether it is locally cached) and fire a c...
virtual AssetBase Get(string id)
Get an asset synchronously.
bool UpdateContent(string id, byte[] data)
Update an asset's content
virtual string Store(AssetBase asset)
Creates a new asset
XAssetService(IConfigSource config, string configName)
virtual AssetMetadata GetMetadata(string id)
Get an asset's metadata
virtual AssetBase GetCached(string id)
Synchronously fetches an asset from the local cache only.
Asset class. All Assets are reference by this class or a class derived from this class ...
virtual bool Delete(string id)
Delete an asset
static XAssetService m_RootInstance
A de-duplicating asset service.
delegate void AssetRetrieved(string id, Object sender, AssetBase asset)
virtual bool[] AssetsExist(string[] ids)
Check if assets exist in the database.
XAssetService(IConfigSource config)
virtual byte[] GetData(string id)
Get an asset's data, ignoring the metadata.