29 using System.Collections.Generic;
31 using System.Reflection;
36 using OpenSim.Framework;
37 using OpenSim.Framework.Serialization;
38 using OpenSim.Services.Interfaces;
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 protected Dictionary<string, byte[]> m_assetDataAwaitingMetadata =
new Dictionary<string, byte[]>();
76 if (null == m_metadata)
78 m_assetDataAwaitingMetadata[assetFilename] = data;
82 ResolveAssetData(assetFilename, data);
92 m_metadata =
new Dictionary<string, AssetMetadata>();
94 StringReader sr =
new StringReader(xml);
95 XmlTextReader reader =
new XmlTextReader(sr);
97 reader.ReadStartElement(
"assets");
100 while (reader.Name.Equals(
"asset"))
106 string filename = reader.ReadElementString(
"filename");
107 m_log.DebugFormat(
"[DEARCHIVER]: Reading node {0}", filename);
109 metadata.Name = reader.ReadElementString(
"name");
110 metadata.Description = reader.ReadElementString(
"description");
111 metadata.AssetType = Convert.ToSByte(reader.ReadElementString(
"asset-type"));
113 m_metadata[filename] = metadata;
116 reader.ReadEndElement();
121 m_log.DebugFormat(
"[DEARCHIVER]: Resolved {0} items of asset metadata", m_metadata.Count);
123 ResolvePendingAssetData();
131 foreach (
string filename
in m_assetDataAwaitingMetadata.Keys)
133 ResolveAssetData(filename, m_assetDataAwaitingMetadata[filename]);
145 string filename = assetPath.Remove(0, ArchiveConstants.ASSETS_PATH.Length);
147 if (m_metadata.ContainsKey(filename))
153 string extension = ArchiveConstants.ASSET_TYPE_TO_EXTENSION[metadata.AssetType];
154 filename = filename.Remove(filename.Length - extension.Length);
157 m_log.DebugFormat(
"[ARCHIVER]: Importing asset {0}", filename);
160 asset.Description = metadata.Description;
163 m_cache.Store(asset);
168 "[DEARCHIVER]: Tried to dearchive data with filename {0} without any corresponding metadata",
IAssetService m_cache
Cache to which dearchived assets will be added
static readonly IDictionary< sbyte, string > ASSET_TYPE_TO_EXTENSION
Constants for the archiving module
void ResolveAssetData(string assetPath, byte[] data)
Resolve a new piece of asset data against stored metadata
Asset class. All Assets are reference by this class or a class derived from this class ...
AssetsDearchiver(IAssetService cache)
void ResolvePendingAssetData()
Resolve asset data that we collected before receiving the metadata
void AddAssetMetadata(string xml)
Add asset metadata xml
void AddAssetData(string assetFilename, byte[] data)
Add asset data to the dearchiver
Dictionary< string, AssetMetadata > m_metadata
Asset metadata. Is null if asset metadata isn't yet available.