2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.ComponentModel.Composition;
9 using System.Windows.Controls;
10 using System.Windows.Forms;
11 using Pithos.Client.WPF.Properties;
13 using MessageBox = System.Windows.MessageBox;
14 using Screen = Caliburn.Micro.Screen;
16 namespace Pithos.Client.WPF.Preferences
18 [Export(typeof(AddAccountViewModel))]
19 public class AddAccountViewModel:Screen
21 private string _accountName;
22 public string AccountName
24 get { return _accountName; }
28 NotifyOfPropertyChange(()=>AccountName);
29 NotifyOfPropertyChange(() => HasCredentials);
33 private string _token;
36 get { return _token; }
40 NotifyOfPropertyChange(()=>Token);
41 NotifyOfPropertyChange(() => HasCredentials);
45 private string _accountPath;
46 public string AccountPath
48 get { return _accountPath; }
52 NotifyOfPropertyChange(() => AccountPath);
53 NotifyOfPropertyChange(() => HasAccountPath);
58 public bool HasAccountPath
60 get { return !String.IsNullOrWhiteSpace(AccountPath); }
63 public bool HasCredentials
65 get { return !(String.IsNullOrWhiteSpace(AccountName) || String.IsNullOrWhiteSpace(Token) ) ; }
69 private bool _isConfirmed;
71 public bool IsConfirmed
73 get { return _isConfirmed; }
77 NotifyOfPropertyChange(() => IsConfirmed);
82 private bool _isAccountActive;
84 public bool IsAccountActive
86 get { return _isAccountActive; }
89 _isAccountActive = value;
90 NotifyOfPropertyChange(() => IsAccountActive);
94 public void SelectAccount()
96 using (var dlg = new FolderBrowserDialog())
98 //Ask the user to select a folder
99 //Note: We need a parent window here, which we retrieve with GetView
100 var view = (Window)GetView();
101 if (DialogResult.OK != dlg.ShowDialog(new Wpf32Window(view)))
104 AccountPath= dlg.SelectedPath;
109 private bool _isRetrieving;
110 public bool IsRetrieving
112 get { return _isRetrieving; }
115 _isRetrieving = value;
116 NotifyOfPropertyChange(() => IsRetrieving);
120 public async void RetrieveCredentials()
127 var credentials = await PithosAccount.RetrieveCredentialsAsync(Settings.Default.PithosLoginUrl);
128 AccountName = credentials.UserName;
129 Token = credentials.Password;
133 catch (Exception exc)
136 MessageBox.Show(exc.ToString(), "Error");
139 IsRetrieving = false;