UUID Changes
[pithos-ms-client] / trunk / Pithos.Client.WPF / Shell / ShellViewModel.cs
index 6bc0f31..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
@@ -141,6 +145,7 @@ namespace Pithos.Client.WPF {
                //Logging in the Pithos client is provided by log4net\r
         private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);\r
 \r
+        #pragma warning disable 649\r
         [Import]\r
            private PollAgent _pollAgent;\r
 \r
@@ -150,8 +155,9 @@ namespace Pithos.Client.WPF {
            [Import]\r
            public Selectives Selectives { get; set; }\r
 \r
+        #pragma warning restore 649\r
 \r
-           public ToggleStatusCommand ToggleMiniStatusCommand { get; set; }\r
+        public ToggleStatusCommand ToggleMiniStatusCommand { get; set; }\r
 \r
            private MiniStatusViewModel _miniStatus;\r
 \r
@@ -227,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
@@ -391,6 +408,20 @@ namespace Pithos.Client.WPF {
 \r
                                Monitors[account.AccountKey] = monitor;\r
 \r
+                if (!Directory.Exists(account.RootPath))\r
+                {\r
+                    account.IsActive = false;\r
+                    Settings.Save();\r
+                    Notify(new Notification\r
+                    {\r
+                        Level = TraceLevel.Error,\r
+                        Title = "Missing account folder",\r
+                        Message = String.Format("Can't find the root folder for account {0} at {1}. The account was deactivated.\r" +\r
+                        "If the account's files were stored in a removable disk, please connect it and reactivate the account", account.AccountName, account.RootPath)\r
+                    });\r
+                }\r
+\r
+\r
                                if (account.IsActive)\r
                                {\r
                                        //Don't start a monitor if it doesn't have an account and ApiKey\r
@@ -439,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
@@ -636,7 +679,7 @@ namespace Pithos.Client.WPF {
                        ShowFileProperties(files[idx].FullName);            \r
                }\r
 \r
-               public async void ShowFileProperties(string filePath)\r
+               public void ShowFileProperties(string filePath)\r
                {\r
                        if (String.IsNullOrWhiteSpace(filePath))\r
                                throw new ArgumentNullException("filePath");\r
@@ -813,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
@@ -837,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
@@ -1117,6 +1161,7 @@ namespace Pithos.Client.WPF {
                                                      percentage,\r
                                                      progress.FileSize.ToByteSize(),\r
                                                      progress.FileName);\r
+                ProgressBar = percentage;\r
                        return;\r
                    }\r
 \r