Changed proxy settings to request update if the proxy requires authentication
[pithos-ms-client] / trunk / Pithos.Core / PithosMonitor.cs
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)