diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs | 526 |
1 files changed, 356 insertions, 170 deletions
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs index 63a32e7..9ad4a7a 100644 --- a/OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs +++ b/OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs | |||
@@ -27,6 +27,7 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Collections.Specialized; | ||
30 | using System.IO; | 31 | using System.IO; |
31 | using System.Net; | 32 | using System.Net; |
32 | using System.Reflection; | 33 | using System.Reflection; |
@@ -122,7 +123,7 @@ namespace OpenSim.Services.Connectors.SimianGrid | |||
122 | m_Enabled = true; | 123 | m_Enabled = true; |
123 | } | 124 | } |
124 | 125 | ||
125 | #region IAssetService | 126 | #region IAssetService |
126 | 127 | ||
127 | public AssetBase Get(string id) | 128 | public AssetBase Get(string id) |
128 | { | 129 | { |
@@ -140,8 +141,9 @@ namespace OpenSim.Services.Connectors.SimianGrid | |||
140 | return asset; | 141 | return asset; |
141 | } | 142 | } |
142 | 143 | ||
143 | return GetRemote(id); | 144 | return SimianGetOperation(id); |
144 | } | 145 | } |
146 | |||
145 | 147 | ||
146 | public AssetBase GetCached(string id) | 148 | public AssetBase GetCached(string id) |
147 | { | 149 | { |
@@ -164,8 +166,6 @@ namespace OpenSim.Services.Connectors.SimianGrid | |||
164 | throw new InvalidOperationException(); | 166 | throw new InvalidOperationException(); |
165 | } | 167 | } |
166 | 168 | ||
167 | AssetMetadata metadata = null; | ||
168 | |||
169 | // Cache fetch | 169 | // Cache fetch |
170 | if (m_cache != null) | 170 | if (m_cache != null) |
171 | { | 171 | { |
@@ -174,50 +174,18 @@ namespace OpenSim.Services.Connectors.SimianGrid | |||
174 | return asset.Metadata; | 174 | return asset.Metadata; |
175 | } | 175 | } |
176 | 176 | ||
177 | Uri url; | 177 | // return GetRemoteMetadata(id); |
178 | 178 | return SimianGetMetadataOperation(id); | |
179 | // Determine if id is an absolute URL or a grid-relative UUID | ||
180 | if (!Uri.TryCreate(id, UriKind.Absolute, out url)) | ||
181 | url = new Uri(m_serverUrl + id); | ||
182 | |||
183 | try | ||
184 | { | ||
185 | HttpWebRequest request = UntrustedHttpWebRequest.Create(url); | ||
186 | request.Method = "HEAD"; | ||
187 | |||
188 | using (WebResponse response = request.GetResponse()) | ||
189 | { | ||
190 | using (Stream responseStream = response.GetResponseStream()) | ||
191 | { | ||
192 | // Create the metadata object | ||
193 | metadata = new AssetMetadata(); | ||
194 | metadata.ContentType = response.ContentType; | ||
195 | metadata.ID = id; | ||
196 | |||
197 | UUID uuid; | ||
198 | if (UUID.TryParse(id, out uuid)) | ||
199 | metadata.FullID = uuid; | ||
200 | |||
201 | string lastModifiedStr = response.Headers.Get("Last-Modified"); | ||
202 | if (!String.IsNullOrEmpty(lastModifiedStr)) | ||
203 | { | ||
204 | DateTime lastModified; | ||
205 | if (DateTime.TryParse(lastModifiedStr, out lastModified)) | ||
206 | metadata.CreationDate = lastModified; | ||
207 | } | ||
208 | } | ||
209 | } | ||
210 | } | ||
211 | catch (Exception ex) | ||
212 | { | ||
213 | m_log.Warn("[SIMIAN ASSET CONNECTOR]: Asset HEAD from " + url + " failed: " + ex.Message); | ||
214 | } | ||
215 | |||
216 | return metadata; | ||
217 | } | 179 | } |
218 | 180 | ||
219 | public byte[] GetData(string id) | 181 | public byte[] GetData(string id) |
220 | { | 182 | { |
183 | if (String.IsNullOrEmpty(m_serverUrl)) | ||
184 | { | ||
185 | m_log.Error("[SIMIAN ASSET CONNECTOR]: No AssetServerURI configured"); | ||
186 | throw new InvalidOperationException(); | ||
187 | } | ||
188 | |||
221 | AssetBase asset = Get(id); | 189 | AssetBase asset = Get(id); |
222 | 190 | ||
223 | if (asset != null) | 191 | if (asset != null) |
@@ -255,14 +223,34 @@ namespace OpenSim.Services.Connectors.SimianGrid | |||
255 | Util.FireAndForget( | 223 | Util.FireAndForget( |
256 | delegate(object o) | 224 | delegate(object o) |
257 | { | 225 | { |
258 | AssetBase asset = GetRemote(id); | 226 | AssetBase asset = SimianGetOperation(id); |
259 | handler(id, sender, asset); | 227 | handler(id, sender, asset); |
260 | } | 228 | }, null, "SimianAssetServiceConnector.GetFromService" |
261 | ); | 229 | ); |
262 | 230 | ||
263 | return true; | 231 | return true; |
264 | } | 232 | } |
265 | 233 | ||
234 | public bool[] AssetsExist(string[] ids) | ||
235 | { | ||
236 | if (String.IsNullOrEmpty(m_serverUrl)) | ||
237 | { | ||
238 | m_log.Error("[SIMIAN ASSET CONNECTOR]: No AssetServerURI configured"); | ||
239 | throw new InvalidOperationException(); | ||
240 | } | ||
241 | |||
242 | bool[] exist = new bool[ids.Length]; | ||
243 | |||
244 | for (int i = 0; i < ids.Length; i++) | ||
245 | { | ||
246 | AssetMetadata metadata = GetMetadata(ids[i]); | ||
247 | if (metadata != null) | ||
248 | exist[i] = true; | ||
249 | } | ||
250 | |||
251 | return exist; | ||
252 | } | ||
253 | |||
266 | /// <summary> | 254 | /// <summary> |
267 | /// Creates a new asset | 255 | /// Creates a new asset |
268 | /// </summary> | 256 | /// </summary> |
@@ -278,7 +266,6 @@ namespace OpenSim.Services.Connectors.SimianGrid | |||
278 | } | 266 | } |
279 | 267 | ||
280 | bool storedInCache = false; | 268 | bool storedInCache = false; |
281 | string errorMessage = null; | ||
282 | 269 | ||
283 | // AssetID handling | 270 | // AssetID handling |
284 | if (String.IsNullOrEmpty(asset.ID) || asset.ID == ZeroID) | 271 | if (String.IsNullOrEmpty(asset.ID) || asset.ID == ZeroID) |
@@ -307,80 +294,9 @@ namespace OpenSim.Services.Connectors.SimianGrid | |||
307 | return asset.ID; | 294 | return asset.ID; |
308 | } | 295 | } |
309 | 296 | ||
310 | // Distinguish public and private assets | 297 | return SimianStoreOperation(asset); |
311 | bool isPublic = true; | ||
312 | switch ((AssetType)asset.Type) | ||
313 | { | ||
314 | case AssetType.CallingCard: | ||
315 | case AssetType.Gesture: | ||
316 | case AssetType.LSLBytecode: | ||
317 | case AssetType.LSLText: | ||
318 | isPublic = false; | ||
319 | break; | ||
320 | } | ||
321 | |||
322 | // Make sure ContentType is set | ||
323 | if (String.IsNullOrEmpty(asset.Metadata.ContentType)) | ||
324 | asset.Metadata.ContentType = SLUtil.SLAssetTypeToContentType(asset.Type); | ||
325 | |||
326 | // Build the remote storage request | ||
327 | List<MultipartForm.Element> postParameters = new List<MultipartForm.Element>() | ||
328 | { | ||
329 | new MultipartForm.Parameter("AssetID", asset.FullID.ToString()), | ||
330 | new MultipartForm.Parameter("CreatorID", asset.Metadata.CreatorID), | ||
331 | new MultipartForm.Parameter("Temporary", asset.Temporary ? "1" : "0"), | ||
332 | new MultipartForm.Parameter("Public", isPublic ? "1" : "0"), | ||
333 | new MultipartForm.File("Asset", asset.Name, asset.Metadata.ContentType, asset.Data) | ||
334 | }; | ||
335 | |||
336 | // Make the remote storage request | ||
337 | try | ||
338 | { | ||
339 | // Simian does not require the asset ID to be in the URL because it's in the post data. | ||
340 | // By appending it to the URL also, we allow caching proxies (squid) to invalidate asset URLs | ||
341 | HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl + asset.FullID.ToString()); | ||
342 | |||
343 | HttpWebResponse response = MultipartForm.Post(request, postParameters); | ||
344 | using (Stream responseStream = response.GetResponseStream()) | ||
345 | { | ||
346 | string responseStr = null; | ||
347 | |||
348 | try | ||
349 | { | ||
350 | responseStr = responseStream.GetStreamString(); | ||
351 | OSD responseOSD = OSDParser.Deserialize(responseStr); | ||
352 | if (responseOSD.Type == OSDType.Map) | ||
353 | { | ||
354 | OSDMap responseMap = (OSDMap)responseOSD; | ||
355 | if (responseMap["Success"].AsBoolean()) | ||
356 | return asset.ID; | ||
357 | else | ||
358 | errorMessage = "Upload failed: " + responseMap["Message"].AsString(); | ||
359 | } | ||
360 | else | ||
361 | { | ||
362 | errorMessage = "Response format was invalid:\n" + responseStr; | ||
363 | } | ||
364 | } | ||
365 | catch (Exception ex) | ||
366 | { | ||
367 | if (!String.IsNullOrEmpty(responseStr)) | ||
368 | errorMessage = "Failed to parse the response:\n" + responseStr; | ||
369 | else | ||
370 | errorMessage = "Failed to retrieve the response: " + ex.Message; | ||
371 | } | ||
372 | } | ||
373 | } | ||
374 | catch (WebException ex) | ||
375 | { | ||
376 | errorMessage = ex.Message; | ||
377 | } | ||
378 | |||
379 | m_log.WarnFormat("[SIMIAN ASSET CONNECTOR]: Failed to store asset \"{0}\" ({1}, {2}): {3}", | ||
380 | asset.Name, asset.ID, asset.Metadata.ContentType, errorMessage); | ||
381 | return null; | ||
382 | } | 298 | } |
383 | 299 | ||
384 | /// <summary> | 300 | /// <summary> |
385 | /// Update an asset's content | 301 | /// Update an asset's content |
386 | /// </summary> | 302 | /// </summary> |
@@ -390,11 +306,17 @@ namespace OpenSim.Services.Connectors.SimianGrid | |||
390 | /// <returns></returns> | 306 | /// <returns></returns> |
391 | public bool UpdateContent(string id, byte[] data) | 307 | public bool UpdateContent(string id, byte[] data) |
392 | { | 308 | { |
309 | if (String.IsNullOrEmpty(m_serverUrl)) | ||
310 | { | ||
311 | m_log.Error("[SIMIAN ASSET CONNECTOR]: No AssetServerURI configured"); | ||
312 | throw new InvalidOperationException(); | ||
313 | } | ||
314 | |||
393 | AssetBase asset = Get(id); | 315 | AssetBase asset = Get(id); |
394 | 316 | ||
395 | if (asset == null) | 317 | if (asset == null) |
396 | { | 318 | { |
397 | m_log.Warn("[SIMIAN ASSET CONNECTOR]: Failed to fetch asset " + id + " for updating"); | 319 | m_log.WarnFormat("[SIMIAN ASSET CONNECTOR]: Failed to fetch asset {0} for updating", id); |
398 | return false; | 320 | return false; |
399 | } | 321 | } |
400 | 322 | ||
@@ -417,83 +339,347 @@ namespace OpenSim.Services.Connectors.SimianGrid | |||
417 | throw new InvalidOperationException(); | 339 | throw new InvalidOperationException(); |
418 | } | 340 | } |
419 | 341 | ||
420 | //string errorMessage = String.Empty; | ||
421 | string url = m_serverUrl + id; | ||
422 | |||
423 | if (m_cache != null) | 342 | if (m_cache != null) |
424 | m_cache.Expire(id); | 343 | m_cache.Expire(id); |
425 | 344 | ||
345 | return SimianDeleteOperation(id); | ||
346 | } | ||
347 | |||
348 | #endregion IAssetService | ||
349 | |||
350 | #region SimianOperations | ||
351 | /// <summary> | ||
352 | /// Invokes the xRemoveAsset operation on the simian server to delete an asset | ||
353 | /// </summary> | ||
354 | /// <param name="id"></param> | ||
355 | /// <returns></returns> | ||
356 | private bool SimianDeleteOperation(string id) | ||
357 | { | ||
426 | try | 358 | try |
427 | { | 359 | { |
428 | HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); | 360 | NameValueCollection requestArgs = new NameValueCollection |
429 | request.Method = "DELETE"; | 361 | { |
362 | { "RequestMethod", "xRemoveAsset" }, | ||
363 | { "AssetID", id } | ||
364 | }; | ||
430 | 365 | ||
431 | using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) | 366 | OSDMap response = SimianGrid.PostToService(m_serverUrl,requestArgs); |
367 | if (! response["Success"].AsBoolean()) | ||
432 | { | 368 | { |
433 | if (response.StatusCode != HttpStatusCode.NoContent) | 369 | m_log.WarnFormat("[SIMIAN ASSET CONNECTOR]: failed to delete asset; {0}",response["Message"].AsString()); |
434 | { | 370 | return false; |
435 | m_log.Warn("[SIMIAN ASSET CONNECTOR]: Unexpected response when deleting asset " + url + ": " + | ||
436 | response.StatusCode + " (" + response.StatusDescription + ")"); | ||
437 | } | ||
438 | } | 371 | } |
439 | 372 | ||
440 | return true; | 373 | return true; |
374 | |||
441 | } | 375 | } |
442 | catch (Exception ex) | 376 | catch (Exception ex) |
443 | { | 377 | { |
444 | m_log.Warn("[SIMIAN ASSET CONNECTOR]: Failed to delete asset " + id + " from the asset service: " + ex.Message); | 378 | m_log.WarnFormat("[SIMIAN ASSET CONNECTOR]: failed to delete asset {0}; {1}", id, ex.Message); |
445 | return false; | ||
446 | } | 379 | } |
447 | } | ||
448 | 380 | ||
449 | #endregion IAssetService | 381 | return false; |
382 | } | ||
450 | 383 | ||
451 | private AssetBase GetRemote(string id) | 384 | /// <summary> |
385 | /// Invokes the xAddAsset operation on the simian server to create or update an asset | ||
386 | /// </summary> | ||
387 | /// <param name="id"></param> | ||
388 | /// <returns></returns> | ||
389 | private string SimianStoreOperation(AssetBase asset) | ||
452 | { | 390 | { |
453 | AssetBase asset = null; | 391 | try |
454 | Uri url; | 392 | { |
393 | NameValueCollection requestArgs = new NameValueCollection | ||
394 | { | ||
395 | { "RequestMethod", "xAddAsset" }, | ||
396 | { "ContentType", asset.Metadata.ContentType }, | ||
397 | { "EncodedData", Convert.ToBase64String(asset.Data) }, | ||
398 | { "AssetID", asset.FullID.ToString() }, | ||
399 | { "CreatorID", asset.Metadata.CreatorID }, | ||
400 | { "Temporary", asset.Temporary ? "1" : "0" }, | ||
401 | { "Name", asset.Name } | ||
402 | }; | ||
403 | |||
404 | OSDMap response = SimianGrid.PostToService(m_serverUrl,requestArgs); | ||
405 | if (! response["Success"].AsBoolean()) | ||
406 | { | ||
407 | m_log.WarnFormat("[SIMIAN ASSET CONNECTOR] failed to store asset; {0}",response["Message"].AsString()); | ||
408 | return null; | ||
409 | } | ||
455 | 410 | ||
456 | // Determine if id is an absolute URL or a grid-relative UUID | 411 | // asset.ID is always set before calling this function |
457 | if (!Uri.TryCreate(id, UriKind.Absolute, out url)) | 412 | return asset.ID; |
458 | url = new Uri(m_serverUrl + id); | 413 | |
414 | } | ||
415 | catch (Exception ex) | ||
416 | { | ||
417 | m_log.ErrorFormat("[SIMIAN ASSET CONNECTOR] failed to store asset; {0}",ex.Message); | ||
418 | } | ||
419 | |||
420 | return null; | ||
421 | } | ||
459 | 422 | ||
460 | try | 423 | /// <summary> |
424 | /// Invokes the xGetAsset operation on the simian server to get data associated with an asset | ||
425 | /// </summary> | ||
426 | /// <param name="id"></param> | ||
427 | /// <returns></returns> | ||
428 | private AssetBase SimianGetOperation(string id) | ||
429 | { | ||
430 | try | ||
461 | { | 431 | { |
462 | HttpWebRequest request = UntrustedHttpWebRequest.Create(url); | 432 | NameValueCollection requestArgs = new NameValueCollection |
433 | { | ||
434 | { "RequestMethod", "xGetAsset" }, | ||
435 | { "ID", id } | ||
436 | }; | ||
463 | 437 | ||
464 | using (WebResponse response = request.GetResponse()) | 438 | OSDMap response = SimianGrid.PostToService(m_serverUrl,requestArgs); |
439 | if (! response["Success"].AsBoolean()) | ||
465 | { | 440 | { |
466 | using (Stream responseStream = response.GetResponseStream()) | 441 | m_log.WarnFormat("[SIMIAN ASSET CONNECTOR] Failed to get asset; {0}",response["Message"].AsString()); |
467 | { | 442 | return null; |
468 | string creatorID = response.Headers.GetOne("X-Asset-Creator-Id") ?? String.Empty; | ||
469 | |||
470 | // Create the asset object | ||
471 | asset = new AssetBase(id, String.Empty, SLUtil.ContentTypeToSLAssetType(response.ContentType), creatorID); | ||
472 | |||
473 | UUID assetID; | ||
474 | if (UUID.TryParse(id, out assetID)) | ||
475 | asset.FullID = assetID; | ||
476 | |||
477 | // Grab the asset data from the response stream | ||
478 | using (MemoryStream stream = new MemoryStream()) | ||
479 | { | ||
480 | responseStream.CopyStream(stream, Int32.MaxValue); | ||
481 | asset.Data = stream.ToArray(); | ||
482 | } | ||
483 | } | ||
484 | } | 443 | } |
444 | |||
445 | AssetBase asset = new AssetBase(); | ||
485 | 446 | ||
486 | // Cache store | 447 | asset.ID = id; |
487 | if (m_cache != null && asset != null) | 448 | asset.Name = String.Empty; |
488 | m_cache.Cache(asset); | 449 | asset.Metadata.ContentType = response["ContentType"].AsString(); // this will also set the asset Type property |
450 | asset.CreatorID = response["CreatorID"].AsString(); | ||
451 | asset.Data = System.Convert.FromBase64String(response["EncodedData"].AsString()); | ||
452 | asset.Local = false; | ||
453 | asset.Temporary = response["Temporary"]; | ||
489 | 454 | ||
490 | return asset; | 455 | return asset; |
491 | } | 456 | } |
492 | catch (Exception ex) | 457 | catch (Exception ex) |
493 | { | 458 | { |
494 | m_log.Warn("[SIMIAN ASSET CONNECTOR]: Asset GET from " + url + " failed: " + ex.Message); | 459 | m_log.WarnFormat("[SIMIAN ASSET CONNECTOR]: failed to retrieve asset {0}; {1}", id, ex.Message); |
495 | return null; | 460 | } |
461 | |||
462 | return null; | ||
463 | } | ||
464 | |||
465 | /// <summary> | ||
466 | /// Invokes the xGetAssetMetadata operation on the simian server to retrieve metadata for an asset | ||
467 | /// This operation is generally used to determine if an asset exists in the database | ||
468 | /// </summary> | ||
469 | /// <param name="id"></param> | ||
470 | /// <returns></returns> | ||
471 | private AssetMetadata SimianGetMetadataOperation(string id) | ||
472 | { | ||
473 | try | ||
474 | { | ||
475 | NameValueCollection requestArgs = new NameValueCollection | ||
476 | { | ||
477 | { "RequestMethod", "xGetAssetMetadata" }, | ||
478 | { "ID", id } | ||
479 | }; | ||
480 | |||
481 | OSDMap response = SimianGrid.PostToService(m_serverUrl,requestArgs); | ||
482 | if (! response["Success"].AsBoolean()) | ||
483 | { | ||
484 | // this is not really an error, this call is used to test existence | ||
485 | // m_log.DebugFormat("[SIMIAN ASSET CONNECTOR] Failed to get asset metadata; {0}",response["Message"].AsString()); | ||
486 | return null; | ||
487 | } | ||
488 | |||
489 | AssetMetadata metadata = new AssetMetadata(); | ||
490 | metadata.ID = id; | ||
491 | metadata.ContentType = response["ContentType"].AsString(); | ||
492 | metadata.CreatorID = response["CreatorID"].AsString(); | ||
493 | metadata.Local = false; | ||
494 | metadata.Temporary = response["Temporary"]; | ||
495 | |||
496 | string lastModifiedStr = response["Last-Modified"].AsString(); | ||
497 | if (! String.IsNullOrEmpty(lastModifiedStr)) | ||
498 | { | ||
499 | DateTime lastModified; | ||
500 | if (DateTime.TryParse(lastModifiedStr, out lastModified)) | ||
501 | metadata.CreationDate = lastModified; | ||
502 | } | ||
503 | |||
504 | return metadata; | ||
505 | } | ||
506 | catch (Exception ex) | ||
507 | { | ||
508 | m_log.WarnFormat("[SIMIAN ASSET CONNECTOR]: Failed to get asset metadata; {0}", ex.Message); | ||
496 | } | 509 | } |
510 | |||
511 | return null; | ||
497 | } | 512 | } |
513 | #endregion | ||
514 | |||
515 | // private AssetMetadata GetRemoteMetadata(string id) | ||
516 | // { | ||
517 | // Uri url; | ||
518 | // AssetMetadata metadata = null; | ||
519 | |||
520 | // // Determine if id is an absolute URL or a grid-relative UUID | ||
521 | // if (!Uri.TryCreate(id, UriKind.Absolute, out url)) | ||
522 | // url = new Uri(m_serverUrl + id); | ||
523 | |||
524 | // try | ||
525 | // { | ||
526 | // HttpWebRequest request = UntrustedHttpWebRequest.Create(url); | ||
527 | // request.Method = "HEAD"; | ||
528 | |||
529 | // using (WebResponse response = request.GetResponse()) | ||
530 | // { | ||
531 | // using (Stream responseStream = response.GetResponseStream()) | ||
532 | // { | ||
533 | // // Create the metadata object | ||
534 | // metadata = new AssetMetadata(); | ||
535 | // metadata.ContentType = response.ContentType; | ||
536 | // metadata.ID = id; | ||
537 | |||
538 | // UUID uuid; | ||
539 | // if (UUID.TryParse(id, out uuid)) | ||
540 | // metadata.FullID = uuid; | ||
541 | |||
542 | // string lastModifiedStr = response.Headers.Get("Last-Modified"); | ||
543 | // if (!String.IsNullOrEmpty(lastModifiedStr)) | ||
544 | // { | ||
545 | // DateTime lastModified; | ||
546 | // if (DateTime.TryParse(lastModifiedStr, out lastModified)) | ||
547 | // metadata.CreationDate = lastModified; | ||
548 | // } | ||
549 | // } | ||
550 | // } | ||
551 | // } | ||
552 | // catch (Exception ex) | ||
553 | // { | ||
554 | // m_log.Warn("[SIMIAN ASSET CONNECTOR]: Asset HEAD from " + url + " failed: " + ex.Message); | ||
555 | // } | ||
556 | |||
557 | // return metadata; | ||
558 | // } | ||
559 | |||
560 | // private AssetBase GetRemote(string id) | ||
561 | // { | ||
562 | // AssetBase asset = null; | ||
563 | // Uri url; | ||
564 | |||
565 | // // Determine if id is an absolute URL or a grid-relative UUID | ||
566 | // if (!Uri.TryCreate(id, UriKind.Absolute, out url)) | ||
567 | // url = new Uri(m_serverUrl + id); | ||
568 | |||
569 | // try | ||
570 | // { | ||
571 | // HttpWebRequest request = UntrustedHttpWebRequest.Create(url); | ||
572 | |||
573 | // using (WebResponse response = request.GetResponse()) | ||
574 | // { | ||
575 | // using (Stream responseStream = response.GetResponseStream()) | ||
576 | // { | ||
577 | // string creatorID = response.Headers.GetOne("X-Asset-Creator-Id") ?? String.Empty; | ||
578 | |||
579 | // // Create the asset object | ||
580 | // asset = new AssetBase(id, String.Empty, SLUtil.ContentTypeToSLAssetType(response.ContentType), creatorID); | ||
581 | |||
582 | // UUID assetID; | ||
583 | // if (UUID.TryParse(id, out assetID)) | ||
584 | // asset.FullID = assetID; | ||
585 | |||
586 | // // Grab the asset data from the response stream | ||
587 | // using (MemoryStream stream = new MemoryStream()) | ||
588 | // { | ||
589 | // responseStream.CopyStream(stream, Int32.MaxValue); | ||
590 | // asset.Data = stream.ToArray(); | ||
591 | // } | ||
592 | // } | ||
593 | // } | ||
594 | |||
595 | // // Cache store | ||
596 | // if (m_cache != null && asset != null) | ||
597 | // m_cache.Cache(asset); | ||
598 | |||
599 | // return asset; | ||
600 | // } | ||
601 | // catch (Exception ex) | ||
602 | // { | ||
603 | // m_log.Warn("[SIMIAN ASSET CONNECTOR]: Asset GET from " + url + " failed: " + ex.Message); | ||
604 | // return null; | ||
605 | // } | ||
606 | // } | ||
607 | |||
608 | // private string StoreRemote(AssetBase asset) | ||
609 | // { | ||
610 | // // Distinguish public and private assets | ||
611 | // bool isPublic = true; | ||
612 | // switch ((AssetType)asset.Type) | ||
613 | // { | ||
614 | // case AssetType.CallingCard: | ||
615 | // case AssetType.Gesture: | ||
616 | // case AssetType.LSLBytecode: | ||
617 | // case AssetType.LSLText: | ||
618 | // isPublic = false; | ||
619 | // break; | ||
620 | // } | ||
621 | |||
622 | // string errorMessage = null; | ||
623 | |||
624 | // // Build the remote storage request | ||
625 | // List<MultipartForm.Element> postParameters = new List<MultipartForm.Element>() | ||
626 | // { | ||
627 | // new MultipartForm.Parameter("AssetID", asset.FullID.ToString()), | ||
628 | // new MultipartForm.Parameter("CreatorID", asset.Metadata.CreatorID), | ||
629 | // new MultipartForm.Parameter("Temporary", asset.Temporary ? "1" : "0"), | ||
630 | // new MultipartForm.Parameter("Public", isPublic ? "1" : "0"), | ||
631 | // new MultipartForm.File("Asset", asset.Name, asset.Metadata.ContentType, asset.Data) | ||
632 | // }; | ||
633 | |||
634 | // // Make the remote storage request | ||
635 | // try | ||
636 | // { | ||
637 | // // Simian does not require the asset ID to be in the URL because it's in the post data. | ||
638 | // // By appending it to the URL also, we allow caching proxies (squid) to invalidate asset URLs | ||
639 | // HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl + asset.FullID.ToString()); | ||
640 | |||
641 | // using (HttpWebResponse response = MultipartForm.Post(request, postParameters)) | ||
642 | // { | ||
643 | // using (Stream responseStream = response.GetResponseStream()) | ||
644 | // { | ||
645 | // string responseStr = null; | ||
646 | |||
647 | // try | ||
648 | // { | ||
649 | // responseStr = responseStream.GetStreamString(); | ||
650 | // OSD responseOSD = OSDParser.Deserialize(responseStr); | ||
651 | // if (responseOSD.Type == OSDType.Map) | ||
652 | // { | ||
653 | // OSDMap responseMap = (OSDMap)responseOSD; | ||
654 | // if (responseMap["Success"].AsBoolean()) | ||
655 | // return asset.ID; | ||
656 | // else | ||
657 | // errorMessage = "Upload failed: " + responseMap["Message"].AsString(); | ||
658 | // } | ||
659 | // else | ||
660 | // { | ||
661 | // errorMessage = "Response format was invalid:\n" + responseStr; | ||
662 | // } | ||
663 | // } | ||
664 | // catch (Exception ex) | ||
665 | // { | ||
666 | // if (!String.IsNullOrEmpty(responseStr)) | ||
667 | // errorMessage = "Failed to parse the response:\n" + responseStr; | ||
668 | // else | ||
669 | // errorMessage = "Failed to retrieve the response: " + ex.Message; | ||
670 | // } | ||
671 | // } | ||
672 | // } | ||
673 | // } | ||
674 | // catch (WebException ex) | ||
675 | // { | ||
676 | // errorMessage = ex.Message; | ||
677 | // } | ||
678 | |||
679 | // m_log.WarnFormat("[SIMIAN ASSET CONNECTOR]: Failed to store asset \"{0}\" ({1}, {2}): {3}", | ||
680 | // asset.Name, asset.ID, asset.Metadata.ContentType, errorMessage); | ||
681 | |||
682 | // return null; | ||
683 | // } | ||
498 | } | 684 | } |
499 | } | 685 | } |