Example #1
0
        /// <summary>
        /// Move the directory
        /// </summary>
        /// <param name="sourcePath">Path to the source directory</param>
        /// <param name="destinationPath">Path to the destination directory</param>
        /// <returns>A task that represents the completion of the operation</returns>
        protected virtual async Task MoveDirectoryAsync(string sourcePath, string destinationPath)
        {
            string fullSourcePath = GetFullPath(GetVirtualPath(sourcePath));

            destinationPath = GetFullPath(GetVirtualPath(_fileProvider.Combine(destinationPath, _fileProvider.GetDirectoryName(fullSourcePath))));

            if (destinationPath.IndexOf(fullSourcePath, StringComparison.InvariantCulture) == 0)
            {
                throw new Exception(GetLanguageResource("E_CannotMoveDirToChild"));
            }

            if (!_fileProvider.DirectoryExists(fullSourcePath))
            {
                throw new Exception(GetLanguageResource("E_MoveDirInvalisPath"));
            }

            if (_fileProvider.DirectoryExists(destinationPath))
            {
                throw new Exception(GetLanguageResource("E_DirAlreadyExists"));
            }

            try
            {
                _fileProvider.DirectoryMove(fullSourcePath, destinationPath);
                await HttpContext.Response.WriteAsync(GetSuccessResponse());
            }
            catch
            {
                throw new Exception($"{GetLanguageResource("E_MoveDir")} \"{sourcePath}\"");
            }
        }