private async Task <DirectoryEntries> ReadDirectoryEntriesAsyncCore(MessageLoop messageLoop = null) { var tcs = new TaskCompletionSource <DirectoryEntries>(); EventHandler <DirectoryEntries> handler = (s, e) => { tcs.TrySetResult(e); }; try { HandleReadDirectoryEntries += handler; if (MessageLoop == null && messageLoop == null) { ReadDirectoryEntries(); } else { Action <PPError> action = new Action <PPError>((e) => { var output = new ArrayOutputAdapterWithStorage <PPDirectoryEntry[]>(); var result = (PPError)PPBFileRef.ReadDirectoryEntries(this, output.PPArrayOutput, new BlockUntilComplete() ); var entries = new List <DirectoryEntry>(); foreach (var entry in output.Output) { entries.Add(new DirectoryEntry(entry)); } tcs.TrySetResult(new DirectoryEntries(result, entries.AsReadOnly())); } ); InvokeHelper(action, messageLoop); } return(await tcs.Task); } catch (Exception exc) { Console.WriteLine(exc.Message); tcs.SetException(exc); return(new DirectoryEntries(PPError.Aborted, new List <DirectoryEntry> ().AsReadOnly())); } finally { HandleReadDirectoryEntries -= handler; } }
private async Task <PPError> TouchAsyncCore(DateTime lastAccessTime, DateTime lastModifiedTime, MessageLoop messageLoop = null) { var tcs = new TaskCompletionSource <PPError>(); EventHandler <PPError> handler = (s, e) => { tcs.TrySetResult(e); }; try { HandleTouch += handler; if (MessageLoop == null && messageLoop == null) { Touch(lastAccessTime, lastModifiedTime); } else { Action <PPError> action = new Action <PPError>((e) => { var result = (PPError)PPBFileRef.Touch(this, PepperSharpUtils.ConvertToPepperTimestamp(lastAccessTime), PepperSharpUtils.ConvertToPepperTimestamp(lastModifiedTime), new BlockUntilComplete() ); tcs.TrySetResult(result); } ); InvokeHelper(action, messageLoop); } return(await tcs.Task); } catch (Exception exc) { Console.WriteLine(exc.Message); tcs.SetException(exc); return(PPError.Aborted); } finally { HandleTouch -= handler; } }
private async Task <FileInfo> QueryAsyncCore(MessageLoop messageLoop = null) { var tcs = new TaskCompletionSource <FileInfo>(); EventHandler <FileInfo> handler = (s, e) => { tcs.TrySetResult(e); }; try { HandleQuery += handler; if (MessageLoop == null && messageLoop == null) { Query(); } else { Action <PPError> action = new Action <PPError>((e) => { var fileInfo = new PPFileInfo(); var result = (PPError)PPBFileRef.Query(this, out fileInfo, new BlockUntilComplete() ); tcs.TrySetResult(new FileInfo(result, fileInfo)); } ); InvokeHelper(action, messageLoop); } return(await tcs.Task); } catch (Exception exc) { Console.WriteLine(exc.Message); tcs.SetException(exc); return(new FileInfo(PPError.Aborted, new PPFileInfo())); } finally { HandleQuery -= handler; } }
private async Task <PPError> RenameAsyncCore(FileRef newFileRef, MessageLoop messageLoop = null) { var tcs = new TaskCompletionSource <PPError>(); EventHandler <PPError> handler = (s, e) => { tcs.TrySetResult(e); }; try { HandleRename += handler; if (MessageLoop == null && messageLoop == null) { Rename(newFileRef); } else { Action <PPError> action = new Action <PPError>((e) => { var result = (PPError)PPBFileRef.Rename(this, newFileRef, new BlockUntilComplete() ); tcs.TrySetResult(result); } ); InvokeHelper(action, messageLoop); } return(await tcs.Task); } catch (Exception exc) { Console.WriteLine(exc.Message); tcs.SetException(exc); return(PPError.Aborted); } finally { HandleRename -= handler; } }
/// <summary> /// Touch() Updates time stamps for a file. You must have write access to the /// file if it exists in the external filesystem. /// </summary> /// <param name="lastAccessTime">The last time the file was accessed.</param> /// <param name="lastModifiedTime">The last time the file was modified.</param> /// <returns>Ok if all went well</returns> public PPError Touch(DateTime lastAccessTime, DateTime lastModifiedTime) => (PPError)PPBFileRef.Touch(this, PepperSharpUtils.ConvertToPepperTimestamp(lastAccessTime), PepperSharpUtils.ConvertToPepperTimestamp(lastModifiedTime), new CompletionCallback(OnTouch));
public FileRef(FileSystem fileSystem, string path) { handle = PPBFileRef.Create(fileSystem, Encoding.UTF8.GetBytes(path)); }
/// <summary> /// ReadDirectoryEntries() Reads all entries in the directory. /// </summary> /// <returns>Error code.</returns> PPError ReadDirectoryEntries() { var listCallback = new CompletionCallbackWithOutput <PPDirectoryEntry[], PPResource>(ListCallback, this); return((PPError)PPBFileRef.ReadDirectoryEntries(this, listCallback, listCallback)); }
/// <summary> /// Query() queries info about a file or directory. You must have access to /// read this file or directory if it exists in the external filesystem. /// </summary> /// <returns>Error code</returns> public PPError Query() { var ficb = new CompletionCallbackWithOutput <PPFileInfo>(OnQuery); return((PPError)PPBFileRef.Query(this, out ficb.OutputAdapter.output, ficb)); }
/// <summary> /// Rename() renames a file or directory. Argument <code>newFileRef</code> /// must refer to files in the same file system as in this object. It is an /// error to rename a file or directory that is in use. It is not valid to /// rename a file in the external file system. /// </summary> /// <param name="newFileRef">A <code>FileRef</code> corresponding to a new /// file reference.</param> /// <returns>Error code</returns> PPError Rename(FileRef newFileRef) => (PPError)PPBFileRef.Rename(this, newFileRef, new CompletionCallback(OnRename));
/// <summary> /// Delete() deletes a file or directory. If <code>FileRef</code> refers to /// a directory, then the directory must be empty. It is an error to delete a /// file or directory that is in use. It is not valid to delete a file in /// the external file system. /// </summary> /// <returns>Error code</returns> public PPError Delete() => (PPError)PPBFileRef.Delete(this, new CompletionCallback(OnDelete));
/// <summary> /// MakeDirectory() makes a new directory in the file system according to the /// given <code>makeDirectoryFlags</code>, which is a bit-mask of the /// <code>MakeDirectoryFlags</code> values. It is not valid to make a /// directory in the external file system. /// </summary> /// <param name="makeDirectoryFlags">A bit-mask of the /// <code>MakeDirectoryFlags</code> values.</param> /// <returns>Error code</returns> PPError MakeDirectory(MakeDirectoryFlags makeDirectoryFlags) => (PPError)PPBFileRef.MakeDirectory(this, (int)makeDirectoryFlags, new CompletionCallback(OnMakeDirectory));