WebDAVDeleteMethodHandler.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Collections.Generic;
  2. using Mtp2Dav.WebDAVSharp.Server._1d2086a502937936ebc6bfe19cfa15d855be1c31.Adapters;
  3. using Mtp2Dav.WebDAVSharp.Server._1d2086a502937936ebc6bfe19cfa15d855be1c31.Stores;
  4. namespace Mtp2Dav.WebDAVSharp.Server._1d2086a502937936ebc6bfe19cfa15d855be1c31.MethodHandlers
  5. {
  6. /// <summary>
  7. /// This class implements the <c>DELETE</c> HTTP method for WebDAV#.
  8. /// </summary>
  9. internal class WebDavDeleteMethodHandler : WebDavMethodHandlerBase, IWebDavMethodHandler
  10. {
  11. /// <summary>
  12. /// Gets the collection of the names of the HTTP methods handled by this instance.
  13. /// </summary>
  14. /// <value>
  15. /// The names.
  16. /// </value>
  17. public IEnumerable<string> Names => new[]
  18. {
  19. "DELETE"
  20. };
  21. /// <summary>
  22. /// Processes the request.
  23. /// </summary>
  24. /// <param name="server">The <see cref="WebDavServer" /> through which the request came in from the client.</param>
  25. /// <param name="context">
  26. /// The
  27. /// <see cref="IHttpListenerContext" /> object containing both the request and response
  28. /// objects to use.
  29. /// </param>
  30. /// <param name="store">The <see cref="IWebDavStore" /> that the <see cref="WebDavServer" /> is hosting.</param>
  31. public void ProcessRequest(WebDavServer server, IHttpListenerContext context, IWebDavStore store)
  32. {
  33. // Get the parent collection of the item
  34. var collection = GetParentCollection(server, store, context.Request.Url);
  35. // Get the item from the collection
  36. var item = GetItemFromCollection(collection, context.Request.Url);
  37. // Deletes the item
  38. collection.Delete(item);
  39. context.SendSimpleResponse();
  40. }
  41. }
  42. }