Revision c92e02f3 trunk/Pithos.Network/CloudFilesClient.cs
b/trunk/Pithos.Network/CloudFilesClient.cs | ||
---|---|---|
133 | 133 |
|
134 | 134 |
Log.InfoFormat("[AUTHENTICATE] Start for {0}", UserName); |
135 | 135 |
|
136 |
var groups = new List<Group>(); |
|
137 |
|
|
136 | 138 |
using (var authClient = new RestClient{BaseAddress=AuthenticationUrl}) |
137 | 139 |
{ |
138 | 140 |
if (Proxy != null) |
... | ... | |
170 | 172 |
throw new InvalidOperationException("Failed to obtain token url"); |
171 | 173 |
Token = token; |
172 | 174 |
|
175 |
/* var keys = authClient.ResponseHeaders.AllKeys.AsQueryable(); |
|
176 |
groups = (from key in keys |
|
177 |
where key.StartsWith("X-Account-Group-") |
|
178 |
let name = key.Substring(16) |
|
179 |
select new Group(name, authClient.ResponseHeaders[key])) |
|
180 |
.ToList(); |
|
181 |
|
|
182 |
*/ |
|
173 | 183 |
} |
174 | 184 |
|
175 | 185 |
Log.InfoFormat("[AUTHENTICATE] End for {0}", UserName); |
176 | 186 |
|
177 | 187 |
|
178 |
return new AccountInfo {StorageUri = StorageUrl, Token = Token, UserName = UserName}; |
|
188 |
return new AccountInfo {StorageUri = StorageUrl, Token = Token, UserName = UserName,Groups=groups};
|
|
179 | 189 |
|
180 | 190 |
} |
181 | 191 |
|
... | ... | |
458 | 468 |
|
459 | 469 |
} |
460 | 470 |
|
471 |
public void UpdateMetadata(ContainerInfo containerInfo) |
|
472 |
{ |
|
473 |
if (containerInfo == null) |
|
474 |
throw new ArgumentNullException("containerInfo"); |
|
475 |
Contract.EndContractBlock(); |
|
476 |
|
|
477 |
using (log4net.ThreadContext.Stacks["Containers"].Push("UpdateMetadata")) |
|
478 |
{ |
|
479 |
if (Log.IsDebugEnabled) Log.DebugFormat("START"); |
|
480 |
|
|
481 |
|
|
482 |
using(var client=new RestClient(_baseClient)) |
|
483 |
{ |
|
484 |
|
|
485 |
client.BaseAddress = GetAccountUrl(containerInfo.Account); |
|
486 |
|
|
487 |
client.Parameters.Clear(); |
|
488 |
|
|
489 |
|
|
490 |
//Set Tags |
|
491 |
foreach (var tag in containerInfo.Tags) |
|
492 |
{ |
|
493 |
var headerTag = String.Format("X-Container-Meta-{0}", tag.Key); |
|
494 |
client.Headers.Add(headerTag, tag.Value); |
|
495 |
} |
|
496 |
|
|
497 |
|
|
498 |
//Set Policies |
|
499 |
foreach (var policy in containerInfo.Policies) |
|
500 |
{ |
|
501 |
var headerPolicy = String.Format("X-Container-Policy-{0}", policy.Key); |
|
502 |
client.Headers.Add(headerPolicy, policy.Value); |
|
503 |
} |
|
504 |
|
|
505 |
|
|
506 |
var uriBuilder = client.GetAddressBuilder(containerInfo.Name,""); |
|
507 |
var uri = uriBuilder.Uri; |
|
508 |
|
|
509 |
var content = client.UploadValues(uri,new NameValueCollection()); |
|
510 |
|
|
511 |
|
|
512 |
client.AssertStatusOK("UpdateMetadata failed"); |
|
513 |
//If the status is NOT ACCEPTED or OK we have a problem |
|
514 |
if (!(client.StatusCode == HttpStatusCode.Accepted || client.StatusCode == HttpStatusCode.OK)) |
|
515 |
{ |
|
516 |
Log.Error("Failed to update metadata"); |
|
517 |
throw new Exception("Failed to update metadata"); |
|
518 |
} |
|
519 |
|
|
520 |
if (Log.IsDebugEnabled) Log.DebugFormat("END"); |
|
521 |
} |
|
522 |
} |
|
523 |
|
|
524 |
} |
|
525 |
|
|
461 | 526 |
|
462 | 527 |
public IList<ObjectInfo> ListObjects(string account, string container, DateTime? since = null) |
463 | 528 |
{ |
... | ... | |
631 | 696 |
case HttpStatusCode.OK: |
632 | 697 |
case HttpStatusCode.NoContent: |
633 | 698 |
var keys = client.ResponseHeaders.AllKeys.AsQueryable(); |
634 |
var tags = (from key in keys |
|
635 |
where key.StartsWith("X-Object-Meta-") |
|
636 |
let name = key.Substring(14) |
|
637 |
select new {Name = name, Value = client.ResponseHeaders[key]}) |
|
638 |
.ToDictionary(t => t.Name, t => t.Value); |
|
699 |
var tags = client.GetMeta("X-Object-Meta-"); |
|
639 | 700 |
var extensions = (from key in keys |
640 | 701 |
where key.StartsWith("X-Object-") && !key.StartsWith("X-Object-Meta-") |
641 | 702 |
select new {Name = key, Value = client.ResponseHeaders[key]}) |
642 | 703 |
.ToDictionary(t => t.Name, t => t.Value); |
643 | 704 |
|
644 |
var permissions=client.GetHeaderValue("X-Object-Sharing", false);
|
|
705 |
var permissions=client.GetHeaderValue("X-Object-Sharing", true);
|
|
645 | 706 |
|
646 | 707 |
|
647 | 708 |
var info = new ObjectInfo |
... | ... | |
712 | 773 |
} |
713 | 774 |
} |
714 | 775 |
|
776 |
|
|
777 |
|
|
715 | 778 |
public ContainerInfo GetContainerInfo(string account, string container) |
716 | 779 |
{ |
717 | 780 |
if (String.IsNullOrWhiteSpace(container)) |
... | ... | |
728 | 791 |
{ |
729 | 792 |
case HttpStatusCode.OK: |
730 | 793 |
case HttpStatusCode.NoContent: |
731 |
var keys = client.ResponseHeaders.AllKeys.AsQueryable(); |
|
732 |
var tags = (from key in keys |
|
733 |
where key.StartsWith("X-Container-Meta-") |
|
734 |
let name = key.Substring(14) |
|
735 |
select new { Name = name, Value = client.ResponseHeaders[name] }) |
|
736 |
.ToDictionary(t => t.Name, t => t.Value); |
|
737 |
var policies= (from key in keys |
|
738 |
where key.StartsWith("X-Container-Policy-") |
|
739 |
let name = key.Substring(14) |
|
740 |
select new { Name = name, Value = client.ResponseHeaders[name] }) |
|
741 |
.ToDictionary(t => t.Name, t => t.Value); |
|
794 |
var tags = client.GetMeta("X-Container-Meta-"); |
|
795 |
var policies = client.GetMeta("X-Container-Policy-"); |
|
742 | 796 |
|
743 | 797 |
var containerInfo = new ContainerInfo |
744 | 798 |
{ |
Also available in: Unified diff