+ ///<summary>
+ /// Updates the visual status indicators of the application depending on status changes, e.g. icon, stat
+ ///</summary>
+ public void UpdateStatus()
+ {
+
+ if (_iconNames.ContainsKey(_pithosStatus))
+ {
+ var info = _iconNames[_pithosStatus];
+ StatusIcon = String.Format(@"../Images/{0}.ico", info.IconName);
+ }
+
+ if (_pithosStatus == PithosStatus.InSynch)
+ StatusMessage = "All files up to date";
+ }
+
+
+
+ private Task StartMonitor(PithosMonitor monitor,int retries=0)
+ {
+ return Task.Factory.StartNew(() =>
+ {
+ using (log4net.ThreadContext.Stacks["Monitor"].Push("Start"))
+ {
+ try
+ {
+ Log.InfoFormat("Start Monitoring {0}", monitor.UserName);
+
+ monitor.Start();
+ }
+ catch (WebException exc)
+ {
+ if (AbandonRetry(monitor, retries))
+ return;
+
+ HttpStatusCode statusCode =HttpStatusCode.OK;
+ var response = exc.Response as HttpWebResponse;
+ if(response!=null)
+ statusCode = response.StatusCode;
+
+ switch (statusCode)
+ {
+ case HttpStatusCode.Unauthorized:
+ var message = String.Format("API Key Expired for {0}. Starting Renewal",
+ monitor.UserName);
+ Log.Error(message, exc);
+ var account = Settings.Accounts.Find(acc => acc.AccountKey == new Uri(new Uri(monitor.AuthenticationUrl), monitor.UserName));
+ account.IsExpired = true;
+ Notify(new ExpirationNotification(account));
+ //TryAuthorize(monitor.UserName, retries).Wait();
+ break;
+ case HttpStatusCode.ProxyAuthenticationRequired:
+ TryAuthenticateProxy(monitor,retries);
+ break;
+ default:
+ TryLater(monitor, exc, retries);
+ break;
+ }
+ }
+ catch (Exception exc)
+ {
+ if (AbandonRetry(monitor, retries))
+ return;
+
+ TryLater(monitor,exc,retries);
+ }
+ }
+ });
+ }
+
+ private void TryAuthenticateProxy(PithosMonitor monitor,int retries)
+ {
+ Execute.OnUIThread(() =>
+ {
+ var proxyAccount = IoC.Get<ProxyAccountViewModel>();
+ proxyAccount.Settings = Settings;
+ if (true != _windowManager.ShowDialog(proxyAccount))
+ return;
+ StartMonitor(monitor, retries);
+ NotifyOfPropertyChange(() => Accounts);
+ });
+ }
+
+ private bool AbandonRetry(PithosMonitor monitor, int retries)
+ {
+ if (retries > 1)
+ {
+ var message = String.Format("Monitoring of account {0} has failed too many times. Will not retry",
+ monitor.UserName);
+ _events.Publish(new Notification
+ {Title = "Account monitoring failed", Message = message, Level = TraceLevel.Error});
+ return true;
+ }
+ return false;
+ }
+
+
+ private void TryLater(PithosMonitor monitor, Exception exc,int retries)
+ {
+ var message = String.Format("An exception occured. Can't start monitoring\nWill retry in 10 seconds");
+ Task.Factory.StartNewDelayed(10000, () => StartMonitor(monitor,retries+1));
+ _events.Publish(new Notification
+ {Title = "Error", Message = message, Level = TraceLevel.Error});
+ Log.Error(message, exc);
+ }
+
+
+ public void NotifyChange(string status, TraceLevel level=TraceLevel.Info)
+ {
+ StatusMessage = status;
+
+ _events.Publish(new Notification { Title = "Pithos+", Message = status, Level = level });
+ }
+
+ public void NotifyChangedFile(string filePath)
+ {
+ if (RecentFiles.Any(e => e.FullPath == filePath))