Changed proxy settings to request update if the proxy requires authentication
authorPanagiotis Kanavos <pkanavos@gmail.com>
Mon, 23 Jan 2012 16:53:20 +0000 (18:53 +0200)
committerPanagiotis Kanavos <pkanavos@gmail.com>
Mon, 23 Jan 2012 17:01:13 +0000 (19:01 +0200)
22 files changed:
trunk/Pithos.Client.WPF/Configuration/PithosSettings.cs
trunk/Pithos.Client.WPF/Pithos.Client.WPF.csproj
trunk/Pithos.Client.WPF/Preferences/PreferencesView.xaml
trunk/Pithos.Client.WPF/Preferences/ProxyAccountView.xaml [new file with mode: 0644]
trunk/Pithos.Client.WPF/Preferences/ProxyAccountView.xaml.cs [new file with mode: 0644]
trunk/Pithos.Client.WPF/Preferences/ProxyAccountViewModel.cs [new file with mode: 0644]
trunk/Pithos.Client.WPF/Properties/Settings.Designer.cs
trunk/Pithos.Client.WPF/Properties/Settings.settings
trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs
trunk/Pithos.Client.WPF/app.config
trunk/Pithos.Core.Test/MockSettings.cs
trunk/Pithos.Core/PithosMonitor.cs
trunk/Pithos.Interfaces/IPithosSettings.cs
trunk/Pithos.Interfaces/Pithos.Interfaces.csproj
trunk/Pithos.Interfaces/PithosSettingsData.cs
trunk/Pithos.Network/CloudFilesClient.cs
trunk/Pithos.Network/ICloudClient.cs
trunk/Pithos.Network/Pithos.Network.csproj
trunk/Pithos.Network/RestClient.cs
trunk/Pithos.ShellExtensions.Test/TestPithosSettings.cs
trunk/Pithos.ShellExtensions/ShellSettings.cs
trunk/Pithos.ShellExtensions/TestPithosSettings.cs

index 05ef20d..eb16a78 100644 (file)
@@ -147,6 +147,12 @@ namespace Pithos.Client.WPF.Configuration
             set { _settings.ProxyPassword = value; }
         }
 
