using System.Collections.Generic;
using System.Text;
using System.Web;
using WebDAVSharp.Server.Adapters;
using WebDAVSharp.Server.Stores;
using WebDAVSharp.Server.Utilities;
namespace WebDAVSharp.Server.MethodHandlers
{
///
/// This class implements the DELETE HTTP method for WebDAV#.
///
internal class WebDavDeleteMethodHandler : WebDavMethodHandlerBase
{
#region Properties
///
/// Gets the collection of the names of the HTTP methods handled by this instance.
///
///
/// The names.
///
public override IEnumerable Names => new[]
{
"DELETE"
};
#endregion
#region Functions
///
/// Processes the request.
///
/// The through which the request came in from the client.
///
/// The
/// object containing both the request and response
/// objects to use.
///
/// The that the is hosting.
public override void ProcessRequest(WebDavServer server, IHttpListenerContext context, IWebDavStore store)
{
IWebDavStoreCollection collection;
// Get the parent collection of the item
collection = GetParentCollection(server, store, context.Request.Url);
// Get the item from the collection
IWebDavStoreItem item = GetItemFromCollection(collection, context.Request.Url);
if (store.LockSystem.GetLocks(item).Count > 0)
{
StringBuilder sb = new StringBuilder(3000);
sb.Append("" + context.Request.Url + "HTTP/1.1 423 Locked ");
byte[] responseBytes = Encoding.UTF8.GetBytes(sb.ToString());
context.Response.StatusCode = (int) WebDavStatusCode.MultiStatus;
context.Response.StatusDescription = HttpWorkerRequest.GetStatusDescription((int) WebDavStatusCode.MultiStatus);
// set the headers of the response
context.Response.ContentLength64 = responseBytes.Length;
context.Response.AdaptedInstance.ContentType = "text/xml";
// the body
context.Response.OutputStream.Write(responseBytes, 0, responseBytes.Length);
context.Response.Close();
}
// Deletes the item
collection.Delete(item);
context.SendSimpleResponse();
}
#endregion
}
}