From 62d5b25ff9989760d80c2f440f5afeb997d3a869 Mon Sep 17 00:00:00 2001 From: Panagiotis Kanavos Date: Thu, 23 Feb 2012 17:20:07 +0200 Subject: [PATCH] Fixes to create the proper filepaths from URLs --- trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs | 14 ++++++++------ trunk/Pithos.Core/Agents/CollectionExtensions.cs | 19 +++++++++++++++++++ trunk/Pithos.Core/PithosMonitor.cs | 9 +++++++-- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs b/trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs index 493d5bc..1689a20 100644 --- a/trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs +++ b/trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs @@ -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 }); } diff --git a/trunk/Pithos.Core/Agents/CollectionExtensions.cs b/trunk/Pithos.Core/Agents/CollectionExtensions.cs index 642d5bc..781631c 100644 --- a/trunk/Pithos.Core/Agents/CollectionExtensions.cs +++ b/trunk/Pithos.Core/Agents/CollectionExtensions.cs @@ -227,5 +227,24 @@ namespace Pithos.Core.Agents //Ensure that the candidate target is indeed below the root && InnerAtOrBelow(targetSegments, rootSegments); } + + /// + /// Returns the part of the target string that comes after the prefix string. + /// The target is not modified if it doesn't start with the prefix string + /// + /// + /// + /// + public static string After(this string target,string prefix) + { + //If the prefix or the target are empty, return the target + if (String.IsNullOrWhiteSpace(prefix) || String.IsNullOrWhiteSpace(target)) + return target; + if (target.StartsWith(prefix)) + return target.Remove(0,prefix.Length); + return target; + } } + + } diff --git a/trunk/Pithos.Core/PithosMonitor.cs b/trunk/Pithos.Core/PithosMonitor.cs index 4e8e393..f1f7486 100644 --- a/trunk/Pithos.Core/PithosMonitor.cs +++ b/trunk/Pithos.Core/PithosMonitor.cs @@ -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(); } /// @@ -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 -- 1.7.10.4