29 using System.Collections.Generic;
31 using System.Reflection;
32 using System.Threading;
37 using OpenSim.Framework;
38 using OpenSim.Framework.Serialization.External;
40 using OpenSim.Region.Framework.Scenes;
41 using OpenSim.Region.Framework.Scenes.Serialization;
42 using OpenSim.Region.Framework.Interfaces;
43 using OpenSim.Services.Interfaces;
53 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
58 private Scene m_scene;
59 private string m_HomeURI;
73 #region Internal functions
77 if (
string.IsNullOrEmpty(url))
80 if (!url.EndsWith(
"/") && !url.EndsWith(
"="))
83 AssetMetadata meta = m_scene.AssetService.GetMetadata(url + assetID.ToString());
86 m_log.DebugFormat(
"[HG ASSET MAPPER]: Fetched metadata for asset {0} of type {1} from {2} ", assetID, meta.Type, url);
88 m_log.DebugFormat(
"[HG ASSET MAPPER]: Unable to fetched metadata for asset {0} from {1} ", assetID, url);
93 private AssetBase FetchAsset(
string url, UUID assetID)
96 AssetBase asset = m_scene.AssetService.Get(assetID.ToString());
99 if (
string.IsNullOrEmpty(url))
102 if (!url.EndsWith(
"/") && !url.EndsWith(
"="))
105 asset = m_scene.AssetService.Get(url + assetID.ToString());
119 if (
string.IsNullOrEmpty(url))
122 if (!url.EndsWith(
"/") && !url.EndsWith(
"="))
127 m_log.Warn(
"[HG ASSET MAPPER]: Tried to post asset to remote server, but asset not in local cache.");
142 asset1.ID = url + asset.ID;
146 asset1.Data = AdjustIdentifiers(asset.
Data);
148 asset1.Data = asset.Data;
150 string id = m_scene.AssetService.Store(asset1);
151 if (
String.IsNullOrEmpty(
id))
153 m_log.DebugFormat(
"[HG ASSET MAPPER]: Asset server {0} did not accept {1}", url, asset.ID);
157 m_log.DebugFormat(
"[HG ASSET MAPPER]: Posted copy of asset {0} from local asset server to {1}", asset1.ID, url);
165 to.Description = from.Description;
166 to.FullID = from.FullID;
168 to.Local = from.Local;
170 to.Temporary = from.Temporary;
177 if (!
string.IsNullOrEmpty(meta.
CreatorID))
179 UUID uuid = UUID.Zero;
180 UUID.TryParse(meta.CreatorID, out uuid);
181 UserAccount creator = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, uuid);
183 meta.CreatorID = m_HomeURI +
";" + creator.FirstName +
" " + creator.LastName;
189 string xml = Utils.BytesToString(data);
190 return Utils.StringToBytes(RewriteSOP(xml));
196 return ExternalRepresentationUtils.RewriteSOP(xmlData, m_scene.Name, m_HomeURI, m_scene.UserAccountService, m_scene.RegionInfo.ScopeID);
212 #region Public interface
214 public void Get(UUID assetID, UUID ownerID,
string userAssetURL)
225 uuidGatherer.AddForInspection(assetID);
226 uuidGatherer.GatherAll();
228 m_log.DebugFormat(
"[HG ASSET MAPPER]: Preparing to get {0} assets", uuidGatherer.GatheredUuids.Count);
230 foreach (
UUID uuid
in uuidGatherer.GatheredUuids.Keys)
231 if (FetchAsset(userAssetURL, uuid) == null)
236 m_log.DebugFormat(
"[HG ASSET MAPPER]: Problems getting item {0} from asset server {1}", assetID, userAssetURL);
238 m_log.DebugFormat(
"[HG ASSET MAPPER]: Successfully got item {0} from asset server {1}", assetID, userAssetURL);
241 public void Post(UUID assetID, UUID ownerID,
string userAssetURL)
243 m_log.DebugFormat(
"[HG ASSET MAPPER]: Starting to send asset {0} with children to asset server {1}", assetID, userAssetURL);
247 AssetBase asset = m_scene.AssetService.Get(assetID.ToString());
250 m_log.DebugFormat(
"[HG ASSET MAPPER]: Something wrong with asset {0}, it could not be found", assetID);
255 uuidGatherer.AddForInspection(asset.FullID);
256 uuidGatherer.GatherAll();
260 string url = userAssetURL;
261 if (!url.EndsWith(
"/") && !url.EndsWith(
"="))
264 string[] remoteAssetIDs =
new string[uuidGatherer.GatheredUuids.Count];
266 foreach (
UUID id in uuidGatherer.GatheredUuids.Keys)
267 remoteAssetIDs[i++] = url + id.ToString();
269 bool[] exist = m_scene.AssetService.AssetsExist(remoteAssetIDs);
271 var existSet =
new HashSet<string>();
273 foreach (
UUID id in uuidGatherer.GatheredUuids.Keys)
276 existSet.Add(id.ToString());
284 foreach (
UUID uuid
in uuidGatherer.GatheredUuids.Keys)
286 if (!existSet.Contains(uuid.ToString()))
288 asset = m_scene.AssetService.Get(uuid.ToString());
291 m_log.DebugFormat(
"[HG ASSET MAPPER]: Could not find asset {0}", uuid);
297 success &= PostAsset(userAssetURL, asset);
303 "[HG ASSET MAPPER]: Failed to post asset {0} (type {1}, length {2}) referenced from {3} to {4} with exception ",
304 asset.ID, asset.Type, asset.Data.Length, assetID, userAssetURL),
318 "[HG ASSET MAPPER]: Didn't post asset {0} referenced from {1} because it already exists in asset server {2}",
319 uuid, assetID, userAssetURL);
324 m_log.DebugFormat(
"[HG ASSET MAPPER]: Problems sending asset {0} with children to asset server {1}", assetID, userAssetURL);
326 m_log.DebugFormat(
"[HG ASSET MAPPER]: Successfully sent asset {0} with children to asset server {1}", assetID, userAssetURL);
void Post(UUID assetID, UUID ownerID, string userAssetURL)
sbyte Type
(sbyte) AssetType enum
HGAssetMapper(Scene scene, string homeURL)
bool PostAsset(string url, AssetBase asset)
bool Local
Is this a region only asset, or does this exist on the asset server also
Asset class. All Assets are reference by this class or a class derived from this class ...
void Get(UUID assetID, UUID ownerID, string userAssetURL)
Interactive OpenSim region server
byte[] AdjustIdentifiers(byte[] data)
bool Temporary
Is this asset going to be saved to the asset database?
string RewriteSOP(string xmlData)