/// <summary>
        /// Copies the item.
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="context">The context.</param>
        /// <param name="store">The store.</param>
        /// <param name="source">The source.</param>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavForbiddenException"></exception>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavPreconditionFailedException"></exception>
        private static void CopyItem(WebDavServer server, IHttpListenerContext context, IWebDavStore store,
                                     IWebDavStoreItem source)
        {
            Uri destinationUri = GetDestinationHeader(context.Request);
            IWebDavStoreCollection destinationParentCollection = GetParentCollection(server, store, destinationUri);

            bool copyContent = (GetDepthHeader(context.Request) != 0);
            bool isNew       = true;

            string           destinationName = destinationUri.GetLastSegment();
            IWebDavStoreItem destination     = destinationParentCollection.GetItemByName(destinationName);

            if (destination != null)
            {
                if (source.ItemPath == destination.ItemPath)
                {
                    throw new WebDavForbiddenException();
                }
                if (!GetOverwriteHeader(context.Request))
                {
                    throw new WebDavPreconditionFailedException();
                }
                if (destination is IWebDavStoreCollection)
                {
                    destinationParentCollection.Delete(destination);
                }
                isNew = false;
            }

            destinationParentCollection.CopyItemHere(source, destinationName, copyContent);

            context.SendSimpleResponse(isNew ? (int)HttpStatusCode.Created : (int)HttpStatusCode.NoContent);
        }
Esempio n. 2
0
        /// <summary>
        /// Copies the item.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="store">The store.</param>
        /// <param name="source">The source.</param>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavForbiddenException"></exception>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavPreconditionFailedException"></exception>
        private static void CopyItem(IWebDavContext context, IWebDavStore store, IWebDavStoreItem source)
        {
            Uri destinationUri = GetDestinationHeader(context.Request);
            IWebDavStoreCollection destinationParentCollection = GetParentCollection(store, context, destinationUri);

            bool copyContent = (GetDepthHeader(context.Request) != 0);
            bool isNew       = true;

            string           destinationName = Uri.UnescapeDataString(destinationUri.Segments.Last().TrimEnd('/', '\\'));
            IWebDavStoreItem destination     = destinationParentCollection.GetItemByName(destinationName);

            if (destination != null)
            {
                if (source.ItemPath == destination.ItemPath)
                {
                    throw new WebDavForbiddenException();
                }
                if (!GetOverwriteHeader(context.Request))
                {
                    throw new WebDavPreconditionFailedException();
                }
                if (destination is IWebDavStoreCollection)
                {
                    destinationParentCollection.Delete(destination);
                }
                isNew = false;
            }

            destinationParentCollection.CopyItemHere(source, destinationName, copyContent);

            var statusCode = isNew ? HttpStatusCode.Created : HttpStatusCode.NoContent;

            context.SetStatusCode(statusCode);
        }