Fixes for v.0.7.20401
[pithos-ms-client] / trunk / Pithos.Client.WPF / Shell / ShellViewModel.cs
index 96a650c..69fae86 100644 (file)
@@ -97,7 +97,7 @@ namespace Pithos.Client.WPF {
                public PithosSettings Settings { get; private set; }
 
 
-               private readonly ConcurrentDictionary<string, PithosMonitor> _monitors = new ConcurrentDictionary<string, PithosMonitor>();
+               private readonly ConcurrentDictionary<Uri, PithosMonitor> _monitors = new ConcurrentDictionary<Uri, PithosMonitor>();
                ///<summary>
                /// Dictionary of account monitors, keyed by account
                ///</summary>
@@ -107,7 +107,7 @@ namespace Pithos.Client.WPF {
                ///</remarks>
                // TODO: Does the Shell REALLY need access to the monitors? Could we achieve the same results with a better design?
                // TODO: The monitors should be internal to Pithos.Core, even though exposing them makes coding of the Object and Container windows easier
-               public ConcurrentDictionary<string, PithosMonitor> Monitors
+               public ConcurrentDictionary<Uri, PithosMonitor> Monitors
                {
                        get { return _monitors; }
                }
@@ -262,17 +262,15 @@ namespace Pithos.Client.WPF {
                {
                        try
                        {
+                if (Settings.IgnoreCertificateErrors)
+                {
+                    ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;
+                }
+                    
                                var accounts = Settings.Accounts.Select(MonitorAccount);
                                await TaskEx.WhenAll(accounts);
                                _statusService = StatusService.Start();
 
-/*
-                               foreach (var account in Settings.Accounts)
-                               {
-                                       await MonitorAccount(account);
-                               }
-*/
-                               
                        }
                        catch (AggregateException exc)
                        {
@@ -302,7 +300,7 @@ namespace Pithos.Client.WPF {
                                PithosMonitor monitor;
                                var accountName = account.AccountName;
 
-                               if (_monitors.TryGetValue(accountName, out monitor))
+                               if (Monitors.TryGetValue(account.AccountKey, out monitor))
                                {
                                        //If the account is active
                     if (account.IsActive)
@@ -319,7 +317,7 @@ namespace Pithos.Client.WPF {
                     {
                         //If the account is inactive
                         //Stop and remove the monitor
-                        RemoveMonitor(accountName);
+                        RemoveMonitor(account.ServerUrl,accountName);
                     }
                                        return;
                                }
@@ -338,7 +336,7 @@ namespace Pithos.Client.WPF {
 
                                monitor.AuthenticationUrl = account.ServerUrl;
 
-                               _monitors[accountName] = monitor;
+                               Monitors[account.AccountKey] = monitor;
 
                                if (account.IsActive)
                                {
@@ -615,9 +613,8 @@ namespace Pithos.Client.WPF {
                {
                        if (currentInfo==null)
                                throw new ArgumentNullException("currentInfo");
-                       Contract.EndContractBlock();
-
-                       var monitor = Monitors[currentInfo.Account];
+                       Contract.EndContractBlock();                
+            var monitor = Monitors[currentInfo.AccountKey];
                        var newInfo=monitor.CloudClient.GetObjectInfo(currentInfo.Account, currentInfo.Container, currentInfo.Name);
                        return newInfo;
                }
@@ -628,7 +625,7 @@ namespace Pithos.Client.WPF {
                                throw new ArgumentNullException("container");
                        Contract.EndContractBlock();
 
-                       var monitor = Monitors[container.Account];
+                       var monitor = Monitors[container.AccountKey];
                        var newInfo = monitor.CloudClient.GetContainerInfo(container.Account, container.Name);
                        return newInfo;
                }
@@ -873,20 +870,21 @@ namespace Pithos.Client.WPF {
                }
 
 
-               public void RemoveMonitor(string accountName)
+               public void RemoveMonitor(string serverUrl,string accountName)
                {
                        if (String.IsNullOrWhiteSpace(accountName))
                                return;
 
-                       var accountInfo=_accounts.FirstOrDefault(account => account.UserName == accountName);
+                       var accountInfo=_accounts.FirstOrDefault(account => account.UserName == accountName && account.StorageUri.ToString().StartsWith(serverUrl));
             if (accountInfo != null)
             {
                 _accounts.TryRemove(accountInfo);
                 _pollAgent.RemoveAccount(accountInfo);
             }
 
+            var accountKey = new Uri(new Uri(serverUrl),accountName);
                    PithosMonitor monitor;
-                       if (Monitors.TryRemove(accountName, out monitor))
+                       if (Monitors.TryRemove(accountKey, out monitor))
                        {
                                monitor.Stop();
                 //TODO: Also remove any pending actions for this account
@@ -926,10 +924,9 @@ namespace Pithos.Client.WPF {
                #region Event Handlers
                
                public void Handle(SelectiveSynchChanges message)
-               {
-                       var accountName = message.Account.AccountName;
+               {            
                        PithosMonitor monitor;
-                       if (_monitors.TryGetValue(accountName, out monitor))
+                       if (Monitors.TryGetValue(message.Account.AccountKey, out monitor))
                        {
                                monitor.SetSelectivePaths(message.Uris,message.Added,message.Removed);