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

            fullName = NormalizeFullName(fullName);
            string newFullName = GetDirectory(fullName) + newName;

            newFullName = NormalizeFullName(newFullName);

            if (newFullName.ToLowerInvariant() == fullName.ToLowerInvariant())
            {
                return(false);
            }

            bool done = provider.RenameFile(fullName, newFullName);

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

            SearchClass.RenameFile(provider.CurrentWiki, provider.GetType().FullName + "|" + fullName, provider.GetType().FullName + "|" + newFullName);

            Host.Instance.OnFileActivity(provider.GetType().FullName, fullName, newFullName, FileActivity.FileRenamed);

            return(true);
        }