Convert all url usages to use the Uri class instead of raw strings.
[pithos-ms-client] / trunk / Pithos.Core / Agents / Uploader.cs
index c27a731..8c49a67 100644 (file)
@@ -1,13 +1,10 @@
 using System;\r
-using System.Collections.Generic;\r
 using System.ComponentModel.Composition;\r
 using System.Diagnostics;\r
 using System.Diagnostics.Contracts;\r
 using System.IO;\r
-using System.Linq;\r
 using System.Net;\r
 using System.Reflection;\r
-using System.Security.Cryptography;\r
 using System.Threading;\r
 using System.Threading.Tasks;\r
 using Pithos.Interfaces;\r
@@ -168,7 +165,7 @@ namespace Pithos.Core.Agents
                                     if (action.IsCreation)\r
                                     {\r
                                         //Add the folder to the Selected URls\r
-                                        var selectiveUri = new Uri(client.RootAddressUri, cloudFile.Uri);\r
+                                        var selectiveUri = client.RootAddressUri.Combine(cloudFile.Uri);\r
                                         Selectives.AddUri(accountInfo, selectiveUri);\r
                                         Selectives.Save(accountInfo);\r
                                     }\r
@@ -315,7 +312,7 @@ namespace Pithos.Core.Agents
         }\r
 \r
 \r
-        public async Task UploadWithHashMap(AccountInfo accountInfo, ObjectInfo cloudFile, FileInfo fileInfo, string url, TreeHash treeHash, CancellationToken token)\r
+        public async Task UploadWithHashMap(AccountInfo accountInfo, ObjectInfo cloudFile, FileInfo fileInfo, Uri uri, TreeHash treeHash, CancellationToken token)\r
         {\r
             if (accountInfo == null)\r
                 throw new ArgumentNullException("accountInfo");\r
@@ -323,12 +320,14 @@ namespace Pithos.Core.Agents
                 throw new ArgumentNullException("cloudFile");\r
             if (fileInfo == null)\r
                 throw new ArgumentNullException("fileInfo");\r
-            if (String.IsNullOrWhiteSpace(url))\r
-                throw new ArgumentNullException(url);\r
+            if (uri==null)\r
+                throw new ArgumentNullException("uri");\r
             if (treeHash == null)\r
                 throw new ArgumentNullException("treeHash");\r
-            if (String.IsNullOrWhiteSpace(cloudFile.Container))\r
+            if (cloudFile.Container==null)\r
                 throw new ArgumentException("Invalid container", "cloudFile");\r
+            if (cloudFile.Container.IsAbsoluteUri)\r
+                throw new ArgumentException("Container URI must be relative", "cloudFile");\r
             Contract.EndContractBlock();\r
 \r
 \r
@@ -344,7 +343,7 @@ namespace Pithos.Core.Agents
 \r
             var client = new CloudFilesClient(accountInfo);\r
             //Send the hashmap to the server            \r
-            var missingHashes = await client.PutHashMap(account, container, url, treeHash).ConfigureAwait(false);\r
+            var missingHashes = await client.PutHashMap(account, container, uri, treeHash).ConfigureAwait(false);\r
             ReportUploadProgress(fileInfo.Name, block, 0, missingHashes.Count, fileInfo.Length);\r
             //If the server returns no missing hashes, we are done\r
 \r
@@ -384,7 +383,7 @@ namespace Pithos.Core.Agents
                         token.ThrowIfCancellationRequested();\r
                         Log.InfoFormat("[BLOCK] Block {0} of {1} uploaded", blockIndex, fullFileName);\r
                     }\r
-                    catch (TaskCanceledException exc)\r
+                    catch (TaskCanceledException)\r
                     {\r
                         throw new OperationCanceledException(token);\r
                     }\r
@@ -397,7 +396,7 @@ namespace Pithos.Core.Agents
 \r
                 token.ThrowIfCancellationRequested();\r
                 //Repeat until there are no more missing hashes                \r
-                missingHashes = await client.PutHashMap(account, container, url, treeHash).ConfigureAwait(false);\r
+                missingHashes = await client.PutHashMap(account, container, uri, treeHash).ConfigureAwait(false);\r
             }\r
 \r
             ReportUploadProgress(fileInfo.Name, missingHashes.Count, 0, missingHashes.Count, fileInfo.Length);\r