Added option to disable selective Synchronization
[pithos-ms-client] / trunk / Pithos.Core / Agents / SelectiveUris.cs
index ee2fa49..225e791 100644 (file)
@@ -24,6 +24,37 @@ namespace Pithos.Core.Agents
             SelectivePaths = new ConcurrentDictionary<Uri, List<string>>();\r
         }\r
 \r
+        readonly Dictionary<Uri, bool> _selectiveEnabled = new Dictionary<Uri, bool>();\r
+\r
+/*\r
+        public void SetIsSelectiveEnabled(AccountInfo account,bool value)\r
+        {\r
+            _selectiveEnabled[account.AccountKey]=value;\r
+        }\r
+*/\r
+\r
+        public void SetIsSelectiveEnabled(Uri accountKey,bool value)\r
+        {\r
+            _selectiveEnabled[accountKey]=value;\r
+        }\r
+/*\r
+\r
+        public bool IsSelectiveEnabled(AccountInfo account)\r
+        {\r
+            bool isEnabled;\r
+            _selectiveEnabled.TryGetValue(account.AccountKey, out isEnabled);\r
+            return isEnabled;\r
+        }\r
+*/\r
+\r
+        public bool IsSelectiveEnabled(Uri accountKey)\r
+        {\r
+            bool isEnabled;\r
+            _selectiveEnabled.TryGetValue(accountKey, out isEnabled);\r
+            return isEnabled;\r
+        }\r
+\r
+\r
         public void SetSelectedUris(AccountInfo account,List<Uri> uris)\r
         {\r
             SelectiveUris[account.AccountKey] = uris;\r
@@ -32,6 +63,12 @@ namespace Pithos.Core.Agents
 \r
         public bool IsSelected(ObjectInfo info)\r
         {\r
+            //Shared folders should NOT be synced if selective syncing is disabled\r
+            var isShared = info.IsShared;\r
+            var selectiveEnabled = IsSelectiveEnabled(info.AccountKey);\r
+            if (!selectiveEnabled)\r
+                return !isShared;\r
+\r
             List<Uri> filterUris;\r
             return !SelectiveUris.TryGetValue(info.AccountKey, out filterUris) \r
                 || filterUris.Count ==0\r
@@ -40,11 +77,22 @@ namespace Pithos.Core.Agents
 \r
         public bool IsSelected(AccountInfo account,FileSystemInfo info)\r
         {\r
+            if (info is DirectoryInfo)\r
+                return true;\r
             return IsSelected(account,info.FullName);\r
         }\r
 \r
         public bool IsSelected(AccountInfo account, string fullPath)\r
         {\r
+            if (Directory.Exists(fullPath))\r
+                return true;\r
+\r
+            //Shared folders should NOT be synced if selective syncing is disabled\r
+            var isShared = fullPath.IsSharedTo(account);\r
+            var selectiveEnabled = IsSelectiveEnabled(account.AccountKey);\r
+            if (!selectiveEnabled)\r
+                return !isShared;\r
+\r
             List<string> paths;\r
             return !SelectivePaths.TryGetValue(account.AccountKey, out paths)\r
                 || paths.Count == 0\r