Use using() semantics in XBakesModule to ensure disposable objects are alway disposed no matter what

mb-throttle-test
Justin Clark-Casey (justincc) 2014-12-20 01:38:48 +00:00
parent 9edc5cac96
commit 798074c66f
1 changed files with 42 additions and 39 deletions

View File

@ -112,33 +112,32 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures
try try
{ {
Stream s = rc.Request(m_Auth); using (Stream s = rc.Request(m_Auth))
XmlTextReader sr = new XmlTextReader(s); using (XmlTextReader sr = new XmlTextReader(s))
sr.ReadStartElement("BakedAppearance");
while (sr.LocalName == "BakedTexture")
{ {
string sTextureIndex = sr.GetAttribute("TextureIndex"); sr.ReadStartElement("BakedAppearance");
int lTextureIndex = Convert.ToInt32(sTextureIndex); while (sr.LocalName == "BakedTexture")
string sCacheId = sr.GetAttribute("CacheId");
UUID lCacheId = UUID.Zero;
if (!(UUID.TryParse(sCacheId, out lCacheId)))
{ {
// ?? Nothing here string sTextureIndex = sr.GetAttribute("TextureIndex");
int lTextureIndex = Convert.ToInt32(sTextureIndex);
string sCacheId = sr.GetAttribute("CacheId");
UUID lCacheId = UUID.Zero;
if (!(UUID.TryParse(sCacheId, out lCacheId)))
{
// ?? Nothing here
}
++size;
sr.ReadStartElement("BakedTexture");
AssetBase a = (AssetBase)m_serializer.Deserialize(sr);
ret.Add(new WearableCacheItem() { CacheId = lCacheId, TextureIndex = (uint)lTextureIndex, TextureAsset = a, TextureID = a.FullID });
sr.ReadEndElement();
} }
++size; m_log.DebugFormat("[XBakes]: read {0} textures for user {1}", ret.Count, id);
sr.ReadStartElement("BakedTexture");
AssetBase a = (AssetBase)m_serializer.Deserialize(sr);
ret.Add(new WearableCacheItem() { CacheId = lCacheId, TextureIndex = (uint)lTextureIndex, TextureAsset = a, TextureID = a.FullID });
sr.ReadEndElement();
} }
m_log.DebugFormat("[XBakes]: read {0} textures for user {1}", ret.Count, id);
sr.Close();
s.Close();
return ret.ToArray(); return ret.ToArray();
} }
@ -153,27 +152,32 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures
if (m_URL == String.Empty) if (m_URL == String.Empty)
return; return;
MemoryStream bakeStream = new MemoryStream(); MemoryStream reqStream;
XmlTextWriter bakeWriter = new XmlTextWriter(bakeStream, null);
bakeWriter.WriteStartElement(String.Empty, "BakedAppearance", String.Empty); using (MemoryStream bakeStream = new MemoryStream())
using (XmlTextWriter bakeWriter = new XmlTextWriter(bakeStream, null))
for (int i = 0; i < data.Length; i++)
{ {
if (data[i] != null) bakeWriter.WriteStartElement(String.Empty, "BakedAppearance", String.Empty);
for (int i = 0; i < data.Length; i++)
{ {
bakeWriter.WriteStartElement(String.Empty, "BakedTexture", String.Empty); if (data[i] != null)
bakeWriter.WriteAttributeString(String.Empty, "TextureIndex", String.Empty, data[i].TextureIndex.ToString()); {
bakeWriter.WriteAttributeString(String.Empty, "CacheId", String.Empty, data[i].CacheId.ToString()); bakeWriter.WriteStartElement(String.Empty, "BakedTexture", String.Empty);
if (data[i].TextureAsset != null) bakeWriter.WriteAttributeString(String.Empty, "TextureIndex", String.Empty, data[i].TextureIndex.ToString());
m_serializer.Serialize(bakeWriter, data[i].TextureAsset); bakeWriter.WriteAttributeString(String.Empty, "CacheId", String.Empty, data[i].CacheId.ToString());
if (data[i].TextureAsset != null)
m_serializer.Serialize(bakeWriter, data[i].TextureAsset);
bakeWriter.WriteEndElement(); bakeWriter.WriteEndElement();
}
} }
}
bakeWriter.WriteEndElement(); bakeWriter.WriteEndElement();
bakeWriter.Flush(); bakeWriter.Flush();
reqStream = new MemoryStream(bakeStream.ToArray());
}
RestClient rc = new RestClient(m_URL); RestClient rc = new RestClient(m_URL);
rc.AddResourcePath("bakes"); rc.AddResourcePath("bakes");
@ -181,7 +185,6 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures
rc.RequestMethod = "POST"; rc.RequestMethod = "POST";
MemoryStream reqStream = new MemoryStream(bakeStream.ToArray());
Util.FireAndForget( Util.FireAndForget(
delegate delegate
{ {
@ -191,4 +194,4 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures
); );
} }
} }
} }