Added cloning of HttpRequestMessage to allow retries using the messages themselves
[pithos-ms-client] / trunk / Pithos.Core / PithosMonitor.cs
index 589dc33..c9526a6 100644 (file)
@@ -40,6 +40,7 @@
  */\r
 #endregion\r
 using System;\r
+using System.Collections.Concurrent;\r
 using System.Collections.Generic;\r
 using System.ComponentModel.Composition;\r
 using System.Diagnostics.Contracts;\r
@@ -226,12 +227,10 @@ namespace Pithos.Core
             }\r
             _cancellationSource = new CancellationTokenSource();\r
 \r
-            lock (this)\r
-            {\r
-                CloudClient = new CloudFilesClient(UserName, ApiKey)\r
-                                  {UsePithos = true, AuthenticationUrl = AuthenticationUrl};\r
-                _accountInfo = CloudClient.Authenticate();\r
-            }\r
+            CloudClient = new CloudFilesClient(UserName, ApiKey)\r
+                                {UsePithos = true, AuthenticationUrl = AuthenticationUrl};\r
+            \r
+            _accountInfo = await CloudClient.Authenticate().ConfigureAwait(false);\r
             _accountInfo.SiteUri = AuthenticationUrl;\r
             _accountInfo.AccountPath = RootPath;\r
 \r
@@ -242,10 +241,10 @@ namespace Pithos.Core
             //Create the cache folder and ensure it is hidden\r
             CreateHiddenFolder(RootPath, FolderConstants.CacheFolder);\r
 \r
-            var policy=CloudClient.GetAccountPolicies(_accountInfo);\r
+            var policy=await CloudClient.GetAccountPolicies(_accountInfo);\r
 \r
             StatusNotification.NotifyAccount(policy);\r
-            EnsurePithosContainers();\r
+            await EnsurePithosContainers().ConfigureAwait(false);\r
             \r
             StatusKeeper.BlockHash = _blockHash;\r
             StatusKeeper.BlockSize = _blockSize;\r
@@ -254,7 +253,7 @@ namespace Pithos.Core
 \r
             LoadSelectivePaths();\r
 \r
-            await IndexLocalFiles().ConfigureAwait(false);\r
+            //await IndexLocalFiles().ConfigureAwait(false);\r
 \r
             StartWatcherAgent();\r
 \r
@@ -276,18 +275,19 @@ namespace Pithos.Core
             CleanupUnselectedStates();\r
         }\r
 \r
-        private void EnsurePithosContainers()\r
+        private async Task EnsurePithosContainers()\r
         {\r
 \r
             //Create the two default containers if they are missing\r
             var pithosContainers = new List<string>{ FolderConstants.TrashContainer,FolderConstants.PithosContainer};\r
             foreach (var container in pithosContainers)\r
-            {                \r
-                var info=CloudClient.GetContainerInfo(UserName, container);\r
+            {\r
+                var escapedUri = container.ToEscapedUri();\r
+                var info=await CloudClient.GetContainerInfo(UserName, escapedUri).ConfigureAwait(false);\r
                 if (info == ContainerInfo.Empty)\r
                 {\r
-                    CloudClient.CreateContainer(UserName, container);\r
-                    info = CloudClient.GetContainerInfo(UserName, container);\r
+                    await CloudClient.CreateContainer(UserName, escapedUri);\r
+                    info = await CloudClient.GetContainerInfo(UserName, escapedUri).ConfigureAwait(false);\r
                 }\r
                 _blockSize = info.BlockSize;\r
                 _blockHash = info.BlockHash;\r
@@ -487,10 +487,10 @@ namespace Pithos.Core
             //var settings = Settings.Accounts.First(s => s.AccountKey == _accountInfo.AccountKey);\r
             if (!Selectives.IsSelectiveEnabled(_accountInfo.AccountKey)) return;\r
 \r
-            List<string> selectivePaths;\r
+            ConcurrentBag<string> selectivePaths;\r
             if (Selectives.SelectivePaths.TryGetValue(_accountInfo.AccountKey, out selectivePaths))\r
             {\r
-                var statePaths= FileState.Queryable.Select(state => state.FilePath).ToList();\r
+                var statePaths= StatusKeeper.GetAllStatePaths();\r
                 var removedPaths = statePaths\r
                     .Where(sp => !selectivePaths.Any(sp.IsAtOrBelow))\r
                     .ToList();\r
@@ -526,7 +526,7 @@ namespace Pithos.Core
                 return;\r
 \r
             //Ensure we remove any file state below the deleted folders\r
-            FileState.UnversionPaths(removed);\r
+            StatusKeeper.UnversionPaths(removed);\r
         }\r
 \r
 \r
@@ -554,7 +554,7 @@ namespace Pithos.Core
         }\r
 \r
 \r
-        public ObjectInfo GetObjectInfo(string filePath)\r
+        public async Task<ObjectInfo> GetObjectInfo(string filePath)\r
         {\r
             if (String.IsNullOrWhiteSpace(filePath))\r
                 throw new ArgumentNullException("filePath");\r
@@ -598,11 +598,11 @@ namespace Pithos.Core
             }\r
             \r
             var client = new CloudFilesClient(accountInfo);\r
-            var objectInfo=client.GetObjectInfo(accountName, container, relativeUrl);\r
+            var objectInfo=await client.GetObjectInfo(accountName, container.ToEscapedUri(), relativeUrl.ToEscapedUri()).ConfigureAwait(false);\r
             return objectInfo;\r
         }\r
         \r
-        public Task<ContainerInfo> GetContainerInfo(string filePath)\r
+        public async Task<ContainerInfo> GetContainerInfo(string filePath)\r
         {\r
             if (String.IsNullOrWhiteSpace(filePath))\r
                 throw new ArgumentNullException("filePath");\r
@@ -642,12 +642,11 @@ namespace Pithos.Core
                 container = parts[0];                \r
             }\r
 \r
-            return Task.Factory.StartNew(() =>\r
-            {\r
-                var client = new CloudFilesClient(accountInfo);\r
-                var containerInfo = client.GetContainerInfo(accountName, container);\r
-                return containerInfo;\r
-            });\r
+            \r
+            var client = new CloudFilesClient(accountInfo);\r
+            var containerInfo = await client.GetContainerInfo(accountName, container.ToEscapedUri()).ConfigureAwait(false);\r
+            return containerInfo;\r
+            \r
         }\r
     }\r
 }\r