예제 #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);
        }
예제 #2
0
        /// <summary>
        /// Determines whether the client has submitted lock tokens for all locked files in the subtree.
        /// </summary>
        /// <returns>Returns <c>true</c> if lock tockens for all locked files in the subtree are submitted.</returns>
        internal bool ClientHasTokenForTree()
        {
            if (!ClientHasToken())
            {
                return(false);
            }

            foreach (IHierarchyItem child in GetChildren(new PropertyName[0]))
            {
                DavFolder childFolder = child as DavFolder;
                if (childFolder != null)
                {
                    if (!childFolder.ClientHasTokenForTree())
                    {
                        return(false);
                    }
                }
                else
                {
                    DavHierarchyItem childItem = child as DavHierarchyItem;
                    if (!childItem.ClientHasToken())
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
예제 #3
0
        protected static void FindLocksDown(IHierarchyItem root, bool skipShared)
        {
            IFolder folder = root as IFolder;

            if (folder != null)
            {
                foreach (IHierarchyItem child in folder.GetChildren(new PropertyName[0]))
                {
                    DavHierarchyItem dbchild = child as DavHierarchyItem;
                    if (dbchild.ItemHasLock(skipShared))
                    {
                        MultistatusException mex = new MultistatusException();
                        mex.AddInnerException(dbchild.Path, new LockedException());
                        throw mex;
                    }

                    FindLocksDown(child, skipShared);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Deletes this folder.
        /// </summary>
        /// <param name="multistatus">Container for errors.
        /// If some child file/folder fails to remove we report error in this container.</param>
        public override void Delete(MultistatusException multistatus)
        {
            DavFolder parent = GetParent();

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

            if (!ClientHasToken())
            {
                throw new LockedException();
            }

            bool deletedAllChildren = true;

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

            if (deletedAllChildren)
            {
                DeleteThisItem(parent);
            }
        }
예제 #5
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);
        }
예제 #6
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);
            }
        }
예제 #7
0
        internal DavFolder CopyThisItem(DavFolder destFolder, DavHierarchyItem destItem, string destName)
        {
            // returns created folder, if any, otherwise null
            DavFolder createdFolder = null;

            Guid destID;

            if (destItem == null)
            {
                // copy item
                string commandText =
                    @"INSERT INTO DMS_Folders(ID, Name, CreatedOn, ModifiedOn, ParentID, CreatorDisplayName, AutoVersion, AutoCheckedOut, TotalContentLength, Attributes)
                      SELECT @Identity, @Name, GETUTCDATE(), GETUTCDATE(), @Parent, CreatorDisplayName, AutoVersion, AutoCheckedOut, TotalContentLength, Attributes
                      FROM DMS_Folders
                      WHERE ID = @ItemId;
                                            
                      INSERT INTO DMS_Documents(ID, Name, CreatedOn, ModifiedOn, ParentID, FileContent, ContentType, SerialNumber, CreatorDisplayName, Comment, AutoVersion, AutoCheckedOut, TotalContentLength, LastChunkSaved, Attributes)
                      SELECT @Identity, @Name, GETUTCDATE(), GETUTCDATE(), @Parent, FileContent, ContentType, SerialNumber, CreatorDisplayName, Comment, AutoVersion, AutoCheckedOut, TotalContentLength, LastChunkSaved, Attributes
                      FROM DMS_Documents
                      WHERE ID = @ItemId";

                destID = Guid.NewGuid();
                Context.ExecuteNonQuery(
                    commandText,
                    "@Name", destName,
                    "@Parent", destFolder.ItemId,
                    "@ItemId", ItemId,
                    "@Identity", destID);

                destFolder.UpdateModified();

                if (this is IFolder)
                {
                    createdFolder = new DavFolder(
                        Context,
                        destID,
                        destFolder.ItemId,
                        destName,
                        destFolder.Path + EncodeUtil.EncodeUrlPart(destName) + "/",
                        DateTime.UtcNow,
                        DateTime.UtcNow, fileAttributes);
                }
            }
            else
            {
                // update existing destination
                destID = destItem.ItemId;

                string commandText =
                    @"UPDATE DMS_Folders SET ModifiedOn = GETUTCDATE()                                       
                                       FROM (SELECT * FROM DMS_Folders WHERE ID=@SrcID) src
                                       WHERE DMS_Folders.ID=@DestID ;
                                         
                                      UPDATE DMS_Documents SET ModifiedOn = GETUTCDATE()                                       
                                       , ContentType = src.ContentType
                                       FROM (SELECT * FROM DMS_Documents WHERE ID=@SrcID) src
                                       WHERE DMS_Documents.ID=@DestID";

                Context.ExecuteNonQuery(
                    commandText,
                    "@SrcID", ItemId,
                    "@DestID", destID);

                // remove old properties from the destination
                Context.ExecuteNonQuery(
                    "DELETE FROM DMS_DocumentProperties WHERE ItemId = @ItemId",
                    "@ItemId", destID);
            }

            // copy properties
            string command =
                @"INSERT INTO DMS_DocumentProperties(ItemId, Name, Namespace, PropVal)
                  SELECT @DestID, Name, Namespace, PropVal
                  FROM DMS_DocumentProperties
                  WHERE ItemId = @SrcID";

            Context.ExecuteNonQuery(
                command,
                "@SrcID", ItemId,
                "@DestID", destID);

            return(createdFolder);
        }