Fixes to create the proper filepaths from URLs
authorPanagiotis Kanavos <pkanavos@gmail.com>
Thu, 23 Feb 2012 15:20:07 +0000 (17:20 +0200)
committerPanagiotis Kanavos <pkanavos@gmail.com>
Thu, 23 Feb 2012 15:20:07 +0000 (17:20 +0200)
trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs
trunk/Pithos.Core/Agents/CollectionExtensions.cs
trunk/Pithos.Core/PithosMonitor.cs

index 493d5bc..1689a20 100644 (file)
@@ -580,7 +580,7 @@ namespace Pithos.Client.WPF {
                                                                var message = String.Format("API Key Expired for {0}. Starting Renewal",
                                                                                                                        monitor.UserName);
                                                                Log.Error(message, exc);
-                                                               TryAuthorize(monitor, retries).Wait();
+                                                               TryAuthorize(monitor.UserName, retries).Wait();
                                                                break;
                                                        case HttpStatusCode.ProxyAuthenticationRequired:
                                                                TryAuthenticateProxy(monitor,retries);
@@ -628,7 +628,7 @@ namespace Pithos.Client.WPF {
                }
 
 
-               private async Task TryAuthorize(PithosMonitor monitor,int retries)
+               private async Task TryAuthorize(string userName, int retries)
                {
                        _events.Publish(new Notification { Title = "Authorization failed", Message = "Your API Key has probably expired. You will be directed to a page where you can renew it", Level = TraceLevel.Error });
 
@@ -638,22 +638,24 @@ namespace Pithos.Client.WPF {
                                var credentials = await PithosAccount.RetrieveCredentials(Settings.PithosLoginUrl);
 
                                var account = Settings.Accounts.First(act => act.AccountName == credentials.UserName);
+                //The server may return credentials for a different account
+                           var monitor = _monitors[account.AccountName];
                                account.ApiKey = credentials.Password;
-                               monitor.ApiKey = credentials.Password;
+                monitor.ApiKey = credentials.Password;
                                Settings.Save();
                                await TaskEx.Delay(10000);
-                               StartMonitor(monitor, retries + 1);
+                StartMonitor(monitor, retries + 1);
                                NotifyOfPropertyChange(()=>Accounts);
                        }
                        catch (AggregateException exc)
                        {
-                               string message = String.Format("API Key retrieval for {0} failed", monitor.UserName);
+                               string message = String.Format("API Key retrieval for {0} failed", userName);
                                Log.Error(message, exc.InnerException);
                                _events.Publish(new Notification { Title = "Authorization failed", Message = message, Level = TraceLevel.Error });
                        }
                        catch (Exception exc)
                        {
-                               string message = String.Format("API Key retrieval for {0} failed", monitor.UserName);
+                               string message = String.Format("API Key retrieval for {0} failed", userName);
                                Log.Error(message, exc);
                                _events.Publish(new Notification { Title = "Authorization failed", Message = message, Level = TraceLevel.Error });
                        }
index 642d5bc..781631c 100644 (file)
@@ -227,5 +227,24 @@ namespace Pithos.Core.Agents
                 //Ensure that the candidate target is indeed below the root\r
                 && InnerAtOrBelow(targetSegments, rootSegments);\r
         }\r
+\r
+        /// <summary>\r
+        /// Returns the part of the target string that comes after the prefix string.\r
+        /// The target is not modified if it doesn't start with the prefix string\r
+        /// </summary>\r
+        /// <param name="target"></param>\r
+        /// <param name="remove"></param>\r
+        /// <returns></returns>\r
+        public static string After(this string target,string prefix)\r
+        {            \r
+            //If the prefix or the target are empty, return the target\r
+            if (String.IsNullOrWhiteSpace(prefix) || String.IsNullOrWhiteSpace(target))\r
+                return target;\r
+            if (target.StartsWith(prefix))\r
+                return target.Remove(0,prefix.Length);\r
+            return target;\r
+        }\r
     }\r
+\r
+\r
 }\r
index 4e8e393..f1f7486 100644 (file)
@@ -503,7 +503,8 @@ namespace Pithos.Core
                     let relativePath = _accountInfo.StorageUri
                         .MakeRelativeUri(uri)
                         .RelativeUriToFilePath()
-                    select Path.Combine(RootPath, relativePath)).ToList();
+                        //Trim the account name
+                    select Path.Combine(RootPath, relativePath.After(_accountInfo.UserName + '\\'))).ToList();            
         }
 
         /// <summary>
@@ -517,7 +518,11 @@ namespace Pithos.Core
 
             foreach (var removedPath in removed.Where(Directory.Exists))
             {
-                Directory.Delete(removedPath,true);
+                try
+                {
+                    Directory.Delete(removedPath, true);
+                }
+                catch { }
             }
 
             //Ensure we remove any file state below the deleted folders