using System;
using System.IO;
using System.Security.Principal;
using System.Threading;
using Common.Logging;
using WebDAVSharp.Server.Stores.BaseClasses;
namespace WebDAVSharp.Server.Stores.DiskStore {
///
/// This class implements a disk-based
/// which can be either
/// a folder on disk (
/// ) or a file on disk
/// (
/// ).
///
public class WebDavDiskStoreItem : WebDavStoreItemBase {
///
/// Gets the Identity of the person logged on via HTTP Request.
///
protected readonly WindowsIdentity Identity;
///
/// Log
///
protected ILog Log;
private readonly IWebDavStoreCollection _parentCollection;
private readonly string _path;
///
/// Initializes a new instance of the class.
///
/// The parent
/// that contains this
/// ;
/// or
/// null if this is the root
/// .
/// The path that this maps to.
/// path
/// is null or empty.
protected WebDavDiskStoreItem(IWebDavStoreCollection parentCollection, string path) : base(parentCollection, path) {
if (String.IsNullOrWhiteSpace(path))
throw new ArgumentNullException("path");
_parentCollection = parentCollection;
_path = path;
//TODO: (Charly): add correct user/impersonation handling
//Identity = (WindowsIdentity)Thread.GetData(Thread.GetNamedDataSlot(WebDavServer.HttpUser));
//Identity = new WindowsIdentity()
Identity = WindowsIdentity.GetCurrent();
Log = LogManager.GetLogger();
}
///
/// Gets the path to this .
///
public override string ItemPath {
get {
return _path;
}
}
#region IWebDAVStoreItem Members
///
/// Gets or sets the name of this .
///
/// Unable to rename item
public new string Name {
get {
return Path.GetFileName(_path);
}
set {
throw new InvalidOperationException("Unable to rename item");
}
}
///
/// Gets if this is a collection.
///
public new bool IsCollection {
get {
// get the file attributes for file or directory
FileAttributes attr = File.GetAttributes(_path);
//detect whether its a directory or file
return (attr & FileAttributes.Directory) == FileAttributes.Directory;
}
}
///
/// Gets the creation date of this .
///
public override DateTime CreationDate {
get {
// get the file attributes for file or directory
return File.GetCreationTime(_path);
}
}
///
/// Gets the modification date of this .
///
public override DateTime ModificationDate {
get {
// get the file attributes for file or directory
return File.GetLastWriteTime(_path);
}
}
///
/// Gets the hidden state of this .
///
///
/// Source:
///
public new int Hidden {
get {
DirectoryInfo dir = new DirectoryInfo(_path);
return (dir.Attributes & FileAttributes.Hidden) != 0 ? 1 : 0;
}
}
#endregion
}
}