Exemple #1
0
        /// <summary>
        /// Copies this file to another folder.
        /// </summary>
        /// <param name="destFolder">Destination folder.</param>
        /// <param name="destName">New file name in destination folder.</param>
        /// <param name="deep">Is not used.</param>
        /// <param name="multistatus">Container for errors with items other than this file.</param>
        public override void CopyTo(
            IItemCollection destFolder,
            string destName,
            bool deep,
            MultistatusException multistatus)
        {
            DavFolder destDavFolder = destFolder as DavFolder;

            if (destFolder == null)
            {
                throw new DavException("Destination folder doesn't exist.", DavStatus.CONFLICT);
            }
            if (!destDavFolder.ClientHasToken())
            {
                throw new LockedException("Doesn't have token for destination folder.");
            }

            DavHierarchyItem destItem = destDavFolder.FindChild(destName);

            if (destItem != null)
            {
                try
                {
                    destItem.Delete(multistatus);
                }
                catch (DavException ex)
                {
                    multistatus.AddInnerException(destItem.Path, ex);
                    return;
                }
            }

            CopyThisItem(destDavFolder, null, destName);
        }
Exemple #2
0
        /// <summary>
        /// Copies this folder to another folder with option to rename it.
        /// </summary>
        /// <param name="destFolder">Folder to copy this folder to.</param>
        /// <param name="destName">New name of this folder.</param>
        /// <param name="deep">Whether children shall be copied.</param>
        /// <param name="multistatus">Container for errors. We put here errors which occur with
        /// individual items being copied.</param>
        public override void CopyTo(IItemCollection destFolder, string destName, bool deep, MultistatusException multistatus)
        {
            DavFolder destDavFolder = destFolder as DavFolder;

            if (destFolder == null)
            {
                throw new DavException("Destination folder doesn't exist", DavStatus.CONFLICT);
            }
            if (!destDavFolder.ClientHasToken())
            {
                throw new LockedException("Doesn't have token for destination folder.");
            }

            if (isRecursive(destDavFolder))
            {
                throw new DavException("Cannot copy folder to its subtree", DavStatus.FORBIDDEN);
            }

            IHierarchyItem destItem = destDavFolder.FindChild(destName);

            if (destItem != null)
            {
                try
                {
                    destItem.Delete(multistatus);
                }
                catch (DavException ex)
                {
                    multistatus.AddInnerException(destItem.Path, ex);
                    return;
                }
            }

            DavFolder newDestFolder = CopyThisItem(destDavFolder, null, destName);

            // copy children
            if (deep)
            {
                foreach (IHierarchyItem child in GetChildren(new PropertyName[0]))
                {
                    var dbchild = child as DavHierarchyItem;
                    try
                    {
                        dbchild.CopyTo(newDestFolder, child.Name, deep, multistatus);
                    }
                    catch (DavException ex)
                    {
                        multistatus.AddInnerException(dbchild.Path, ex);
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Moves this file to different folder and renames it.
        /// </summary>
        /// <param name="destFolder">Destination folder.</param>
        /// <param name="destName">New file name.</param>
        /// <param name="multistatus">Container for errors with items other than this file.</param>
        public override void MoveTo(IItemCollection destFolder, string destName, MultistatusException multistatus)
        {
            DavFolder destDavFolder = destFolder as DavFolder;

            if (destFolder == null)
            {
                throw new DavException("Destination folder doesn't exist.", DavStatus.CONFLICT);
            }

            DavFolder parent = GetParent();

            if (parent == null)
            {
                throw new DavException("Cannot move root.", DavStatus.CONFLICT);
            }
            if (!ClientHasToken() || !destDavFolder.ClientHasToken() || !parent.ClientHasToken())
            {
                throw new LockedException();
            }

            DavHierarchyItem destItem = destDavFolder.FindChild(destName);

            if (destItem != null)
            {
                try
                {
                    destItem.Delete(multistatus);
                }
                catch (DavException ex)
                {
                    multistatus.AddInnerException(destItem.Path, ex);
                    return;
                }
            }

            MoveThisItem(destDavFolder, destName, parent);
        }
Exemple #4
0
        /// <summary>
        /// Moves this folder to destination folder with option to rename.
        /// </summary>
        /// <param name="destFolder">Folder to copy this folder to.</param>
        /// <param name="destName">New name of this folder.</param>
        /// <param name="multistatus">Container for errors. We put here errors occurring while moving
        /// individual files/folders.</param>
        public override void MoveTo(IItemCollection destFolder, string destName, MultistatusException multistatus)
        {
            DavFolder destDavFolder = destFolder as DavFolder;

            if (destFolder == null)
            {
                throw new DavException("Destination folder doesn't exist", DavStatus.CONFLICT);
            }

            if (isRecursive(destDavFolder))
            {
                throw new DavException("Cannot move folder to its subtree", DavStatus.FORBIDDEN);
            }

            DavFolder parent = GetParent();

            if (parent == null)
            {
                throw new DavException("Cannot move root", DavStatus.CONFLICT);
            }
            if (!ClientHasToken() || !destDavFolder.ClientHasToken() || !parent.ClientHasToken())
            {
                throw new LockedException();
            }

            DavHierarchyItem destItem = destDavFolder.FindChild(destName);
            DavFolder        newDestFolder;

            // copy this folder
            if (destItem != null)
            {
                if (destItem is IFile)
                {
                    try
                    {
                        destItem.Delete(multistatus);
                    }
                    catch (DavException ex)
                    {
                        multistatus.AddInnerException(destItem.Path, ex);
                        return;
                    }

                    newDestFolder = CopyThisItem(destDavFolder, null, destName);
                }
                else
                {
                    newDestFolder = destItem as DavFolder;
                    if (newDestFolder == null)
                    {
                        multistatus.AddInnerException(
                            destItem.Path,
                            new DavException("Destionation item is not folder", DavStatus.CONFLICT));
                    }
                }
            }
            else
            {
                newDestFolder = CopyThisItem(destDavFolder, null, destName);
            }

            // move children
            bool movedAllChildren = true;

            foreach (IHierarchyItem child in GetChildren(new PropertyName[0]))
            {
                DavHierarchyItem dbchild = child as DavHierarchyItem;
                try
                {
                    dbchild.MoveTo(newDestFolder, child.Name, multistatus);
                }
                catch (DavException ex)
                {
                    multistatus.AddInnerException(dbchild.Path, ex);
                    movedAllChildren = false;
                }
            }

            if (movedAllChildren)
            {
                DeleteThisItem(parent);
            }
        }