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; }
88 var perms=from permission in value.Permissions
89 select new Permission(permission.Key, permission.Value);
90 perms.Apply(perm=>Permissions.Add(perm));
92 var tags=from tag in value.Tags
93 select new Tag(tag.Key, tag.Value);
94 tags.Apply(tag=>Tags.Add(tag));
96 Kind=value.Content_Type;
97 ShortSize = value.Bytes.ToByteSize();
98 Size = String.Format("{0} ({1:N0} bytes)", ShortSize, value.Bytes);
99 Where = Uri.UnescapeDataString(value.Name);
100 FileName = Uri.UnescapeDataString(value.Name.Split('/').Last());
101 Container = value.Container;
102 Modified = value.Last_Modified;
103 ModifiedBy = value.ModifiedBy;
104 Version = value.Version??0;
106 using (var icon = Icon.ExtractAssociatedIcon(LocalFileName))
108 FileIcon = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty,
109 BitmapSizeOptions.FromEmptyOptions());
111 NotifyOfPropertyChange(()=>PithosFile);
117 private readonly ObservableCollection<Tag> _tags = new ObservableCollection<Tag>();
118 public ObservableCollection<Tag> Tags
120 get { return _tags; }
123 private readonly ObservableCollection<Permission> _permissions = new ObservableCollection<Permission>();
124 public ObservableCollection<Permission> Permissions
126 get { return _permissions; }
131 PithosFile=Shell.RefreshObjectInfo(PithosFile);
134 public override void CanClose(Action<bool> callback)
136 base.CanClose(callback);
139 public void SaveChanges()
145 public void RejectChanges()
150 public void ApplyChanges()
155 private void DoSave()