public Task <PCLStorage.IFile> CreateFileAsync(string desiredName, PCLStorage.CreationCollisionOption option, CancellationToken cancellationToken = default) { var file = new CustomFile { Name = desiredName, Path = System.IO.Path.Combine(DefaultPath, desiredName), Stream = File.Create(System.IO.Path.Combine(DefaultPath, desiredName)), }; return(Task.FromResult((PCLStorage.IFile)file)); }
/// <summary> /// Creates a file in this folder /// </summary> /// <param name="desiredName">The name of the file to create</param> /// <param name="option">Specifies how to behave if the specified file already exists</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The newly created file</returns> public async Task <IFile> CreateFileAsync(string desiredName, PCLStorage.CreationCollisionOption option, CancellationToken cancellationToken) { Requires.NotNullOrEmpty(desiredName, "desiredName"); StorageFile wrtFile; try { wrtFile = await _wrappedFolder.CreateFileAsync(desiredName, GetWinRTCreationCollisionOption(option)).AsTask(cancellationToken).ConfigureAwait(false); } catch (Exception ex) { if (ex.HResult == FILE_ALREADY_EXISTS) { // File already exists (and potentially other failures, not sure what the HResult represents) throw new IOException(ex.Message, ex); } throw; } return(new WinRTFile(wrtFile)); }
Windows.Storage.CreationCollisionOption GetWinRTCreationCollisionOption(PCLStorage.CreationCollisionOption option) { if (option == PCLStorage.CreationCollisionOption.GenerateUniqueName) { return(Windows.Storage.CreationCollisionOption.GenerateUniqueName); } else if (option == PCLStorage.CreationCollisionOption.ReplaceExisting) { return(Windows.Storage.CreationCollisionOption.ReplaceExisting); } else if (option == PCLStorage.CreationCollisionOption.FailIfExists) { return(Windows.Storage.CreationCollisionOption.FailIfExists); } else if (option == PCLStorage.CreationCollisionOption.OpenIfExists) { return(Windows.Storage.CreationCollisionOption.OpenIfExists); } else { throw new ArgumentException("Unrecognized CreationCollisionOption value: " + option); } }
public Task <PCLStorage.IFolder> CreateFolderAsync(string desiredName, PCLStorage.CreationCollisionOption option, CancellationToken cancellationToken = default) => throw new NotImplementedException();