Revision c92e02f3 trunk/Pithos.Client.WPF/FileProperties/ContainerPropertiesViewModel.cs
b/trunk/Pithos.Client.WPF/FileProperties/ContainerPropertiesViewModel.cs | ||
---|---|---|
5 | 5 |
using System.ComponentModel.Composition; |
6 | 6 |
using System.Diagnostics.Contracts; |
7 | 7 |
using System.Linq; |
8 |
using System.Net; |
|
8 | 9 |
using System.Text; |
10 |
using System.Threading.Tasks; |
|
11 |
using System.Windows; |
|
9 | 12 |
using Caliburn.Micro; |
10 | 13 |
using Pithos.Network; |
11 | 14 |
|
... | ... | |
14 | 17 |
[Export(typeof(ContainerPropertiesViewModel))] |
15 | 18 |
public class ContainerPropertiesViewModel:Screen |
16 | 19 |
{ |
20 |
private string _containerName; |
|
21 |
|
|
17 | 22 |
/// <summary> |
18 | 23 |
/// Name of the displayed container |
19 | 24 |
/// </summary> |
20 |
public string ContainerName { get; set; } |
|
25 |
public string ContainerName |
|
26 |
{ |
|
27 |
get { return _containerName; } |
|
28 |
set |
|
29 |
{ |
|
30 |
_containerName = value; |
|
31 |
NotifyOfPropertyChange(()=>ContainerName); |
|
32 |
} |
|
33 |
} |
|
34 |
|
|
35 |
private string _title; |
|
21 | 36 |
/// <summary> |
22 | 37 |
/// Window title |
23 | 38 |
/// </summary> |
24 |
public string Title { get; set; } |
|
39 |
public string Title |
|
40 |
{ |
|
41 |
get { return _title; } |
|
42 |
set |
|
43 |
{ |
|
44 |
_title = value; |
|
45 |
NotifyOfPropertyChange(() => Title); |
|
46 |
} |
|
47 |
} |
|
48 |
|
|
49 |
private long _count; |
|
25 | 50 |
|
26 | 51 |
/// <summary> |
27 | 52 |
/// Count of files in the container |
28 | 53 |
/// </summary> |
29 |
public long Count { get; set; } |
|
54 |
public long Count |
|
55 |
{ |
|
56 |
get { return _count; } |
|
57 |
set |
|
58 |
{ |
|
59 |
_count = value; |
|
60 |
NotifyOfPropertyChange(() => Count); |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
private DateTime _modified; |
|
30 | 65 |
|
31 | 66 |
/// <summary> |
32 | 67 |
/// Date of last modification |
33 | 68 |
/// </summary> |
34 |
public DateTime Modified { get; set; } |
|
35 |
|
|
69 |
public DateTime Modified |
|
70 |
{ |
|
71 |
get { return _modified; } |
|
72 |
set |
|
73 |
{ |
|
74 |
_modified = value; |
|
75 |
NotifyOfPropertyChange(() => Modified); |
|
76 |
} |
|
77 |
} |
|
78 |
|
|
79 |
private string _size; |
|
80 |
|
|
36 | 81 |
/// <summary> |
37 | 82 |
/// Total size of the container in bytes |
38 | 83 |
/// </summary> |
39 |
public string Size { get; set; } |
|
84 |
public string Size |
|
85 |
{ |
|
86 |
get { return _size; } |
|
87 |
set |
|
88 |
{ |
|
89 |
_size = value; |
|
90 |
NotifyOfPropertyChange(() => Size); |
|
91 |
} |
|
92 |
} |
|
93 |
|
|
94 |
private string _shortSize; |
|
40 | 95 |
|
41 | 96 |
/// <summary> |
42 | 97 |
/// Total size of the container formatted in KB,MB etc |
43 | 98 |
/// </summary> |
44 |
public string ShortSize { get; set; } |
|
99 |
public string ShortSize |
|
100 |
{ |
|
101 |
get { return _shortSize; } |
|
102 |
set |
|
103 |
{ |
|
104 |
_shortSize = value; |
|
105 |
NotifyOfPropertyChange(() => ShortSize); |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
private int _blockSize; |
|
45 | 110 |
|
46 | 111 |
/// <summary> |
47 | 112 |
/// Block size used by the container |
48 | 113 |
/// </summary> |
49 |
public int BlockSize { get; set; } |
|
114 |
public int BlockSize |
|
115 |
{ |
|
116 |
get { return _blockSize; } |
|
117 |
set |
|
118 |
{ |
|
119 |
_blockSize = value; |
|
120 |
NotifyOfPropertyChange(() => BlockSize); |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
private string _blockHash; |
|
50 | 125 |
|
51 | 126 |
/// <summary> |
52 | 127 |
/// Hash algorithm used to calculate block hashes |
53 | 128 |
/// </summary> |
54 |
public string BlockHash { get; set; } |
|
129 |
public string BlockHash |
|
130 |
{ |
|
131 |
get { return _blockHash; } |
|
132 |
set |
|
133 |
{ |
|
134 |
_blockHash = value; |
|
135 |
NotifyOfPropertyChange(() => BlockHash); |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 |
private ShellViewModel _shell; |
|
55 | 140 |
|
56 | 141 |
/// <summary> |
57 | 142 |
/// Reference to the parent Shell |
58 | 143 |
/// </summary> |
59 |
protected ShellViewModel Shell { get; set; } |
|
144 |
protected ShellViewModel Shell |
|
145 |
{ |
|
146 |
get { return _shell; } |
|
147 |
set |
|
148 |
{ |
|
149 |
_shell = value; |
|
150 |
NotifyOfPropertyChange(() => Shell); |
|
151 |
} |
|
152 |
} |
|
60 | 153 |
|
61 | 154 |
private ContainerInfo _container; |
62 | 155 |
/// <summary> |
... | ... | |
69 | 162 |
{ |
70 | 163 |
_container = value; |
71 | 164 |
|
72 |
Tags.Clear(); |
|
73 |
var tags = from tag in value.Tags |
|
74 |
select new Tag(tag.Key, tag.Value); |
|
75 |
tags.Apply(tag => Tags.Add(tag)); |
|
165 |
|
|
76 | 166 |
|
167 |
LoadFromDictionary(Tags, value.Tags); |
|
168 |
TagsChanged = false; |
|
169 |
//LoadFromDictionary(Policies, value.Policies); |
|
77 | 170 |
|
171 |
if (value.Policies.ContainsKey("Versioning")) |
|
172 |
{ |
|
173 |
Versioning version; |
|
174 |
if (Enum.TryParse(value.Policies["Versioning"], out version)) |
|
175 |
{ |
|
176 |
SelectedVersion = version; |
|
177 |
} |
|
178 |
} |
|
179 |
|
|
180 |
if (value.Policies.ContainsKey("Quota")) |
|
181 |
{ |
|
182 |
int quota; |
|
183 |
if (int.TryParse(value.Policies["Quota"], out quota)) |
|
184 |
{ |
|
185 |
Quota=quota; |
|
186 |
} |
|
187 |
} |
|
188 |
|
|
189 |
Title = String.Format("{0} Properties", _container.Name); |
|
78 | 190 |
Count = value.Count; |
79 | 191 |
ShortSize = value.Bytes.ToByteSize(); |
80 | 192 |
Size = String.Format("{0} ({1:N0} bytes)", ShortSize, value.Bytes); |
... | ... | |
84 | 196 |
ContainerName = Uri.UnescapeDataString(value.Name.Split('/').Last()); |
85 | 197 |
|
86 | 198 |
NotifyOfPropertyChange(() => Container); |
199 |
IsBusy = false; |
|
200 |
} |
|
201 |
} |
|
202 |
|
|
203 |
private int _quota; |
|
204 |
public int Quota |
|
205 |
{ |
|
206 |
get { return _quota; } |
|
207 |
set |
|
208 |
{ |
|
209 |
if (value < 0) |
|
210 |
throw new ArgumentOutOfRangeException("Quota"); |
|
211 |
|
|
212 |
_quota = value; |
|
213 |
NotifyOfPropertyChange(() => Quota); |
|
87 | 214 |
} |
88 | 215 |
} |
89 | 216 |
|
90 | 217 |
|
91 |
private readonly ObservableCollection<Tag> _tags = new ObservableCollection<Tag>(); |
|
92 |
public ObservableCollection<Tag> Tags |
|
218 |
|
|
219 |
private Versioning[] _versions={Versioning.manual,Versioning.auto,Versioning.none}; |
|
220 |
public Versioning[] Versions |
|
221 |
{ |
|
222 |
get { return _versions; } |
|
223 |
} |
|
224 |
|
|
225 |
|
|
226 |
private Versioning _selectedVersion; |
|
227 |
public Versioning SelectedVersion |
|
228 |
{ |
|
229 |
get { return _selectedVersion; } |
|
230 |
set { |
|
231 |
_selectedVersion = value; |
|
232 |
NotifyOfPropertyChange(()=>SelectedVersion); |
|
233 |
} |
|
234 |
} |
|
235 |
|
|
236 |
private void LoadFromDictionary(ICollection<MetaValue> collection,Dictionary<string,string> source ) |
|
237 |
{ |
|
238 |
collection.Clear(); |
|
239 |
var items = from item in source |
|
240 |
select new MetaValue(item.Key, item.Value); |
|
241 |
|
|
242 |
items.Apply(collection.Add); |
|
243 |
} |
|
244 |
|
|
245 |
private readonly ObservableCollection<MetaValue> _tags; |
|
246 |
public ObservableCollection<MetaValue> Tags |
|
93 | 247 |
{ |
94 | 248 |
get { return _tags; } |
95 | 249 |
} |
96 | 250 |
|
251 |
/* private readonly ObservableCollection<MetaValue> _policies; |
|
252 |
public ObservableCollection<MetaValue> Policies |
|
253 |
{ |
|
254 |
get { return _policies; } |
|
255 |
}*/ |
|
256 |
|
|
257 |
private bool _tagsChanged; |
|
258 |
public bool TagsChanged |
|
259 |
{ |
|
260 |
get { return _tagsChanged; } |
|
261 |
private set |
|
262 |
{ |
|
263 |
_tagsChanged = value; |
|
264 |
NotifyOfPropertyChange(()=>TagsChanged); |
|
265 |
NotifyOfPropertyChange(() => CanApplyChanges); |
|
266 |
} |
|
267 |
} |
|
268 |
|
|
269 |
//public bool PoliciesChanged { get; private set; } |
|
270 |
|
|
271 |
private bool _isBusy=true; |
|
272 |
public bool IsBusy |
|
273 |
{ |
|
274 |
get { return _isBusy; } |
|
275 |
set |
|
276 |
{ |
|
277 |
_isBusy = value; |
|
278 |
NotifyOfPropertyChange(()=>IsBusy); |
|
279 |
} |
|
280 |
} |
|
97 | 281 |
|
98 |
public ContainerPropertiesViewModel(ShellViewModel shell, ContainerInfo container, string localFolderName)
|
|
282 |
public ContainerPropertiesViewModel(ShellViewModel shell, Task<ContainerInfo> container, string localFolderName)
|
|
99 | 283 |
{ |
100 | 284 |
if (shell==null) |
101 | 285 |
throw new ArgumentNullException("shell"); |
... | ... | |
104 | 288 |
if (String.IsNullOrWhiteSpace(localFolderName)) |
105 | 289 |
throw new ArgumentNullException("localFolderName"); |
106 | 290 |
Contract.EndContractBlock(); |
291 |
|
|
292 |
_tags = new ObservableCollection<MetaValue>(); |
|
293 |
_tags.CollectionChanged += (sender, evt) => { TagsChanged = true; }; |
|
294 |
|
|
295 |
/*_policies = new ObservableCollection<MetaValue>(); |
|
296 |
_policies.CollectionChanged += (sender, evt) => { PoliciesChanged = true; }; |
|
297 |
*/ |
|
107 | 298 |
|
108 | 299 |
Shell = shell; |
109 | 300 |
ContainerName = localFolderName; |
110 |
Container = container; |
|
111 |
Title = String.Format("{0} Properties", container.Name); |
|
112 |
|
|
113 |
} |
|
301 |
container.ContinueWith(t =>{ |
|
302 |
if (t.IsFaulted) |
|
303 |
{ |
|
304 |
IsBusy = false; |
|
305 |
Execute.OnUIThread(() => ShowError(t.Exception)); |
|
306 |
this.TryClose(); |
|
114 | 307 |
|
308 |
} |
|
309 |
else |
|
310 |
Execute.OnUIThread(()=>Container = t.Result); |
|
311 |
}); |
|
312 |
} |
|
115 | 313 |
|
314 |
private void ShowError(AggregateException exception) |
|
315 |
{ |
|
316 |
MessageView view=null; |
|
317 |
if (exception.InnerException is RetryException) |
|
318 |
view=new MessageView(exception.InnerException as RetryException); |
|
319 |
else if (exception.InnerException is WebException) |
|
320 |
view = new MessageView(exception.InnerException as WebException); |
|
321 |
else |
|
322 |
view = new MessageView(exception.InnerException); |
|
323 |
view.ShowDialog(); |
|
324 |
} |
|
116 | 325 |
|
117 | 326 |
public void Reload() |
118 | 327 |
{ |
... | ... | |
140 | 349 |
DoSave(); |
141 | 350 |
} |
142 | 351 |
|
352 |
public bool CanApplyChanges |
|
353 |
{ |
|
354 |
get { return TagsChanged; } |
|
355 |
} |
|
356 |
|
|
143 | 357 |
private void DoSave() |
144 | 358 |
{ |
359 |
|
|
360 |
if (TagsChanged) |
|
361 |
{ |
|
362 |
Container.Tags = this.Tags.ToDictionary(tag => tag.Name, tag => tag.Value); |
|
363 |
var monitor = Shell.Monitors[Container.Account]; |
|
364 |
monitor.CloudClient.UpdateMetadata(Container); |
|
365 |
} |
|
366 |
|
|
367 |
//Container.Policies["Quota"] = Quota.ToString(); |
|
368 |
//Container.Policies["Versioning"] = Enum.GetName(typeof (Versioning), SelectedVersion); |
|
369 |
|
|
370 |
/* |
|
371 |
if (PoliciesChanged) |
|
372 |
{ |
|
373 |
Container.Policies = this.Policies.ToDictionary(policy=> policy.Name, tag => tag.Value); |
|
374 |
} |
|
375 |
*/ |
|
376 |
|
|
145 | 377 |
|
146 | 378 |
} |
147 | 379 |
|
148 | 380 |
} |
381 |
|
|
382 |
|
|
149 | 383 |
} |
Also available in: Unified diff