+ using (var client = new RestClient(_baseClient))
+ {
+ client.Parameters.Clear();
+ client.Parameters.Add("format", "json");
+ client.IfModifiedSince = since;
+
+ //Extract the username from the base address
+ client.BaseAddress = RootAddressUri.AbsoluteUri;
+
+ var content = client.DownloadStringWithRetry(@"", 3);
+
+ client.AssertStatusOK("ListSharingAccounts failed");
+
+ //If the result is empty, return an empty list,
+ var infos = String.IsNullOrWhiteSpace(content)
+ ? new List<ShareAccountInfo>()
+ //Otherwise deserialize the account list into a list of ShareAccountInfos
+ : JsonConvert.DeserializeObject<IList<ShareAccountInfo>>(content);
+
+ Log.DebugFormat("END");
+ return infos;
+ }
+ }
+ }
+
+ //Request listing of all objects in a container modified since a specific time.
+ //If the *since* value is missing, return all objects
+ public IList<ObjectInfo> ListSharedObjects(DateTime? since = null)
+ {
+
+ using (ThreadContext.Stacks["Share"].Push("List Objects"))
+ {
+ if (Log.IsDebugEnabled) Log.DebugFormat("START");
+ //'since' is not used here because we need to have ListObjects return a NoChange result
+ //for all shared accounts,containers
+ var accounts = ListSharingAccounts();
+ var items = from account in accounts
+ let containers = ListContainers(account.name)
+ from container in containers
+ select ListObjects(account.name, container.Name,since);
+ var objects=items.SelectMany(r=> r).ToList();
+/*
+ var objects = new List<ObjectInfo>();
+ foreach (var containerObjects in items)
+ {
+ objects.AddRange(containerObjects);
+ }
+*/
+ if (Log.IsDebugEnabled) Log.DebugFormat("END");
+ return objects;
+ }
+ }
+
+ public void SetTags(ObjectInfo target,IDictionary<string,string> tags)
+ {
+ if (String.IsNullOrWhiteSpace(Token))
+ throw new InvalidOperationException("The Token is not set");
+ if (StorageUrl == null)
+ throw new InvalidOperationException("The StorageUrl is not set");
+ if (target == null)
+ throw new ArgumentNullException("target");
+ Contract.EndContractBlock();
+
+ using (ThreadContext.Stacks["Share"].Push("Share Object"))
+ {
+ if (Log.IsDebugEnabled) Log.DebugFormat("START");
+
+ using (var client = new RestClient(_baseClient))
+ {
+
+ client.BaseAddress = GetAccountUrl(target.Account);
+
+ client.Parameters.Clear();
+ client.Parameters.Add("update", "");
+
+ foreach (var tag in tags)
+ {
+ var headerTag = String.Format("X-Object-Meta-{0}", tag.Key);
+ client.Headers.Add(headerTag, tag.Value);
+ }
+
+ client.DownloadStringWithRetry(target.Container, 3);
+
+
+ client.AssertStatusOK("SetTags failed");
+ //If the status is NOT ACCEPTED we have a problem
+ if (client.StatusCode != HttpStatusCode.Accepted)
+ {
+ Log.Error("Failed to set tags");
+ throw new Exception("Failed to set tags");
+ }
+
+ if (Log.IsDebugEnabled) Log.DebugFormat("END");
+ }
+ }