private async Task <Result <StorageFile> > ToNativeAsync(File file) { StorageFile storageFile; try { storageFile = await StorageFile.GetFileFromPathAsync(file.Path).AsTask().ConfigureAwait(false); } catch (FileNotFoundException e) { // The file does not exist Logger.Info(e); return(Result.Fail <StorageFile>(new FileNotFoundError("The file does not exist").CausedBy(e))); } catch (UnauthorizedAccessException e) { // Insufficient permission to access this folder. Logger.Info(e); return(Result.Fail <StorageFile>(new UnauthorizedAccessError("Insufficient permission to access this file.").CausedBy(e))); } catch (ArgumentException e) { // The path cannot be a relative path or a Uri. Logger.Info(e); return(Result.Fail <StorageFile>(new ArgumentError("The path cannot be a relative path or a Uri.").CausedBy(e))); } return(Result.Ok(storageFile)); }
public static async Task <Result <StorageFile> > ToNative(this File file) { Guard.IsNotNull(file, nameof(file)); StorageFile nativeFile; try { nativeFile = await StorageFile.GetFileFromPathAsync(file.Path).AsTask().ConfigureAwait(false); } catch (FileNotFoundException e) { // TODO include error information return(Result.Fail(new FileNotFoundError().CausedBy(e))); } catch (UnauthorizedAccessException e) { // TODO include error information return(Result.Fail(new UnauthorizedAccessError().CausedBy(e))); } catch (ArgumentException e) { // TODO include error information return(Result.Fail(new ArgumentError().CausedBy(e))); } return(Result.Ok <StorageFile>(nativeFile)); }
private async Task <StorageFile> ToNative(File file) { var path = file.Path.Replace('\\', '/'); var storageFile = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(path); return(storageFile); }
public async Task <File> WriteTextAsync(File file, string content) { var storageFile = await StorageFile.GetFileFromPathAsync(file.Path).AsTask().ConfigureAwait(false); await FileIO.WriteTextAsync(storageFile, content); return(file); }
public async Task <string> ReadTextAsync(File file) { var result = await file.ToNative().ConfigureAwait(false); if (result.IsFailed) { // TODO throw new Exception("Exception"); } var nativeFile = result.Value; return(await FileIO.ReadTextAsync(nativeFile).AsTask().ConfigureAwait(false)); }
public async Task WriteTextAsync(File file, string content) { var result = await file.ToNative().ConfigureAwait(false); if (result.IsFailed) { // TODO throw new Exception("Exception"); } var nativeFile = result.Value; await FileIO.WriteTextAsync(nativeFile, content).AsTask().ConfigureAwait(false); }
public async Task <Result <File> > CopyAsync(File source, Folder target) { Guard.ArgNotNull(source, nameof(source)); Guard.ArgNotNull(target, nameof(target)); var targetFolderTask = ToNativeAsync(target); var sourceFileTask = ToNativeAsync(source); await Task.WhenAll(targetFolderTask, sourceFileTask).ConfigureAwait(false); var result2 = Result.Merge(await targetFolderTask, await sourceFileTask); if (result2.IsFailed) { return(result2.ToResult <File>()); } var targetStorageFolder2 = (await targetFolderTask).Value; var sourceStorageFile2 = (await sourceFileTask).Value; var targetStorageFile = await sourceStorageFile2.CopyAsync(targetStorageFolder2).AsTask().ConfigureAwait(false); return(Result.Ok(new File(targetStorageFile.Path))); }
private Task <StorageFile> ToNative(File file) { var storageFile = StorageFile.GetFileFromPathAsync(file.Path).AsTask(); return(storageFile); }
public async Task <string> ReadTextAsync(File file) { var storageFile = await ToNative(file); return(await FileIO.ReadTextAsync(storageFile)); }