+        public string ProxyDomain
+        {
+            get { return _settings.ProxyDomain; }
+            set { _settings.ProxyDomain = value; }
+        }
+
         public bool ProxyAuthentication
         {
 
index 8b8bbc0..555f5ae 100644 (file)
       <DependentUpon>GroupsView.xaml</DependentUpon>
     </Compile>
     <Compile Include="Preferences\GroupsViewModel.cs" />
+    <Compile Include="Preferences\ProxyAccountView.xaml.cs">
+      <DependentUpon>ProxyAccountView.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="Preferences\ProxyAccountViewModel.cs" />
     <Compile Include="Shell\AboutView.xaml.cs">
       <DependentUpon>AboutView.xaml</DependentUpon>
     </Compile>
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </Page>
+    <Page Include="Preferences\ProxyAccountView.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Shell\AboutView.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
index 35b6b7d..47d0510 100644 (file)
                                 <CheckBox Content="Proxy requires authentication" Height="16" VerticalAlignment="Top" Name="Settings_ProxyAuthentication" />
                             </GroupBox.Header>
                             <Grid >
-                                <Label Content="Username" Height="28" HorizontalAlignment="Left" Margin="0,6,0,0" Name="label3" VerticalAlignment="Top" />
-                                <Label Content="Password" Height="28" HorizontalAlignment="Left" Margin="0,32,0,0" Name="label4" VerticalAlignment="Top" />
-                                <TextBox Height="23" HorizontalAlignment="Left" Margin="65,6,0,0" Name="Settings_ProxyUsername" VerticalAlignment="Top" Width="157" IsEnabled="{Binding IsChecked,ElementName=Settings_ProxyAuthentication}"/>
-                                <TextBox Height="23" HorizontalAlignment="Left" Margin="65,37,0,0" Name="Settings_ProxyPassword" VerticalAlignment="Top" Width="157" IsEnabled="{Binding IsChecked,ElementName=Settings_ProxyAuthentication}"/>
+                            <Grid.RowDefinitions>
+                                <RowDefinition/>
+                                <RowDefinition/>
+                                <RowDefinition/>
+                            </Grid.RowDefinitions>
+                            <Grid.ColumnDefinitions>
+                                <ColumnDefinition/>
+                                <ColumnDefinition/>
+                            </Grid.ColumnDefinitions>
+                                <Label Content="Username" Height="28" HorizontalAlignment="Left" Grid.Row="0" Grid.Column="0" VerticalAlignment="Top" />
+                            <Label Content="Password" Height="28" HorizontalAlignment="Left" Grid.Row="1" Grid.Column="0" VerticalAlignment="Top" />
+                            <Label Content="Domain" Height="28" HorizontalAlignment="Left" Grid.Row="2" Grid.Column="0"  VerticalAlignment="Top" />
+                            <TextBox Height="23" HorizontalAlignment="Left" Grid.Row="0" Grid.Column="1" Name="Settings_ProxyUsername" VerticalAlignment="Top" Width="157" IsEnabled="{Binding IsChecked,ElementName=Settings_ProxyAuthentication}"/>
+                            <TextBox Height="23" HorizontalAlignment="Left" Grid.Row="1" Grid.Column="1" Name="Settings_ProxyPassword" VerticalAlignment="Top" Width="157" IsEnabled="{Binding IsChecked,ElementName=Settings_ProxyAuthentication}"/>
+                            <TextBox Height="23" HorizontalAlignment="Left" Grid.Row="2" Grid.Column="1" Name="Settings_ProxyDomain" VerticalAlignment="Top" Width="157" IsEnabled="{Binding IsChecked,ElementName=Settings_ProxyAuthentication}"/>
                             </Grid>
                         </GroupBox>
                     </Grid>
diff --git a/trunk/Pithos.Client.WPF/Preferences/ProxyAccountView.xaml b/trunk/Pithos.Client.WPF/Preferences/ProxyAccountView.xaml
new file mode 100644 (file)
index 0000000..b3144f7
--- /dev/null
@@ -0,0 +1,69 @@
+<Window x:Class="Pithos.Client.WPF.Preferences.ProxyAccountView"\r
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\r
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"\r
+        xmlns:Converters="clr-namespace:Pithos.Client.WPF.Converters" Title="ProxyAccountView" Height="300" Width="400">\r
+    <Window.Resources>\r
+        <ResourceDictionary>\r
+            <ResourceDictionary.MergedDictionaries>\r
+                <ResourceDictionary Source="..\PithosStyles.xaml" />\r
+            </ResourceDictionary.MergedDictionaries>\r
+            <Converters:NullToVisibilityConverter x:Key="NullToVisible" />\r
+        </ResourceDictionary>\r
+    </Window.Resources>\r
+    <Grid>\r
+        <Grid.RowDefinitions>\r
+            <RowDefinition Height="Auto"/>\r
+            <RowDefinition Height="Auto"/>\r
+            <RowDefinition Height="Auto"/>\r
+            <RowDefinition/>\r
+            <RowDefinition Height="Auto"/>\r
+        </Grid.RowDefinitions>\r
+        <Grid.ColumnDefinitions>\r
+            <ColumnDefinition Width="Auto"/>\r
+            <ColumnDefinition />\r
+        </Grid.ColumnDefinitions>\r
+        <RadioButton Name="Settings_UseDefaultProxy" Content="Use System Defaults" Margin="5,6,5,0" Height="16" VerticalAlignment="Top"/>\r
+        <RadioButton Name="Settings_UseManualProxy" Content="Manual" Margin="5,28,5,0" Height="16" VerticalAlignment="Top"/>\r
+        <Label Content="Server" Height="28" HorizontalAlignment="Left" Margin="5,47,0,0" Name="label2" VerticalAlignment="Top" />\r
+        <TextBox Height="23" HorizontalAlignment="Left" Margin="76,51,0,0" Name="Settings_ProxyServer" VerticalAlignment="Top" Width="162" IsEnabled="{Binding ElementName=Settings_UseManualProxy, Path=IsChecked}"/>\r
+        <TextBlock Height="23" HorizontalAlignment="Left" Margin="244,51,0,0" Name="textBlock1" Text=":" VerticalAlignment="Top" />\r
+        <TextBox Height="23" HorizontalAlignment="Left" Margin="254,51,0,0" Name="Settings_ProxyPort" VerticalAlignment="Top" Width="65" IsEnabled="{Binding ElementName=Settings_UseManualProxy, Path=IsChecked}"/>\r
+\r
+        <GroupBox Height="109" HorizontalAlignment="Left" Margin="5,80,0,0" Name="groupBox2" VerticalAlignment="Top" Width="373" IsEnabled="{Binding ElementName=Settings_UseManualProxy, Path=IsChecked}">\r
+            <GroupBox.Header>\r
+                <CheckBox Content="Proxy requires authentication" Height="16" VerticalAlignment="Top" Name="Settings_ProxyAuthentication" />\r
+            </GroupBox.Header>\r
+            <Grid >\r
+                <Grid.RowDefinitions>\r
+                    <RowDefinition/>\r
+                    <RowDefinition/>\r
+                    <RowDefinition/>\r
+                </Grid.RowDefinitions>\r
+                <Grid.ColumnDefinitions>\r
+                    <ColumnDefinition/>\r
+                    <ColumnDefinition/>\r
+                </Grid.ColumnDefinitions>\r
+                <Label Content="Username" Height="28" HorizontalAlignment="Left" Grid.Row="0" Grid.Column="0" VerticalAlignment="Top" />\r
+                <Label Content="Password" Height="28" HorizontalAlignment="Left" Grid.Row="1" Grid.Column="0" VerticalAlignment="Top" />\r
+                <Label Content="Domain" Height="28" HorizontalAlignment="Left" Grid.Row="2" Grid.Column="0"  VerticalAlignment="Top" />\r
+                <TextBox Height="23" HorizontalAlignment="Left" Grid.Row="0" Grid.Column="1" Name="Settings_ProxyUsername" VerticalAlignment="Top" Width="157" IsEnabled="{Binding IsChecked,ElementName=Settings_ProxyAuthentication}"/>\r
+                <TextBox Height="23" HorizontalAlignment="Left" Grid.Row="1" Grid.Column="1" Name="Settings_ProxyPassword" VerticalAlignment="Top" Width="157" IsEnabled="{Binding IsChecked,ElementName=Settings_ProxyAuthentication}"/>\r
+                <TextBox Height="23" HorizontalAlignment="Left" Grid.Row="2" Grid.Column="1" Name="Settings_ProxyDomain" VerticalAlignment="Top" Width="157" IsEnabled="{Binding IsChecked,ElementName=Settings_ProxyAuthentication}"/>\r
+            </Grid>\r
+        </GroupBox>\r
+    \r
+\r
+<!--\r
+    <TextBlock Text="UserName" Grid.Row="0" Grid.Column="0" Margin="5"/>\r
+            <TextBox x:Name="UserName" Grid.Row="0" Grid.Column="1" Margin="5"/>\r
+            <TextBlock Text="Password" Grid.Row="1" Grid.Column="0" Margin="5"/>\r
+            <TextBox x:Name="Password" Grid.Row="1" Grid.Column="1" Margin="5"/>\r
+            <TextBlock Text="Domain" Grid.Row="2" Grid.Column="0" Margin="5"/>\r
+            <TextBox x:Name="Domain" Grid.Row="2" Grid.Column="1" Margin="5"/>\r
+-->\r
+        <StackPanel Orientation="Horizontal" Grid.Row="3" Grid.ColumnSpan="2" HorizontalAlignment="Right" VerticalAlignment="Bottom">\r
+            <Button Name="SaveChanges" Content="OK" Margin="5,5,10,5" Style="{StaticResource ButtonStyle}"/>\r
+            <Button Name="RejectChanges" Content="Cancel" Margin="5,5,10,5" Style="{StaticResource ButtonStyle}"/>\r
+        </StackPanel>\r
+    </Grid>\r
+</Window>\r
diff --git a/trunk/Pithos.Client.WPF/Preferences/ProxyAccountView.xaml.cs b/trunk/Pithos.Client.WPF/Preferences/ProxyAccountView.xaml.cs
new file mode 100644 (file)
index 0000000..940b358
--- /dev/null
@@ -0,0 +1,26 @@
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Text;\r
+using System.Windows;\r
+using System.Windows.Controls;\r
+using System.Windows.Data;\r
+using System.Windows.Documents;\r
+using System.Windows.Input;\r
+using System.Windows.Media;\r
+using System.Windows.Media.Imaging;\r
+using System.Windows.Shapes;\r
+\r
+namespace Pithos.Client.WPF.Preferences\r
+{\r
+    /// <summary>\r
+    /// Interaction logic for ProxyAccountView.xaml\r
+    /// </summary>\r
+    public partial class ProxyAccountView : Window\r
+    {\r
+        public ProxyAccountView()\r
+        {\r
+            InitializeComponent();\r
+        }\r
+    }\r
+}\r
diff --git a/trunk/Pithos.Client.WPF/Preferences/ProxyAccountViewModel.cs b/trunk/Pithos.Client.WPF/Preferences/ProxyAccountViewModel.cs
new file mode 100644 (file)
index 0000000..e40b991
--- /dev/null
@@ -0,0 +1,115 @@
+// -----------------------------------------------------------------------\r
+// <copyright file="ProxyAccountViewModel.cs" company="Microsoft">\r
+// TODO: Update copyright text.\r
+// </copyright>\r
+// -----------------------------------------------------------------------\r
+\r
+using System.ComponentModel.Composition;\r
+using System.Diagnostics.Contracts;\r
+using System.Net;\r
+using Caliburn.Micro;\r
+using Pithos.Client.WPF.Configuration;\r
+\r
+namespace Pithos.Client.WPF.Preferences\r
+{\r
+    using System;\r
+    using System.Collections.Generic;\r
+    using System.Linq;\r
+    using System.Text;\r
+\r
+    [Export(typeof(ProxyAccountViewModel))]\r
+    public class ProxyAccountViewModel:Screen\r
+    {\r
+        public override string DisplayName\r
+        {\r
+            get { return "Proxy Settings"; }\r
+            set\r
+            {\r
+                base.DisplayName = value;\r
+            }\r
+        }\r
+        private string _userName;\r
+        public string UserName\r
+        {\r
+            get { return _userName; }\r
+            set\r
+            {\r
+                if (String.IsNullOrWhiteSpace(value))\r
+                    throw new ArgumentNullException();\r
+                _userName = value;\r
+                NotifyOfPropertyChange(()=>UserName);\r
+            }\r
+        }\r
+\r
+        private string _password;        \r
+        public string Password\r
+        {\r
+            get { return _password; }\r
+            set\r
+            {\r
+                if (String.IsNullOrWhiteSpace(value))\r
+                    throw new ArgumentNullException();\r
+                _password = value;\r
+                NotifyOfPropertyChange(()=>Password);\r
+            }\r
+        }\r
+\r
+        private string _domain;\r
+        public string Domain\r
+        {\r
+            get { return _domain; }\r
+            set\r
+            {\r
+                _domain = value;\r
+                NotifyOfPropertyChange(()=>Domain);\r
+            }\r
+        }\r
+\r
+        public PithosSettings Settings\r
+        {\r
+            get { return _settings; }\r
+            set\r
+            {\r
+                _settings = value;\r
+                NotifyOfPropertyChange(()=>Settings);\r
+            }\r
+        }\r
+\r
+        private PithosSettings _settings;\r
+\r
+        public ProxyAccountViewModel(PithosSettings settings)\r
+        {\r
+            if (settings == null)\r
+                throw new ArgumentNullException("settings");\r
+            Contract.EndContractBlock();\r
+\r
+            Settings = settings;\r
+            UserName = Settings.ProxyUsername;\r
+            Password = Settings.ProxyPassword;\r
+            Domain = Settings.ProxyDomain;\r
+        }\r
+\r
+        public void SaveChanges()\r
+        {\r
+/*\r
+            Settings.ProxyUsername = UserName;\r
+            Settings.ProxyPassword = Password;\r
+            Settings.ProxyDomain = Domain;\r
+            Settings.UseManualProxy = true;\r
+            Settings.UseDefaultProxy = false;\r
+            Settings.UseNoProxy = false;\r
+            Settings.ProxyAuthentication = true;\r
+*/\r
+            Settings.Save();\r
+            CredentialCache.DefaultNetworkCredentials.Password = Settings.ProxyPassword;\r
+            CredentialCache.DefaultNetworkCredentials.UserName = Settings.ProxyUsername;\r
+            CredentialCache.DefaultNetworkCredentials.Domain= Settings.ProxyDomain;\r
+            this.TryClose(true);            \r
+        }\r
+\r
+        public void RejectChanges()\r
+        {\r
+            this.TryClose();\r
+        }\r
+    }\r
+}\r
index dd1fe77..20a6dc5 100644 (file)
@@ -97,7 +97,7 @@ namespace Pithos.Client.WPF.Properties {
         
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("False")]
+        [global::System.Configuration.DefaultSettingValueAttribute("True")]
         public bool ProxyAuthentication {
             get {
                 return ((bool)(this["ProxyAuthentication"]));
@@ -181,7 +181,7 @@ namespace Pithos.Client.WPF.Properties {
         
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("True")]
+        [global::System.Configuration.DefaultSettingValueAttribute("False")]
         public bool UseDefaultProxy {
             get {
                 return ((bool)(this["UseDefaultProxy"]));
@@ -193,7 +193,7 @@ namespace Pithos.Client.WPF.Properties {
         
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("False")]
+        [global::System.Configuration.DefaultSettingValueAttribute("True")]
         public bool UseManualProxy {
             get {
                 return ((bool)(this["UseManualProxy"]));
@@ -282,5 +282,17 @@ namespace Pithos.Client.WPF.Properties {
                 this["PollingInterval"] = value;
             }
         }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("")]
+        public string ProxyDomain {
+            get {
+                return ((string)(this["ProxyDomain"]));
+            }
+            set {
+                this["ProxyDomain"] = value;
+            }
+        }
     }
 }
index 62f529b..7a69659 100644 (file)
@@ -21,7 +21,7 @@
       <Value Profile="(Default)" />
     </Setting>
     <Setting Name="ProxyAuthentication" Type="System.Boolean" Scope="User">
-      <Value Profile="(Default)">False</Value>
+      <Value Profile="(Default)">True</Value>
     </Setting>
     <Setting Name="ExtensionsActivated" Type="System.Boolean" Scope="User">
       <Value Profile="(Default)">True</Value>
       <Value Profile="(Default)">False</Value>
     </Setting>
     <Setting Name="UseDefaultProxy" Type="System.Boolean" Scope="User">
-      <Value Profile="(Default)">True</Value>
+      <Value Profile="(Default)">False</Value>
     </Setting>
     <Setting Name="UseManualProxy" Type="System.Boolean" Scope="User">
-      <Value Profile="(Default)">False</Value>
+      <Value Profile="(Default)">True</Value>
     </Setting>
     <Setting Name="CloudfilesAuthenticationUrl" Type="System.String" Scope="Application">
       <Value Profile="(Default)">https://auth.api.rackspacecloud.com</Value>
@@ -71,5 +71,8 @@
     <Setting Name="PollingInterval" Type="System.Int32" Scope="User">
       <Value Profile="(Default)">10</Value>
     </Setting>
+    <Setting Name="ProxyDomain" Type="System.String" Scope="User">
+      <Value Profile="(Default)" />
+    </Setting>
   </Settings>
 </SettingsFile>
\ No newline at end of file
index d0ca919..55cbd44 100644 (file)
@@ -12,6 +12,7 @@ using Caliburn.Micro;
 using Hardcodet.Wpf.TaskbarNotification;
 using Pithos.Client.WPF.Configuration;
 using Pithos.Client.WPF.FileProperties;
+using Pithos.Client.WPF.Preferences;
 using Pithos.Client.WPF.SelectiveSynch;
 using Pithos.Client.WPF.Services;
 using Pithos.Client.WPF.Shell;
@@ -509,16 +510,26 @@ namespace Pithos.Client.WPF {
                                                if (AbandonRetry(monitor, retries))
                                                        return;
 
-                                               if (IsUnauthorized(exc))
-                                               {
-                                                       var message = String.Format("API Key Expired for {0}. Starting Renewal",monitor.UserName);                            
-                                                       Log.Error(message,exc);
-                                                       TryAuthorize(monitor,retries).Wait();
-                                               }
-                                               else
-                                               {
-                                                       TryLater(monitor, exc,retries);
-                                               }
+                        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);
+                                TryAuthorize(monitor, retries).Wait();
+                                break;
+                            case HttpStatusCode.ProxyAuthenticationRequired:
+                                TryAuthenticateProxy(monitor,retries);
+                                break;
+                            default:
+                                TryLater(monitor, exc, retries);
+                                break;
+                        }
                                        }
                                        catch (Exception exc)
                                        {
@@ -531,7 +542,21 @@ namespace Pithos.Client.WPF {
                        });
                }
 
