Revision c92e02f3 trunk/Pithos.Client.WPF/FileProperties/FilePropertiesViewModel.cs

b/trunk/Pithos.Client.WPF/FileProperties/FilePropertiesViewModel.cs
12 12
using System.Diagnostics;
13 13
using System.Diagnostics.Contracts;
14 14
using System.Drawing;
15
using System.Net;
16
using System.Threading.Tasks;
15 17
using System.Windows;
16 18
using System.Windows.Interop;
17 19
using System.Windows.Media.Imaging;
......
91 93
            }
92 94
        }
93 95

  
94
        public string Kind { get; set; }
95
        public string Size { get; set; }
96
        public string ShortSize { get; set; }
97
        public string Where { get; set; }
98
        public DateTime Modified { get; set; }
99
        public string ModifiedBy { get; set; }
100
        public long Version { get; set; }
101
        protected string LocalFileName { get; set; }
102
        public BitmapSource FileIcon { get; set; }
103
        public string PublicUrl { get; set; }
96
        private string _kind;
97
        public string Kind
98
        {
99
            get { return _kind; }
100
            set
101
            {
102
                _kind = value;
103
                NotifyOfPropertyChange(() => Kind);
104
            }
105
        }
106

  
107
        private string _size;
108
        public string Size
109
        {
110
            get { return _size; }
111
            set
112
            {
113
                _size = value;
114
                NotifyOfPropertyChange(() => Size);
115
            }
116
        }
104 117

  
105
        public string FileName { get; set; }
106
        public string Container { get; set; }
118
        private string _shortSize;
119
        public string ShortSize
120
        {
121
            get { return _shortSize; }
122
            set
123
            {
124
                _shortSize = value;
125
                NotifyOfPropertyChange(() => ShortSize);
126
            }
127
        }
128

  
129
        private string _where;
130
        public string Where
131
        {
132
            get { return _where; }
133
            set
134
            {
135
                _where = value;
136
                NotifyOfPropertyChange(() => Where);
137
            }
138
        }
139

  
140
        private DateTime _modified;
141
        public DateTime Modified
142
        {
143
            get { return _modified; }
144
            set
145
            {
146
                _modified = value;
147
                NotifyOfPropertyChange(() => Modified);
148
            }
149
        }
150

  
151
        private string _modifiedBy;
152
        public string ModifiedBy
153
        {
154
            get { return _modifiedBy; }
155
            set
156
            {
157
                _modifiedBy = value;
158
                NotifyOfPropertyChange(() => ModifiedBy);
159
            }
160
        }
161

  
162
        private long _version;
163
        public long Version
164
        {
165
            get { return _version; }
166
            set
167
            {
168
                _version = value;
169
                NotifyOfPropertyChange(() => Version);
170
            }
171
        }
172

  
173
        private string _localFileName;
174
        protected string LocalFileName
175
        {
176
            get { return _localFileName; }
177
            set
178
            {
179
                _localFileName = value;
180
                NotifyOfPropertyChange(() => LocalFileName);
181
            }
182
        }
183

  
184
        private BitmapSource _fileIcon;
185
        public BitmapSource FileIcon
186
        {
187
            get { return _fileIcon; }
188
            set
189
            {
190
                _fileIcon = value;
191
                NotifyOfPropertyChange(() => FileIcon);
192
            }
193
        }
194

  
195
        private string _publicUrl;
196
        public string PublicUrl
197
        {
198
            get { return _publicUrl; }
199
            set
200
            {
201
                _publicUrl = value;
202
                NotifyOfPropertyChange(() => PublicUrl);
203
            }
204
        }
205

  
206
        private string _fileName;
207
        public string FileName
208
        {
209
            get { return _fileName; }
210
            set
211
            {
212
                _fileName = value;
213
                NotifyOfPropertyChange(() => FileName);
214
            }
215
        }
216

  
217
        private string _container;
218
        public string Container
219
        {
220
            get { return _container; }
221
            set
222
            {
223
                _container = value;
224
                NotifyOfPropertyChange(() => Container);
225
            }
226
        }
107 227

  
108 228
        public bool TagsChanged { get; private set; }
109 229
        public bool PermissionsChanged { get; private set; }
110 230

  
111
        public FilePropertiesViewModel(ShellViewModel shell,ObjectInfo pithosFile,string localFileName)
231
        private bool _isBusy = true;
232
        public bool IsBusy
233
        {
234
            get { return _isBusy; }
235
            set
236
            {
237
                _isBusy = value;
238
                NotifyOfPropertyChange(() => IsBusy);
239
            }
240
        }
241

  
242

  
243
        public FilePropertiesViewModel(ShellViewModel shell,Task<ObjectInfo> pithosFile,string localFileName)
112 244
        {
113 245
            if (shell==null)
114 246
                throw new ArgumentNullException("shell");
......
119 251
            Contract.EndContractBlock();
120 252

  
121 253

  
122
            _tags = new ObservableCollection<Tag>();
254
            _tags = new ObservableCollection<MetaValue>();
123 255
            _tags.CollectionChanged += (sender, evt) => { TagsChanged = true; };
124 256
            _permissions = new ObservableCollection<Permission>();
125 257
            _permissions.CollectionChanged += (sender, evt) => { PermissionsChanged = true; };
126 258
            
127 259
            Shell = shell;
128 260
            LocalFileName = localFileName;
129
            PithosFile = pithosFile;
130
            Title = String.Format("{0} Properties", pithosFile.Name);
261
            pithosFile.ContinueWith(t =>
262
            {
263
                if (t.IsFaulted)
264
                {
265
                    IsBusy = false;
266
                    Execute.OnUIThread(()=>ShowError(t.Exception));
267
                    this.TryClose();
268

  
269
                }
270
                else
271
                    Execute.OnUIThread(() => PithosFile = t.Result);
272
            });                        
273
        }
274

  
275
        private void ShowError(AggregateException exception)
276
        {
277
            MessageView view = null;
278
            if (exception.InnerException is RetryException)
279
                view = new MessageView(exception.InnerException as RetryException);
280
            else if (exception.InnerException is WebException)
281
                view = new MessageView(exception.InnerException as WebException);
282
            else
283
                view = new MessageView(exception.InnerException);
284
            view.ShowDialog();
131 285
        }
132 286

  
133
        
134 287

  
135 288
        protected ShellViewModel Shell { get; set; }
136 289

  
......
150 303
                perms.Apply(perm=>Permissions.Add(perm));
151 304
                
152 305
                var tags=from tag in value.Tags
153
                             select new Tag(tag.Key, tag.Value);
154
                tags.Apply(tag=>Tags.Add(tag));                                            
306
                             select new MetaValue(tag.Key, tag.Value);
307
                tags.Apply(tag=>Tags.Add(tag));
155 308

  
309
                Title = String.Format("{0} Properties", value.Name);
156 310
                Kind=value.Content_Type;
157 311
                ShortSize = value.Bytes.ToByteSize();
158 312
                Size = String.Format("{0} ({1:N0} bytes)", ShortSize, value.Bytes);
......
176 330
                                                                   BitmapSizeOptions.FromEmptyOptions());
177 331
                }
178 332
                NotifyOfPropertyChange(()=>PithosFile);
333
                IsBusy = false;
179 334
            }
180 335
        }
181 336

  
182 337

  
183
        private readonly ObservableCollection<Tag> _tags ;
184
        public ObservableCollection<Tag> Tags
338
        private readonly ObservableCollection<MetaValue> _tags ;
339
        public ObservableCollection<MetaValue> Tags
185 340
        {
186 341
            get { return _tags;}
187 342
        }

Also available in: Unified diff