/// <summary> /// Initializes a new instance of the <see cref="WebDAVStoreBase"/> class. /// </summary> /// <param name="root"> /// The root <see cref="IWebDAVStoreCollection"/>. /// </param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="root"/> is <c>null</c>.</para> /// </exception> protected WebDAVStoreBase(IWebDAVStoreCollection root) { if (root == null) { throw new ArgumentNullException("root"); } _Root = root; }
/// <summary> /// Initializes a new instance of the <see cref="WebDAVStoreItemBase"/> class. /// </summary> /// <param name="parentCollection"> /// The parent <see cref="IWebDAVStoreCollection"/> that contains this <see cref="IWebDAVStoreItem"/> implementation. /// </param> /// <param name="name"> /// The name of this <see cref="IWebDAVStoreItem"/> /// </param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="name"/> is <c>null</c>.</para> /// </exception> protected WebDAVStoreItemBase(IWebDAVStoreCollection parentCollection, string name) { if (StringEx.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException("name"); } _ParentCollection = parentCollection; _Name = name; }
/// <summary> /// Retrieves a store item through the specified <see cref="Uri"/> from the /// specified <see cref="WebDAVServer"/> and <see cref="IWebDAVStore"/>. /// </summary> /// <param name="uri"> /// The <see cref="Uri"/> to retrieve the store item for. /// </param> /// <param name="server"> /// The <see cref="WebDAVServer"/> that hosts the <paramref name="store"/>. /// </param> /// <param name="store"> /// The <see cref="IWebDAVStore"/> from which to retrieve the store item. /// </param> /// <returns> /// The retrieved store item. /// </returns> /// <exception cref="ArgumentNullException"> /// <para><paramref name="uri"/> is <c>null</c>.</para> /// <para><paramref name="server"/> is <c>null</c>.</para> /// <para><paramref name="store"/> is <c>null</c>.</para> /// </exception> /// <exception cref="HttpConflictException"> /// <para><paramref name="uri"/> refers to a document in a collection, where the collection does not exist.</para> /// </exception> /// <exception cref="HttpNotFoundException"> /// <para><paramref name="uri"/> refers to a document that does not exist.</para> /// </exception> public static IWebDAVStoreItem GetItem(this Uri uri, WebDAVServer server, IWebDAVStore store) { if (uri == null) { throw new ArgumentNullException("uri"); } if (server == null) { throw new ArgumentNullException("server"); } if (store == null) { throw new ArgumentNullException("store"); } Uri prefixUri = uri.GetPrefixUri(server); IWebDAVStoreCollection collection = store.Root; IWebDAVStoreItem item = null; if (prefixUri.Segments.Length == uri.Segments.Length) { return(collection); } for (int index = prefixUri.Segments.Length; index < uri.Segments.Length; index++) { string segmentName = uri.Segments[index]; IWebDAVStoreItem nextItem = collection.GetItemByName(segmentName.TrimEnd('/', '\\')); if (nextItem == null) { throw new HttpConflictException(); } if (index == uri.Segments.Length - 1) { item = nextItem; } else { collection = nextItem as IWebDAVStoreCollection; if (collection == null) { throw new HttpNotFoundException(); } } } if (item == null) { throw new HttpNotFoundException(); } return(item); }
/// <summary> /// Initializes a new instance of the <see cref="WebDAVDiskStore"/> class. /// </summary> /// <param name="rootPath"> /// The root path of a folder on disk to host in this <see cref="WebDAVDiskStore"/>. /// </param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="rootPath"/> is <c>null</c>.</para> /// </exception> /// <exception cref="DirectoryNotFoundException"> /// <para><paramref name="rootPath"/> specifies a folder that does not exist.</para> /// </exception> public WebDAVDiskStore(string rootPath) { if (rootPath == null) { throw new ArgumentNullException(rootPath); } if (!Directory.Exists(rootPath)) { throw new DirectoryNotFoundException(rootPath); } _RootPath = rootPath; _RootCollection = new WebDAVDiskStoreCollection(null, rootPath); }
private IWebDAVStoreCollection CopyCollection(IWebDAVStoreCollection source, string destinationName) { IWebDAVStoreItem existingItem = GetItemByName(destinationName); if (existingItem != null) { Delete(existingItem); } IWebDAVStoreCollection destination = CreateCollection(destinationName); foreach (IWebDAVStoreItem subItem in source.Items) { destination.CopyItemHere(subItem, subItem.Name); } return(destination); }
/// <summary> /// Initializes a new instance of the <see cref="WebDAVMemoryStoreItem"/> class. /// </summary> /// <param name="parentCollection">The parent <see cref="IWebDAVStoreCollection"/> that contains this <see cref="IWebDAVStoreItem"/> implementation.</param> /// <param name="name">The name of this <see cref="IWebDAVStoreItem"/></param> /// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> public WebDAVMemoryStoreItem(IWebDAVStoreCollection parentCollection, string name) : base(parentCollection, name) { // Do nothing here }
private void MoveCollection(WebDAVServer server, IHttpListenerContext context, IWebDAVStore store, IWebDAVStoreCollection source) { var destinationUri = new Uri(context.Request.Headers["Destination"]); var destinationParentCollection = destinationUri.GetParentUri().GetItem(server, store) as IWebDAVStoreCollection; if (destinationParentCollection == null) { throw new HttpConflictException(); } string destinationName = destinationUri.Segments.Last().TrimEnd('/', '\\'); var destination = destinationParentCollection.GetItemByName(destinationName); if (destination != null) { if (context.Request.Headers["Overwrite"] == "F") { throw new HttpException(HttpStatusCodes.ClientErrors.PreconditionFailed); } destinationParentCollection.Delete(destination); } destinationParentCollection.MoveItemHere(source, destinationName); context.SendSimpleResponse(HttpStatusCodes.Successful.Created); }