UUID Changes
[pithos-ms-client] / trunk / Pithos.Client.WPF / Shell / ShellViewModel.cs
index dd3afb7..4a2a4c9 100644 (file)
@@ -44,6 +44,7 @@ using System.Diagnostics;
 using System.Diagnostics.Contracts;\r
 using System.IO;\r
 using System.Net;\r
+using System.Net.Http;\r
 using System.Reflection;\r
 using System.Runtime.InteropServices;\r
 using System.ServiceModel;\r
@@ -68,8 +69,10 @@ using System;
 using System.Collections.Generic;\r
 using System.Linq;\r
 using Pithos.Network;\r
+using Pithos.OFM;\r
 using StatusService = Pithos.Client.WPF.Services.StatusService;\r
 \r
+\r
 namespace Pithos.Client.WPF {\r
        using System.ComponentModel.Composition;\r
 \r
@@ -113,6 +116,7 @@ namespace Pithos.Client.WPF {
                \r
                private readonly IEventAggregator _events;\r
 \r
+        \r
                public PithosSettings Settings { get; private set; }\r
 \r
 \r
@@ -229,6 +233,17 @@ namespace Pithos.Client.WPF {
                VersionMessage = String.Format("Pithos+ {0}", fileVersion.FileVersion);\r
            }\r
 \r
+\r
+        public void openOFM()\r
+        {\r
+            var fileManager = IoC.Get<FileManagerViewModel>();\r
+            fileManager.Accounts = Settings.Accounts;\r
+            fileManager.CurrentAccount = fileManager.Accounts.First();// Settings.Accounts.First();\r
+            _windowManager.ShowWindow(fileManager);\r
+            //var ofm = new OFM.GUI.OFM();\r
+            //ofm.Show();\r
+        }\r
+\r
         public void CurrentSyncStatus()\r
         {\r
             if (Accounts.Count == 0)\r
@@ -396,6 +411,7 @@ namespace Pithos.Client.WPF {
                 if (!Directory.Exists(account.RootPath))\r
                 {\r
                     account.IsActive = false;\r
+                    Settings.Save();\r
                     Notify(new Notification\r
                     {\r
                         Level = TraceLevel.Error,\r
@@ -454,6 +470,18 @@ namespace Pithos.Client.WPF {
                        }\r
                }\r
 \r
+        private double _ProgressBar;\r
+        public double ProgressBar\r
+        {\r
+            get { return _ProgressBar; }\r
+            set\r
+            {\r
+                _ProgressBar = value;\r
+                NotifyOfPropertyChange(() => ProgressBar);\r
+            }\r
+        }\r
+\r
+\r
         public string VersionMessage { get; set; }\r
 \r
            public string TooltipMessage\r
@@ -828,7 +856,7 @@ namespace Pithos.Client.WPF {
            public Notifier GetNotifier(string startMessage, string endMessage, bool isActive=true,params object[] args)\r
            {\r
                return isActive?new Notifier(this, \r
-                new StatusNotification(String.Format(startMessage,args)), \r
+                new StatusNotification(String.Format(startMessage,args)),\r
                 new StatusNotification(String.Format(endMessage,args)))\r
                 :new Notifier(this,(Notification) null,null);\r
            }\r
@@ -852,59 +880,60 @@ namespace Pithos.Client.WPF {
 \r
 \r
           \r
-               private Task StartMonitor(PithosMonitor monitor,int retries=0)\r
+               public async Task StartMonitor(PithosMonitor monitor,int retries=0)\r
                {\r
-                       return Task.Factory.StartNew(() =>\r
-                       {\r
-                               using (log4net.ThreadContext.Stacks["Monitor"].Push("Start"))\r
-                               {\r
-                                       try\r
-                                       {\r
-                                               Log.InfoFormat("Start Monitoring {0}", monitor.UserName);\r
-\r
-                                               monitor.Start();\r
-                                       }\r
-                                       catch (WebException exc)\r
-                                       {\r
-                                               if (AbandonRetry(monitor, retries))\r
-                                                       return;\r
-\r
-                                               HttpStatusCode statusCode =HttpStatusCode.OK;\r
-                                               var response = exc.Response as HttpWebResponse;\r
-                                               if(response!=null)\r
-                                                       statusCode = response.StatusCode;\r
-\r
-                                               switch (statusCode)\r
-                                               {\r
-                                                       case HttpStatusCode.Unauthorized:\r
-                                                               var message = String.Format("API Key Expired for {0}. Starting Renewal",\r
-                                                                                                                       monitor.UserName);\r
-                                                               Log.Error(message, exc);\r
-                                var account = Settings.Accounts.Find(acc => acc.AccountKey == new Uri(monitor.AuthenticationUrl).Combine(monitor.UserName));                                \r
-                                                       account.IsExpired = true;\r
-                                Notify(new ExpirationNotification(account));\r
-                                                               //TryAuthorize(monitor.UserName, retries).Wait();\r
-                                                               break;\r
-                                                       case HttpStatusCode.ProxyAuthenticationRequired:\r
-                                                               TryAuthenticateProxy(monitor,retries);\r
-                                                               break;\r
-                                                       default:\r
-                                                               TryLater(monitor, exc, retries);\r
-                                                               break;\r
-                                               }\r
-                                       }\r
-                                       catch (Exception exc)\r
-                                       {\r
-                                               if (AbandonRetry(monitor, retries)) \r
-                                                       return;\r
-\r
-                                               TryLater(monitor,exc,retries);\r
-                                       }\r
-                               }\r
-                       });\r
+                   using (log4net.ThreadContext.Stacks["Monitor"].Push("Start"))\r
+                   {\r
+                       try\r
+                       {\r
+                           Log.InfoFormat("Start Monitoring {0}", monitor.UserName);\r
+\r
+                           await monitor.Start();\r
+                       }\r
+                catch (HttpRequestWithStatusException exc)\r
+                       {\r
+                           if (AbandonRetry(monitor, retries))\r
+                               return;\r
+\r
+                           //HttpStatusCode statusCode = HttpStatusCode.OK;\r
+                           //var response =  as HttpWebResponse;\r
+                           //if (response != null)\r
+                           var statusCode = exc.StatusCode;//response.StatusCode;\r
+\r
+                           switch (statusCode)\r
+                           {\r
+                               case HttpStatusCode.Unauthorized:\r
+                                   var message = String.Format("API Key Expired for {0}. Starting Renewal",\r
+                                                               monitor.UserName);\r
+                                   Log.Error(message, exc);\r
+                                   var account =\r
+                                       Settings.Accounts.Find(\r
+                                           acc => acc.AccountKey == new Uri(monitor.AuthenticationUrl).Combine(monitor.UserName));\r
+                                   account.IsExpired = true;\r
+                            Settings.Save();\r
+                                   Notify(new ExpirationNotification(account));\r
+                                   //TryAuthorize(monitor.UserName, retries).Wait();\r
+                                   break;\r
+                               case HttpStatusCode.ProxyAuthenticationRequired:\r
+                                   TryAuthenticateProxy(monitor, retries);\r
+                                   break;\r
+                               default:\r
+                                   TryLater(monitor, exc, retries);\r
+                                   break;\r
+                           }\r
+                       }\r
+                       catch (Exception exc)\r
+                       {\r
+                           if (AbandonRetry(monitor, retries))\r
+                               return;\r
+\r
+                           TryLater(monitor, exc, retries);\r
+                       }\r
+                   }\r
+\r
                }\r
 \r
-               private void TryAuthenticateProxy(PithosMonitor monitor,int retries)\r
+           private void TryAuthenticateProxy(PithosMonitor monitor,int retries)\r
                {\r
                        Execute.OnUIThread(() =>\r
                                                                   {                                       \r
@@ -1132,6 +1161,7 @@ namespace Pithos.Client.WPF {
                                                      percentage,\r
                                                      progress.FileSize.ToByteSize(),\r
                                                      progress.FileName);\r
+                ProgressBar = percentage;\r
                        return;\r
                    }\r
 \r