Revision 62d5b25f

b/trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs
580 580
								var message = String.Format("API Key Expired for {0}. Starting Renewal",
581 581
															monitor.UserName);
582 582
								Log.Error(message, exc);
583
								TryAuthorize(monitor, retries).Wait();
583
								TryAuthorize(monitor.UserName, retries).Wait();
584 584
								break;
585 585
							case HttpStatusCode.ProxyAuthenticationRequired:
586 586
								TryAuthenticateProxy(monitor,retries);
......
628 628
		}
629 629

  
630 630

  
631
		private async Task TryAuthorize(PithosMonitor monitor,int retries)
631
		private async Task TryAuthorize(string userName, int retries)
632 632
		{
633 633
			_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 });
634 634

  
......
638 638
				var credentials = await PithosAccount.RetrieveCredentials(Settings.PithosLoginUrl);
639 639

  
640 640
				var account = Settings.Accounts.First(act => act.AccountName == credentials.UserName);
641
                //The server may return credentials for a different account
642
			    var monitor = _monitors[account.AccountName];
641 643
				account.ApiKey = credentials.Password;
642
				monitor.ApiKey = credentials.Password;
644
                monitor.ApiKey = credentials.Password;
643 645
				Settings.Save();
644 646
				await TaskEx.Delay(10000);
645
				StartMonitor(monitor, retries + 1);
647
                StartMonitor(monitor, retries + 1);
646 648
				NotifyOfPropertyChange(()=>Accounts);
647 649
			}
648 650
			catch (AggregateException exc)
649 651
			{
650
				string message = String.Format("API Key retrieval for {0} failed", monitor.UserName);
652
				string message = String.Format("API Key retrieval for {0} failed", userName);
651 653
				Log.Error(message, exc.InnerException);
652 654
				_events.Publish(new Notification { Title = "Authorization failed", Message = message, Level = TraceLevel.Error });
653 655
			}
654 656
			catch (Exception exc)
655 657
			{
656
				string message = String.Format("API Key retrieval for {0} failed", monitor.UserName);
658
				string message = String.Format("API Key retrieval for {0} failed", userName);
657 659
				Log.Error(message, exc);
658 660
				_events.Publish(new Notification { Title = "Authorization failed", Message = message, Level = TraceLevel.Error });
659 661
			}
b/trunk/Pithos.Core/Agents/CollectionExtensions.cs
227 227
                //Ensure that the candidate target is indeed below the root
228 228
                && InnerAtOrBelow(targetSegments, rootSegments);
229 229
        }
230

  
231
        /// <summary>
232
        /// Returns the part of the target string that comes after the prefix string.
233
        /// The target is not modified if it doesn't start with the prefix string
234
        /// </summary>
235
        /// <param name="target"></param>
236
        /// <param name="remove"></param>
237
        /// <returns></returns>
238
        public static string After(this string target,string prefix)
239
        {            
240
            //If the prefix or the target are empty, return the target
241
            if (String.IsNullOrWhiteSpace(prefix) || String.IsNullOrWhiteSpace(target))
242
                return target;
243
            if (target.StartsWith(prefix))
244
                return target.Remove(0,prefix.Length);
245
            return target;
246
        }
230 247
    }
248

  
249

  
231 250
}
b/trunk/Pithos.Core/PithosMonitor.cs
503 503
                    let relativePath = _accountInfo.StorageUri
504 504
                        .MakeRelativeUri(uri)
505 505
                        .RelativeUriToFilePath()
506
                    select Path.Combine(RootPath, relativePath)).ToList();
506
                        //Trim the account name
507
                    select Path.Combine(RootPath, relativePath.After(_accountInfo.UserName + '\\'))).ToList();            
507 508
        }
508 509

  
509 510
        /// <summary>
......
517 518

  
518 519
            foreach (var removedPath in removed.Where(Directory.Exists))
519 520
            {
520
                Directory.Delete(removedPath,true);
521
                try
522
                {
523
                    Directory.Delete(removedPath, true);
524
                }
525
                catch { }
521 526
            }
522 527

  
523 528
            //Ensure we remove any file state below the deleted folders

Also available in: Unified diff