public void Dispose() { if (FileRef != null) { FileRef.Dispose(); } GC.SuppressFinalize(this); }
/// <summary> /// AppendFileRangeToBody() is used to append part or /// all of a file, to be uploaded, to the request body. A content-length /// request header will be automatically generated. /// </summary> /// <param name="fileRef">A <code>FileRef</code> containing the file /// reference.</param> /// <param name="startOffset">An optional starting point offset within the /// file.</param> /// <param name="length">An optional number of bytes of the file to /// be included. If the value is -1, then the sub-range to upload extends /// to the end of the file.</param> /// <param name="utcExpectedLastModifiedTime">An optional last /// modified time stamp used to validate that the file was not modified since /// the given time before it was uploaded. The upload will fail with an error /// code of <code>ErrorFilechanged</code> if the file has been modified /// since the given time. If utcExpectedLastModifiedTime is null, then no /// validation is performed.</param> /// <returns>true if successful, false if any of the parameters are invalid.</returns> public bool AppendFileRangeToBody(FileRef fileRef, long startOffset, long length, DateTime?utcExpectedLastModifiedTime = null) => PPBURLRequestInfo.AppendFileToBody(this, fileRef, startOffset, length, (utcExpectedLastModifiedTime.HasValue) ? PepperSharpUtils.ConvertToPepperTimestamp(utcExpectedLastModifiedTime.Value) : 0) == PPBool.True;
private async Task <PPError> OpenAsyncCore(FileRef fileRef, FileOpenFlags openFlags, MessageLoop openLoop = null) { var tcs = new TaskCompletionSource <PPError>(); EventHandler <PPError> handler = (s, e) => { tcs.TrySetResult(e); }; try { HandleOpen += handler; if (MessageLoop == null && openLoop == null) { Open(fileRef, openFlags); } else { Action <PPError> action = new Action <PPError>((e) => { var result = (PPError)PPBFileIO.Open(this, fileRef, (int)openFlags, new BlockUntilComplete() ); tcs.TrySetResult(result); } ); InvokeHelper(action, openLoop); } return(await tcs.Task); } catch (Exception exc) { Console.WriteLine(exc.Message); tcs.SetException(exc); return(PPError.Aborted); } finally { HandleOpen -= 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> /// Open() opens the specified regular file for I/O according to the given /// open flags, which is a bit-mask of the FileOpenFlags values. Upon /// success, the corresponding file is classified as "in use" by this FileIO /// object until such time as the FileIO object is closed or destroyed. /// </summary> /// <param name="fileRef">A FileRef instance</param> /// <param name="openFlags">A bit-mask of <code>FileOpenFlags</code> values.</param> /// <param name="openLoop">Optional MessageLoop instance that can be used to post the command to</param> /// <returns>Error code</returns> public Task <PPError> OpenAsync(FileRef fileRef, FileOpenFlags openFlags, MessageLoop openLoop = null) => OpenAsyncCore(fileRef, openFlags, openLoop);
/// <summary> /// Open() opens the specified regular file for I/O according to the given /// open flags, which is a bit-mask of the FileOpenFlags values. Upon /// success, the corresponding file is classified as "in use" by this FileIO /// object until such time as the FileIO object is closed or destroyed. /// </summary> /// <param name="fileRef">A FileRef instance</param> /// <param name="openFlags">A bit-mask of <code>FileOpenFlags</code> values.</param> /// <returns>Error code</returns> public PPError Open(FileRef fileRef, FileOpenFlags openFlags) => (PPError)PPBFileIO.Open(this, fileRef, (int)openFlags, new CompletionCallback(OnOpen));
internal DirectoryEntry(PPDirectoryEntry directoryEntry) { FileRef = new FileRef(directoryEntry.file_ref); FileType = (FileType)directoryEntry.file_type; }
/// <summary> /// Rename() renames a file or directory asynchronously. 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> /// <param name="messageLoop">Optional MessageLoop instance used to run the command on.</param> /// <returns></returns> public Task <PPError> RenameAsync(FileRef newFileRef, MessageLoop messageLoop = null) => RenameAsyncCore(newFileRef, messageLoop);
/// <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> /// AppendFileToBody() is used to append an entire file, to be uploaded, to /// the request body. A content-length request header will be automatically /// generated. /// </summary> /// <param name="fileRef">A <code>FileRef</code> containing the file /// reference.</param> /// <param name="utcExpectedLastModifiedTime">An optional last /// modified time stamp used to validate that the file was not modified since /// the given time before it was uploaded. The upload will fail with an error /// code of <code>ErrorFilechanged</code> if the file has been modified /// since the given time. If utcExpectedLastModifiedTime is null, then no /// validation is performed.</param> /// <returns>true if successful, false if any of the parameters are invalid.</returns> public bool AppendFileToBody(FileRef fileRef, DateTime?utcExpectedLastModifiedTime = null) => AppendFileRangeToBody(fileRef, 0, -1, utcExpectedLastModifiedTime);