Revision aba9e6d9 trunk/Pithos.Network/CloudFilesClient.cs
b/trunk/Pithos.Network/CloudFilesClient.cs | ||
---|---|---|
5 | 5 |
|
6 | 6 |
using System; |
7 | 7 |
using System.Collections.Generic; |
8 |
using System.Collections.Specialized; |
|
8 | 9 |
using System.ComponentModel.Composition; |
9 | 10 |
using System.Diagnostics.Contracts; |
10 | 11 |
using System.IO; |
... | ... | |
399 | 400 |
} |
400 | 401 |
} |
401 | 402 |
|
403 |
public void UpdateMetadata(ObjectInfo objectInfo) |
|
404 |
{ |
|
405 |
if (objectInfo == null) |
|
406 |
throw new ArgumentNullException("objectInfo"); |
|
407 |
Contract.EndContractBlock(); |
|
408 |
|
|
409 |
using (log4net.ThreadContext.Stacks["Objects"].Push("UpdateMetadata")) |
|
410 |
{ |
|
411 |
if (Log.IsDebugEnabled) Log.DebugFormat("START"); |
|
412 |
|
|
413 |
|
|
414 |
using(var client=new RestClient(_baseClient)) |
|
415 |
{ |
|
416 |
|
|
417 |
client.BaseAddress = GetAccountUrl(objectInfo.Account); |
|
418 |
|
|
419 |
client.Parameters.Clear(); |
|
420 |
|
|
421 |
|
|
422 |
//Set Tags |
|
423 |
foreach (var tag in objectInfo.Tags) |
|
424 |
{ |
|
425 |
var headerTag = String.Format("X-Object-Meta-{0}", tag.Key); |
|
426 |
client.Headers.Add(headerTag, tag.Value); |
|
427 |
} |
|
428 |
|
|
429 |
//Set Permissions |
|
430 |
|
|
431 |
var permissions=objectInfo.GetPermissionString(); |
|
432 |
client.SetNonEmptyHeaderValue("X-Object-Sharing",permissions); |
|
433 |
|
|
434 |
client.SetNonEmptyHeaderValue("Content-Disposition",objectInfo.ContendDisposition); |
|
435 |
client.SetNonEmptyHeaderValue("Content-Encoding",objectInfo.ContentEncoding); |
|
436 |
client.SetNonEmptyHeaderValue("X-Object-Manifest",objectInfo.Manifest); |
|
437 |
client.SetNonEmptyHeaderValue("X-Object-Public", objectInfo.PublicUrl); |
|
438 |
|
|
439 |
|
|
440 |
var uriBuilder = client.GetAddressBuilder(objectInfo.Container, objectInfo.Name); |
|
441 |
var uri = uriBuilder.Uri; |
|
442 |
|
|
443 |
var content = client.UploadValues(uri,new NameValueCollection()); |
|
444 |
|
|
445 |
|
|
446 |
client.AssertStatusOK("UpdateMetadata failed"); |
|
447 |
//If the status is NOT ACCEPTED or OK we have a problem |
|
448 |
if (!(client.StatusCode == HttpStatusCode.Accepted || client.StatusCode == HttpStatusCode.OK)) |
|
449 |
{ |
|
450 |
Log.Error("Failed to update metadata"); |
|
451 |
throw new Exception("Failed to update metadata"); |
|
452 |
} |
|
453 |
|
|
454 |
if (Log.IsDebugEnabled) Log.DebugFormat("END"); |
|
455 |
} |
|
456 |
} |
|
457 |
|
|
458 |
} |
|
459 |
|
|
402 | 460 |
|
403 | 461 |
public IList<ObjectInfo> ListObjects(string account, string container, DateTime? since = null) |
404 | 462 |
{ |
... | ... | |
575 | 633 |
var tags = (from key in keys |
576 | 634 |
where key.StartsWith("X-Object-Meta-") |
577 | 635 |
let name = key.Substring(14) |
578 |
select new {Name = name, Value = client.ResponseHeaders[name]})
|
|
636 |
select new {Name = name, Value = client.ResponseHeaders[key]})
|
|
579 | 637 |
.ToDictionary(t => t.Name, t => t.Value); |
580 | 638 |
var extensions = (from key in keys |
581 | 639 |
where key.StartsWith("X-Object-") && !key.StartsWith("X-Object-Meta-") |
582 | 640 |
select new {Name = key, Value = client.ResponseHeaders[key]}) |
583 | 641 |
.ToDictionary(t => t.Name, t => t.Value); |
642 |
|
|
643 |
|
|
584 | 644 |
var info = new ObjectInfo |
585 | 645 |
{ |
586 | 646 |
Account = account, |
... | ... | |
591 | 651 |
Bytes = Convert.ToInt64(client.GetHeaderValue("Content-Length")), |
592 | 652 |
Tags = tags, |
593 | 653 |
Last_Modified = client.LastModified, |
594 |
Extensions = extensions |
|
654 |
Extensions = extensions, |
|
655 |
ContentEncoding=client.GetHeaderValue("Content-Encoding",true), |
|
656 |
ContendDisposition = client.GetHeaderValue("Content-Disposition",true), |
|
657 |
Manifest=client.GetHeaderValue("X-Object-Manifest",true), |
|
658 |
PublicUrl=client.GetHeaderValue("X-Object-Public",true) |
|
595 | 659 |
}; |
596 | 660 |
return info; |
597 | 661 |
case HttpStatusCode.NotFound: |
Also available in: Unified diff