Revision c636df1f trunk/Pithos.Client.WPF/Preferences/PreferencesViewModel.cs
b/trunk/Pithos.Client.WPF/Preferences/PreferencesViewModel.cs | ||
---|---|---|
40 | 40 |
*/ |
41 | 41 |
#endregion |
42 | 42 |
|
43 |
// </copyright> |
|
44 |
// ----------------------------------------------------------------------- |
|
45 | 43 |
|
46 | 44 |
using System.Collections.Concurrent; |
47 | 45 |
using System.ComponentModel.Composition; |
48 | 46 |
using System.Diagnostics; |
49 | 47 |
using System.IO; |
50 |
using System.Net; |
|
51 | 48 |
using System.Threading.Tasks; |
52 | 49 |
using System.Windows; |
53 | 50 |
using System.Windows.Forms; |
54 | 51 |
using Caliburn.Micro; |
55 | 52 |
using Pithos.Client.WPF.Configuration; |
53 |
using Pithos.Client.WPF.Properties; |
|
56 | 54 |
using Pithos.Client.WPF.SelectiveSynch; |
57 | 55 |
using Pithos.Core; |
58 | 56 |
using Pithos.Interfaces; |
... | ... | |
63 | 61 |
namespace Pithos.Client.WPF.Preferences |
64 | 62 |
{ |
65 | 63 |
/// <summary> |
66 |
/// TODO: Update summary. |
|
64 |
/// The preferences screen displays user and account settings and updates the PithosMonitor |
|
65 |
/// classes when account settings change. |
|
67 | 66 |
/// </summary> |
67 |
/// <remarks> |
|
68 |
/// The class is a single ViewModel for all Preferences tabs. It can be broken in separate |
|
69 |
/// ViewModels, one for each tab. |
|
70 |
/// </remarks> |
|
68 | 71 |
[Export] |
69 | 72 |
public class PreferencesViewModel : Screen |
70 | 73 |
{ |
71 |
private IEventAggregator _events; |
|
74 |
private readonly IEventAggregator _events;
|
|
72 | 75 |
|
73 | 76 |
//Logging in the Pithos client is provided by log4net |
74 | 77 |
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger("Pithos"); |
... | ... | |
102 | 105 |
|
103 | 106 |
public PreferencesViewModel(IWindowManager windowManager, IEventAggregator events, ShellViewModel shell, PithosSettings settings, string currentTab) |
104 | 107 |
{ |
108 |
// ReSharper disable DoNotCallOverridableMethodsInConstructor |
|
109 |
//Caliburn.Micro uses DisplayName for the view's title |
|
110 |
DisplayName = "Pithos Preferences"; |
|
111 |
// ReSharper restore DoNotCallOverridableMethodsInConstructor |
|
112 |
|
|
105 | 113 |
_windowManager = windowManager; |
106 | 114 |
_events = events; |
107 | 115 |
|
108 |
DisplayName = "Pithos Preferences"; |
|
109 | 116 |
Shell = shell; |
110 | 117 |
|
111 | 118 |
Settings=settings; |
... | ... | |
193 | 200 |
set |
194 | 201 |
{ |
195 | 202 |
if (value<0) |
196 |
throw new ArgumentOutOfRangeException("value","The Startup Delay must be greater or equal to 0");
|
|
203 |
throw new ArgumentOutOfRangeException("value",Resources.PreferencesViewModel_StartupDelay_Greater_or_equal_to_0);
|
|
197 | 204 |
Settings.StartupDelay = TimeSpan.FromMinutes(value); |
198 | 205 |
NotifyOfPropertyChange(()=>StartupDelay); |
199 | 206 |
} |
... | ... | |
222 | 229 |
{ |
223 | 230 |
_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 }); |
224 | 231 |
|
225 |
//var userName = CurrentAccount.AccountName; |
|
226 | 232 |
try |
227 | 233 |
{ |
228 | 234 |
|
229 | 235 |
var credentials = await PithosAccount.RetrieveCredentials(Settings.PithosLoginUrl); |
230 |
|
|
236 |
//The server will return credentials for a different account, not just the current account |
|
237 |
//We need to find the correct account first |
|
231 | 238 |
var account = Accounts.First(act => act.AccountName == credentials.UserName); |
232 |
//The server may return credentials for a different account |
|
233 |
var monitor = Shell.Monitors[account.AccountName]; |
|
234 |
account.ApiKey = credentials.Password; |
|
235 |
monitor.ApiKey = credentials.Password; |
|
239 |
account.ApiKey = credentials.Password; |
|
236 | 240 |
account.IsExpired = false; |
237 | 241 |
Settings.Save(); |
238 | 242 |
TaskEx.Delay(10000).ContinueWith(_ =>Shell.MonitorAccount(account.Account)); |
... | ... | |
334 | 338 |
IsActive=wizard.IsAccountActive |
335 | 339 |
}; |
336 | 340 |
Settings.Accounts.Add(newAccount); |
337 |
var accountVM = new AccountViewModel(newAccount);
|
|
338 |
(Accounts as IProducerConsumerCollection<AccountViewModel>).TryAdd(accountVM);
|
|
339 |
CurrentAccount = accountVM;
|
|
341 |
var accountVm = new AccountViewModel(newAccount);
|
|
342 |
(Accounts as IProducerConsumerCollection<AccountViewModel>).TryAdd(accountVm);
|
|
343 |
CurrentAccount = accountVm;
|
|
340 | 344 |
NotifyOfPropertyChange(() => Accounts); |
341 | 345 |
NotifyOfPropertyChange(() => Settings); |
342 | 346 |
} |
... | ... | |
441 | 445 |
}*/ |
442 | 446 |
|
443 | 447 |
private AccountViewModel _currentAccount; |
444 |
private IWindowManager _windowManager; |
|
445 |
private string _shortcutPath; |
|
448 |
private readonly IWindowManager _windowManager;
|
|
449 |
private readonly string _shortcutPath;
|
|
446 | 450 |
|
447 | 451 |
|
448 | 452 |
|
... | ... | |
517 | 521 |
Directory.Delete(oldPath, true); |
518 | 522 |
|
519 | 523 |
//We also need to change the path of the existing file states |
520 |
if (monitor != null) |
|
521 |
monitor.MoveFileStates(oldPath, newPath); |
|
524 |
monitor.MoveFileStates(oldPath, newPath); |
|
522 | 525 |
} |
523 | 526 |
} |
524 | 527 |
//Replace the old rootpath with the new |
Also available in: Unified diff