/// <summary> /// Initializes a new instance of the <see cref="WebDavDiskStoreItem" /> class. /// </summary> /// <param name="parentCollection"> /// The parent /// <see cref="WebDavDiskStoreCollection" /> that contains this /// <see cref="WebDavDiskStoreItem" />; /// or /// <c>null</c> if this is the root /// <see cref="WebDavDiskStoreCollection" />. /// </param> /// <param name="path">The path that this <see cref="WebDavDiskStoreItem" /> maps to.</param> /// <param name="store"></param> /// <exception cref="System.ArgumentNullException">path</exception> /// <exception cref="ArgumentNullException"><paramref name="path" /> is <c>null</c> or empty.</exception> protected WebDavDiskStoreItem(WebDavDiskStoreCollection parentCollection, string path, IWebDavStore store) : base(parentCollection, path, store) { if (IsNullOrWhiteSpace(path)) throw new ArgumentNullException(nameof(path)); _path = path; }
/// <summary> /// Retrieves a store item by its name. /// </summary> /// <param name="name">The name of the store item to retrieve.</param> /// <returns> /// The store item that has the specified /// <paramref name="name" />; /// or /// <c>null</c> if there is no store item with that name. /// </returns> public IWebDavStoreItem GetItemByName(string name) { var path = Path.Combine(ItemPath, name); IWebDavStoreItem document = null; WindowsIdentity.RunImpersonated(WindowsIdentity.GetCurrent().AccessToken, () => { if (File.Exists(path) && CanReadFile(path)) { document = new WebDavDiskStoreDocument(this, path); } if (Directory.Exists(path) && CanReadDirectory(path)) { document = new WebDavDiskStoreCollection(this, path); } }); return(document); //using (Identity.Impersonate()) //{ // if (File.Exists(path) && CanReadFile(path)) // return new WebDavDiskStoreDocument(this, path); // if (Directory.Exists(path) && CanReadDirectory(path)) // return new WebDavDiskStoreCollection(this, path); //} //return null; }
/// <summary> /// Copies an existing store item into this collection, overwriting any existing items. /// </summary> /// <param name="source">The store item to copy from.</param> /// <param name="destinationName">The name of the copy to create of <paramref name="source" />.</param> /// <param name="includeContent">The boolean for copying the containing files/folders or not.</param> /// <returns> /// The created <see cref="IWebDavStoreItem" /> instance. /// </returns> /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavUnauthorizedException">If the user is unauthorized or has no access</exception> public IWebDavStoreItem CopyItemHere(IWebDavStoreItem source, string destinationName, bool includeContent) { // We get the path of var destinationItemPath = Path.Combine(ItemPath, destinationName); // the moving of the item if (source.IsCollection) { try { // Impersonate the current user and move the directory WindowsIdentity.RunImpersonated(WindowsIdentity.GetCurrent().AccessToken, () => { DirectoryCopy(source.ItemPath, destinationItemPath, true); }); //WindowsImpersonationContext wic = Identity.Impersonate(); //DirectoryCopy(source.ItemPath, destinationItemPath, true); //wic.Undo(); } catch { throw new WebDavUnauthorizedException(); } // We return the moved file as a WebDAVDiskStoreDocument var collection = new WebDavDiskStoreCollection(this, destinationItemPath); _items.Add(destinationName, new WeakReference(collection)); return(collection); } // We copy the file with an override. try { // Impersonate the current user and copy the file WindowsIdentity.RunImpersonated(WindowsIdentity.GetCurrent().AccessToken, () => { File.Copy(source.ItemPath, destinationItemPath, true); }); // WindowsImpersonationContext wic = Identity.Impersonate(); // File.Copy(source.ItemPath, destinationItemPath, true); // wic.Undo(); } catch { throw new WebDavUnauthorizedException(); } // We return the moved file as a WebDAVDiskStoreDocument var document = new WebDavDiskStoreDocument(this, destinationItemPath); _items.Add(destinationName, new WeakReference(document)); return(document); }
/// <summary> /// Initializes a new instance of the <see cref="WebDavDiskStoreItem" /> class. /// </summary> /// <param name="parentCollection">The parent /// <see cref="WebDavDiskStoreCollection" /> that contains this /// <see cref="WebDavDiskStoreItem" />; /// or /// <c>null</c> if this is the root /// <see cref="WebDavDiskStoreCollection" />.</param> /// <param name="path">The path that this <see cref="WebDavDiskStoreItem" /> maps to.</param> /// <exception cref="System.ArgumentNullException">path</exception> /// <exception cref="ArgumentNullException"><paramref name="path" /> is <c>null</c> or empty.</exception> protected WebDavDiskStoreItem(WebDavDiskStoreCollection parentCollection, string path) : base(parentCollection, path) { if (String.IsNullOrWhiteSpace(path)) throw new ArgumentNullException("path"); _path = path; Identity = (WindowsIdentity)Thread.GetData(Thread.GetNamedDataSlot(Constants.HttpUser)); }
/// <summary> /// Initializes a new instance of the <see cref="WebDavDiskStoreItem" /> class. /// </summary> /// <param name="parentCollection">The parent /// <see cref="WebDavDiskStoreCollection" /> that contains this /// <see cref="WebDavDiskStoreItem" />; /// or /// <c>null</c> if this is the root /// <see cref="WebDavDiskStoreCollection" />.</param> /// <param name="path">The path that this <see cref="WebDavDiskStoreItem" /> maps to.</param> /// <exception cref="System.ArgumentNullException">path</exception> /// <exception cref="ArgumentNullException"><paramref name="path" /> is <c>null</c> or empty.</exception> protected WebDavDiskStoreItem(WebDavDiskStoreCollection parentCollection, string path) : base(parentCollection, path) { if (String.IsNullOrWhiteSpace(path)) { throw new ArgumentNullException("path"); } _path = path; Identity = (WindowsIdentity)Thread.GetData(Thread.GetNamedDataSlot(Constants.HttpUser)); }
/// <summary> /// Initializes a new instance of the <see cref="WebDavDiskStoreItem" /> class. /// </summary> /// <param name="parentCollection">The parent /// <see cref="WebDavDiskStoreCollection" /> that contains this /// <see cref="WebDavDiskStoreItem" />; /// or /// <c>null</c> if this is the root /// <see cref="WebDavDiskStoreCollection" />.</param> /// <param name="path">The path that this <see cref="WebDavDiskStoreItem" /> maps to.</param> /// <exception cref="System.ArgumentNullException">path</exception> /// <exception cref="ArgumentNullException"><paramref name="path" /> is <c>null</c> or empty.</exception> protected WebDavDiskStoreItem(WebDavDiskStoreCollection parentCollection, string path) : base(parentCollection, path) { if (String.IsNullOrWhiteSpace(path)) throw new ArgumentNullException("path"); _parentCollection = parentCollection; _path = path; Identity = (WindowsIdentity)Thread.GetData(Thread.GetNamedDataSlot(WebDavServer.HttpUser)); Log = LogManager.GetCurrentClassLogger(); }
/// <summary> /// Moves an existing store item into this collection, overwriting any existing items. /// </summary> /// <param name="source">The store item to move.</param> /// <param name="destinationName">The /// <see cref="IWebDavStoreItem" /> that refers to the item that was moved, /// in its new location.</param> /// <returns> /// The moved <see cref="IWebDavStoreItem" /> instance. /// </returns> /// <exception cref="System.Exception">Path to the source item not defined.</exception> /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavUnauthorizedException">If the user is unauthorized or has no access</exception> /// <remarks> /// Note that the method should fail without creating or overwriting content in the /// target collection if the move cannot go through. /// </remarks> public IWebDavStoreItem MoveItemHere(IWebDavStoreItem source, string destinationName) { // try to get the path of the source item string sourceItemPath = ""; WebDavDiskStoreItem sourceItem = (WebDavDiskStoreItem)source; sourceItemPath = sourceItem.ItemPath; if (sourceItemPath.Equals("")) { throw new Exception("Path to the source item not defined."); } // We get the path of string destinationItemPath = Path.Combine(ItemPath, destinationName); // the moving of the item if (source.IsCollection) { try { // Impersonate the current user and move the directory WindowsImpersonationContext wic = Identity.Impersonate(); Directory.Move(sourceItemPath, destinationItemPath); wic.Undo(); } catch { throw new WebDavUnauthorizedException(); } // We return the moved file as a WebDAVDiskStoreDocument var collection = new WebDavDiskStoreCollection(this, destinationItemPath); _items.Add(destinationName, new WeakReference(collection)); return(collection); } try { // Impersonate the current user and move the file WindowsImpersonationContext wic = Identity.Impersonate(); File.Move(sourceItemPath, destinationItemPath); wic.Undo(); } catch { throw new WebDavUnauthorizedException(); } // We return the moved file as a WebDAVDiskStoreDocument WebDavDiskStoreDocument document = new WebDavDiskStoreDocument(this, destinationItemPath); _items.Add(destinationName, new WeakReference(document)); return(document); }
/// <summary> /// Initializes a new instance of the <see cref="WebDavDiskStoreItem" /> class. /// </summary> /// <param name="parentCollection">The parent /// <see cref="WebDavDiskStoreCollection" /> that contains this /// <see cref="WebDavDiskStoreItem" />; /// or /// <c>null</c> if this is the root /// <see cref="WebDavDiskStoreCollection" />.</param> /// <param name="path">The path that this <see cref="WebDavDiskStoreItem" /> maps to.</param> /// <exception cref="System.ArgumentNullException">path</exception> /// <exception cref="ArgumentNullException"><paramref name="path" /> is <c>null</c> or empty.</exception> protected WebDavDiskStoreItem(WebDavDiskStoreCollection parentCollection, string path) : base(parentCollection, path) { if (String.IsNullOrWhiteSpace(path)) { throw new ArgumentNullException("path"); } _parentCollection = parentCollection; _path = path; Identity = (WindowsIdentity)Thread.GetData(Thread.GetNamedDataSlot(WebDavServer.HttpUser)); Log = LogManager.GetCurrentClassLogger(); }
/// <summary> /// Initializes a new instance of the <see cref="WebDavDiskStoreDocument" /> class. /// </summary> /// <param name="parentCollection">The parent /// <see cref="WebDavDiskStoreCollection" /> that contains this /// <see cref="WebDavDiskStoreItem" />; /// or /// <c>null</c> if this is the root /// <see cref="WebDavDiskStoreCollection" />.</param> /// <param name="path">The path that this <see cref="WebDavDiskStoreItem" /> maps to.</param> /// <exception cref="ArgumentNullException"><paramref name="path" /> is <c>null</c> or empty.</exception> public WebDavDiskStoreDocument(WebDavDiskStoreCollection parentCollection, string path) : base(parentCollection, path) { // Do nothing here }
/// <summary> /// Initializes a new instance of the <see cref="WebDavDiskStoreDocument" /> class. /// </summary> /// <param name="parentCollection"> /// The parent /// <see cref="WebDavDiskStoreCollection" /> that contains this /// <see cref="WebDavDiskStoreItem" />; /// or /// <c>null</c> if this is the root /// <see cref="WebDavDiskStoreCollection" />. /// </param> /// <param name="path">The path that this <see cref="WebDavDiskStoreItem" /> maps to.</param> /// <param name="store"></param> /// <exception cref="ArgumentNullException"><paramref name="path" /> is <c>null</c> or empty.</exception> public WebDavDiskStoreDocument(WebDavDiskStoreCollection parentCollection, string path, IWebDavStore store) : base(parentCollection, path, store) { // Do nothing here }
/// <summary> /// Initializes a new instance of the <see cref="WebDavDiskStoreCollection" /> class. /// </summary> /// <param name="parentCollection">The parent <see cref="WebDavDiskStoreCollection" /> that contains this <see cref="WebDavDiskStoreCollection" />.</param> /// <param name="path">The path to the folder on this that this <see cref="WebDavDiskStoreCollection" /> maps to.</param> public WebDavDiskStoreCollection(WebDavDiskStoreCollection parentCollection, string path) : base(parentCollection, path) { }
/// <summary> /// Moves an existing store item into this collection, overwriting any existing items. /// </summary> /// <param name="source">The store item to move.</param> /// <param name="destinationName">The /// <see cref="IWebDavStoreItem" /> that refers to the item that was moved, /// in its new location.</param> /// <returns> /// The moved <see cref="IWebDavStoreItem" /> instance. /// </returns> /// <exception cref="System.Exception">Path to the source item not defined.</exception> /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavUnauthorizedException">If the user is unauthorized or has no access</exception> /// <remarks> /// Note that the method should fail without creating or overwriting content in the /// target collection if the move cannot go through. /// </remarks> public IWebDavStoreItem MoveItemHere(IWebDavStoreItem source, string destinationName) { // try to get the path of the source item WebDavDiskStoreItem sourceItem = (WebDavDiskStoreItem)source; string sourceItemPath = sourceItem.ItemPath; if (sourceItemPath.Equals(string.Empty)) { throw new Exception("Path to the source item not defined."); } // We get the path of string destinationItemPath = Path.Combine(ItemPath, destinationName); // the moving of the item if (source.IsCollection) { try { // Impersonate the current user and move the directory WindowsImpersonationContext wic = Identity.Impersonate(); Directory.Move(sourceItemPath, destinationItemPath); wic.Undo(); } catch { throw new WebDavUnauthorizedException(); } // We return the moved file as a WebDAVDiskStoreDocument var collection = new WebDavDiskStoreCollection(this, destinationItemPath); _items.Add(destinationName, new WeakReference(collection)); return collection; } try { // Impersonate the current user and move the file WindowsImpersonationContext wic = Identity.Impersonate(); File.Move(sourceItemPath, destinationItemPath); wic.Undo(); } catch { throw new WebDavUnauthorizedException(); } // We return the moved file as a WebDAVDiskStoreDocument WebDavDiskStoreDocument document = new WebDavDiskStoreDocument(this, destinationItemPath); _items.Add(destinationName, new WeakReference(document)); return document; }
/// <summary> /// Copies an existing store item into this collection, overwriting any existing items. /// </summary> /// <param name="source">The store item to copy from.</param> /// <param name="destinationName">The name of the copy to create of <paramref name="source" />.</param> /// <param name="includeContent">The boolean for copying the containing files/folders or not.</param> /// <returns> /// The created <see cref="IWebDavStoreItem" /> instance. /// </returns> /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavUnauthorizedException">If the user is unauthorized or has no access</exception> public IWebDavStoreItem CopyItemHere(IWebDavStoreItem source, string destinationName, bool includeContent) { // We get the path of string destinationItemPath = Path.Combine(ItemPath, destinationName); // the moving of the item if (source.IsCollection) { try { // Impersonate the current user and move the directory WindowsImpersonationContext wic = Identity.Impersonate(); DirectoryCopy(source.ItemPath, destinationItemPath, true); wic.Undo(); } catch { throw new WebDavUnauthorizedException(); } // We return the moved file as a WebDAVDiskStoreDocument WebDavDiskStoreCollection collection = new WebDavDiskStoreCollection(this, destinationItemPath); _items.Add(destinationName, new WeakReference(collection)); return collection; } // We copy the file with an override. try { // Impersonate the current user and copy the file WindowsImpersonationContext wic = Identity.Impersonate(); File.Copy(source.ItemPath, destinationItemPath, true); wic.Undo(); } catch { throw new WebDavUnauthorizedException(); } // We return the moved file as a WebDAVDiskStoreDocument WebDavDiskStoreDocument document = new WebDavDiskStoreDocument(this, destinationItemPath); _items.Add(destinationName, new WeakReference(document)); return document; }
/// <summary> /// Initializes a new instance of the <see cref="WebDavDiskStoreCollection" /> class. /// </summary> /// <param name="parentCollection"> /// The parent <see cref="WebDavDiskStoreCollection" /> that contains this /// <see cref="WebDavDiskStoreCollection" />. /// </param> /// <param name="path">The path to the folder on this that this <see cref="WebDavDiskStoreCollection" /> maps to.</param> /// <param name="store"></param> public WebDavDiskStoreCollection(WebDavDiskStoreCollection parentCollection, string path, IWebDavStore store) : base(parentCollection, path, store) { }