예제 #1
0
 /// <summary>
 /// Reads <i>count</i> bytes from the large object. The only case when fewer bytes are read is when end of stream is reached.
 /// </summary>
 /// <param name="buffer">The buffer where read data should be stored.</param>
 /// <param name="offset">The offset in the buffer where the first byte should be read.</param>
 /// <param name="count">The maximum number of bytes that should be read.</param>
 /// <param name="cancellationToken">Cancellation token</param>
 /// <returns>How many bytes actually read, or 0 if end of file was already reached.</returns>
 public override Task <int> ReadAsync(byte[] buffer, int offset, int count,
                                      CancellationToken cancellationToken)
 => SynchronizationContextSwitcher.NoContext(async() =>
 {
     cancellationToken.ThrowIfCancellationRequested();
     return(await Read(buffer, offset, count, true));
 });
예제 #2
0
 /// <summary>
 /// Imports a large object to be stored as a large object in the database from a file stored on the backend. This requires superuser permissions.
 /// </summary>
 /// <param name="path">Path to read the file on the backend</param>
 /// <param name="oid">A preferred oid, or specify 0 if one should be automatically assigned</param>
 /// <param name="cancellationToken">Cancellation token.</param>
 public Task ImportRemoteAsync(string path, uint oid, CancellationToken cancellationToken)
 => SynchronizationContextSwitcher.NoContext(async() =>
 {
     cancellationToken.ThrowIfCancellationRequested();
     await ExecuteFunction <object>("lo_import", true, path, (int)oid);
 });
예제 #3
0
 /// <summary>
 /// Deletes a large object on the backend.
 /// </summary>
 /// <param name="oid">Oid of the object to delete</param>
 /// <param name="cancellationToken">Cancellation token.</param>
 public Task UnlinkAsync(uint oid, CancellationToken cancellationToken)
 => SynchronizationContextSwitcher.NoContext(async() =>
 {
     cancellationToken.ThrowIfCancellationRequested();
     await ExecuteFunction <object>("lo_unlink", true, (int)oid);
 });
예제 #4
0
 /// <summary>
 /// Opens a large object on the backend, returning a stream controlling this remote object.
 /// Note that this method, as well as operations on the stream must be wrapped inside a transaction.
 /// </summary>
 /// <param name="oid">Oid of the object</param>
 /// <param name="cancellationToken">Cancellation token.</param>
 /// <returns>An NpgsqlLargeObjectStream</returns>
 public Task <NpgsqlLargeObjectStream> OpenReadWriteAsync(uint oid, CancellationToken cancellationToken)
 => SynchronizationContextSwitcher.NoContext(async() =>
 {
     cancellationToken.ThrowIfCancellationRequested();
     return(await OpenReadWrite(oid, true));
 });
예제 #5
0
 public Task RollbackAsync(CancellationToken cancellationToken)
 => SynchronizationContextSwitcher.NoContext(async() =>
 {
     cancellationToken.ThrowIfCancellationRequested();
     await Rollback(true, cancellationToken);
 });
예제 #6
0
 /// <summary>
 /// Writes <i>count</i> bytes to the large object.
 /// </summary>
 /// <param name="buffer">The buffer to write data from.</param>
 /// <param name="offset">The offset in the buffer at which to begin copying bytes.</param>
 /// <param name="count">The number of bytes to write.</param>
 /// <param name="cancellationToken">Cancellation token.</param>
 public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
 => SynchronizationContextSwitcher.NoContext(async() =>
 {
     cancellationToken.ThrowIfCancellationRequested();
     await Write(buffer, offset, count, true);
 });