diff options
author | Justin Clark-Casey (justincc) | 2014-12-20 01:38:48 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2014-12-20 01:38:48 +0000 |
commit | 798074c66f59eeeba7fbda52fcbf63f7a56c14c1 (patch) | |
tree | 02158bc82a0fc3bf1d06165ca62b6347ab2d5964 /OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs | |
parent | In XBakes use proper disposal semantics to always close the stream on Store()... (diff) | |
download | opensim-SC_OLD-798074c66f59eeeba7fbda52fcbf63f7a56c14c1.zip opensim-SC_OLD-798074c66f59eeeba7fbda52fcbf63f7a56c14c1.tar.gz opensim-SC_OLD-798074c66f59eeeba7fbda52fcbf63f7a56c14c1.tar.bz2 opensim-SC_OLD-798074c66f59eeeba7fbda52fcbf63f7a56c14c1.tar.xz |
Use using() semantics in XBakesModule to ensure disposable objects are alway disposed no matter what
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs | 81 |
1 files changed, 42 insertions, 39 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs b/OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs index 5e35135..c6c54b2 100644 --- a/OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs | |||
@@ -112,33 +112,32 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures | |||
112 | 112 | ||
113 | try | 113 | try |
114 | { | 114 | { |
115 | Stream s = rc.Request(m_Auth); | 115 | using (Stream s = rc.Request(m_Auth)) |
116 | XmlTextReader sr = new XmlTextReader(s); | 116 | using (XmlTextReader sr = new XmlTextReader(s)) |
117 | |||
118 | sr.ReadStartElement("BakedAppearance"); | ||
119 | while (sr.LocalName == "BakedTexture") | ||
120 | { | 117 | { |
121 | string sTextureIndex = sr.GetAttribute("TextureIndex"); | 118 | sr.ReadStartElement("BakedAppearance"); |
122 | int lTextureIndex = Convert.ToInt32(sTextureIndex); | 119 | while (sr.LocalName == "BakedTexture") |
123 | string sCacheId = sr.GetAttribute("CacheId"); | ||
124 | UUID lCacheId = UUID.Zero; | ||
125 | if (!(UUID.TryParse(sCacheId, out lCacheId))) | ||
126 | { | 120 | { |
127 | // ?? Nothing here | 121 | string sTextureIndex = sr.GetAttribute("TextureIndex"); |
122 | int lTextureIndex = Convert.ToInt32(sTextureIndex); | ||
123 | string sCacheId = sr.GetAttribute("CacheId"); | ||
124 | UUID lCacheId = UUID.Zero; | ||
125 | if (!(UUID.TryParse(sCacheId, out lCacheId))) | ||
126 | { | ||
127 | // ?? Nothing here | ||
128 | } | ||
129 | |||
130 | ++size; | ||
131 | |||
132 | sr.ReadStartElement("BakedTexture"); | ||
133 | AssetBase a = (AssetBase)m_serializer.Deserialize(sr); | ||
134 | ret.Add(new WearableCacheItem() { CacheId = lCacheId, TextureIndex = (uint)lTextureIndex, TextureAsset = a, TextureID = a.FullID }); | ||
135 | |||
136 | sr.ReadEndElement(); | ||
128 | } | 137 | } |
129 | 138 | ||
130 | ++size; | 139 | m_log.DebugFormat("[XBakes]: read {0} textures for user {1}", ret.Count, id); |
131 | |||
132 | sr.ReadStartElement("BakedTexture"); | ||
133 | AssetBase a = (AssetBase)m_serializer.Deserialize(sr); | ||
134 | ret.Add(new WearableCacheItem() { CacheId = lCacheId, TextureIndex = (uint)lTextureIndex, TextureAsset = a, TextureID = a.FullID }); | ||
135 | |||
136 | sr.ReadEndElement(); | ||
137 | } | 140 | } |
138 | m_log.DebugFormat("[XBakes]: read {0} textures for user {1}", ret.Count, id); | ||
139 | sr.Close(); | ||
140 | s.Close(); | ||
141 | |||
142 | 141 | ||
143 | return ret.ToArray(); | 142 | return ret.ToArray(); |
144 | } | 143 | } |
@@ -153,27 +152,32 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures | |||
153 | if (m_URL == String.Empty) | 152 | if (m_URL == String.Empty) |
154 | return; | 153 | return; |
155 | 154 | ||
156 | MemoryStream bakeStream = new MemoryStream(); | 155 | MemoryStream reqStream; |
157 | XmlTextWriter bakeWriter = new XmlTextWriter(bakeStream, null); | ||
158 | |||
159 | bakeWriter.WriteStartElement(String.Empty, "BakedAppearance", String.Empty); | ||
160 | 156 | ||
161 | for (int i = 0; i < data.Length; i++) | 157 | using (MemoryStream bakeStream = new MemoryStream()) |
158 | using (XmlTextWriter bakeWriter = new XmlTextWriter(bakeStream, null)) | ||
162 | { | 159 | { |
163 | if (data[i] != null) | 160 | bakeWriter.WriteStartElement(String.Empty, "BakedAppearance", String.Empty); |
161 | |||
162 | for (int i = 0; i < data.Length; i++) | ||
164 | { | 163 | { |
165 | bakeWriter.WriteStartElement(String.Empty, "BakedTexture", String.Empty); | 164 | if (data[i] != null) |
166 | bakeWriter.WriteAttributeString(String.Empty, "TextureIndex", String.Empty, data[i].TextureIndex.ToString()); | 165 | { |
167 | bakeWriter.WriteAttributeString(String.Empty, "CacheId", String.Empty, data[i].CacheId.ToString()); | 166 | bakeWriter.WriteStartElement(String.Empty, "BakedTexture", String.Empty); |
168 | if (data[i].TextureAsset != null) | 167 | bakeWriter.WriteAttributeString(String.Empty, "TextureIndex", String.Empty, data[i].TextureIndex.ToString()); |
169 | m_serializer.Serialize(bakeWriter, data[i].TextureAsset); | 168 | bakeWriter.WriteAttributeString(String.Empty, "CacheId", String.Empty, data[i].CacheId.ToString()); |
169 | if (data[i].TextureAsset != null) | ||
170 | m_serializer.Serialize(bakeWriter, data[i].TextureAsset); | ||
170 | 171 | ||
171 | bakeWriter.WriteEndElement(); | 172 | bakeWriter.WriteEndElement(); |
173 | } | ||
172 | } | 174 | } |
173 | } | ||
174 | 175 | ||
175 | bakeWriter.WriteEndElement(); | 176 | bakeWriter.WriteEndElement(); |
176 | bakeWriter.Flush(); | 177 | bakeWriter.Flush(); |
178 | |||
179 | reqStream = new MemoryStream(bakeStream.ToArray()); | ||
180 | } | ||
177 | 181 | ||
178 | RestClient rc = new RestClient(m_URL); | 182 | RestClient rc = new RestClient(m_URL); |
179 | rc.AddResourcePath("bakes"); | 183 | rc.AddResourcePath("bakes"); |
@@ -181,7 +185,6 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures | |||
181 | 185 | ||
182 | rc.RequestMethod = "POST"; | 186 | rc.RequestMethod = "POST"; |
183 | 187 | ||
184 | MemoryStream reqStream = new MemoryStream(bakeStream.ToArray()); | ||
185 | Util.FireAndForget( | 188 | Util.FireAndForget( |
186 | delegate | 189 | delegate |
187 | { | 190 | { |
@@ -191,4 +194,4 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures | |||
191 | ); | 194 | ); |
192 | } | 195 | } |
193 | } | 196 | } |
194 | } | 197 | } \ No newline at end of file |