Revision dd5f5163

b/trunk/Pithos.Client.WPF/Pithos.Client.WPF.csproj
268 268
      <HintPath>..\packages\Microsoft.SqlServer.Compact.4.0.8876.1\lib\net40\System.Data.SqlServerCe.dll</HintPath>
269 269
    </Reference>
270 270
    <Reference Include="System.Drawing" />
271
    <Reference Include="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
272
      <SpecificVersion>False</SpecificVersion>
273
      <HintPath>..\..\..\..\..\..\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll</HintPath>
274
    </Reference>
271 275
    <Reference Include="System.Runtime.Serialization" />
272 276
    <Reference Include="System.ServiceModel" />
273 277
    <Reference Include="System.Windows.Forms" />
b/trunk/Pithos.Client.WPF/Preferences/PreferencesViewModel.cs
146 146
        protected override void OnViewLoaded(object view)
147 147
        {
148 148
            base.OnViewLoaded(view);
149

  
149 150
            Settings.Reload();
151

  
150 152
            Accounts.Clear();
151 153

  
152 154
            if (Settings.Accounts == null)
......
158 160
                             select new AccountViewModel(account);
159 161

  
160 162
            Accounts.AddFromEnumerable(accountVMs);
163

  
161 164
        }
162 165

  
163 166
        private string _selectedTab = "General";
......
772 775
                {
773 776
                    monitor.RootPath = newPath;
774 777
                    if (CurrentAccount.IsActive)
775
                        monitor.Start();
778
                        Shell.StartMonitor(monitor);
779
                        
776 780
                }
777 781
                else
778 782
                    Shell.MonitorAccount(CurrentAccount.Account);
b/trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs
44 44
using System.Diagnostics.Contracts;
45 45
using System.IO;
46 46
using System.Net;
47
using System.Net.Http;
47 48
using System.Reflection;
48 49
using System.Runtime.InteropServices;
49 50
using System.ServiceModel;
......
113 114
		
114 115
		private readonly IEventAggregator _events;
115 116

  
117
        
116 118
		public PithosSettings Settings { get; private set; }
117 119

  
118 120

  
......
853 855

  
854 856

  
855 857
	   
856
		private Task StartMonitor(PithosMonitor monitor,int retries=0)
858
		public async Task StartMonitor(PithosMonitor monitor,int retries=0)
