Statistics
| Branch: | Revision:

root / trunk / Pithos.Client.WPF / FileProperties / ContainerPropertiesViewModel.cs @ 20e9a378

History | View | Annotate | Download (4.1 kB)

1
using System;
2
using System.Collections.Concurrent;
3
using System.Collections.Generic;
4
using System.Collections.ObjectModel;
5
using System.ComponentModel.Composition;
6
using System.Diagnostics.Contracts;
7
using System.Linq;
8
using System.Text;
9
using Caliburn.Micro;
10
using Pithos.Network;
11

    
12
namespace Pithos.Client.WPF.FileProperties
13
{
14
    [Export(typeof(ContainerPropertiesViewModel))]
15
    public class ContainerPropertiesViewModel:Screen
16
    {
17
        /// <summary>
18
        /// Name of the displayed container
19
        /// </summary>
20
        public string ContainerName { get; set; }
21
        /// <summary>
22
        /// Window title
23
        /// </summary>
24
        public string Title { get; set; }
25

    
26
        /// <summary>
27
        /// Count of files in the container
28
        /// </summary>
29
        public long Count { get; set; }
30

    
31
        /// <summary>
32
        /// Date of last modification
33
        /// </summary>
34
        public DateTime Modified { get; set; }
35
        
36
        /// <summary>
37
        /// Total size of the container in bytes
38
        /// </summary>
39
        public string Size { get; set; }
40

    
41
        /// <summary>
42
        /// Total size of the container formatted in KB,MB etc
43
        /// </summary>
44
        public string ShortSize { get; set; }
45

    
46
        /// <summary>
47
        /// Block size used by the container
48
        /// </summary>
49
        public int BlockSize { get; set; }
50

    
51
        /// <summary>
52
        /// Hash algorithm used to calculate block hashes
53
        /// </summary>
54
        public string BlockHash { get; set; }
55

    
56
        /// <summary>
57
        /// Reference to the parent Shell
58
        /// </summary>
59
        protected ShellViewModel Shell { get; set; }
60

    
61
        private ContainerInfo _container;
62
        /// <summary>
63
        /// The displayed ContainerInfo
64
        /// </summary>
65
        protected ContainerInfo Container
66
        {
67
            get { return _container; }
68
            set
69
            {
70
                _container = value;
71

    
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));                                            
76

    
77

    
78
                Count = value.Count;
79
                ShortSize = value.Bytes.ToByteSize();
80
                Size = String.Format("{0} ({1:N0} bytes)", ShortSize, value.Bytes);
81
                Modified = value.Last_Modified;
82
                BlockSize = value.BlockSize;
83
                BlockHash = value.BlockHash;                
84
                ContainerName = Uri.UnescapeDataString(value.Name.Split('/').Last());                                                
85

    
86
                NotifyOfPropertyChange(() => Container);
87
            }
88
        }
89

    
90

    
91
        private readonly ObservableCollection<Tag> _tags = new ObservableCollection<Tag>();
92
        public ObservableCollection<Tag> Tags
93
        {
94
            get { return _tags; }
95
        }
96

    
97

    
98
        public ContainerPropertiesViewModel(ShellViewModel shell, ContainerInfo container, string localFolderName)
99
        {
100
            if (shell==null)
101
                throw new ArgumentNullException("shell");
102
            if (container==null)
103
                throw new ArgumentNullException("container");
104
            if (String.IsNullOrWhiteSpace(localFolderName))
105
                throw new ArgumentNullException("localFolderName");
106
            Contract.EndContractBlock();
107

    
108
            Shell = shell;
109
            ContainerName = localFolderName;
110
            Container = container;
111
            Title = String.Format("{0} Properties", container.Name);
112
            
113
        }
114

    
115

    
116

    
117
        public void Reload()
118
        {
119
            Container = Shell.RefreshContainerInfo(Container);
120
        }
121

    
122
        public override void CanClose(Action<bool> callback)
123
        {
124
            base.CanClose(callback);
125
        }
126

    
127
        public void SaveChanges()
128
        {
129
            DoSave();
130
            TryClose();
131
        }
132

    
133
        public void RejectChanges()
134
        {
135
            TryClose();
136
        }
137

    
138
        public void ApplyChanges()
139
        {
140
            DoSave();
141
        }
142

    
143
        private void DoSave()
144
        {
145

    
146
        }
147

    
148
    }
149
}