예제 #1
0
      /// <summary>
      /// Rename a blob (folder, file etc.).
      /// </summary>
      /// <param name="blobStorage"></param>
      /// <param name="oldPath"></param>
      /// <param name="newPath"></param>
      /// <param name="cancellationToken"></param>
      /// <returns></returns>
      public static async Task RenameAsync(this IBlobStorage blobStorage,
         string oldPath, string newPath, CancellationToken cancellationToken = default)
      {
         if(oldPath is null)
            throw new ArgumentNullException(nameof(oldPath));
         if(newPath is null)
            throw new ArgumentNullException(nameof(newPath));

         //try to use extended client here
         if(blobStorage is IExtendedBlobStorage extendedBlobStorage)
         {
            await extendedBlobStorage.RenameAsync(oldPath, newPath, cancellationToken).ConfigureAwait(false);
         }
         else
         {
            //this needs to be done recursively
            foreach(Blob item in await blobStorage.ListAsync(oldPath, recurse: true).ConfigureAwait(false))
            {
               if(item.IsFile)
               {
                  string renamedPath = item.FullPath.Replace(oldPath, newPath);

                  await blobStorage.CopyToAsync(item, blobStorage, renamedPath, cancellationToken).ConfigureAwait(false);
                  await blobStorage.DeleteAsync(item, cancellationToken).ConfigureAwait(false);
               }
            }

            //rename self
            await blobStorage.CopyToAsync(oldPath, blobStorage, newPath, cancellationToken).ConfigureAwait(false);
            await blobStorage.DeleteAsync(oldPath, cancellationToken).ConfigureAwait(false);
         }


      }
예제 #2
0
        public async Task Open_copy_to_memory_stream_succeeds()
        {
            string id = await GetRandomStreamIdAsync();

            IBlobStorage ms = StorageFactory.Blobs.InMemory();

            //if this doesn't crash it means the returned stream is compatible with usual .net streaming
            await _storage.CopyToAsync(id, ms, id);
        }