New SQLite version
[pithos-ms-client] / trunk / Pithos.Client.WPF / PithosAccount.cs
index e684131..4549b11 100644 (file)
@@ -44,6 +44,8 @@
 // -----------------------------------------------------------------------
 
 using System.IO;
+using System.Reflection;
+using Pithos.Client.WPF.Preferences;
 using Pithos.Network;
 using log4net;
 
@@ -67,42 +69,57 @@ namespace Pithos.Client.WPF
     /// </summary>
     public static class PithosAccount
     {
-        private static readonly ILog Log = LogManager.GetLogger(typeof(PithosAccount));
+        private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
 
         /// <summary>
         /// Asynchronously retrieves PITHOS credentials
         /// </summary>
         /// <param name="loginUrl">URL to retrieve the account info from PITHOS. Must end with =</param>
         /// <returns>The credentials wrapped in a Task</returns>
-        public static Task<NetworkCredential> RetrieveCredentials(string loginUrl)
+        public static NetworkCredential RetrieveCredentials(string loginUrl,string accountName=null)
         {
             Contract.Requires(Uri.IsWellFormedUriString(loginUrl, UriKind.Absolute));
 
             if (!Uri.IsWellFormedUriString(loginUrl, UriKind.Absolute))
                 throw new ArgumentException("The pithosSite parameter must be a valid absolute URL", "loginUrl");
             
-            int port = GetFreePort();
+            //int port = GetFreePort();
             
             //TODO:Force logout here to take care of existing cookies
 
 
-            var listenerUrl = String.Format("http://127.0.0.1:{0}/", port);
+            //var listenerUrl = String.Format("http://127.0.0.1:{0}", port);
+            var listenerUrl = "pithos://127.0.0.1";
 
             
 
-            var receiveCredentials = ListenForRedirectAsync(port);
+            //var receiveCredentials = ListenForRedirectAsync(port);
 
-            var logoutUrl = loginUrl.Replace("login", "im/logout");
-            var logoutProcess=Process.Start(logoutUrl);
-            TaskEx.Delay(100).Wait();
-            var uriBuilder=new UriBuilder(loginUrl);                       
-            uriBuilder.Query="next=" + listenerUrl;
+            //var logoutUrl = loginUrl.Replace("login", "im/logout");
+            //var logoutProcess=Process.Start(logoutUrl);            
+            //TaskEx.Delay(2000).Wait();
+            var uriBuilder = new UriBuilder(loginUrl)
+                                 {
+                                     Query = String.Format("next={0}&force=", listenerUrl)
+                                 };
 
             var retrieveUri = uriBuilder.Uri;
+
+
+            var browser = new LoginView(retrieveUri,accountName);            
+            if (true == browser.ShowDialog())
+            {
+                return new NetworkCredential(browser.Account, browser.Token);
+            }
+            return null;
+
+/*
+
             Log.InfoFormat("[RETRIEVE] Open Browser at {0}", retrieveUri);
             Process.Start(retrieveUri.ToString());
 
             return receiveCredentials;
+*/
         }
 
 /*