Fixed incorrect account key in PollAgent.cs
authorpkanavos <pkanavos@gmail.com>
Mon, 9 Apr 2012 17:56:02 +0000 (20:56 +0300)
committerpkanavos <pkanavos@gmail.com>
Mon, 9 Apr 2012 17:56:02 +0000 (20:56 +0300)
Fixed incorrect check for Uri and Path relations in CollectionExtensions.cs

trunk/Pithos.Client.WPF/SelectiveSynch/SelectiveSynchViewModel.cs
trunk/Pithos.Core.Test/Pithos.Core.Test.csproj
trunk/Pithos.Core/Agents/CollectionExtensions.cs
trunk/Pithos.Core/Agents/PollAgent.cs
trunk/Pithos.Core/Agents/SnapshotDifferencer.cs
trunk/Pithos.Interfaces/PermissionConverter.cs
trunk/Pithos.sln

index 00ce722..71074a8 100644 (file)
@@ -103,7 +103,7 @@ namespace Pithos.Client.WPF.SelectiveSynch
                        select new DirectoryRecord
                                   {
                                       DisplayName = container.Name,
-                                      Uri=new Uri(client.StorageUrl,container.Name),
+                                      Uri=new Uri(client.StorageUrl,String.Format(@"{0}/{1}",Account.AccountName, container.Name)),
                                       Directories = (from dir in client.ListObjects(_monitor.UserName, container.Name)                                                     
                                                      where dir.Content_Type == DirectoryType
                                                      select dir).ToTree()
index 4b91404..31c33ac 100644 (file)
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="CollectionExtensionsTest.cs" />
     <Compile Include="EnumerableExtensionsTest.cs" />
     <Compile Include="ExtensionTests.cs" />
     <Compile Include="FileSystemWatcherAdapterTest.cs" />
index b4e92c5..2a785cc 100644 (file)
@@ -166,8 +166,9 @@ namespace Pithos.Core.Agents
             //If the uri is below the root, it should match the root's segments one by one\r
             //If there is any root segment that doesn't match its corresponding target segment,\r
             //the target is not below the root\r
+            //DON'T FORGET that Uri segments include the slashes. Must remove them to ensure proper checks\r
             var mismatch = rootSegments\r
-                .Where((t, i) => !String.Equals(targetSegments[i], t))\r
+                .Where((t, i) => !String.Equals(targetSegments[i].TrimEnd('/'), t.TrimEnd('/')))\r
                 .Any();\r
             return !mismatch;\r
         }\r
@@ -187,6 +188,8 @@ namespace Pithos.Core.Agents
                 throw new ArgumentNullException("target");\r
             Contract.EndContractBlock();\r
 \r
+            if (target.Equals(root))\r
+                return true;\r
             return\r
                 //If the target is directly below the root, it will have exactly \r
                 //one segment more than the root            \r
@@ -229,7 +232,8 @@ namespace Pithos.Core.Agents
                 throw new ArgumentNullException("rootPath");\r
             Contract.EndContractBlock();\r
 \r
-\r
+            if (targetPath==rootPath)\r
+                return true;\r
             var targetSegments = targetPath.Split('\\');\r
             var rootSegments = rootPath.Split('\\');\r
 \r
index 3a4a2bf..55f1a4d 100644 (file)
@@ -87,7 +87,7 @@ namespace Pithos.Core.Agents
         private readonly AsyncManualResetEvent _syncEvent = new AsyncManualResetEvent();\r
 \r
         private readonly ConcurrentDictionary<string, DateTime> _lastSeen = new ConcurrentDictionary<string, DateTime>();\r
-        private readonly ConcurrentDictionary<string, AccountInfo> _accounts = new ConcurrentDictionary<string,AccountInfo>();\r
+        private readonly ConcurrentDictionary<Uri, AccountInfo> _accounts = new ConcurrentDictionary<Uri,AccountInfo>();\r
 \r
 \r
         /// <summary>\r
@@ -614,15 +614,15 @@ namespace Pithos.Core.Agents
         public void AddAccount(AccountInfo accountInfo)\r
         {\r
             //Avoid adding a duplicate accountInfo\r
-            _accounts.TryAdd(accountInfo.UserName, accountInfo);\r
+            _accounts.TryAdd(accountInfo.AccountKey, accountInfo);\r
         }\r
 \r
         public void RemoveAccount(AccountInfo accountInfo)\r
         {\r
             AccountInfo account;\r
-            _accounts.TryRemove(accountInfo.UserName,out account);\r
+            _accounts.TryRemove(accountInfo.AccountKey, out account);\r
             SnapshotDifferencer differencer;\r
-            _differencer.Differencers.TryRemove(accountInfo.UserName, out differencer);\r
+            _differencer.Differencers.TryRemove(accountInfo.AccountKey, out differencer);\r
         }\r
     }\r
 }\r
index 2725e72..c340529 100644 (file)
@@ -39,6 +39,8 @@
  * -----------------------------------------------------------------------\r
  */\r
 #endregion\r
+\r
+using System;\r
 using System.Collections.Concurrent;\r
 using System.Diagnostics.Contracts;\r
 using Pithos.Interfaces;\r
