Ejemplo n.º 1
0
        /// <summary>
        /// Renames a directory and re-indexes all contents.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="fullPath">The full path of the directory to rename.</param>
        /// <param name="newName">The new name of the directory.</param>
        /// <returns><c>true</c> if the directory was renamed, <c>false</c> otherwise.</returns>
        public static bool RenameDirectory(IFilesStorageProviderV40 provider, string fullPath, string newName)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (fullPath == null)
            {
                throw new ArgumentNullException("fullPath");
            }
            if (fullPath.Length == 0)
            {
                throw new ArgumentException("Cannot rename the root directory", "fullPath");
            }
            if (newName == null)
            {
                throw new ArgumentNullException("newName");
            }
            if (newName.Length == 0)
            {
                throw new ArgumentException("New Name cannot be empty", "newName");
            }

            fullPath = NormalizeFullPath(fullPath);
            string newFullPath = GetDirectory(fullPath) + newName;

            newFullPath = NormalizeFullPath(newFullPath);

            bool done = provider.RenameDirectory(fullPath, newFullPath);

            if (!done)
            {
                return(false);
            }

            MovePermissions(provider, fullPath, newFullPath);
            ReindexDirectory(provider, fullPath, newFullPath);

            Host.Instance.OnDirectoryActivity(provider.GetType().FullName, fullPath, newFullPath, FileActivity.DirectoryRenamed);

            return(true);
        }