Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (4.9 kB)

1
// -----------------------------------------------------------------------
2
// <copyright file="FilePropertiesViewModel.cs" company="Microsoft">
3
// TODO: Update copyright text.
4
// </copyright>
5
// -----------------------------------------------------------------------
6

    
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;
13
using System.Drawing;
14
using System.Windows;
15
using System.Windows.Interop;
16
using System.Windows.Media.Imaging;
17
using Caliburn.Micro;
18
using Pithos.Client.WPF.FileProperties;
19
using Pithos.Interfaces;
20

    
21
namespace Pithos.Client.WPF
22
{
23
    using System;
24
    using System.Collections.Generic;
25
    using System.Linq;
26
    using System.Text;
27

    
28
    /// <summary>
29
    /// TODO: Update summary.
30
    /// </summary>
31
    [Export(typeof(FilePropertiesViewModel))]
32
    public class FilePropertiesViewModel : Screen
33
    {
34
        private string _title;
35
        public string Title
36
        {
37
            get { return _title; }
38
            set
39
            {
40
                _title = value;
41
                NotifyOfPropertyChange(()=>Title);
42
            }
43
        }
44

    
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; }
54

    
55
        public string FileName { get; set; }
56
        public string Container { get; set; }
57

    
58
        public FilePropertiesViewModel(ShellViewModel shell,ObjectInfo pithosFile,string localFileName)
59
        {
60
            if (shell==null)
61
                throw new ArgumentNullException("shell");
62
            if (pithosFile==null)
63
                throw new ArgumentNullException("pithosFile");
64
            if (String.IsNullOrWhiteSpace(localFileName))
65
                throw new ArgumentNullException("localFileName");
66
            Contract.EndContractBlock();
67

    
68
            Shell = shell;
69
            LocalFileName = localFileName;
70
            PithosFile = pithosFile;
71
            Title = String.Format("{0} Properties", pithosFile.Name);
72
        }
73

    
74

    
75
        protected ShellViewModel Shell { get; set; }
76

    
77
        private ObjectInfo _pithosFile;
78
        public ObjectInfo PithosFile
79
        {
80
            get { return _pithosFile; }
81
            set
82
            {
83
                _pithosFile = value;
84
                
85
                Permissions.Clear();
86
                Tags.Clear();
87

    
88
                var perms=from permission in value.Permissions
89
                            select new Permission(permission.Key, permission.Value);
90
                perms.Apply(perm=>Permissions.Add(perm));
91
                
92
                var tags=from tag in value.Tags
93
                             select new Tag(tag.Key, tag.Value);
94
                tags.Apply(tag=>Tags.Add(tag));                                            
95

    
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;
105

    
106
                using (var icon = Icon.ExtractAssociatedIcon(LocalFileName))
107
                {
108
                    FileIcon = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty,
109
                                                                   BitmapSizeOptions.FromEmptyOptions());
110
                }
111
                NotifyOfPropertyChange(()=>PithosFile);
112
            }
113
        }
114

    
115

    
116

    
117
        private readonly ObservableCollection<Tag> _tags = new ObservableCollection<Tag>();
118
        public ObservableCollection<Tag> Tags
119
        {
120
            get { return _tags; }
121
        }
122

    
123
        private readonly ObservableCollection<Permission> _permissions = new ObservableCollection<Permission>();
124
        public ObservableCollection<Permission> Permissions
125
        {
126
            get { return _permissions; }
127
        }
128

    
129
        public void Reload()
130
        {
131
            PithosFile=Shell.RefreshObjectInfo(PithosFile);
132
        }
133

    
134
        public override void CanClose(Action<bool> callback)
135
        {
136
            base.CanClose(callback);
137
        }
138

    
139
        public void SaveChanges()
140
        {
141
            DoSave();
142
            TryClose();
143
        }
144

    
145
        public void RejectChanges()
146
        {
147
            TryClose();
148
        }
149

    
150
        public void ApplyChanges()
151
        {
152
            DoSave();
153
        }
154

    
155
        private void DoSave()
156
        {
157
            
158
        }
159

    
160

    
161
    }
162
}