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);
}
- 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 });
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 });
}
//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
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>
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