Added manual token refresh button to account page. Closes #2095
authorPanagiotis Kanavos <pkanavos@gmail.com>
Thu, 23 Feb 2012 16:15:56 +0000 (18:15 +0200)
committerPanagiotis Kanavos <pkanavos@gmail.com>
Thu, 23 Feb 2012 16:15:56 +0000 (18:15 +0200)
Modified check for interrupted files to raise notification only if there are actual interrupted files. Closes #2081

trunk/Pithos.Client.WPF/PithosAccount.cs
trunk/Pithos.Client.WPF/Preferences/PreferencesView.xaml
trunk/Pithos.Client.WPF/Preferences/PreferencesViewModel.cs
trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs
trunk/Pithos.Core/Agents/WorkflowAgent.cs

index 3921074..e684131 100644 (file)
@@ -92,6 +92,9 @@ 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 uriBuilder=new UriBuilder(loginUrl);                       
             uriBuilder.Query="next=" + listenerUrl;
 
index a88a868..c50c561 100644 (file)
                             <TextBox Name="CurrentAccount_ServerUrl" Grid.Column="1" Grid.Row="0" Margin="5"/>
                             <Label Content="Account" Grid.Column="0" Grid.Row="1" Margin="0,5" HorizontalAlignment="Left"/>
                             <TextBox Name="CurrentAccount_AccountName" Grid.Column="1" Grid.Row="1" Margin="5"/>
-                            <Label Content="API Key" Grid.Column="0" Grid.Row="2" Margin="0,5" HorizontalAlignment="Left"/>
-                            <TextBox  Name="CurrentAccount_ApiKey" Grid.Column="1" Grid.Row="2" Margin="5"/>
+                            <Grid Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" >
+                                <Grid.ColumnDefinitions>
+                                    <ColumnDefinition Width="Auto"/>
+                                    <ColumnDefinition Width="*"/>
+                                    <ColumnDefinition Width="Auto"/>
+                                </Grid.ColumnDefinitions>
+                                <Label Content="API Key" Grid.Column="0"  Margin="0,5" HorizontalAlignment="Left"/>
+                                <TextBox  Name="CurrentAccount_ApiKey" Grid.Column="1" Margin="5" />
+                                <Button Name="RefreshApiKey" Grid.Column="2" Content="Refresh" Margin="5"/>
+                            </Grid>
                             <Label Content="Folder" Grid.Column="0" Grid.Row="3" Margin="0,5" HorizontalAlignment="Left"/>
                             <Grid Grid.Row="3" Grid.Column="1" >
                                 <Grid.ColumnDefinitions>
index fe643b9..da83649 100644 (file)
@@ -47,6 +47,7 @@ using System.Collections.Concurrent;
 using System.ComponentModel.Composition;
 using System.IO;
 using System.Net;
+using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Forms;
 using Caliburn.Micro;
@@ -193,6 +194,12 @@ namespace Pithos.Client.WPF.Preferences
                 
             }
         }
+
+        public async Task RefreshApiKey()
+        {            
+            await Shell.TryAuthorize(CurrentAccount.AccountName, 3);
+            NotifyOfPropertyChange(()=>CurrentAccount);
+        }
     
         public void SaveChanges()
         {
index 1689a20..8f27113 100644 (file)
@@ -628,7 +628,7 @@ namespace Pithos.Client.WPF {
                }
 
 
-               private async Task TryAuthorize(string userName, int retries)
+               public async Task TryAuthorize(string userName, int retries)
                {
                        _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 });
 
index aafc377..d05f8d3 100644 (file)
@@ -206,7 +206,6 @@ namespace Pithos.Core.Agents
         public void RestartInterruptedFiles(AccountInfo accountInfo)
         {
             
-            StatusNotification.NotifyChange("Restart processing interrupted files", TraceLevel.Verbose);
 
             using (log4net.ThreadContext.Stacks["Workflow"].Push("Restart"))
             {
@@ -219,25 +218,23 @@ namespace Pithos.Core.Agents
 
 
                 var account = accountInfo;
-                var pendingEntries = from state in FileState.Queryable
+                var pendingEntries = (from state in FileState.Queryable
                                      where state.FileStatus != FileStatus.Unchanged &&
                                            !state.FilePath.StartsWith(cachePath) &&
                                            !state.FilePath.EndsWith(".ignore") &&
                                            state.FilePath.StartsWith(account.AccountPath)
-                                     select state;
-                var pendingStates = new List<WorkflowState>();
-                foreach (var state in pendingEntries)
-                {
-                        pendingStates.Add(new WorkflowState(account, state));
-                }
+                                     select state).ToList();
+                if (pendingEntries.Count>0)
+                    StatusNotification.NotifyChange("Restart processing interrupted files", TraceLevel.Verbose);
+
+                var pendingStates = pendingEntries
+                    .Select(state => new WorkflowState(account, state))
+                    .ToList();
+
                 if (Log.IsDebugEnabled)
                     Log.DebugFormat("Found {0} interrupted files", pendingStates.Count);
 
-
-                foreach (var entry in pendingStates)
-                {
-                       Post(entry);
-                }
+                pendingStates.ForEach(Post);
             }
         }