From 7d855abd516b3881a486b5cc175aeeab06cd0162 Mon Sep 17 00:00:00 2001 From: pkanavos Date: Tue, 1 May 2012 21:11:08 +0300 Subject: [PATCH] All containers and first level folders are automatically added to Selective Sync when adding a new account. Shared Objects are NOT added --- trunk/Pithos.Client.WPF/App.xaml.cs | 51 ++- .../Preferences/PreferencesViewModel.cs | 28 +- trunk/Pithos.Client.WPF/app.config | 472 ++++++++++---------- 3 files changed, 315 insertions(+), 236 deletions(-) diff --git a/trunk/Pithos.Client.WPF/App.xaml.cs b/trunk/Pithos.Client.WPF/App.xaml.cs index c44afb1..b399db6 100644 --- a/trunk/Pithos.Client.WPF/App.xaml.cs +++ b/trunk/Pithos.Client.WPF/App.xaml.cs @@ -210,18 +210,52 @@ namespace Pithos.Client.WPF }); - var message = String.Format(@"{0}" + Environment.NewLine + "{1}" + Environment.NewLine + "{2}", + //Do not display any messages if this is a 304 code + var ignoreExceptions = from exc in e.Exception.InnerExceptions.OfType() + where IsAllowedException(exc) + select exc; + + if (ignoreExceptions.Any()) + { + e.SetObserved(); + return; + } + + + /* var message = String.Format(@"{0}" + Environment.NewLine + "{1}" + Environment.NewLine + "{2}", WPF.Properties.Resources.Unexpected_Error, WPF.Properties.Resources.We_Apologize, WPF.Properties.Resources.Please_Submit_Error); - ShowMessages("Oops!",message, messages); + ShowMessages("Oops!",message, messages);*/ e.SetObserved(); } + private bool IsAllowedException(Exception exc) + { + var we = exc as WebException; + if (we==null) + { + return false; + } + var response = we.Response as HttpWebResponse; + return (response != null && response.StatusCode == HttpStatusCode.NotModified); + } + private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e) { + + //Do not display any messages if this is a 304 code + if (IsAllowedException(e.ExceptionObject as Exception)) + { + return; + } + Log.Error("Unhandled exception", (Exception)e.ExceptionObject); + if (!e.IsTerminating) + //Do not display a message unless the application is terminating + return; + var description = e.IsTerminating ? WPF.Properties.Resources.Unexpected_Error_Terminating : WPF.Properties.Resources.Unexpected_Error; @@ -230,7 +264,6 @@ namespace Pithos.Client.WPF WPF.Properties.Resources.We_Apologize, WPF.Properties.Resources.Please_Submit_Error); - var exc = ((Exception) e.ExceptionObject); var messages = new[]{ new UserMessage @@ -245,11 +278,19 @@ namespace Pithos.Client.WPF ShowMessages("Oops!", message,messages); } + + void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { + //Do not display any messages if this is a 304 code + if (IsAllowedException(e.Exception)) + { + return; + } + Log.Error("Unhandled Dispatcher exception", e.Exception); - var messages = new[]{ + /* var messages = new[]{ new UserMessage { Message = e.Exception.Message, @@ -259,7 +300,7 @@ namespace Pithos.Client.WPF }; ShowMessages(WPF.Properties.Resources.Error_Title, WPF.Properties.Resources.Unexpected_Error, - messages); + messages);*/ e.Handled=true; } diff --git a/trunk/Pithos.Client.WPF/Preferences/PreferencesViewModel.cs b/trunk/Pithos.Client.WPF/Preferences/PreferencesViewModel.cs index bf22074..3970428 100644 --- a/trunk/Pithos.Client.WPF/Preferences/PreferencesViewModel.cs +++ b/trunk/Pithos.Client.WPF/Preferences/PreferencesViewModel.cs @@ -43,6 +43,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; +using System.Collections.Specialized; using System.ComponentModel.Composition; using System.Diagnostics; using System.IO; @@ -55,10 +56,12 @@ using Caliburn.Micro; using Pithos.Client.WPF.Configuration; using Pithos.Client.WPF.Properties; using Pithos.Client.WPF.SelectiveSynch; +using Pithos.Client.WPF.Utils; using Pithos.Core; using Pithos.Interfaces; using System; using System.Linq; +using Pithos.Network; using MessageBox = System.Windows.MessageBox; using Screen = Caliburn.Micro.Screen; @@ -405,7 +408,7 @@ namespace Pithos.Client.WPF.Preferences var account = Accounts.FirstOrDefault(act => act.AccountName == wizard.AccountName && act.ServerUrl == wizard.CurrentServer); if (account != null) { - if (MessageBox.Show("The account you specified already exists. Do you want to update it?","The account exists") == MessageBoxResult.Yes) + if (MessageBox.Show("The account you specified already exists. Do you want to update it?", "The account exists") == MessageBoxResult.Yes) { account.ApiKey = wizard.Token; account.IsExpired = false; @@ -420,8 +423,29 @@ namespace Pithos.Client.WPF.Preferences ServerUrl = wizard.CurrentServer, ApiKey = wizard.Token, RootPath = actualRootPath, - IsActive = wizard.IsAccountActive + IsActive = wizard.IsAccountActive, }; + + + var client = new CloudFilesClient(newAccount.AccountName, newAccount.ApiKey) + { + AuthenticationUrl = newAccount.ServerUrl, UsePithos = true + }; + client.Authenticate(); + + + var dirs = (from container in client.ListContainers(newAccount.AccountName) + from dir in client.ListObjects(newAccount.AccountName, container.Name) + where container.Name != "trash" + select dir) + .ToTree() + .Select(d=>d.Uri.ToString()) + .ToArray(); + + newAccount.SelectiveFolders.AddRange(dirs); + + //TODO:Add the "pithos" container as a default selection + _accountsToAdd.Add(newAccount); var accountVm = new AccountViewModel(newAccount); (Accounts as IProducerConsumerCollection).TryAdd(accountVm); diff --git a/trunk/Pithos.Client.WPF/app.config b/trunk/Pithos.Client.WPF/app.config index 8bb6d1b..79da321 100644 --- a/trunk/Pithos.Client.WPF/app.config +++ b/trunk/Pithos.Client.WPF/app.config @@ -1,219 +1,229 @@  - - -
- - -
- -
- - - - - - - - - - - - - - - - - + + +
+ + +
+ +
+ + + + + + + + + + + + + + + + + - - - - - - - - e:\Pithos - - - C:\Program Files\Common Files\TortoiseOverlays\icons\XPStyle - - - - - - 8080 - - - - - - - - - True - - - True - - - pkanavos - - - 9d3cb7b231e96f72ebe96af1c6cd5112 - - - True - - - True - - - False - - - True - - - False - - - True - - - 10 - - - - - - 1 - - - 00:01:00 - - - False - - - 24.00:00:00 - - - False - - - False - - - - - - - - - - https://auth.api.rackspacecloud.com - - - https://pithos.dev.grnet.gr/im/feedback - - - https://pithos.okeanos.grnet.gr - - - https://pithos.dev.grnet.gr - - - https://code.grnet.gr/projects/pithos-ms-client/repository/revisions/master/raw/trunk/Pithos.Installer/versioninfo.xml - - - 00:00:10 - - - True - - - - - - https://pithos.okeanos.grnet.gr - https://pithos.okeanos.grnet.gr/login - https://accounts.okeanos.grnet.gr/im/logout - - - https://pithos.dev.grnet.gr - https://pithos.dev.grnet.gr/login - https://pithos.dev.grnet.gr/im/logout - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + \ No newline at end of file -- 1.7.10.4