Changed the retry function in PithosClient to use the TPL
[pithos-ms-client] / trunk / Pithos.Core / PithosMonitor.cs
index 0652075..831c082 100644 (file)
@@ -331,7 +331,7 @@ namespace Pithos.Core
                                       
                                       var onlyLocal = from localFile in pithosDir.EnumerateFiles()
                                                       where !remoteFiles.Contains(localFile.Name.ToLower()) 
-                                                      select new ListenerAction(CloudActionType.UploadUnconditional, localFile,null);
+                                                      select new ListenerAction(CloudActionType.UploadUnconditional, localFile,ObjectInfo.Empty);
 
 
 
@@ -340,7 +340,7 @@ namespace Pithos.Core
 
                                       var onlyRemote = from upFile in remoteObjects
                                                        where !localNames.Contains(upFile.Name.ToLower())
-                                                       select new ListenerAction(CloudActionType.DownloadUnconditional,null,upFile);
+                                                       select new ListenerAction(CloudActionType.DownloadUnconditional,new FileInfo(""), upFile);
 
 
                                       var commonObjects = from  upFile in remoteObjects
@@ -385,7 +385,6 @@ namespace Pithos.Core
                     switch (action.Action)
                     {
                         case CloudActionType.UploadUnconditional:
-
                             UploadCloudFile(localFile.Name,localFile.Length,localFile.FullName,action.LocalHash.Value);
                             break;
                         case CloudActionType.DownloadUnconditional:
@@ -552,6 +551,11 @@ namespace Pithos.Core
 
         private void DownloadCloudFile(string container, string fileName, string localPath)
         {
+            var state = StatusKeeper.GetNetworkState(fileName);
+            //Abort if the file is already being uploaded or downloaded
+            if (state != NetworkState.None)
+                return;
+
             StatusKeeper.SetNetworkState(localPath,NetworkState.Downloading);
             CloudClient.GetObject(container, fileName, localPath)
             .ContinueWith(t=>
@@ -566,6 +570,10 @@ namespace Pithos.Core
         private void UploadCloudFile(string fileName, long fileSize, string path,string hash)
         {
             Contract.Requires(!Path.IsPathRooted(fileName));
+            var state=StatusKeeper.GetNetworkState(fileName);
+            //Abort if the file is already being uploaded or downloaded
+            if (state != NetworkState.None)
+                return;
 
             StatusKeeper.SetNetworkState(fileName,NetworkState.Uploading);
             
@@ -584,8 +592,7 @@ namespace Pithos.Core
                 {
                     this.StatusKeeper.StoreInfo(path,info);
                 }
-            }
-            )
+            })
             .ContinueWith(t => 
                 this.StatusKeeper.SetFileState(path, FileStatus.Unchanged, FileOverlayStatus.Normal))
                 .ContinueWith(t=>