root / trunk / Pithos.Client.WPF / Preferences / AddAccountViewModel.cs @ ebc37b0d
History | View | Annotate | Download (10.3 kB)
1 | 255f5f86 | Panagiotis Kanavos | #region |
---|---|---|---|
2 | 255f5f86 | Panagiotis Kanavos | /* ----------------------------------------------------------------------- |
3 | 255f5f86 | Panagiotis Kanavos | * <copyright file="AddAccountViewModel.cs" company="GRNet"> |
4 | 255f5f86 | Panagiotis Kanavos | * |
5 | 255f5f86 | Panagiotis Kanavos | * Copyright 2011-2012 GRNET S.A. All rights reserved. |
6 | 255f5f86 | Panagiotis Kanavos | * |
7 | 255f5f86 | Panagiotis Kanavos | * Redistribution and use in source and binary forms, with or |
8 | 255f5f86 | Panagiotis Kanavos | * without modification, are permitted provided that the following |
9 | 255f5f86 | Panagiotis Kanavos | * conditions are met: |
10 | 255f5f86 | Panagiotis Kanavos | * |
11 | 255f5f86 | Panagiotis Kanavos | * 1. Redistributions of source code must retain the above |
12 | 255f5f86 | Panagiotis Kanavos | * copyright notice, this list of conditions and the following |
13 | 255f5f86 | Panagiotis Kanavos | * disclaimer. |
14 | 255f5f86 | Panagiotis Kanavos | * |
15 | 255f5f86 | Panagiotis Kanavos | * 2. Redistributions in binary form must reproduce the above |
16 | 255f5f86 | Panagiotis Kanavos | * copyright notice, this list of conditions and the following |
17 | 255f5f86 | Panagiotis Kanavos | * disclaimer in the documentation and/or other materials |
18 | 255f5f86 | Panagiotis Kanavos | * provided with the distribution. |
19 | 255f5f86 | Panagiotis Kanavos | * |
20 | 255f5f86 | Panagiotis Kanavos | * |
21 | 255f5f86 | Panagiotis Kanavos | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
22 | 255f5f86 | Panagiotis Kanavos | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
23 | 255f5f86 | Panagiotis Kanavos | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
24 | 255f5f86 | Panagiotis Kanavos | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
25 | 255f5f86 | Panagiotis Kanavos | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
26 | 255f5f86 | Panagiotis Kanavos | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
27 | 255f5f86 | Panagiotis Kanavos | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
28 | 255f5f86 | Panagiotis Kanavos | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
29 | 255f5f86 | Panagiotis Kanavos | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
30 | 255f5f86 | Panagiotis Kanavos | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
31 | 255f5f86 | Panagiotis Kanavos | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
32 | 255f5f86 | Panagiotis Kanavos | * POSSIBILITY OF SUCH DAMAGE. |
33 | 255f5f86 | Panagiotis Kanavos | * |
34 | 255f5f86 | Panagiotis Kanavos | * The views and conclusions contained in the software and |
35 | 255f5f86 | Panagiotis Kanavos | * documentation are those of the authors and should not be |
36 | 255f5f86 | Panagiotis Kanavos | * interpreted as representing official policies, either expressed |
37 | 255f5f86 | Panagiotis Kanavos | * or implied, of GRNET S.A. |
38 | 255f5f86 | Panagiotis Kanavos | * </copyright> |
39 | 255f5f86 | Panagiotis Kanavos | * ----------------------------------------------------------------------- |
40 | 255f5f86 | Panagiotis Kanavos | */ |
41 | 255f5f86 | Panagiotis Kanavos | #endregion |
42 | 255f5f86 | Panagiotis Kanavos | using System; |
43 | 77f3c897 | Panagiotis Kanavos | using System.Collections.Generic; |
44 | 77f3c897 | Panagiotis Kanavos | using System.ComponentModel.Composition; |
45 | fe62b7f4 | Panagiotis Kanavos | using System.IO; |
46 | fe62b7f4 | Panagiotis Kanavos | using System.Linq; |
47 | f734ab5b | Panagiotis Kanavos | using System.Threading.Tasks; |
48 | 3ddbb7b8 | Panagiotis Kanavos | using System.Windows; |
49 | 3ddbb7b8 | Panagiotis Kanavos | using System.Windows.Forms; |
50 | 3ddbb7b8 | Panagiotis Kanavos | using Pithos.Client.WPF.Properties; |
51 | f734ab5b | Panagiotis Kanavos | using Pithos.Network; |
52 | 3ddbb7b8 | Panagiotis Kanavos | using MessageBox = System.Windows.MessageBox; |
53 | 3ddbb7b8 | Panagiotis Kanavos | using Screen = Caliburn.Micro.Screen; |
54 | 77f3c897 | Panagiotis Kanavos | |
55 | 77f3c897 | Panagiotis Kanavos | namespace Pithos.Client.WPF.Preferences |
56 | 77f3c897 | Panagiotis Kanavos | { |
57 | 77f3c897 | Panagiotis Kanavos | [Export(typeof(AddAccountViewModel))] |
58 | 77f3c897 | Panagiotis Kanavos | public class AddAccountViewModel:Screen |
59 | 77f3c897 | Panagiotis Kanavos | { |
60 | f734ab5b | Panagiotis Kanavos | |
61 | f734ab5b | Panagiotis Kanavos | private readonly List<string> _servers; |
62 | f734ab5b | Panagiotis Kanavos | |
63 | f734ab5b | Panagiotis Kanavos | public List<string> Servers |
64 | f734ab5b | Panagiotis Kanavos | { |
65 | f734ab5b | Panagiotis Kanavos | get { return _servers; } |
66 | f734ab5b | Panagiotis Kanavos | } |
67 | f734ab5b | Panagiotis Kanavos | |
68 | f734ab5b | Panagiotis Kanavos | private bool _isValidServer; |
69 | f734ab5b | Panagiotis Kanavos | public bool IsValidServer |
70 | f734ab5b | Panagiotis Kanavos | { |
71 | f734ab5b | Panagiotis Kanavos | get { return _isValidServer; } |
72 | f734ab5b | Panagiotis Kanavos | set |
73 | f734ab5b | Panagiotis Kanavos | { |
74 | f734ab5b | Panagiotis Kanavos | _isValidServer = value; |
75 | f734ab5b | Panagiotis Kanavos | NotifyOfPropertyChange(()=>IsValidServer); |
76 | f734ab5b | Panagiotis Kanavos | } |
77 | f734ab5b | Panagiotis Kanavos | } |
78 | f734ab5b | Panagiotis Kanavos | |
79 | f734ab5b | Panagiotis Kanavos | |
80 | f734ab5b | Panagiotis Kanavos | private string _currentServer; |
81 | f734ab5b | Panagiotis Kanavos | public string CurrentServer |
82 | f734ab5b | Panagiotis Kanavos | { |
83 | f734ab5b | Panagiotis Kanavos | get { return _currentServer; } |
84 | f734ab5b | Panagiotis Kanavos | set |
85 | f734ab5b | Panagiotis Kanavos | { |
86 | f734ab5b | Panagiotis Kanavos | if (!Uri.IsWellFormedUriString(value, UriKind.Absolute)) |
87 | f734ab5b | Panagiotis Kanavos | { |
88 | f734ab5b | Panagiotis Kanavos | IsValidServer = false; |
89 | f734ab5b | Panagiotis Kanavos | throw new UriFormatException(); |
90 | f734ab5b | Panagiotis Kanavos | } |
91 | f734ab5b | Panagiotis Kanavos | _currentServer = value; |
92 | f734ab5b | Panagiotis Kanavos | IsValidServer = true; |
93 | f734ab5b | Panagiotis Kanavos | HasValidCredentials = false; |
94 | f734ab5b | Panagiotis Kanavos | IsConfirmed = false; |
95 | f734ab5b | Panagiotis Kanavos | NotifyOfPropertyChange(()=>CurrentServer); |
96 | f734ab5b | Panagiotis Kanavos | } |
97 | f734ab5b | Panagiotis Kanavos | } |
98 | f734ab5b | Panagiotis Kanavos | |
99 | 77f3c897 | Panagiotis Kanavos | private string _accountName; |
100 | 77f3c897 | Panagiotis Kanavos | public string AccountName |
101 | 77f3c897 | Panagiotis Kanavos | { |
102 | 77f3c897 | Panagiotis Kanavos | get { return _accountName; } |
103 | 77f3c897 | Panagiotis Kanavos | set |
104 | 77f3c897 | Panagiotis Kanavos | { |
105 | 77f3c897 | Panagiotis Kanavos | _accountName = value; |
106 | 77f3c897 | Panagiotis Kanavos | NotifyOfPropertyChange(()=>AccountName); |
107 | 3ddbb7b8 | Panagiotis Kanavos | NotifyOfPropertyChange(() => HasCredentials); |
108 | 77f3c897 | Panagiotis Kanavos | } |
109 | 77f3c897 | Panagiotis Kanavos | } |
110 | 77f3c897 | Panagiotis Kanavos | |
111 | 77f3c897 | Panagiotis Kanavos | private string _token; |
112 | 77f3c897 | Panagiotis Kanavos | public string Token |
113 | 77f3c897 | Panagiotis Kanavos | { |
114 | 77f3c897 | Panagiotis Kanavos | get { return _token; } |
115 | 77f3c897 | Panagiotis Kanavos | set |
116 | 77f3c897 | Panagiotis Kanavos | { |
117 | 77f3c897 | Panagiotis Kanavos | _token = value; |
118 | 77f3c897 | Panagiotis Kanavos | NotifyOfPropertyChange(()=>Token); |
119 | 3ddbb7b8 | Panagiotis Kanavos | NotifyOfPropertyChange(() => HasCredentials); |
120 | 77f3c897 | Panagiotis Kanavos | } |
121 | 77f3c897 | Panagiotis Kanavos | } |
122 | 77f3c897 | Panagiotis Kanavos | |
123 | 77f3c897 | Panagiotis Kanavos | private string _accountPath; |
124 | 77f3c897 | Panagiotis Kanavos | public string AccountPath |
125 | 77f3c897 | Panagiotis Kanavos | { |
126 | 77f3c897 | Panagiotis Kanavos | get { return _accountPath; } |
127 | 77f3c897 | Panagiotis Kanavos | set |
128 | 77f3c897 | Panagiotis Kanavos | { |
129 | 77f3c897 | Panagiotis Kanavos | _accountPath = value; |
130 | 3ddbb7b8 | Panagiotis Kanavos | NotifyOfPropertyChange(() => AccountPath); |
131 | 3ddbb7b8 | Panagiotis Kanavos | NotifyOfPropertyChange(() => HasAccountPath); |
132 | 77f3c897 | Panagiotis Kanavos | } |
133 | 77f3c897 | Panagiotis Kanavos | } |
134 | 3ddbb7b8 | Panagiotis Kanavos | |
135 | 3ddbb7b8 | Panagiotis Kanavos | |
136 | 3ddbb7b8 | Panagiotis Kanavos | public bool HasAccountPath |
137 | 3ddbb7b8 | Panagiotis Kanavos | { |
138 | 3ddbb7b8 | Panagiotis Kanavos | get { return !String.IsNullOrWhiteSpace(AccountPath); } |
139 | 3ddbb7b8 | Panagiotis Kanavos | } |
140 | 3ddbb7b8 | Panagiotis Kanavos | |
141 | 3ddbb7b8 | Panagiotis Kanavos | public bool HasCredentials |
142 | 3ddbb7b8 | Panagiotis Kanavos | { |
143 | 3ddbb7b8 | Panagiotis Kanavos | get { return !(String.IsNullOrWhiteSpace(AccountName) || String.IsNullOrWhiteSpace(Token) ) ; } |
144 | 3ddbb7b8 | Panagiotis Kanavos | } |
145 | 3ddbb7b8 | Panagiotis Kanavos | |
146 | 3ddbb7b8 | Panagiotis Kanavos | |
147 | 3ddbb7b8 | Panagiotis Kanavos | private bool _isConfirmed; |
148 | 3ddbb7b8 | Panagiotis Kanavos | |
149 | 3ddbb7b8 | Panagiotis Kanavos | public bool IsConfirmed |
150 | 3ddbb7b8 | Panagiotis Kanavos | { |
151 | 3ddbb7b8 | Panagiotis Kanavos | get { return _isConfirmed; } |
152 | 3ddbb7b8 | Panagiotis Kanavos | set |
153 | 3ddbb7b8 | Panagiotis Kanavos | { |
154 | 3ddbb7b8 | Panagiotis Kanavos | _isConfirmed = value; |
155 | f734ab5b | Panagiotis Kanavos | HasValidCredentials = false; |
156 | 3ddbb7b8 | Panagiotis Kanavos | NotifyOfPropertyChange(() => IsConfirmed); |
157 | 3ddbb7b8 | Panagiotis Kanavos | } |
158 | 3ddbb7b8 | Panagiotis Kanavos | } |
159 | 3ddbb7b8 | Panagiotis Kanavos | |
160 | 3ddbb7b8 | Panagiotis Kanavos | |
161 | 3ddbb7b8 | Panagiotis Kanavos | private bool _isAccountActive; |
162 | 3ddbb7b8 | Panagiotis Kanavos | |
163 | 3ddbb7b8 | Panagiotis Kanavos | public bool IsAccountActive |
164 | 3ddbb7b8 | Panagiotis Kanavos | { |
165 | 3ddbb7b8 | Panagiotis Kanavos | get { return _isAccountActive; } |
166 | 3ddbb7b8 | Panagiotis Kanavos | set |
167 | 3ddbb7b8 | Panagiotis Kanavos | { |
168 | 3ddbb7b8 | Panagiotis Kanavos | _isAccountActive = value; |
169 | 3ddbb7b8 | Panagiotis Kanavos | NotifyOfPropertyChange(() => IsAccountActive); |
170 | 3ddbb7b8 | Panagiotis Kanavos | } |
171 | 3ddbb7b8 | Panagiotis Kanavos | } |
172 | 3ddbb7b8 | Panagiotis Kanavos | |
173 | fe62b7f4 | Panagiotis Kanavos | |
174 | fe62b7f4 | Panagiotis Kanavos | private bool _shouldCreateOkeanosFolder; |
175 | fe62b7f4 | Panagiotis Kanavos | public bool ShouldCreateOkeanosFolder |
176 | fe62b7f4 | Panagiotis Kanavos | { |
177 | fe62b7f4 | Panagiotis Kanavos | get { return _shouldCreateOkeanosFolder; } |
178 | fe62b7f4 | Panagiotis Kanavos | set |
179 | fe62b7f4 | Panagiotis Kanavos | { |
180 | fe62b7f4 | Panagiotis Kanavos | _shouldCreateOkeanosFolder = value; |
181 | fe62b7f4 | Panagiotis Kanavos | NotifyOfPropertyChange(()=>ShouldCreateOkeanosFolder); |
182 | fe62b7f4 | Panagiotis Kanavos | } |
183 | fe62b7f4 | Panagiotis Kanavos | } |
184 | fe62b7f4 | Panagiotis Kanavos | |
185 | 3ddbb7b8 | Panagiotis Kanavos | public void SelectAccount() |
186 | 3ddbb7b8 | Panagiotis Kanavos | { |
187 | c636df1f | Panagiotis Kanavos | using (var dlg = new FolderBrowserDialog{Description=Resources.AddAccountViewModel_SelectAccount_Please_select_a_folder}) |
188 | 3ddbb7b8 | Panagiotis Kanavos | { |
189 | 3ddbb7b8 | Panagiotis Kanavos | //Ask the user to select a folder |
190 | 3ddbb7b8 | Panagiotis Kanavos | //Note: We need a parent window here, which we retrieve with GetView |
191 | 3ddbb7b8 | Panagiotis Kanavos | var view = (Window)GetView(); |
192 | 3ddbb7b8 | Panagiotis Kanavos | if (DialogResult.OK != dlg.ShowDialog(new Wpf32Window(view))) |
193 | 3ddbb7b8 | Panagiotis Kanavos | return; |
194 | 3ddbb7b8 | Panagiotis Kanavos | |
195 | 3ddbb7b8 | Panagiotis Kanavos | AccountPath= dlg.SelectedPath; |
196 | fe62b7f4 | Panagiotis Kanavos | |
197 | fe62b7f4 | Panagiotis Kanavos | ShouldCreateOkeanosFolder=Directory.EnumerateFileSystemEntries(AccountPath).Any(); |
198 | 3ddbb7b8 | Panagiotis Kanavos | } |
199 | 3ddbb7b8 | Panagiotis Kanavos | } |
200 | 3ddbb7b8 | Panagiotis Kanavos | |
201 | 3ddbb7b8 | Panagiotis Kanavos | |
202 | badcef63 | Panagiotis Kanavos | public void RetrieveCredentials() |
203 | 3ddbb7b8 | Panagiotis Kanavos | { |
204 | 8dd2bdfb | Panagiotis Kanavos | SetBusy("Waiting for credentials.", "Please enter your credentials in the Pithos logon page"); |
205 | 3ddbb7b8 | Panagiotis Kanavos | IsConfirmed = false; |
206 | 3ddbb7b8 | Panagiotis Kanavos | |
207 | 3ddbb7b8 | Panagiotis Kanavos | try |
208 | 3ddbb7b8 | Panagiotis Kanavos | { |
209 | 81c5c310 | pkanavos | var loginUri=new Uri(new Uri(CurrentServer) , "login"); |
210 | 81c5c310 | pkanavos | var credentials = PithosAccount.RetrieveCredentials(loginUri.ToString()); |
211 | badcef63 | Panagiotis Kanavos | if (credentials == null) |
212 | badcef63 | Panagiotis Kanavos | return; |
213 | 3ddbb7b8 | Panagiotis Kanavos | AccountName = credentials.UserName; |
214 | 3ddbb7b8 | Panagiotis Kanavos | Token = credentials.Password; |
215 | 3ddbb7b8 | Panagiotis Kanavos | |
216 | 3ddbb7b8 | Panagiotis Kanavos | IsConfirmed = true; |
217 | ebc37b0d | pkanavos | |
218 | 3ddbb7b8 | Panagiotis Kanavos | } |
219 | 34bdb91d | Panagiotis Kanavos | catch (PithosException exc) |
220 | 34bdb91d | Panagiotis Kanavos | { |
221 | 34bdb91d | Panagiotis Kanavos | ClearBusy(); |
222 | 34bdb91d | Panagiotis Kanavos | MessageBox.Show(exc.Message, "Unable to retrieve credentials"); |
223 | 34bdb91d | Panagiotis Kanavos | } |
224 | 3ddbb7b8 | Panagiotis Kanavos | catch (Exception exc) |
225 | 3ddbb7b8 | Panagiotis Kanavos | { |
226 | 3ddbb7b8 | Panagiotis Kanavos | IsConfirmed = false; |
227 | 3ddbb7b8 | Panagiotis Kanavos | MessageBox.Show(exc.ToString(), "Error"); |
228 | 3ddbb7b8 | Panagiotis Kanavos | throw; |
229 | 3ddbb7b8 | Panagiotis Kanavos | } |
230 | 8dd2bdfb | Panagiotis Kanavos | finally |
231 | 8dd2bdfb | Panagiotis Kanavos | { |
232 | 8dd2bdfb | Panagiotis Kanavos | ClearBusy(); |
233 | 8dd2bdfb | Panagiotis Kanavos | |
234 | c636df1f | Panagiotis Kanavos | ((Window) GetView()).Activate(); |
235 | 8dd2bdfb | Panagiotis Kanavos | } |
236 | 3ddbb7b8 | Panagiotis Kanavos | |
237 | ebc37b0d | pkanavos | if (IsConfirmed) |
238 | ebc37b0d | pkanavos | TaskEx.Run(TestAccount); |
239 | ebc37b0d | pkanavos | |
240 | 3ddbb7b8 | Panagiotis Kanavos | } |
241 | f734ab5b | Panagiotis Kanavos | |
242 | f734ab5b | Panagiotis Kanavos | public AddAccountViewModel() |
243 | f734ab5b | Panagiotis Kanavos | { |
244 | f734ab5b | Panagiotis Kanavos | _servers=new List<string> |
245 | f734ab5b | Panagiotis Kanavos | { |
246 | f734ab5b | Panagiotis Kanavos | Settings.Default.ProductionServer, |
247 | f734ab5b | Panagiotis Kanavos | Settings.Default.DevelopmentServer |
248 | f734ab5b | Panagiotis Kanavos | }; |
249 | f734ab5b | Panagiotis Kanavos | CurrentServer = _servers[0]; |
250 | f734ab5b | Panagiotis Kanavos | } |
251 | f734ab5b | Panagiotis Kanavos | |
252 | f734ab5b | Panagiotis Kanavos | private bool _hasValidCredentials; |
253 | f734ab5b | Panagiotis Kanavos | public bool HasValidCredentials |
254 | f734ab5b | Panagiotis Kanavos | { |
255 | f734ab5b | Panagiotis Kanavos | get { return _hasValidCredentials; } |
256 | f734ab5b | Panagiotis Kanavos | set |
257 | f734ab5b | Panagiotis Kanavos | { |
258 | f734ab5b | Panagiotis Kanavos | _hasValidCredentials = value; |
259 | f734ab5b | Panagiotis Kanavos | NotifyOfPropertyChange(()=>HasValidCredentials); |
260 | f734ab5b | Panagiotis Kanavos | } |
261 | f734ab5b | Panagiotis Kanavos | } |
262 | f734ab5b | Panagiotis Kanavos | |
263 | 06f11e8b | Panagiotis Kanavos | private string _validationMessage; |
264 | 06f11e8b | Panagiotis Kanavos | public string ValidationMessage |
265 | 06f11e8b | Panagiotis Kanavos | { |
266 | 06f11e8b | Panagiotis Kanavos | get { return _validationMessage; } |
267 | 06f11e8b | Panagiotis Kanavos | set |
268 | 06f11e8b | Panagiotis Kanavos | { |
269 | 06f11e8b | Panagiotis Kanavos | _validationMessage = value; |
270 | 06f11e8b | Panagiotis Kanavos | NotifyOfPropertyChange(()=>ValidationMessage); |
271 | 06f11e8b | Panagiotis Kanavos | } |
272 | 06f11e8b | Panagiotis Kanavos | } |
273 | f734ab5b | Panagiotis Kanavos | |
274 | 8dd2bdfb | Panagiotis Kanavos | private bool _isWorking; |
275 | 8dd2bdfb | Panagiotis Kanavos | public bool IsWorking |
276 | f734ab5b | Panagiotis Kanavos | { |
277 | 8dd2bdfb | Panagiotis Kanavos | get { return _isWorking; } |
278 | f734ab5b | Panagiotis Kanavos | set |
279 | f734ab5b | Panagiotis Kanavos | { |
280 | 8dd2bdfb | Panagiotis Kanavos | _isWorking = value; |
281 | 8dd2bdfb | Panagiotis Kanavos | NotifyOfPropertyChange(()=>IsWorking); |
282 | f734ab5b | Panagiotis Kanavos | } |
283 | f734ab5b | Panagiotis Kanavos | } |
284 | f734ab5b | Panagiotis Kanavos | |
285 | 8dd2bdfb | Panagiotis Kanavos | private string _busyTitle; |
286 | 8dd2bdfb | Panagiotis Kanavos | public string BusyTitle |
287 | 8dd2bdfb | Panagiotis Kanavos | { |
288 | 8dd2bdfb | Panagiotis Kanavos | get { return _busyTitle; } |
289 | 8dd2bdfb | Panagiotis Kanavos | set |
290 | 8dd2bdfb | Panagiotis Kanavos | { |
291 | 8dd2bdfb | Panagiotis Kanavos | _busyTitle = value; |
292 | 8dd2bdfb | Panagiotis Kanavos | NotifyOfPropertyChange(()=>BusyTitle); |
293 | 8dd2bdfb | Panagiotis Kanavos | } |
294 | 8dd2bdfb | Panagiotis Kanavos | } |
295 | 8dd2bdfb | Panagiotis Kanavos | |
296 | 8dd2bdfb | Panagiotis Kanavos | private string _busyDetail; |
297 | 8dd2bdfb | Panagiotis Kanavos | public string BusyDetail |
298 | 8dd2bdfb | Panagiotis Kanavos | { |
299 | 8dd2bdfb | Panagiotis Kanavos | get { return _busyDetail; } |
300 | 8dd2bdfb | Panagiotis Kanavos | set |
301 | 8dd2bdfb | Panagiotis Kanavos | { |
302 | 8dd2bdfb | Panagiotis Kanavos | _busyDetail = value; |
303 | 8dd2bdfb | Panagiotis Kanavos | NotifyOfPropertyChange(()=>BusyDetail); |
304 | 8dd2bdfb | Panagiotis Kanavos | } |
305 | 8dd2bdfb | Panagiotis Kanavos | } |
306 | 8dd2bdfb | Panagiotis Kanavos | |
307 | 8dd2bdfb | Panagiotis Kanavos | private void SetBusy(string title,string detail) |
308 | 8dd2bdfb | Panagiotis Kanavos | { |
309 | 8dd2bdfb | Panagiotis Kanavos | IsWorking = true; |
310 | 8dd2bdfb | Panagiotis Kanavos | BusyTitle = title; |
311 | 8dd2bdfb | Panagiotis Kanavos | BusyDetail = detail; |
312 | 8dd2bdfb | Panagiotis Kanavos | } |
313 | 8dd2bdfb | Panagiotis Kanavos | |
314 | 8dd2bdfb | Panagiotis Kanavos | private void ClearBusy() |
315 | 8dd2bdfb | Panagiotis Kanavos | { |
316 | 8dd2bdfb | Panagiotis Kanavos | IsWorking = false; |
317 | 8dd2bdfb | Panagiotis Kanavos | BusyTitle = ""; |
318 | 8dd2bdfb | Panagiotis Kanavos | BusyDetail = ""; |
319 | 8dd2bdfb | Panagiotis Kanavos | |
320 | 8dd2bdfb | Panagiotis Kanavos | } |
321 | 8dd2bdfb | Panagiotis Kanavos | |
322 | f734ab5b | Panagiotis Kanavos | public async void TestAccount() |
323 | f734ab5b | Panagiotis Kanavos | { |
324 | f734ab5b | Panagiotis Kanavos | try |
325 | f734ab5b | Panagiotis Kanavos | { |
326 | 06f11e8b | Panagiotis Kanavos | SetBusy("Validating Credentials", ""); |
327 | 34bdb91d | Panagiotis Kanavos | var client = new CloudFilesClient(AccountName, Token) { AuthenticationUrl = CurrentServer,/*Proxy=Proxy */}; |
328 | c636df1f | Panagiotis Kanavos | await TaskEx.Run(() => |
329 | c636df1f | Panagiotis Kanavos | { |
330 | c636df1f | Panagiotis Kanavos | client.Authenticate(); |
331 | c636df1f | Panagiotis Kanavos | return client.ListContainers(AccountName); |
332 | c636df1f | Panagiotis Kanavos | }); |
333 | 06f11e8b | Panagiotis Kanavos | HasValidCredentials = true; |
334 | 06f11e8b | Panagiotis Kanavos | ValidationMessage = "Credentials Validated"; |
335 | 06f11e8b | Panagiotis Kanavos | } |
336 | 5e31048f | Panagiotis Kanavos | catch |
337 | f734ab5b | Panagiotis Kanavos | { |
338 | f734ab5b | Panagiotis Kanavos | HasValidCredentials = false; |
339 | f734ab5b | Panagiotis Kanavos | MessageBox.Show("The account is not valid", "Account Error", MessageBoxButton.OK, MessageBoxImage.Stop); |
340 | 06f11e8b | Panagiotis Kanavos | ValidationMessage = "Credentials validation failed"; |
341 | f734ab5b | Panagiotis Kanavos | } |
342 | f734ab5b | Panagiotis Kanavos | finally |
343 | f734ab5b | Panagiotis Kanavos | { |
344 | 8dd2bdfb | Panagiotis Kanavos | ClearBusy(); |
345 | f734ab5b | Panagiotis Kanavos | } |
346 | f734ab5b | Panagiotis Kanavos | } |
347 | 3ddbb7b8 | Panagiotis Kanavos | |
348 | 77f3c897 | Panagiotis Kanavos | } |
349 | 77f3c897 | Panagiotis Kanavos | } |