public void Delete(string id) { var container = CurrentCloudBlobClient.GetContainerReference(GetContainer(id)); var listOfBlobs = container.ListBlobs(GetPrefix(id)); Parallel.ForEach(listOfBlobs, item => { var blob = CurrentCloudBlobClient.GetBlobReferenceFromServer(item.StorageUri); blob.Delete(); }); }
public virtual Stream OpenReadOnly(string blobKey) { if (Exists(blobKey)) { //var container = this.CurrentCloudBlobClient.GetContainerReference(DefaultBlobContainerName); //var cloudBlob = container.GetBlobReferenceFromServer(blobKey); var cloudBlob = CurrentCloudBlobClient.GetBlobReferenceFromServer(GetUri(blobKey)); var stream = new MemoryStream(); cloudBlob.DownloadToStream(stream); if (stream.CanSeek) { stream.Seek(0, SeekOrigin.Begin); } return(stream); } else { return(null); } }
public void Rename(string id, string name) { var container = CurrentCloudBlobClient.GetContainerReference(GetContainer(id)); var prefix = GetPrefix(id); int index = prefix.LastIndexOf(CurrentCloudBlobClient.DefaultDelimiter, 1, StringComparison.Ordinal); var names = prefix.Split(new [] { CurrentCloudBlobClient.DefaultDelimiter }, StringSplitOptions.RemoveEmptyEntries); names[names.Length - 1] = name; var newPrefix = names.JoinStrings(CurrentCloudBlobClient.DefaultDelimiter); if (prefix.EndsWith(CurrentCloudBlobClient.DefaultDelimiter)) { newPrefix += CurrentCloudBlobClient.DefaultDelimiter; } var listOfBlobs = container.ListBlobs(prefix); Parallel.ForEach(listOfBlobs, item => { var oldBlob = CurrentCloudBlobClient.GetBlobReferenceFromServer(item.StorageUri); var newBlob = container.GetBlockBlobReference(oldBlob.Name.Replace(prefix, newPrefix)); newBlob.StartCopyFromBlob(item.Uri); oldBlob.Delete(); }); }
public virtual FolderItem GetFolderItemById(string itemId) { FolderItem retVal = this.ChangeTracker.TrackingEntries.Select(x => x.Entity) .OfType <FolderItem>() .FirstOrDefault(x => x.FolderItemId == itemId); if (retVal == null) { var cloudBlob = CurrentCloudBlobClient.GetBlobReferenceFromServer(GetUri(itemId)) as CloudBlockBlob; if (cloudBlob != null && cloudBlob.Exists()) { string folderItemTypeName = this._entityFactory.GetEntityTypeStringName(typeof(FolderItem)); retVal = this._entityFactory.CreateEntityForType(folderItemTypeName) as FolderItem; this.MapCloudBlob2FolderItem(cloudBlob, retVal); } if (retVal != null) { this.ChangeTracker.Attach(retVal); } } return(retVal); }