@@ -214,17 +216,17 @@ namespace Pithos.Core.Agents
 \r
     public class AccountsDifferencer\r
     {\r
-        readonly ConcurrentDictionary<string, SnapshotDifferencer> _differencers = new ConcurrentDictionary<string, SnapshotDifferencer>();\r
+        readonly ConcurrentDictionary<Uri, SnapshotDifferencer> _differencers = new ConcurrentDictionary<Uri, SnapshotDifferencer>();\r
 \r
-        public ConcurrentDictionary<string, SnapshotDifferencer> Differencers { get { return _differencers; } }\r
+        public ConcurrentDictionary<Uri, SnapshotDifferencer> Differencers { get { return _differencers; } }\r
 \r
         public SnapshotDifferencer PostSnapshot(AccountInfo accountInfo, List<ObjectInfo> cleanRemotes)\r
         {\r
             SnapshotDifferencer differencer;\r
-            if (!_differencers.TryGetValue(accountInfo.UserName, out differencer))\r
+            if (!_differencers.TryGetValue(accountInfo.AccountKey, out differencer))\r
             {\r
                 differencer = new SnapshotDifferencer();\r
-                _differencers[accountInfo.UserName] = differencer;\r
+                _differencers[accountInfo.AccountKey] = differencer;\r
             }\r
             differencer.Post(cleanRemotes);\r
             return differencer;\r
index f179225..b9da9ae 100644 (file)
@@ -69,12 +69,18 @@ namespace Pithos.Interfaces
             
             var permissionString= (string) reader.Value;
 
+            var permissions = ParsePermissions(permissionString);
+
+            return permissions;
+        }
+
+        public static Dictionary<string, string> ParsePermissions(string permissionString)
+        {
             var permissions = (from permisson in permissionString.Split(';')
                                let parsed = permisson.Split('=')
                                from account in parsed[1].Split(',')
-                               select new { account, Permission = parsed[0] })
-                .ToDictionary(perm=>perm.account,perm=>perm.Permission);
-
+                               select new {account, Permission = parsed[0]})
+                .Distinct().ToDictionary(perm => perm.account, perm => perm.Permission);
             return permissions;
         }
 
index 2db5942..0aea32e 100644 (file)
@@ -43,6 +43,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetSparkle2010", "NetSparkl
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pithos.Client.WPF.Test", "Pithos.Client.WPF.Test\Pithos.Client.WPF.Test.csproj", "{7B5BFE77-FC4D-43B3-84A0-9CB457238951}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pithos.Interfaces.Test", "Pithos.Interfaces.Test\Pithos.Interfaces.Test.csproj", "{881F7260-CA40-40FD-AEEC-860B346DC2DC}"
+EndProject
 Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
                Debug All|Any CPU = Debug All|Any CPU
@@ -564,6 +566,36 @@ Global
                {7B5BFE77-FC4D-43B3-84A0-9CB457238951}.Test|Mixed Platforms.Build.0 = Release|Any CPU
                {7B5BFE77-FC4D-43B3-84A0-9CB457238951}.Test|x64.ActiveCfg = Release|Any CPU
                {7B5BFE77-FC4D-43B3-84A0-9CB457238951}.Test|x86.ActiveCfg = Release|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Debug All|Any CPU.ActiveCfg = Debug|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Debug All|Any CPU.Build.0 = Debug|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Debug All|Mixed Platforms.ActiveCfg = Debug|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Debug All|Mixed Platforms.Build.0 = Debug|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Debug All|x64.ActiveCfg = Debug|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Debug All|x86.ActiveCfg = Debug|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Debug|x64.ActiveCfg = Debug|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Debug|x86.ActiveCfg = Debug|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Premium Debug|Any CPU.ActiveCfg = Debug|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Premium Debug|Any CPU.Build.0 = Debug|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Premium Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Premium Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Premium Debug|x64.ActiveCfg = Debug|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Premium Debug|x86.ActiveCfg = Debug|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Release|Any CPU.Build.0 = Release|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Release|x64.ActiveCfg = Release|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Release|x86.ActiveCfg = Release|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Test|Any CPU.ActiveCfg = Release|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Test|Any CPU.Build.0 = Release|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Test|Mixed Platforms.ActiveCfg = Release|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Test|Mixed Platforms.Build.0 = Release|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Test|x64.ActiveCfg = Release|Any CPU
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC}.Test|x86.ActiveCfg = Release|Any CPU
        EndGlobalSection
        GlobalSection(SolutionProperties) = preSolution
                HideSolutionNode = FALSE
@@ -574,5 +606,6 @@ Global
                {E027200B-C26A-4877-BFD9-1A18CF5DF2F4} = {B5DD7C4D-D396-4C55-A8D5-DCFE865AA095}
                {F9AF3E97-BCB7-46B7-8014-7FC858AEE9BA} = {B5DD7C4D-D396-4C55-A8D5-DCFE865AA095}
                {7B5BFE77-FC4D-43B3-84A0-9CB457238951} = {B5DD7C4D-D396-4C55-A8D5-DCFE865AA095}
+               {881F7260-CA40-40FD-AEEC-860B346DC2DC} = {B5DD7C4D-D396-4C55-A8D5-DCFE865AA095}
        EndGlobalSection
 EndGlobal