예제 #1
0
        public override Task <StorageFolder> RenameAsync(
            string newName,
            NameCollisionOption options,
            CancellationToken cancellationToken = default
            )
        {
            _ = newName ?? throw new ArgumentNullException(nameof(newName));
            if (newName.Length == 0)
            {
                throw new ArgumentException(ExceptionStrings.String.CannotBeEmpty(), nameof(newName));
            }

            if (newName.Contains(PhysicalPathHelper.InvalidNewNameCharacters))
            {
                throw new ArgumentException(
                          ExceptionStrings.StorageFolder.NewNameContainsInvalidChar(FileSystem.PathInformation),
                          nameof(newName)
                          );
            }

            if (!EnumInfo.IsDefined(options))
            {
                throw new ArgumentException(ExceptionStrings.Enum.UndefinedValue(options), nameof(options));
            }

            var destinationPath = _fullParentPath?.Join(newName) ?? FileSystem.GetPath(newName);

            return(MoveAsync(destinationPath, options, cancellationToken));
        }
예제 #2
0
        public override async Task <StorageFile> RenameAsync(
            string newName,
            NameCollisionOption options,
            CancellationToken cancellationToken = default
            )
        {
            _ = newName ?? throw new ArgumentNullException(nameof(newName));
            if (newName.Length == 0)
            {
                throw new ArgumentException(ExceptionStrings.String.CannotBeEmpty(), nameof(newName));
            }

            if (newName.Contains(PhysicalPathHelper.InvalidNewNameCharacters))
            {
                throw new ArgumentException(
                          ExceptionStrings.StorageFile.NewNameContainsInvalidChar(FileSystem.PathInformation),
                          nameof(newName)
                          );
            }

            if (!EnumInfo.IsDefined(options))
            {
                throw new ArgumentException(ExceptionStrings.Enum.UndefinedValue(options), nameof(options));
            }

            var destinationPath = _fullParentPath.Join(newName).FullPath;
            var destinationFile = FileSystem.GetFile(destinationPath);

            var file = await FsHelper.GetFileAsync(_fullPath, cancellationToken).ConfigureAwait(false);

            await file
            .RenameAsync(newName, options.ToWinOptions())
            .AsTask(cancellationToken)
            .WithConvertedException()
            .ConfigureAwait(false);

            return(destinationFile);
        }