Revision 31c97141 trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs

b/trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs
124 124
		//Lazily initialized File Version info. This is done once and lazily to avoid blocking the UI
125 125
		private Lazy<FileVersionInfo> _fileVersion;
126 126

  
127
	    private PollAgent _pollAgent;
128

  
127 129
		///<summary>
128 130
		/// The Shell depends on MEF to provide implementations for windowManager, events, the status checker service and the settings
129 131
		///</summary>
......
131 133
		/// The PithosSettings class encapsulates the app's settings to abstract their storage mechanism (App settings, a database or registry)
132 134
		///</remarks>
133 135
		[ImportingConstructor]		
134
		public ShellViewModel(IWindowManager windowManager, IEventAggregator events, IStatusChecker statusChecker, PithosSettings settings)
136
		public ShellViewModel(IWindowManager windowManager, IEventAggregator events, IStatusChecker statusChecker, PithosSettings settings,PollAgent pollAgent)
135 137
		{
136 138
			try
137 139
			{
......
144 146
				_events = events;
145 147
				_events.Subscribe(this);
146 148

  
149
			    _pollAgent = pollAgent;
147 150
				Settings = settings;
148 151

  
149 152
				Proxy.SetFromSettings(settings);
......
471 474

  
472 475
		public void SynchNow()
473 476
		{
474
			var agent = IoC.Get<PollAgent>();
475
			agent.SynchNow();
477
			_pollAgent.SynchNow();
476 478
		}
477 479

  
478 480
		public ObjectInfo RefreshObjectInfo(ObjectInfo currentInfo)
......
637 639
		}
638 640

  
639 641

  
640
		public async Task TryAuthorize(string userName, int retries)
641
		{
642
			_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 });
643

  
644
			try
645
			{
646

  
647
				var credentials = await PithosAccount.RetrieveCredentials(Settings.PithosLoginUrl);
648

  
649
				var account = Settings.Accounts.First(act => act.AccountName == credentials.UserName);
650
                //The server may return credentials for a different account
651
			    var monitor = _monitors[account.AccountName];
652
				account.ApiKey = credentials.Password;
653
                monitor.ApiKey = credentials.Password;
654
			    account.IsExpired = false;
655
				Settings.Save();
656
				TaskEx.Delay(10000).ContinueWith(_=>
657
                            StartMonitor(monitor, retries + 1));
658
				NotifyOfPropertyChange(()=>Accounts);
659
			}
660
			catch (AggregateException exc)
661
			{
662
				string message = String.Format("API Key retrieval for {0} failed", userName);
663
				Log.Error(message, exc.InnerException);
664
				_events.Publish(new Notification { Title = "Authorization failed", Message = message, Level = TraceLevel.Error });
665
			}
666
			catch (Exception exc)
667
			{
668
				string message = String.Format("API Key retrieval for {0} failed", userName);
669
				Log.Error(message, exc);
670
				_events.Publish(new Notification { Title = "Authorization failed", Message = message, Level = TraceLevel.Error });
671
			}
672

  
673
		}
674 642

  
675 643
		private static bool IsUnauthorized(WebException exc)
676 644
		{

Also available in: Unified diff