root / trunk / Pithos.Client.WPF / FileProperties / ContainerPropertiesViewModel.cs @ 42800be8
History | View | Annotate | Download (3.6 kB)
1 |
using System; |
---|---|
2 |
using System.Collections.Concurrent; |
3 |
using System.Collections.Generic; |
4 |
using System.ComponentModel.Composition; |
5 |
using System.Diagnostics.Contracts; |
6 |
using System.Linq; |
7 |
using System.Text; |
8 |
using Caliburn.Micro; |
9 |
using Pithos.Network; |
10 |
|
11 |
namespace Pithos.Client.WPF.FileProperties |
12 |
{ |
13 |
[Export(typeof(ContainerPropertiesViewModel))] |
14 |
public class ContainerPropertiesViewModel:Screen |
15 |
{ |
16 |
/// <summary> |
17 |
/// Name of the displayed container |
18 |
/// </summary> |
19 |
public string ContainerName { get; set; } |
20 |
/// <summary> |
21 |
/// Window title |
22 |
/// </summary> |
23 |
public string Title { get; set; } |
24 |
|
25 |
/// <summary> |
26 |
/// Count of files in the container |
27 |
/// </summary> |
28 |
public long Count { get; set; } |
29 |
|
30 |
/// <summary> |
31 |
/// Date of last modification |
32 |
/// </summary> |
33 |
public DateTime Modified { get; set; } |
34 |
|
35 |
/// <summary> |
36 |
/// Total size of the container in bytes |
37 |
/// </summary> |
38 |
public string Size { get; set; } |
39 |
|
40 |
/// <summary> |
41 |
/// Total size of the container formatted in KB,MB etc |
42 |
/// </summary> |
43 |
public string ShortSize { get; set; } |
44 |
|
45 |
/// <summary> |
46 |
/// Block size used by the container |
47 |
/// </summary> |
48 |
public int BlockSize { get; set; } |
49 |
|
50 |
/// <summary> |
51 |
/// Hash algorithm used to calculate block hashes |
52 |
/// </summary> |
53 |
public string BlockHash { get; set; } |
54 |
|
55 |
/// <summary> |
56 |
/// Reference to the parent Shell |
57 |
/// </summary> |
58 |
protected ShellViewModel Shell { get; set; } |
59 |
|
60 |
private ContainerInfo _container; |
61 |
/// <summary> |
62 |
/// The displayed ContainerInfo |
63 |
/// </summary> |
64 |
protected ContainerInfo Container |
65 |
{ |
66 |
get { return _container; } |
67 |
set |
68 |
{ |
69 |
_container = value; |
70 |
|
71 |
Count = value.Count; |
72 |
ShortSize = value.Bytes.ToByteSize(); |
73 |
Size = String.Format("{0} ({1:N0} bytes)", ShortSize, value.Bytes); |
74 |
Modified = value.Last_Modified; |
75 |
BlockSize = value.BlockSize; |
76 |
BlockHash = value.BlockHash; |
77 |
ContainerName = Uri.UnescapeDataString(value.Name.Split('/').Last()); |
78 |
|
79 |
NotifyOfPropertyChange(() => Container); |
80 |
} |
81 |
} |
82 |
|
83 |
|
84 |
|
85 |
|
86 |
public ContainerPropertiesViewModel(ShellViewModel shell, ContainerInfo container, string localFolderName) |
87 |
{ |
88 |
if (shell==null) |
89 |
throw new ArgumentNullException("shell"); |
90 |
if (container==null) |
91 |
throw new ArgumentNullException("container"); |
92 |
if (String.IsNullOrWhiteSpace(localFolderName)) |
93 |
throw new ArgumentNullException("localFolderName"); |
94 |
Contract.EndContractBlock(); |
95 |
|
96 |
Shell = shell; |
97 |
ContainerName = localFolderName; |
98 |
Container = container; |
99 |
Title = String.Format("{0} Properties", container.Name); |
100 |
|
101 |
} |
102 |
|
103 |
|
104 |
|
105 |
public void Refresh() |
106 |
{ |
107 |
Container = Shell.RefreshContainerInfo(Container); |
108 |
} |
109 |
|
110 |
public override void CanClose(Action<bool> callback) |
111 |
{ |
112 |
base.CanClose(callback); |
113 |
} |
114 |
|
115 |
public void SaveChanges() |
116 |
{ |
117 |
DoSave(); |
118 |
TryClose(); |
119 |
} |
120 |
|
121 |
public void RejectChanges() |
122 |
{ |
123 |
TryClose(); |
124 |
} |
125 |
|
126 |
public void ApplyChanges() |
127 |
{ |
128 |
DoSave(); |
129 |
} |
130 |
|
131 |
private void DoSave() |
132 |
{ |
133 |
|
134 |
} |
135 |
|
136 |
} |
137 |
} |