Replaced object load and update with direct HQL execution to resolve database locks...
[pithos-ms-client] / trunk / Pithos.Network / CloudFilesClient.cs
index cf04099..3089b0e 100644 (file)
@@ -1110,7 +1110,7 @@ namespace Pithos.Network
         }
 
 
-        public Task<TreeHash> GetHashMap(string account, string container, string objectName)
+        public async Task<TreeHash> GetHashMap(string account, string container, string objectName)
         {
             if (String.IsNullOrWhiteSpace(container))
                 throw new ArgumentNullException("container");
@@ -1128,40 +1128,26 @@ namespace Pithos.Network
                 //object to avoid concurrency errors.
                 //
                 //Download operations take a long time therefore they have no timeout.
-                //TODO: Do we really? this is a hashmap operation, not a download
-                var client = new RestClient(_baseClient) { Timeout = 0 };
-                if (!String.IsNullOrWhiteSpace(account))
-                    client.BaseAddress = GetAccountUrl(account);
-
-
-                //The container and objectName are relative names. They are joined with the client's
-                //BaseAddress to create the object's absolute address
-                var builder = client.GetAddressBuilder(container, objectName);
-                builder.Query = "format=json&hashmap";
-                var uri = builder.Uri;
+                //TODO: Do they really? this is a hashmap operation, not a download
                 
                 //Start downloading the object asynchronously
-                var downloadTask = client.DownloadStringTask(uri);
-                
-                //Once the download completes
-                return downloadTask.ContinueWith(download =>
+                using (var client = new RestClient(_baseClient) { Timeout = 0 })
                 {
-                    //Delete the local client object
-                    client.Dispose();
-                    //And report failure or completion
-                    if (download.IsFaulted)
-                    {
-                        Log.ErrorFormat("[GET HASH] FAIL for {0} with \r{1}", objectName,
-                                        download.Exception);
-                        throw download.Exception;
-                    }
-                                          
-                    //The server will return an empty string if the file is empty
-                    var json = download.Result;
+                    if (!String.IsNullOrWhiteSpace(account))
+                        client.BaseAddress = GetAccountUrl(account);
+
+                    //The container and objectName are relative names. They are joined with the client's
+                    //BaseAddress to create the object's absolute address
+                    var builder = client.GetAddressBuilder(container, objectName);
+                    builder.Query = "format=json&hashmap";
+                    var uri = builder.Uri;
+
+
+                    var json = await client.DownloadStringTaskAsync(uri);
                     var treeHash = TreeHash.Parse(json);
-                    Log.InfoFormat("[GET HASH] END {0}", objectName);                                             
+                    Log.InfoFormat("[GET HASH] END {0}", objectName);
                     return treeHash;
-                });
+                }
             }
             catch (Exception exc)
             {
@@ -1169,8 +1155,6 @@ namespace Pithos.Network
                 throw;
             }
 
-
-
         }