Temp fixes
[pithos-ms-client] / trunk / Pithos.Client.WPF / Preferences / PreferencesViewModel.cs
index c432009..2857dc8 100644 (file)
@@ -109,7 +109,7 @@ namespace Pithos.Client.WPF.Preferences
         {
             // ReSharper disable DoNotCallOverridableMethodsInConstructor
             //Caliburn.Micro uses DisplayName for the view's title
-            DisplayName = "Pithos Preferences";
+            DisplayName = "Pithos+ Preferences";
             // ReSharper restore DoNotCallOverridableMethodsInConstructor
 
             _windowManager = windowManager;
@@ -227,17 +227,23 @@ namespace Pithos.Client.WPF.Preferences
             }
         }
 
-        public async Task RefreshApiKey()
+        public void RefreshApiKey()
         {
-            _events.Publish(new Notification { Title = "Authorization failed", Message = "Your API Key has probably expired. You will be directed to a page where you can renew it", Level = TraceLevel.Error });
-
+            //_events.Publish(new Notification { Title = "Authorization failed", Message = "Your API Key has probably expired. You will be directed to a page where you can renew it", Level = TraceLevel.Error });
+            if (CurrentAccount == null)
+                return;
             try
             {
 
-                var credentials = await PithosAccount.RetrieveCredentials(Settings.PithosLoginUrl);
+                var name = CurrentAccount.AccountName;
+
+                var loginUri = new Uri(new Uri(CurrentAccount.ServerUrl), "login");
+                var credentials = PithosAccount.RetrieveCredentials(loginUri.ToString(),name);
+                if (credentials==null)
+                    return;
                 //The server will return credentials for a different account, not just the current account
                 //We need to find the correct account first
-                var account = Accounts.First(act => act.AccountName == credentials.UserName);
+                var account = Accounts.First(act => act.AccountName == credentials.UserName && act.ServerUrl == ?? );
                 account.ApiKey = credentials.Password;                
                 account.IsExpired = false;
                 Settings.Save();
@@ -264,6 +270,13 @@ namespace Pithos.Client.WPF.Preferences
         {
             Shell.OpenLogPath();
         }
+
+        public void OpenLogConsole()
+        {
+            var logView=IoC.Get<LogConsole.LogConsoleViewModel>();            
+            _windowManager.ShowWindow(logView);
+        }
+
         public void SaveChanges()
         {
             DoSave();
@@ -295,18 +308,27 @@ namespace Pithos.Client.WPF.Preferences
             {
                 Settings.Accounts.Add(account);    
             }
-            
+
             Settings.Save();
 
 
-            foreach (var account in _accountsToRemove)
+            try
             {
-                Shell.RemoveMonitor(account.AccountName);
-            }
+                foreach (var account in _accountsToRemove)
+                {
+                    Shell.RemoveMonitor(account.AccountName);
+                    Shell.RemoveAccountFromDatabase(account);
+                }
 
-            foreach (var account in Settings.Accounts)
-            {                                
-                Shell.MonitorAccount(account);
+                foreach (var account in Settings.Accounts)
+                {
+                    Shell.MonitorAccount(account);
+                }
+            }                
+            finally
+            {
+                _accountsToRemove.Clear();
+                _accountsToAdd.Clear();
             }
 
             NotifyOfPropertyChange(()=>Settings);
@@ -345,13 +367,19 @@ namespace Pithos.Client.WPF.Preferences
            if (_windowManager.ShowDialog(wizard) == true)
            {
                string selectedPath = wizard.AccountPath;
-               var initialRootPath = Path.Combine(selectedPath, "Okeanos");
+               var initialRootPath = wizard.ShouldCreateOkeanosFolder?
+                   Path.Combine(selectedPath, "Okeanos")
+                   :selectedPath;
                var actualRootPath= initialRootPath;
-               int attempt = 1;
-               while (Directory.Exists(actualRootPath) || File.Exists(actualRootPath))
+               if (wizard.ShouldCreateOkeanosFolder)
                {
-                   actualRootPath = String.Format("{0} {1}", initialRootPath,attempt++);
+                   int attempt = 1;
+                   while (Directory.Exists(actualRootPath) || File.Exists(actualRootPath))
+                   {
+                       actualRootPath = String.Format("{0} {1}", initialRootPath, attempt++);
+                   }
                }
+               ### Check that the account does not already exist
 
                var newAccount = new AccountSettings
                                     {
@@ -373,9 +401,12 @@ namespace Pithos.Client.WPF.Preferences
             
        }
 
-        public async void AddPithosAccount()
+/*
+        public void AddPithosAccount()
        {
-            var credentials=await PithosAccount.RetrieveCredentials(Settings.PithosLoginUrl);
+            var credentials=PithosAccount.RetrieveCredentials(null);
+            if (credentials == null)
+                return;
             var account = Settings.Accounts.FirstOrDefault(act => act.AccountName == credentials.UserName);
             var accountVM = new AccountViewModel(account);
             if (account == null)
@@ -397,6 +428,7 @@ namespace Pithos.Client.WPF.Preferences
             NotifyOfPropertyChange(() => Accounts);
             NotifyOfPropertyChange(()=>Settings);                       
        }
+*/
 
 
         readonly List<AccountSettings> _accountsToRemove = new List<AccountSettings>();
@@ -441,6 +473,14 @@ namespace Pithos.Client.WPF.Preferences
             }
         }
 
+        public bool DebugLoggingEnabled
+        {
+            get { return Settings.DebugLoggingEnabled; }
+            set { 
+                Settings.DebugLoggingEnabled = value;
+                NotifyOfPropertyChange(()=>DebugLoggingEnabled);
+            }
+        }
        
         #endregion
 
@@ -538,6 +578,7 @@ namespace Pithos.Client.WPF.Preferences
                                                                             SearchOption.AllDirectories))
                         File.Copy(newFilePath, newFilePath.Replace(oldPath, newPath));
 
+                    Log.InfoFormat("Deleting account folder {0}",oldPath);
                     Directory.Delete(oldPath, true);
 
                     //We also need to change the path of the existing file states