1 // -----------------------------------------------------------------------
2 // <copyright file="FilePropertiesViewModel.cs" company="Microsoft">
3 // TODO: Update copyright text.
5 // -----------------------------------------------------------------------
7 using System.Collections;
8 using System.Collections.Concurrent;
9 using System.Collections.ObjectModel;
10 using System.ComponentModel.Composition;
11 using System.Diagnostics;
12 using System.Diagnostics.Contracts;
15 using System.Windows.Interop;
16 using System.Windows.Media.Imaging;
18 using Pithos.Client.WPF.FileProperties;
19 using Pithos.Interfaces;
21 namespace Pithos.Client.WPF
24 using System.Collections.Generic;
29 /// TODO: Update summary.
31 [Export(typeof(FilePropertiesViewModel))]
32 public class FilePropertiesViewModel : Screen
34 private string _title;
37 get { return _title; }
41 NotifyOfPropertyChange(()=>Title);
45 public string Kind { get; set; }
46 public string Size { get; set; }
47 public string ShortSize { get; set; }
48 public string Where { get; set; }
49 public DateTime Modified { get; set; }
50 public string ModifiedBy { get; set; }
51 public long Version { get; set; }
52 protected string LocalFileName { get; set; }
53 public BitmapSource FileIcon { get; set; }
55 public string FileName { get; set; }
56 public string Container { get; set; }
58 public FilePropertiesViewModel(ShellViewModel shell,ObjectInfo pithosFile,string localFileName)
61 throw new ArgumentNullException("shell");
63 throw new ArgumentNullException("pithosFile");
64 if (String.IsNullOrWhiteSpace(localFileName))
65 throw new ArgumentNullException("localFileName");
66 Contract.EndContractBlock();
69 LocalFileName = localFileName;
70 PithosFile = pithosFile;
71 Title = String.Format("{0} Properties", pithosFile.Name);
75 protected ShellViewModel Shell { get; set; }
77 private ObjectInfo _pithosFile;
78 public ObjectInfo PithosFile
80 get { return _pithosFile; }
85 if (Permissions!=null)
86 ((IDictionary<string,string>)Permissions).Clear();
87 value.Permissions.Apply(perm=>Permissions.Add(perm.Key,perm.Value));
88 Kind=value.Content_Type;
89 ShortSize = value.Bytes.ToByteSize();
90 Size = String.Format("{0} ({1:N0} bytes)", ShortSize, value.Bytes);
91 Where = Uri.UnescapeDataString(value.Name);
92 FileName = Uri.UnescapeDataString(value.Name.Split('/').Last());
93 Container = value.Container;
94 Modified = value.Last_Modified;
95 ModifiedBy = value.ModifiedBy;
96 Version = value.Version??0;
98 using (var icon = Icon.ExtractAssociatedIcon(LocalFileName))
100 FileIcon = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty,
101 BitmapSizeOptions.FromEmptyOptions());
103 NotifyOfPropertyChange(()=>PithosFile);
109 private ObservableConcurrentDictionary<string, string> _permissions;
110 public ObservableConcurrentDictionary<string, string> Permissions
112 get { return _permissions; }
115 _permissions = value;
120 public void Refresh()
122 PithosFile=Shell.RefreshObjectInfo(PithosFile);
125 public override void CanClose(Action<bool> callback)
127 base.CanClose(callback);
130 public void SaveChanges()
136 public void RejectChanges()
141 public void ApplyChanges()
146 private void DoSave()