-               private bool AbandonRetry(PithosMonitor monitor, int retries)
+           private void TryAuthenticateProxy(PithosMonitor monitor,int retries)
+           {
+               Execute.OnUIThread(() =>
+                                      {
+                                          var proxyAccount = new ProxyAccountViewModel(this.Settings);
+                                          if (true == _windowManager.ShowDialog(proxyAccount))
+                                          {
+                                           
+                                              StartMonitor(monitor, retries);
+                                              NotifyOfPropertyChange(() => Accounts);
+                                          }
+                                      });
+           }
+
+           private bool AbandonRetry(PithosMonitor monitor, int retries)
                {
                        if (retries > 1)
                        {
index 596bdef..707287d 100644 (file)
@@ -46,7 +46,7 @@
         <value />
       </setting>
       <setting name="ProxyAuthentication" serializeAs="String">
-        <value>False</value>
+        <value>True</value>
       </setting>
       <setting name="ExtensionsActivated" serializeAs="String">
         <value>True</value>
         <value>False</value>
       </setting>
       <setting name="UseDefaultProxy" serializeAs="String">
-        <value>True</value>
+        <value>False</value>
       </setting>
       <setting name="UseManualProxy" serializeAs="String">
-        <value>False</value>
+        <value>True</value>
       </setting>
       <setting name="MustUpgrade" serializeAs="String">
         <value>True</value>
@@ -78,6 +78,9 @@
       <setting name="PollingInterval" serializeAs="String">
         <value>10</value>
       </setting>
+      <setting name="ProxyDomain" serializeAs="String">
+        <value />
+      </setting>
     </Pithos.Client.WPF.Properties.Settings>
   </userSettings>
   <connectionStrings>
index 734647d..ee26ebb 100644 (file)
@@ -32,6 +32,7 @@ namespace Pithos.Core.Test
 
         public string ProxyPassword { get; set; }
 
+        public string ProxyDomain { get; set; }
 
         public bool ProxyAuthentication { get; set; }
         public bool ExtensionsActivated { get; set; }
index c34d70e..705c5f2 100644 (file)
@@ -6,6 +6,7 @@ using System.Diagnostics;
 using System.Diagnostics.Contracts;
 using System.IO;
 using System.Linq;
+using System.Net;
 using System.Net.NetworkInformation;
 using System.Security.Cryptography;
 using System.ServiceModel.Description;
@@ -168,8 +169,8 @@ namespace Pithos.Core
             
 
             CloudClient=new CloudFilesClient(UserName,ApiKey);
-            var proxyUri = ProxyFromSettings();            
-            CloudClient.Proxy = proxyUri;
+            var proxy = ProxyFromSettings();            
+            CloudClient.Proxy = proxy;
             CloudClient.UsePithos = true;
             CloudClient.AuthenticationUrl = this.AuthenticationUrl;            
 
@@ -225,21 +226,22 @@ namespace Pithos.Core
 
         public string AuthenticationUrl { get; set; }
 
-        private Uri ProxyFromSettings()
+        private WebProxy ProxyFromSettings()
         {            
             if (Settings.UseManualProxy)
             {
-                var proxyUri = new UriBuilder
-                                   {
-                                       Host = Settings.ProxyServer, 
-                                       Port = Settings.ProxyPort
-                                   };
+                var proxy = new WebProxy(Settings.ProxyServer, Settings.ProxyPort);
+                //If the proxy requires specific authentication settings, use them
                 if (Settings.ProxyAuthentication)
                 {
-                    proxyUri.UserName = Settings.ProxyUsername;
-                    proxyUri.Password = Settings.ProxyPassword;
+                    proxy.Credentials=new NetworkCredential(Settings.ProxyUsername,Settings.ProxyPassword,Settings.ProxyDomain);
                 }
-                return proxyUri.Uri;
+                    //Otherwise, if there are generic authentication settings, use them
+                if (!String.IsNullOrWhiteSpace(CredentialCache.DefaultNetworkCredentials.UserName))
+                {
+                    proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
+                }
+                return proxy;
             }
             return null;
         }
@@ -279,18 +281,19 @@ namespace Pithos.Core
 
         private void StartWorkflowAgent()
         {
-            //On Vista and up we can check for a network connection
+            WorkflowAgent.StatusNotification = StatusNotification;
+
+/*            //On Vista and up we can check for a network connection
             bool connected=Environment.OSVersion.Version.Major < 6 || NetworkListManager.IsConnectedToInternet;
             //If we are not connected retry later
             if (!connected)
             {
                 Task.Factory.StartNewDelayed(10000, StartWorkflowAgent);
                 return;
-            }
+            }*/
 
             try
             {
-                WorkflowAgent.StatusNotification = StatusNotification;
                 WorkflowAgent.Start();                
             }
             catch (Exception)
index f1235b4..a680105 100644 (file)
@@ -26,9 +26,8 @@ namespace Pithos.Interfaces
         
 
         string ProxyUsername { get; set; }
-
-
         string ProxyPassword { get; set; }
+        string ProxyDomain { get; set; }
         
 
         bool ProxyAuthentication{ get; set; }
index 9ed8987..e611977 100644 (file)
@@ -28,7 +28,7 @@
     <CodeContractsRuntimeThrowOnFailure>True</CodeContractsRuntimeThrowOnFailure>
     <CodeContractsRuntimeCallSiteRequires>False</CodeContractsRuntimeCallSiteRequires>
     <CodeContractsRuntimeSkipQuantifiers>False</CodeContractsRuntimeSkipQuantifiers>
-    <CodeContractsRunCodeAnalysis>True</CodeContractsRunCodeAnalysis>
+    <CodeContractsRunCodeAnalysis>False</CodeContractsRunCodeAnalysis>
     <CodeContractsNonNullObligations>False</CodeContractsNonNullObligations>
     <CodeContractsBoundsObligations>False</CodeContractsBoundsObligations>
     <CodeContractsArithmeticObligations>False</CodeContractsArithmeticObligations>
index f94a406..e5cf2b8 100644 (file)
@@ -62,6 +62,7 @@ namespace Pithos.Interfaces
         public int ProxyPort { get; set; }
         public string ProxyUsername { get; set; }
         public string ProxyPassword { get; set; }
+        public string ProxyDomain { get; set; }
         public bool ProxyAuthentication { get; set; }
         public bool ExtensionsActivated { get; set; }
         public int PollingInterval { get; set; }
@@ -88,6 +89,7 @@ namespace Pithos.Interfaces
             ProxyPort = other.ProxyPort;
             ProxyUsername = other.ProxyUsername;
             ProxyPassword = other.ProxyPassword;
+            ProxyDomain = other.ProxyDomain;
             ProxyAuthentication = other.ProxyAuthentication;
             ExtensionsActivated = other.ExtensionsActivated;
             PollingInterval = other.PollingInterval;
index 0cb2355..63d4211 100644 (file)
@@ -93,7 +93,20 @@ namespace Pithos.Network
 
         protected Uri RootAddressUri { get; set; }
 
-        private Uri _proxy;
+        private WebProxy _proxy;
+        public WebProxy Proxy
+        {
+            get { return _proxy; }
+            set
+            {
+                _proxy = value;
+                if (_baseClient != null)
+                    _baseClient.Proxy = value;                
+            }
+        }
+
+
+        /* private Uri _proxy;
         public Uri Proxy
         {
             get { return _proxy; }
@@ -103,7 +116,7 @@ namespace Pithos.Network
                 if (_baseClient != null)
                     _baseClient.Proxy = new WebProxy(value);                
             }
-        }
+        }*/
 
         public double DownloadPercentLimit { get; set; }
         public double UploadPercentLimit { get; set; }
@@ -141,7 +154,8 @@ namespace Pithos.Network
             {
                 BaseAddress = accountInfo.StorageUri.ToString(),
                 Timeout = 10000,
-                Retries = 3
+                Retries = 3,
+                Proxy=this.Proxy
             };
             StorageUrl = accountInfo.StorageUri;
             Token = accountInfo.Token;
@@ -175,9 +189,9 @@ namespace Pithos.Network
             var groups = new List<Group>();
 
             using (var authClient = new RestClient{BaseAddress=AuthenticationUrl})
-            {
+            {                
                 if (Proxy != null)
-                    authClient.Proxy = new WebProxy(Proxy);
+                    authClient.Proxy = Proxy;
 
                 Contract.Assume(authClient.Headers!=null);
 
@@ -196,7 +210,8 @@ namespace Pithos.Network
                 {
                     BaseAddress = storageUrl,
                     Timeout = 10000,
-                    Retries = 3
+                    Retries = 3,
+                    Proxy=Proxy
                 };
 
                 StorageUrl = new Uri(storageUrl);
index e41536c..070468b 100644 (file)
@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.Diagnostics.Contracts;
+using System.Net;
 using System.Threading.Tasks;
 using Pithos.Interfaces;
 
@@ -18,7 +19,7 @@ namespace Pithos.Network
 
         bool UsePithos { get; set; }
         AccountInfo Authenticate();
-        Uri Proxy { get; set; }
+        WebProxy Proxy { get; set; }
         double DownloadPercentLimit { get; set; }
         double UploadPercentLimit { get; set; }
         string AuthenticationUrl { get; set; }
@@ -75,7 +76,7 @@ namespace Pithos.Network
         public Uri StorageUrl { get; set; }
         public string Token { get; set; }
 
-        public Uri Proxy { get; set; }
+        public WebProxy Proxy { get; set; }
         public double DownloadPercentLimit { get; set; }
         public double UploadPercentLimit { get; set; }
 
index ac27603..32a05d8 100644 (file)
@@ -28,7 +28,7 @@
     <CodeContractsRuntimeThrowOnFailure>True</CodeContractsRuntimeThrowOnFailure>
     <CodeContractsRuntimeCallSiteRequires>False</CodeContractsRuntimeCallSiteRequires>
     <CodeContractsRuntimeSkipQuantifiers>False</CodeContractsRuntimeSkipQuantifiers>
-    <CodeContractsRunCodeAnalysis>True</CodeContractsRunCodeAnalysis>
+    <CodeContractsRunCodeAnalysis>False</CodeContractsRunCodeAnalysis>
     <CodeContractsNonNullObligations>False</CodeContractsNonNullObligations>
     <CodeContractsBoundsObligations>False</CodeContractsBoundsObligations>
     <CodeContractsArithmeticObligations>False</CodeContractsArithmeticObligations>
index a63d0c7..8bb8dd2 100644 (file)
@@ -121,7 +121,7 @@ namespace Pithos.Network
             TimedOut = false;
             var webRequest = base.GetWebRequest(address);            
             var request = (HttpWebRequest)webRequest;
-            request.ServicePoint.ConnectionLimit = 10;
+            request.ServicePoint.ConnectionLimit = 50;
             if (IfModifiedSince.HasValue)
                 request.IfModifiedSince = IfModifiedSince.Value;
             request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
@@ -261,8 +261,19 @@ namespace Pithos.Network
 
             }, actualRetries);
 
-            var result = task.Result;
-            return result;
+            try
+            {
+                var result = task.Result;
+                return result;
+
+            }
+            catch (AggregateException exc)
+            {
+                //If the task fails, propagate the original exception
+                if (exc.InnerException!=null)
+                    throw exc.InnerException;
+                throw;
+            }
         }
 
         public void Head(string address,int retries=0)
index 9f585e1..4bc4589 100644 (file)
@@ -45,6 +45,8 @@ namespace Pithos.ShellExtensions.Test
 
         public string ProxyPassword { get; set; }
 
+        public string ProxyDomain { get; set; }
+
 
         public bool ProxyAuthentication { get; set; }
 
index 9f1f849..06ae957 100644 (file)
@@ -142,6 +142,12 @@ namespace Pithos.ShellExtensions
             set { _settings.Value.ProxyPassword = value; }
         }
 
+        public string ProxyDomain
+        {
+            get { return _settings.Value.ProxyDomain; }
+            set { _settings.Value.ProxyDomain = value; }
+        }
+
         public bool ProxyAuthentication
         {
 
index 8f589ac..b621d84 100644 (file)
@@ -46,6 +46,8 @@ namespace Pithos.ShellExtensions.Test
 
         public string ProxyPassword { get; set; }
 
+        public string ProxyDomain { get; set; }
+
         public bool ExtensionsActivated { get; set; }
 
         public int PollingInterval { get; set; }