Replaced auto reauthorization with a message that asks the user to renew the api...
authorPanagiotis Kanavos <pkanavos@gmail.com>
Fri, 24 Feb 2012 17:24:04 +0000 (19:24 +0200)
committerPanagiotis Kanavos <pkanavos@gmail.com>
Fri, 24 Feb 2012 17:24:04 +0000 (19:24 +0200)
Modified the account page of Preferences to display warnings for expired accounts

trunk/Pithos.Client.WPF/Pithos.Client.WPF.csproj
trunk/Pithos.Client.WPF/PithosAccount.cs
trunk/Pithos.Client.WPF/Preferences/PreferencesView.xaml
trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs
trunk/Pithos.Core/IStatusNotification.cs
trunk/Pithos.Interfaces/AccountSettings.cs

index 46ff9b0..2d995e3 100644 (file)
   <ItemGroup>
     <Resource Include="Images\Warning.png" />
   </ItemGroup>
+  <ItemGroup>
+    <Resource Include="Images\SmallWarning.png" />
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
index e684131..06d7963 100644 (file)
@@ -93,8 +93,8 @@ namespace Pithos.Client.WPF
             var receiveCredentials = ListenForRedirectAsync(port);
 
             var logoutUrl = loginUrl.Replace("login", "im/logout");
-            var logoutProcess=Process.Start(logoutUrl);
-            TaskEx.Delay(100).Wait();
+            var logoutProcess=Process.Start(logoutUrl);            
+            TaskEx.Delay(2000).Wait();
             var uriBuilder=new UriBuilder(loginUrl);                       
             uriBuilder.Query="next=" + listenerUrl;
 
index c50c561..8399d68 100644 (file)
@@ -17,6 +17,7 @@
             <ResourceDictionary Source="..\PithosStyles.xaml" />
             </ResourceDictionary.MergedDictionaries>
             <Converters:NullToVisibilityConverter x:Key="NullToVisible" />
+            <BooleanToVisibilityConverter x:Key="BoolToVisible" />
         </ResourceDictionary>
     </Window.Resources>
 <!--    <Window.TaskbarItemInfo>
                         <ListBox Name="Accounts" Grid.Row="0" VerticalAlignment="Stretch" ItemsSource="{Binding Accounts,Mode=OneWay}" SelectedItem="{Binding CurrentAccount,Mode=TwoWay}" >
                             <ListBox.ItemTemplate>
                                 <DataTemplate>
+                                    <StackPanel Orientation="Horizontal">
+                                    <Image Visibility="{Binding Converter={StaticResource BoolToVisible}, Path=IsExpired}" Source="/Pithos.Client.WPF;component/Images/SmallWarning.png" Margin="2,0"/>
                                     <TextBlock Text="{Binding AccountName}" />
+                                    </StackPanel>
                                 </DataTemplate>
                             </ListBox.ItemTemplate>
                         </ListBox>
index 8f27113..5f008df 100644 (file)
@@ -55,6 +55,7 @@ using Hardcodet.Wpf.TaskbarNotification;
 using Pithos.Client.WPF.Configuration;
 using Pithos.Client.WPF.FileProperties;
 using Pithos.Client.WPF.Preferences;
+using Pithos.Client.WPF.Properties;
 using Pithos.Client.WPF.SelectiveSynch;
 using Pithos.Client.WPF.Services;
 using Pithos.Client.WPF.Shell;
@@ -349,7 +350,7 @@ namespace Pithos.Client.WPF {
 
                public void ShowPreferences()
                {
-                       Settings.Reload();
+                       //Settings.Reload();
                        var preferences = new PreferencesViewModel(_windowManager,_events, this,Settings);            
                        _windowManager.ShowDialog(preferences);
                        
@@ -580,7 +581,10 @@ namespace Pithos.Client.WPF {
                                                                var message = String.Format("API Key Expired for {0}. Starting Renewal",
                                                                                                                        monitor.UserName);
                                                                Log.Error(message, exc);
-                                                               TryAuthorize(monitor.UserName, retries).Wait();
+                                                       var account = Settings.Accounts.Find(acc => acc.AccountName == monitor.UserName);                                
+                                                       account.IsExpired = true;
+                                Notify(new ExpirationNotification(account));
+                                                               //TryAuthorize(monitor.UserName, retries).Wait();
                                                                break;
                                                        case HttpStatusCode.ProxyAuthenticationRequired:
                                                                TryAuthenticateProxy(monitor,retries);
@@ -642,9 +646,10 @@ namespace Pithos.Client.WPF {
                            var monitor = _monitors[account.AccountName];
                                account.ApiKey = credentials.Password;
                 monitor.ApiKey = credentials.Password;
+                           account.IsExpired = false;
                                Settings.Save();
-                               await TaskEx.Delay(10000);
-                StartMonitor(monitor, retries + 1);
+                               TaskEx.Delay(10000).ContinueWith(_=>
+                            StartMonitor(monitor, retries + 1));
                                NotifyOfPropertyChange(()=>Accounts);
                        }
                        catch (AggregateException exc)
index a1411f3..196973f 100644 (file)
@@ -94,4 +94,15 @@ namespace Pithos.Core
     {\r
         \r
     }\r
+\r
+    public class ExpirationNotification:Notification<AccountSettings>\r
+    {\r
+        public ExpirationNotification(AccountSettings account)\r
+        {\r
+            Data = account;\r
+            Level = TraceLevel.Error;\r
+            Title = "Account key expired";\r
+            Message = string.Format("Please renew the key for the account {0} from the Preferences page", account.AccountName);\r
+        }\r
+    }\r
 }
\ No newline at end of file
index c99c90e..33ec9e5 100644 (file)
@@ -64,7 +64,13 @@ namespace Pithos.Interfaces
 
         private StringCollection _selectiveFolders = new StringCollection();
 
-        
+        private bool _isExpired;
+        public bool IsExpired
+        {
+            get { return _isExpired; }
+            set { _isExpired = value; }
+        }
+
         public StringCollection SelectiveFolders
         {
             get { return _selectiveFolders; }