Ejemplo n.º 1
0
 public static async Task <byte[]> ReadAllBytesAsync(this IStorageRecord record, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var source = await record.CreateReadableStreamAsync(cancellationToken))
     {
         return(await source.ToByteArrayAsync(cancellationToken));
     }
 }
Ejemplo n.º 2
0
 public async Task CopyToAsync(
     IStorageRecord record,
     Stream destination,
     int?bufferSize     = null,
     IProgress progress = null,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     if (record is StorageRecord googleStorageRecord)
     {
         await googleStorageRecord.StorageRoot.DownloadRecordAsync(googleStorageRecord, destination, bufferSize, cancellationToken).ConfigureAwait(false);
     }
     else
     {
         throw new InvalidOperationException($"Invalid storage record of type {record.GetType()}");
     }
 }
Ejemplo n.º 3
0
        public static async Task CopyToAsync(
            this IStorageRecord record,
            Stream destination,
            int?bufferSize     = null,
            IProgress progress = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (record.GetStorageProvider().Features.TryGetFeature(out IRecordCopyFeature implementation))
            {
                await implementation.CopyToAsync(record, destination, bufferSize, progress, cancellationToken);
            }
            else
            {
                using (var buffer = await record.CreateReadableStreamAsync(cancellationToken))
                {
                    await buffer.CopyToAsync(destination, bufferSize ?? 8192, progress, cancellationToken);

                    await destination.FlushAsync();
                }
            }
        }
Ejemplo n.º 4
0
 public static void CopyTo(
     this IStorageRecord record,
     Stream destination,
     int?bufferSize     = null,
     IProgress progress = null)
 => record.CopyToAsync(destination, bufferSize, progress).GetAwaiter().GetResult();
Ejemplo n.º 5
0
 public static byte[] ReadAllBytes(this IStorageRecord record) => record.ReadAllBytesAsync().GetAwaiter().GetResult();
Ejemplo n.º 6
0
 public static IStorageRecord Rename(this IStorageRecord storageRecord, string name, IProgress progress = null) => storageRecord.RenameAsync(name, progress).GetAwaiter().GetResult();
Ejemplo n.º 7
0
 public static void UpdateContent(this IStorageRecord storageRecord, Stream contents, string contentType = null, IProgress progress = null)
 => storageRecord.UpdateContentAsync(contents, contentType, progress).GetAwaiter().GetResult();
Ejemplo n.º 8
0
 public static Stream CreateReadableStream(this IStorageRecord storageRecord) => storageRecord.CreateReadableStreamAsync().GetAwaiter().GetResult();
Ejemplo n.º 9
0
 public static void UpdateSecurity(
     this IStorageRecord record,
     IStorageSecurity storageSecurity,
     IProgress progress = null)
 => record.UpdateSecurityAsync(storageSecurity, progress).GetAwaiter().GetResult();