Statistics
| Branch: | Revision:

root / trunk / Pithos.Client.WPF / FileProperties / FilePropertiesViewModel.cs @ 42800be8

History | View | Annotate | Download (4.5 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
                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;
97

    
98
                using (var icon = Icon.ExtractAssociatedIcon(LocalFileName))
99
                {
100
                    FileIcon = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty,
101
                                                                   BitmapSizeOptions.FromEmptyOptions());
102
                }
103
                NotifyOfPropertyChange(()=>PithosFile);
104
            }
105
        }
106
        
107

    
108

    
109
        private ObservableConcurrentDictionary<string, string> _permissions;
110
        public ObservableConcurrentDictionary<string, string> Permissions
111
        {
112
            get { return _permissions; }
113
            set
114
            {
115
                _permissions = value;
116
            }
117
        }
118

    
119

    
120
        public void Refresh()
121
        {
122
            PithosFile=Shell.RefreshObjectInfo(PithosFile);
123
        }
124

    
125
        public override void CanClose(Action<bool> callback)
126
        {
127
            base.CanClose(callback);
128
        }
129

    
130
        public void SaveChanges()
131
        {
132
            DoSave();
133
            TryClose();
134
        }
135

    
136
        public void RejectChanges()
137
        {
138
            TryClose();
139
        }
140

    
141
        public void ApplyChanges()
142
        {
143
            DoSave();
144
        }
145

    
146
        private void DoSave()
147
        {
148
            
149
        }
150

    
151

    
152
    }
153
}