// -----------------------------------------------------------------------
//
// TODO: Update copyright text.
//
// -----------------------------------------------------------------------
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Drawing;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
using Caliburn.Micro;
using Pithos.Client.WPF.FileProperties;
using Pithos.Interfaces;
namespace Pithos.Client.WPF
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
///
/// TODO: Update summary.
///
[Export(typeof(FilePropertiesViewModel))]
public class FilePropertiesViewModel : Screen
{
private string _title;
public string Title
{
get { return _title; }
set
{
_title = value;
NotifyOfPropertyChange(()=>Title);
}
}
public string Kind { get; set; }
public string Size { get; set; }
public string ShortSize { get; set; }
public string Where { get; set; }
public DateTime Modified { get; set; }
public string ModifiedBy { get; set; }
public long Version { get; set; }
protected string LocalFileName { get; set; }
public BitmapSource FileIcon { get; set; }
public string FileName { get; set; }
public string Container { get; set; }
public FilePropertiesViewModel(ShellViewModel shell,ObjectInfo pithosFile,string localFileName)
{
if (shell==null)
throw new ArgumentNullException("shell");
if (pithosFile==null)
throw new ArgumentNullException("pithosFile");
if (String.IsNullOrWhiteSpace(localFileName))
throw new ArgumentNullException("localFileName");
Contract.EndContractBlock();
Shell = shell;
LocalFileName = localFileName;
PithosFile = pithosFile;
Title = String.Format("{0} Properties", pithosFile.Name);
}
protected ShellViewModel Shell { get; set; }
private ObjectInfo _pithosFile;
public ObjectInfo PithosFile
{
get { return _pithosFile; }
set
{
_pithosFile = value;
Permissions.Clear();
Tags.Clear();
var perms=from permission in value.Permissions
select new Permission(permission.Key, permission.Value);
perms.Apply(perm=>Permissions.Add(perm));
var tags=from tag in value.Tags
select new Tag(tag.Key, tag.Value);
tags.Apply(tag=>Tags.Add(tag));
Kind=value.Content_Type;
ShortSize = value.Bytes.ToByteSize();
Size = String.Format("{0} ({1:N0} bytes)", ShortSize, value.Bytes);
Where = Uri.UnescapeDataString(value.Name);
FileName = Uri.UnescapeDataString(value.Name.Split('/').Last());
Container = value.Container;
Modified = value.Last_Modified;
ModifiedBy = value.ModifiedBy;
Version = value.Version??0;
using (var icon = Icon.ExtractAssociatedIcon(LocalFileName))
{
FileIcon = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
}
NotifyOfPropertyChange(()=>PithosFile);
}
}
private readonly ObservableCollection _tags = new ObservableCollection();
public ObservableCollection Tags
{
get { return _tags; }
}
private readonly ObservableCollection _permissions = new ObservableCollection();
public ObservableCollection Permissions
{
get { return _permissions; }
}
public void Reload()
{
PithosFile=Shell.RefreshObjectInfo(PithosFile);
}
public override void CanClose(Action callback)
{
base.CanClose(callback);
}
public void SaveChanges()
{
DoSave();
TryClose();
}
public void RejectChanges()
{
TryClose();
}
public void ApplyChanges()
{
DoSave();
}
private void DoSave()
{
}
}
}