Revision 62d5b25f trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs

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
			}

Also available in: Unified diff