857 859
		{
858
			return Task.Factory.StartNew(() =>
859
			{
860
				using (log4net.ThreadContext.Stacks["Monitor"].Push("Start"))
861
				{
862
					try
863
					{
864
						Log.InfoFormat("Start Monitoring {0}", monitor.UserName);
865

  
866
						monitor.Start();
867
					}
868
					catch (WebException exc)
869
					{
870
						if (AbandonRetry(monitor, retries))
871
							return;
872

  
873
						HttpStatusCode statusCode =HttpStatusCode.OK;
874
						var response = exc.Response as HttpWebResponse;
875
						if(response!=null)
876
							statusCode = response.StatusCode;
877

  
878
						switch (statusCode)
879
						{
880
							case HttpStatusCode.Unauthorized:
881
								var message = String.Format("API Key Expired for {0}. Starting Renewal",
882
															monitor.UserName);
883
								Log.Error(message, exc);
884
                                var account = Settings.Accounts.Find(acc => acc.AccountKey == new Uri(monitor.AuthenticationUrl).Combine(monitor.UserName));                                
885
						        account.IsExpired = true;
886
                                Notify(new ExpirationNotification(account));
887
								//TryAuthorize(monitor.UserName, retries).Wait();
888
								break;
889
							case HttpStatusCode.ProxyAuthenticationRequired:
890
								TryAuthenticateProxy(monitor,retries);
891
								break;
892
							default:
893
								TryLater(monitor, exc, retries);
894
								break;
895
						}
896
					}
897
					catch (Exception exc)
898
					{
899
						if (AbandonRetry(monitor, retries)) 
900
							return;
901

  
902
						TryLater(monitor,exc,retries);
903
					}
904
				}
905
			});
860
		    using (log4net.ThreadContext.Stacks["Monitor"].Push("Start"))
861
		    {
862
		        try
863
		        {
864
		            Log.InfoFormat("Start Monitoring {0}", monitor.UserName);
865

  
866
		            await monitor.Start();
867
		        }
868
                catch (HttpRequestWithStatusException exc)
869
		        {
870
		            if (AbandonRetry(monitor, retries))
871
		                return;
872

  
873
		            //HttpStatusCode statusCode = HttpStatusCode.OK;
874
		            //var response =  as HttpWebResponse;
875
		            //if (response != null)
876
		            var statusCode = exc.StatusCode;//response.StatusCode;
877

  
878
		            switch (statusCode)
879
		            {
880
		                case HttpStatusCode.Unauthorized:
881
		                    var message = String.Format("API Key Expired for {0}. Starting Renewal",
882
		                                                monitor.UserName);
883
		                    Log.Error(message, exc);
884
		                    var account =
885
		                        Settings.Accounts.Find(
886
		                            acc => acc.AccountKey == new Uri(monitor.AuthenticationUrl).Combine(monitor.UserName));
887
		                    account.IsExpired = true;
888
                            Settings.Save();
889
		                    Notify(new ExpirationNotification(account));
890
		                    //TryAuthorize(monitor.UserName, retries).Wait();
891
		                    break;
892
		                case HttpStatusCode.ProxyAuthenticationRequired:
893
		                    TryAuthenticateProxy(monitor, retries);
894
		                    break;
895
		                default:
896
		                    TryLater(monitor, exc, retries);
897
		                    break;
898
		            }
899
		        }
900
		        catch (Exception exc)
901
		        {
902
		            if (AbandonRetry(monitor, retries))
903
		                return;
904

  
905
		            TryLater(monitor, exc, retries);
906
		        }
907
		    }
908

  
906 909
		}
907 910

  
908
		private void TryAuthenticateProxy(PithosMonitor monitor,int retries)
911
	    private void TryAuthenticateProxy(PithosMonitor monitor,int retries)
909 912
		{
910 913
			Execute.OnUIThread(() =>
911 914
								   {                                       
b/trunk/Pithos.Interfaces/AccountSettings.cs
67 67

  
68 68
        public string ServerUrl { get; set; }
69 69

  
70
        public bool IsExpired { get; set; }
70
        public bool IsExpired
71
        {
72
            get { return _isExpired; }
73
            set { _isExpired = value; }
74
        }
71 75

  
72 76
        public bool SelectiveSyncEnabled { get; set; }
73 77

  
74 78
        private StringCollection _selectiveFolders = new StringCollection();
79
        private bool _isExpired;
75 80

  
76 81
        public StringCollection SelectiveFolders
77 82
        {
b/trunk/Pithos.Network/Pithos.Network.csproj
309 309
    <Compile Include="ContainerInfo.cs" />
310 310
    <Compile Include="DownloadArgs.cs" />
311 311
    <Compile Include="FileBlockContent.cs" />
312
    <Compile Include="HttpRequestWithStatusException.cs" />
312 313
    <Compile Include="ICloudClient.cs" />
313 314
    <Compile Include="MD5BlockCalculator.cs" />
314 315
    <Compile Include="NoModificationInfo.cs" />
b/trunk/Pithos.Network/WebExtensions.cs
319 319
                        throw innerException ?? new RetryException();                        
320 320
                    else
321 321
                        //Otherwise force the exception that corresponds to the response
322
                        result.EnsureSuccessStatusCode();
322
                        throw new HttpRequestWithStatusException(result.StatusCode,result.ReasonPhrase);
323 323
            }
324 324
            throw new RetryException();
325 325
        }

Also available in: Unified diff