public static async Task <byte[]> ReadAllBytesAsync(this IFile file) { var a = await file.BeginLocalAccess(); Exception err = null; var r = new byte[0]; try { r = File.ReadAllBytes(a.LocalPath); } catch (Exception ex) { err = ex; } await a.End(); if (err != null) { throw new AggregateException(err); } return(r); }
public static async Task <bool> Copy(this IFile src, IFileSystem destFileSystem, string destPath) { #if PORTABLE return(false); #else IFile dest = null; var r = false; LocalFileAccess srcLocal = null; LocalFileAccess destLocal = null; try { dest = await destFileSystem.CreateFile(destPath, ""); srcLocal = await src.BeginLocalAccess(); destLocal = await dest.BeginLocalAccess(); var srcLocalPath = srcLocal.LocalPath; var destLocalPath = destLocal.LocalPath; System.IO.File.Copy(srcLocalPath, destLocalPath, overwrite: true); r = true; } catch (Exception ex) { Debug.WriteLine(ex); r = false; } if (srcLocal != null) { await srcLocal.End(); } if (destLocal != null) { await destLocal.End(); } return(r); // await Task.Factory.StartNew (() => { // // var fc = new NSFileCoordinator (filePresenterOrNil: null); // NSError coordErr; // // fc.CoordinateReadWrite ( // srcPath, NSFileCoordinatorReadingOptions.WithoutChanges, // destPath, NSFileCoordinatorWritingOptions.ForReplacing, // out coordErr, (readUrl, writeUrl) => { // // var r = false; // try { // File.Copy (readUrl.Path, writeUrl.Path, overwrite: true); // r = true; // } catch (Exception) { // r = false; // } // tcs.SetResult (r); // }); // }); #endif }