-/*\r
- public Task<IList<string>> PutHashMap(string account, Uri container, Uri objectName, TreeHash hash)\r
- {\r
- if (container == null)\r
- throw new ArgumentNullException("container", "The container property can't be empty");\r
- if (container.IsAbsoluteUri)\r
- throw new ArgumentException("The container must be relative","container");\r
- if (objectName == null)\r
- throw new ArgumentNullException("objectName", "The objectName property can't be empty");\r
- if (objectName.IsAbsoluteUri)\r
- throw new ArgumentException("The objectName must be relative","objectName");\r
- if (hash == null)\r
- throw new ArgumentNullException("hash");\r
- if (String.IsNullOrWhiteSpace(Token))\r
- throw new InvalidOperationException("Invalid Token");\r
- if (StorageUrl == null)\r
- throw new InvalidOperationException("Invalid Storage Url");\r
- Contract.EndContractBlock();\r
-\r
- \r
-\r
- //Don't use a timeout because putting the hashmap may be a long process\r
- var client = new RestClient(_baseClient) { Timeout = 0 }; \r
- if (!String.IsNullOrWhiteSpace(account))\r
- client.BaseAddress = GetAccountUrl(account);\r
-\r
- //The container and objectName are relative names. They are joined with the client's\r
- //BaseAddress to create the object's absolute address\r
- var builder = client.GetAddressBuilder(container, objectName);\r
- builder.Query = "format=json&hashmap";\r
- var uri = builder.Uri;\r
-\r
-\r
- //Send the tree hash as Json to the server \r
- client.Headers[HttpRequestHeader.ContentType] = "application/octet-stream";\r
- var jsonHash = hash.ToJson();\r
- \r
- client.Headers.Add("ETag",hash.TopHash.ToHashString());\r
- var uploadTask=client.UploadStringTask(uri, "PUT", jsonHash);\r
- if (Log.IsDebugEnabled)\r
- Log.DebugFormat("Hashes:\r\n{0}", jsonHash);\r
- return uploadTask.ContinueWith(t =>\r
- {\r
-\r
- var empty = (IList<string>)new List<string>();\r
- \r
-\r
- //The server will respond either with 201-created if all blocks were already on the server\r
- if (client.StatusCode == HttpStatusCode.Created) \r
- {\r
- //in which case we return an empty hash list\r
- return empty;\r
- }\r
- //or with a 409-conflict and return the list of missing parts\r
- //A 409 will cause an exception so we need to check t.IsFaulted to avoid propagating the exception \r
- if (t.IsFaulted)\r
- {\r
- var ex = t.Exception.InnerException;\r
- var we = ex as WebException;\r
- var response = we.Response as HttpWebResponse;\r
- if (response!=null && response.StatusCode==HttpStatusCode.Conflict)\r
- {\r
- //In case of 409 the missing parts will be in the response content \r
- using (var stream = response.GetResponseStream())\r
- using(var reader=stream.GetLoggedReader(Log))\r
- {\r
- //We used to have to cleanup the content before returning it because it contains\r
- //error content after the list of hashes\r
- //\r
- //As of 30/1/2012, the result is a proper Json array so we don't need to read the content\r
- //line by line\r
- \r
- var serializer = new JsonSerializer(); \r
- serializer.Error += (sender, args) => Log.ErrorFormat("Deserialization error at [{0}] [{1}]", args.ErrorContext.Error, args.ErrorContext.Member);\r
- var hashes = (List<string>)serializer.Deserialize(reader, typeof(List<string>));\r
- return hashes;\r
- } \r
- } \r
- //Any other status code is unexpected and the exception should be rethrown\r
- Log.LogError(response);\r
- throw ex;\r
- \r
- }\r
-\r
- //Any other status code is unexpected but there was no exception. We can probably continue processing\r
- Log.WarnFormat("Unexcpected status code when putting map: {0} - {1}",client.StatusCode,client.StatusDescription); \r
- \r
- return empty;\r
- });\r
-\r
- }\r
-\r
-*/\r
-\r
- \r