Beispiel #1
0
        public override async Task CreateAsync(
            bool recursive,
            CreationCollisionOption options,
            CancellationToken cancellationToken = default
            )
        {
            if (!EnumInfo.IsDefined(options))
            {
                throw new ArgumentException(ExceptionStrings.Enum.UndefinedValue(options), nameof(options));
            }

            await EnsureNoConflictingFolderExistsAsync(cancellationToken).ConfigureAwait(false);

            WinStorageFolder parentFolder;

            if (recursive)
            {
                parentFolder = await FsHelper
                               .GetOrCreateFolderAsync(_fullParentPath, cancellationToken)
                               .ConfigureAwait(false);
            }
            else
            {
                parentFolder = await FsHelper
                               .GetFolderAsync(_fullParentPath, cancellationToken)
                               .ConfigureAwait(false);
            }

            await parentFolder
            .CreateFileAsync(_fullPath.Name, options.ToWinOptions())
            .AsTask(cancellationToken)
            .WithConvertedException()
            .ConfigureAwait(false);
        }
Beispiel #2
0
        public override async Task CreateAsync(
            bool recursive,
            CreationCollisionOption options,
            CancellationToken cancellationToken = default
            )
        {
            if (!EnumInfo.IsDefined(options))
            {
                throw new ArgumentException(ExceptionStrings.Enum.UndefinedValue(options), nameof(options));
            }

            // We cannot reasonably create a root directory with the Windows Storage API.
            // If someone tries to do so, we'll simply deny the call. In most cases, the root
            // folder will exist anyway.
            if (_fullParentPath is null)
            {
                throw new UnauthorizedAccessException();
            }

            await EnsureNoConflictingFileExistsAsync(cancellationToken).ConfigureAwait(false);

            WinStorageFolder parentFolder;

            if (recursive)
            {
                parentFolder = await FsHelper
                               .GetOrCreateFolderAsync(_fullParentPath, cancellationToken)
                               .ConfigureAwait(false);
            }
            else
            {
                parentFolder = await FsHelper
                               .GetFolderAsync(_fullParentPath, cancellationToken)
                               .ConfigureAwait(false);
            }

            await parentFolder
            .CreateFolderAsync(_fullPath.Name, options.ToWinOptions())
            .AsTask(cancellationToken)
            .WithConvertedException()
            .ConfigureAwait(false);
        }