/// <summary> /// Constructs a web request to create a new block blob or page blob, or to update the content /// of an existing block blob. /// </summary> /// <param name="uri">The absolute URI to the blob.</param> /// <param name="timeout">The server timeout interval.</param> /// <param name="properties">The properties to set for the blob.</param> /// <param name="blobType">The type of the blob.</param> /// <param name="pageBlobSize">For a page blob, the size of the blob. This parameter is ignored /// for block blobs.</param> /// <param name="accessCondition">The access condition to apply to the request.</param> /// <returns>A web request to use to perform the operation.</returns> public static HttpRequestMessage Put(Uri uri, int? timeout, BlobProperties properties, BlobType blobType, long pageBlobSize, AccessCondition accessCondition, HttpContent content, OperationContext operationContext) { if (blobType == BlobType.Unspecified) { throw new InvalidOperationException(SR.UndefinedBlobType); } HttpRequestMessage request = HttpRequestMessageFactory.CreateRequestMessage(HttpMethod.Put, uri, timeout, null /* builder */, content, operationContext); if (properties.CacheControl != null) { request.Headers.CacheControl = CacheControlHeaderValue.Parse(properties.CacheControl); } if (content != null) { if (properties.ContentType != null) { content.Headers.ContentType = MediaTypeHeaderValue.Parse(properties.ContentType); } if (properties.ContentMD5 != null) { content.Headers.ContentMD5 = Convert.FromBase64String(properties.ContentMD5); } if (properties.ContentLanguage != null) { content.Headers.ContentLanguage.Add(properties.ContentLanguage); } if (properties.ContentEncoding != null) { content.Headers.ContentEncoding.Add(properties.ContentEncoding); } if (properties.ContentDisposition != null) { content.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse(properties.ContentDisposition); } } if (blobType == BlobType.PageBlob) { request.Headers.Add(Constants.HeaderConstants.BlobType, Constants.HeaderConstants.PageBlob); request.Headers.Add(Constants.HeaderConstants.BlobContentLengthHeader, pageBlobSize.ToString(NumberFormatInfo.InvariantInfo)); properties.Length = pageBlobSize; } else if (blobType == BlobType.BlockBlob) { request.Headers.Add(Constants.HeaderConstants.BlobType, Constants.HeaderConstants.BlockBlob); } else { request.Headers.Add(Constants.HeaderConstants.BlobType, Constants.HeaderConstants.AppendBlob); } request.ApplyAccessCondition(accessCondition); return request; }
public void ContentType(BlobType content) { var ticketBuilder = new PipeTicketBuilder(); ticketBuilder.ContentType = content; Assert.Equal(content, ticketBuilder.ContentType); }
internal static BlobRequestOptions ApplyDefaults(BlobRequestOptions options, BlobType blobType, CloudBlobClient serviceClient, bool applyExpiry = true) { BlobRequestOptions modifiedOptions = new BlobRequestOptions(options); modifiedOptions.RetryPolicy = modifiedOptions.RetryPolicy ?? serviceClient.RetryPolicy; modifiedOptions.ServerTimeout = modifiedOptions.ServerTimeout ?? serviceClient.ServerTimeout; modifiedOptions.MaximumExecutionTime = modifiedOptions.MaximumExecutionTime ?? serviceClient.MaximumExecutionTime; if (applyExpiry && !modifiedOptions.OperationExpiryTime.HasValue && modifiedOptions.MaximumExecutionTime.HasValue) { modifiedOptions.OperationExpiryTime = DateTime.Now + modifiedOptions.MaximumExecutionTime.Value; } #if WINDOWS_PHONE modifiedOptions.DisableContentMD5Validation = true; modifiedOptions.StoreBlobContentMD5 = false; modifiedOptions.UseTransactionalMD5 = false; #else modifiedOptions.DisableContentMD5Validation = modifiedOptions.DisableContentMD5Validation ?? false; modifiedOptions.StoreBlobContentMD5 = modifiedOptions.StoreBlobContentMD5 ?? (blobType == BlobType.BlockBlob); modifiedOptions.UseTransactionalMD5 = modifiedOptions.UseTransactionalMD5 ?? false; #endif return modifiedOptions; }
public static List<string> CreateBlobsTask(CloudBlobContainer container, int count, BlobType type) { string name; List<string> blobs = new List<string>(); for (int i = 0; i < count; i++) { switch (type) { case BlobType.BlockBlob: name = "bb" + Guid.NewGuid().ToString(); CloudBlockBlob blockBlob = container.GetBlockBlobReference(name); blockBlob.PutBlockListAsync(new string[] { }).Wait(); blobs.Add(name); break; case BlobType.PageBlob: name = "pb" + Guid.NewGuid().ToString(); CloudPageBlob pageBlob = container.GetPageBlobReference(name); pageBlob.CreateAsync(0).Wait(); blobs.Add(name); break; } } return blobs; }
private static CloudBlob GetCloudBlob(string containerName, string blobName, BlobType blobType) { CloudBlobClient client = GetCloudBlobClient(); CloudBlobContainer container = client.GetContainerReference(containerName); container.CreateIfNotExists(); CloudBlob cloudBlob; switch (blobType) { case BlobType.AppendBlob: cloudBlob = container.GetAppendBlobReference(blobName); break; case BlobType.BlockBlob: cloudBlob = container.GetBlockBlobReference(blobName); break; case BlobType.PageBlob: cloudBlob = container.GetPageBlobReference(blobName); break; case BlobType.Unspecified: default: throw new ArgumentException(string.Format("Invalid blob type {0}", blobType.ToString()), "blobType"); } return cloudBlob; }
public static ConsultResponse Consult(this GlobalMedicalFileConsultationPortTypeClient client, CommonInputType common, RoutingType routing, RetrieveTransactionRequestType detailValue, out ArchivingInfo archivingInfo) { var detail = new BlobType(); detail.Id = "_" + Guid.NewGuid().ToString(); detail.ContentType = "text/xml"; detail.ContentEncoding = "none"; var detailStream = new MemoryStream(); var serializer = new XmlSerializer(typeof(RetrieveTransactionRequestType)); serializer.Serialize(detailStream, detailValue); detail.Value = detailStream.ToArray(); ResponseReturnType super = client.Consult(common, routing, detail); archivingInfo = new ArchivingInfo(); archivingInfo.RequestDetail = detail; archivingInfo.RequestXadesT = null; archivingInfo.ResponseDetail = super.Detail; archivingInfo.ResponseXadesT = super.XadesT; var retVal = new ConsultResponse(); retVal.Common = super.CommonOutput; if (super.Detail.ContentType == "text/xml" && super.Detail.ContentEncoding == "none") { var reader = XmlReader.Create(new MemoryStream(super.Detail.Value)); var deserializer = new XmlSerializer(typeof(RetrieveTransactionResponseType)); if (deserializer.CanDeserialize(reader)) { retVal.DetailValue = deserializer.Deserialize(reader) as RetrieveTransactionResponseType; } } return retVal; }
public static async Task<List<string>> CreateBlobsAsync(CloudBlobContainer container, int count, BlobType type) { string name; List<string> blobs = new List<string>(); for (int i = 0; i < count; i++) { switch (type) { case BlobType.BlockBlob: name = "bb" + Guid.NewGuid().ToString(); CloudBlockBlob blockBlob = container.GetBlockBlobReference(name); await blockBlob.PutBlockListAsync(new string[] { }); blobs.Add(name); break; case BlobType.PageBlob: name = "pb" + Guid.NewGuid().ToString(); CloudPageBlob pageBlob = container.GetPageBlobReference(name); await pageBlob.CreateAsync(0); blobs.Add(name); break; case BlobType.AppendBlob: name = "ab" + Guid.NewGuid().ToString(); CloudAppendBlob appendBlob = container.GetAppendBlobReference(name); await appendBlob.CreateOrReplaceAsync(); blobs.Add(name); break; } } return blobs; }
/// <summary> /// /// </summary> /// <param name="blobId"></param> /// <param name="blobType"></param> /// <returns></returns> public static async Task<bool> StorageContainsBlobAsync(string blobId, BlobType blobType) { var file = await GetStoryFile(blobId, blobType); if (file == null) return false; var properties = await file.GetBasicPropertiesAsync(); return (properties.Size != 0); }
/// <summary> /// Initializes a new instance of the PipeTicket class. /// </summary> /// <param name="pipeId"></param> /// <param name="fxId"></param> /// <param name="srcPortId"></param> /// <param name="destPortId"></param> public PipeTicket(Guid pipeId, BlobType contentType, Guid srcElId, Guid srcPortId, Guid destElId, Guid destPortId) { PipeId = pipeId; ContentType = contentType; SrcElementId = srcElId; SrcPortId = srcPortId; DestElementId = destElId; DestPortId = destPortId; }
public static TestBlob DefineBlob(string name, bool isReplicated = false, int numSnapshots = 0, BlobType blobType = BlobType.BlockBlob, string copyDestination = "") { return new TestBlob { Name = name, IsReplicated = isReplicated, NumberOfSnapshots = numSnapshots, BlobType = blobType, CopyDestination = copyDestination, }; }
private SerializableCloudBlob(SerializationInfo info, StreamingContext context) { if (info == null) { throw new ArgumentNullException("info"); } this.blobUri = (Uri)info.GetValue(BlobUriName, typeof(Uri)); this.blobType = (BlobType)info.GetValue(BlobTypeName, typeof(BlobType)); this.CreateCloudBlobInstance(null); }
/// <summary> /// Constructs a web request to create a new block blob or page blob, or to update the content /// of an existing block blob. /// </summary> /// <param name="uri">The absolute URI to the blob.</param> /// <param name="timeout">The server timeout interval.</param> /// <param name="properties">The properties to set for the blob.</param> /// <param name="blobType">The type of the blob.</param> /// <param name="leaseId">The lease ID, if the blob has an active lease.</param> /// <param name="pageBlobSize">For a page blob, the size of the blob. This parameter is ignored /// for block blobs.</param> /// <returns>A web request to use to perform the operation.</returns> public static HttpWebRequest Put(Uri uri, int timeout, BlobProperties properties, BlobType blobType, string leaseId, long pageBlobSize) { if (blobType == BlobType.Unspecified) { throw new InvalidOperationException(SR.UndefinedBlobType); } HttpWebRequest request = CreateWebRequest(uri, timeout, null); request.Method = "PUT"; if (properties.CacheControl != null) { request.Headers.Add(HttpRequestHeader.CacheControl, properties.CacheControl); } if (properties.ContentType != null) { // Setting it using Headers is an exception request.ContentType = properties.ContentType; } if (properties.ContentMD5 != null) { request.Headers.Add(HttpRequestHeader.ContentMd5, properties.ContentMD5); } if (properties.ContentLanguage != null) { request.Headers.Add(HttpRequestHeader.ContentLanguage, properties.ContentLanguage); } if (properties.ContentEncoding != null) { request.Headers.Add(HttpRequestHeader.ContentEncoding, properties.ContentEncoding); } if (blobType == BlobType.PageBlob) { request.ContentLength = 0; request.Headers.Add(Constants.HeaderConstants.BlobType, Constants.HeaderConstants.PageBlob); request.Headers.Add(Constants.HeaderConstants.Size, pageBlobSize.ToString(NumberFormatInfo.InvariantInfo)); properties.Length = pageBlobSize; } else { request.Headers.Add(Constants.HeaderConstants.BlobType, Constants.HeaderConstants.BlockBlob); } Request.AddLeaseId(request, leaseId); return request; }
internal static BlobRequestOptions ApplyDefaults(BlobRequestOptions options, BlobType blobType, CloudBlobClient serviceClient) { BlobRequestOptions modifiedOptions = new BlobRequestOptions(options); modifiedOptions.RetryPolicy = modifiedOptions.RetryPolicy ?? serviceClient.RetryPolicy; modifiedOptions.ServerTimeout = modifiedOptions.ServerTimeout ?? serviceClient.ServerTimeout; modifiedOptions.MaximumExecutionTime = modifiedOptions.MaximumExecutionTime ?? serviceClient.MaximumExecutionTime; modifiedOptions.DisableContentMD5Validation = modifiedOptions.DisableContentMD5Validation ?? false; modifiedOptions.StoreBlobContentMD5 = modifiedOptions.StoreBlobContentMD5 ?? (blobType == BlobType.BlockBlob); modifiedOptions.UseTransactionalMD5 = modifiedOptions.UseTransactionalMD5 ?? false; return modifiedOptions; }
public static ResponseReturnType Consult(this GlobalMedicalFileConsultationPortTypeClient client, CommonInputType common, RoutingType routing, BlobType detail) { SendRequestType request = new SendRequestType(); request.CommonInput = common; request.Routing = routing; request.Detail = detail; //No xades required SendResponseType response = client.consultGlobalMedicalFile(request); if (response.Status.Code != "200") throw new InvalidOperationException(String.Format("eHealth returned the following status: {0}, {1}", response.Status.Code, response.Status.Message[0].Value)); //No xades returned return response.Return; }
public static HttpWebRequest PutBlobRequest(BlobContext context, string containerName, string blobName, BlobProperties properties, BlobType blobType, byte[] content, long pageBlobSize, AccessCondition accessCondition) { bool valid = BlobTests.ContainerNameValidator(containerName) && BlobTests.BlobNameValidator(blobName) && BlobTests.PutPropertiesValidator(properties) && BlobTestUtils.ContentValidator(content); bool fatal = !BlobTests.PutPropertiesValidator(properties); Uri uri = BlobTests.ConstructPutUri(context.Address, containerName, blobName); HttpWebRequest request = null; OperationContext opContext = new OperationContext(); try { request = BlobHttpWebRequestFactory.Put(uri, context.Timeout, properties, blobType, pageBlobSize, accessCondition, opContext); if (fatal) { Assert.Fail(); } } catch (InvalidOperationException) { if (valid) { Assert.Fail(); } } if (valid) { Assert.IsNotNull(request); Assert.IsNotNull(request.Method); Assert.AreEqual("PUT", request.Method); BlobTestUtils.VersionHeader(request, false); BlobTestUtils.ContentTypeHeader(request, null); BlobTestUtils.ContentDispositionHeader(request, properties.ContentDisposition); BlobTestUtils.ContentEncodingHeader(request, properties.ContentEncoding); BlobTestUtils.ContentLanguageHeader(request, null); BlobTestUtils.ContentMd5Header(request, null); BlobTestUtils.CacheControlHeader(request, null); BlobTestUtils.BlobTypeHeader(request, properties.BlobType); BlobTestUtils.BlobSizeHeader(request, (properties.BlobType == BlobType.PageBlob) ? properties.Length : (long?)null); } return request; }
public ICloudBlob GetCloudBlob(string blobName, BlobType blobType = BlobType.BlockBlob) { ICloudBlob cloudBlob; switch (blobType) { case BlobType.AppendBlob: cloudBlob = _blobContainer.GetAppendBlobReference(blobName); break; case BlobType.BlockBlob: cloudBlob = _blobContainer.GetBlockBlobReference(blobName); break; case BlobType.PageBlob: cloudBlob = _blobContainer.GetPageBlobReference(blobName); break; case BlobType.Unspecified: cloudBlob = _blobContainer.GetBlobReferenceFromServer(blobName); break; default: throw new ArgumentException($"Invalid blob type {blobType}", nameof(blobType)); } return cloudBlob; }
public bool EnqueueRequest(string absoluteFilePath, BlobType type, string blobName) { absoluteFilePath = Path.GetFullPath(absoluteFilePath); if (!string.IsNullOrEmpty(blobName) && Requests.Count > 0) { throw new ArgumentException(Resources.BlobNameShouldBeEmptyWhenUploading); } else { BlobName = blobName; Type = type; } if (!System.IO.File.Exists(absoluteFilePath)) { if (System.IO.Directory.Exists(absoluteFilePath)) { return false; } else { throw new ArgumentException(String.Format(Resources.FileNotFound, absoluteFilePath)); } } string dirPath = Path.GetDirectoryName(absoluteFilePath).ToLower(); if (string.IsNullOrEmpty(root) || !dirPath.StartsWith(root)) { root = GetCommonDirectory(root, dirPath); } Requests.Enqueue(absoluteFilePath); return true; }
private void ValidateRangeDecryption(BlobType type, int blobSize, int? blobOffset, int? length, int? verifyLength = null) { CloudBlobContainer container = GetRandomContainerReference(); try { container.Create(); byte[] buffer = GetRandomBuffer(blobSize); ICloudBlob blob = GetCloudBlobReference(type, container); // Create the Key to be used for wrapping. SymmetricKey aesKey = new SymmetricKey("symencryptionkey"); // Create the encryption policy to be used for upload. BlobEncryptionPolicy uploadPolicy = new BlobEncryptionPolicy(aesKey, null); // Set the encryption policy on the request options. BlobRequestOptions options = new BlobRequestOptions() { EncryptionPolicy = uploadPolicy }; // Upload the encrypted contents to the blob. MemoryStream stream = new MemoryStream(buffer); blob.UploadFromStream(stream, blobSize, null, options, null); // Download a range in the encrypted blob. MemoryStream outputStream = new MemoryStream(); blob.DownloadRangeToStream(outputStream, blobOffset, length, null, options, null); outputStream.Seek(0, SeekOrigin.Begin); if (length.HasValue) { if (verifyLength.HasValue) { Assert.AreEqual(verifyLength.Value, outputStream.Length); } else { Assert.AreEqual(length.Value, outputStream.Length); } } // Compare that the decrypted contents match the input data. byte[] outputArray = outputStream.ToArray(); for (int i = 0; i < outputArray.Length; i++) { int bufferOffset = (int) (blobOffset.HasValue ? blobOffset : 0); Assert.AreEqual(buffer[bufferOffset + i], outputArray[i]); } } finally { container.DeleteIfExists(); } }
private void DoBlobEncryptedWriteStreamTestAPM(BlobType type) { byte[] buffer = GetRandomBuffer(8 * 1024); CloudBlobContainer container = GetRandomContainerReference(); try { container.Create(); ICloudBlob blob = null; // Create the Key to be used for wrapping. SymmetricKey aesKey = new SymmetricKey("symencryptionkey"); // Create the encryption policy to be used for upload. BlobEncryptionPolicy uploadPolicy = new BlobEncryptionPolicy(aesKey, null); // Set the encryption policy on the request options. BlobRequestOptions uploadOptions = new BlobRequestOptions() { EncryptionPolicy = uploadPolicy }; OperationContext opContext = new OperationContext(); CloudBlobStream blobStream = null; using (AutoResetEvent waitHandle = new AutoResetEvent(false)) { IAsyncResult result; if (type == BlobType.BlockBlob) { blob = container.GetBlockBlobReference("blob1"); blob.StreamWriteSizeInBytes = 16 * 1024; result = ((CloudBlockBlob)blob).BeginOpenWrite(null, uploadOptions, opContext, ar => waitHandle.Set(), null); waitHandle.WaitOne(); blobStream = ((CloudBlockBlob)blob).EndOpenWrite(result); } else if (type == BlobType.PageBlob) { blob = container.GetPageBlobReference("blob1"); blob.StreamWriteSizeInBytes = 16 * 1024; result = ((CloudPageBlob)blob).BeginOpenWrite(40 * 1024, null, uploadOptions, opContext, ar => waitHandle.Set(), null); waitHandle.WaitOne(); blobStream = ((CloudPageBlob)blob).EndOpenWrite(result); } else { blob = container.GetAppendBlobReference("blob1"); blob.StreamWriteSizeInBytes = 16 * 1024; result = ((CloudAppendBlob)blob).BeginOpenWrite(true, null, uploadOptions, opContext, ar => waitHandle.Set(), null); waitHandle.WaitOne(); blobStream = ((CloudAppendBlob)blob).EndOpenWrite(result); } } using (MemoryStream wholeBlob = new MemoryStream()) { using (blobStream) { using (AutoResetEvent waitHandle = new AutoResetEvent(false)) { IAsyncResult result; for (int i = 0; i < 3; i++) { result = blobStream.BeginWrite( buffer, 0, buffer.Length, ar => waitHandle.Set(), null); waitHandle.WaitOne(); blobStream.EndWrite(result); wholeBlob.Write(buffer, 0, buffer.Length); } // Append and Page blobs have one extra call due to create. if (type == BlobType.BlockBlob) { Assert.AreEqual(1, opContext.RequestResults.Count); } else { Assert.AreEqual(2, opContext.RequestResults.Count); } result = blobStream.BeginWrite( buffer, 0, buffer.Length, ar => waitHandle.Set(), null); waitHandle.WaitOne(); blobStream.EndWrite(result); wholeBlob.Write(buffer, 0, buffer.Length); result = blobStream.BeginWrite( buffer, 0, buffer.Length, ar => waitHandle.Set(), null); waitHandle.WaitOne(); blobStream.EndWrite(result); wholeBlob.Write(buffer, 0, buffer.Length); // Append and Page blobs have one extra call due to create. if (type == BlobType.BlockBlob) { Assert.AreEqual(2, opContext.RequestResults.Count); } else { Assert.AreEqual(3, opContext.RequestResults.Count); } result = blobStream.BeginCommit( ar => waitHandle.Set(), null); waitHandle.WaitOne(); blobStream.EndCommit(result); Assert.AreEqual(4, opContext.RequestResults.Count); } } Assert.AreEqual(4, opContext.RequestResults.Count); using (MemoryStream downloadedBlob = new MemoryStream()) { blob.DownloadToStream(downloadedBlob, null, uploadOptions); TestHelper.AssertStreamsAreEqual(wholeBlob, downloadedBlob); } } } finally { container.DeleteIfExists(); } }
/// <summary> /// Internal Constructor. /// </summary> internal BlobProperties( DateTimeOffset lastModified, DateTimeOffset createdOn, IDictionary <string, string> metadata, string objectReplicationDestinationPolicyId, IList <ObjectReplicationPolicy> objectReplicationSourceProperties, BlobType blobType, DateTimeOffset copyCompletedOn, string copyStatusDescription, string copyId, string copyProgress, Uri copySource, CopyStatus?blobCopyStatus, bool isIncrementalCopy, string destinationSnapshot, LeaseDurationType leaseDuration, LeaseState leaseState, LeaseStatus leaseStatus, long contentLength, string contentType, ETag eTag, byte[] contentHash, string contentEncoding, string contentDisposition, string contentLanguage, string cacheControl, long blobSequenceNumber, string acceptRanges, int blobCommittedBlockCount, bool isServerEncrypted, string encryptionKeySha256, string encryptionScope, string accessTier, bool accessTierInferred, string archiveStatus, DateTimeOffset accessTierChangedOn, string versionId, bool isLatestVersion, long tagCount, DateTimeOffset expiresOn, bool isSealed, string rehydratePriority, DateTimeOffset lastAccessed, BlobImmutabilityPolicy immutabilityPolicy, bool hasLegalHold) { LastModified = lastModified; LeaseStatus = leaseStatus; ContentLength = contentLength; ContentType = contentType; ETag = eTag; LeaseState = leaseState; ContentEncoding = contentEncoding; ContentDisposition = contentDisposition; ContentLanguage = contentLanguage; CacheControl = cacheControl; BlobSequenceNumber = blobSequenceNumber; LeaseDuration = leaseDuration; AcceptRanges = acceptRanges; DestinationSnapshot = destinationSnapshot; BlobCommittedBlockCount = blobCommittedBlockCount; IsIncrementalCopy = isIncrementalCopy; IsServerEncrypted = isServerEncrypted; BlobCopyStatus = blobCopyStatus; EncryptionKeySha256 = encryptionKeySha256; CopySource = copySource; EncryptionScope = encryptionScope; CopyProgress = copyProgress; AccessTier = accessTier; CopyId = copyId; AccessTierInferred = accessTierInferred; CopyStatusDescription = copyStatusDescription; ArchiveStatus = archiveStatus; CopyCompletedOn = copyCompletedOn; AccessTierChangedOn = accessTierChangedOn; BlobType = blobType; VersionId = versionId; ObjectReplicationSourceProperties = objectReplicationSourceProperties; IsLatestVersion = isLatestVersion; ObjectReplicationDestinationPolicyId = objectReplicationDestinationPolicyId; TagCount = tagCount; Metadata = metadata; ExpiresOn = expiresOn; CreatedOn = createdOn; IsSealed = isSealed; RehydratePriority = rehydratePriority; ContentHash = contentHash; LastAccessed = lastAccessed; ImmutabilityPolicy = immutabilityPolicy; HasLegalHold = hasLegalHold; }
private static ICloudBlob GetCloudBlobReference(BlobType type, CloudBlobContainer container) { ICloudBlob blob; if (type == BlobType.BlockBlob) { blob = container.GetBlockBlobReference("blockblob"); } else if (type == BlobType.PageBlob) { blob = container.GetPageBlobReference("pageblob"); } else { blob = container.GetAppendBlobReference("appendblob"); } return blob; }
public static async Task <List <string> > CreateBlobs(CloudBlobContainer container, int count, BlobType type) { string name; List <string> blobs = new List <string>(); List <Task> tasks = new List <Task>(); for (int i = 0; i < count; i++) { switch (type) { case BlobType.BlockBlob: name = "bb" + Guid.NewGuid().ToString(); CloudBlockBlob blockBlob = container.GetBlockBlobReference(name); tasks.Add(Task.Run(() => blockBlob.PutBlockList(new string[] { }))); blobs.Add(name); break; case BlobType.PageBlob: name = "pb" + Guid.NewGuid().ToString(); CloudPageBlob pageBlob = container.GetPageBlobReference(name); tasks.Add(Task.Run(() => pageBlob.Create(0))); blobs.Add(name); break; case BlobType.AppendBlob: name = "ab" + Guid.NewGuid().ToString(); CloudAppendBlob appendBlob = container.GetAppendBlobReference(name); tasks.Add(Task.Run(() => appendBlob.CreateOrReplace())); blobs.Add(name); break; } } await Task.WhenAll(tasks); return(blobs); }
public async Task PutBlobScenarioTest(string containerName, string blobName, BlobProperties properties, BlobType blobType, byte[] content, HttpStatusCode?expectedError) { HttpRequestMessage request = BlobTests.PutBlobRequest(BlobContext, containerName, blobName, properties, blobType, content, content.Length, null); request.Content = new ByteArrayContent(content); Assert.IsTrue(request != null, "Failed to create HttpRequestMessage"); //HttpRequestHandler.SetContentLength(request, content.Length); using (HttpResponseMessage response = await BlobTestUtils.GetResponse(request, BlobContext)) { BlobTests.PutBlobResponse(response, BlobContext, expectedError); } }
public async Task HashTagsAutoCompleteTest() { // Create users SocialPlusClient client1 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); SocialPlusClient client2 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); string firstName1 = "Stan"; string lastName1 = "TopicMan"; string bio1 = string.Empty; PostUserResponse postUserResponse1 = await TestUtilities.DoLogin(client1, firstName1, lastName1, bio1); string auth1 = AuthHelper.CreateSocialPlusAuth(postUserResponse1.SessionToken); string firstName2 = "Emily"; string lastName2 = "Johnson"; string bio2 = string.Empty; PostUserResponse postUserResponse2 = await TestUtilities.DoLogin(client2, firstName2, lastName2, bio2); string auth2 = AuthHelper.CreateSocialPlusAuth(postUserResponse2.SessionToken); // First Topic by first user string topicTitle1 = "My Favorite Topic"; string topicText1 = "It is all about sports! #sports #NFL"; BlobType blobType1 = BlobType.Image; string blobHandle1 = "http://myBlobHandle/"; string language1 = "en-US"; string deepLink1 = "Sports!"; string categories1 = "sports, ncurrency"; string friendlyName1 = "Game On!"; string group1 = "mygroup"; PostTopicRequest postTopicRequest1 = new PostTopicRequest( publisherType: PublisherType.User, text: topicText1, title: topicTitle1, blobType: blobType1, blobHandle: blobHandle1, language: language1, deepLink: deepLink1, categories: categories1, friendlyName: friendlyName1, group: group1); HttpOperationResponse <PostTopicResponse> postTopicOperationResponse1 = await client1.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest1, authorization : auth1); // If the first post topic operation failed, clean up if (!postTopicOperationResponse1.Response.IsSuccessStatusCode) { await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : auth1); await client2.Users.DeleteUserWithHttpMessagesAsync(authorization : auth2); Assert.Fail("Failed to post first topic"); } // Delay to ensure that the topics are ordered correctly await Task.Delay(TestConstants.SearchDelay); // Second Topic by first user // Create a GUID for the word that we will test autocomplete against. // Reduce the size of the guid to fit into the query. Max size is 25. string guidstring = Guid.NewGuid().ToString().Substring(0, 24); string topicTitle2 = "My Second Favorite Topic"; string topicText2 = "It is all about food! #food" + " #" + guidstring + " #" + guidstring + guidstring; BlobType blobType2 = BlobType.Custom; string blobHandle2 = "http://myBlobHandle/"; string language2 = "en-US"; string deepLink2 = "Food!"; string categories2 = guidstring + " " + guidstring; string friendlyName2 = "Eat!"; string group2 = "mygroup"; PostTopicRequest postTopicRequest2 = new PostTopicRequest( publisherType: PublisherType.User, text: topicText2, title: topicTitle2, blobType: blobType2, blobHandle: blobHandle2, language: language2, deepLink: deepLink2, categories: categories2, friendlyName: friendlyName2, group: group2); HttpOperationResponse <PostTopicResponse> postTopicOperationResponse2 = await client1.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest2, authorization : auth2); // If the second post topic operation failed, clean up if (!postTopicOperationResponse2.Response.IsSuccessStatusCode) { // clean up user 1 and topic 1 await client1.Topics.DeleteTopicWithHttpMessagesAsync(postTopicOperationResponse1.Body.TopicHandle, auth1); await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : auth1); // clean up user 2 await client2.Users.DeleteUserWithHttpMessagesAsync(authorization : auth2); Assert.Fail("Failed to post second topic"); } await Task.Delay(TestConstants.SearchDelay); // Get Autocomplete HttpOperationResponse <IList <string> > autocompleteResponse1 = await client2.Hashtags.GetAutocompletedHashtagsWithHttpMessagesAsync(authorization : auth2, query : "#" + guidstring); // Clean up topics await client1.Topics.DeleteTopicWithHttpMessagesAsync(postTopicOperationResponse1.Body.TopicHandle, auth1); await client1.Topics.DeleteTopicWithHttpMessagesAsync(postTopicOperationResponse2.Body.TopicHandle, auth2); // Clean up users HttpOperationResponse <object> deleteUser1 = await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : auth1); HttpOperationResponse <object> deleteUser2 = await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : auth2); // Validate the Autocomplete part Assert.IsTrue(autocompleteResponse1.Response.IsSuccessStatusCode); Assert.IsNotNull(autocompleteResponse1, "Failed to get autocomplete hashtags"); Assert.IsNotNull(autocompleteResponse1.Body, "Failed to get autocomplete hashtags"); Assert.AreEqual(2, autocompleteResponse1.Body.Count); Assert.AreEqual("#" + guidstring, autocompleteResponse1.Body[0].ToString()); Assert.AreEqual("#" + guidstring + guidstring, autocompleteResponse1.Body[1].ToString()); }
public override bool SetAzureStorageBlobContent(string FileName, string ContainerName, BlobType Type, string BlobName = "", bool Force = true, int ConcurrentCount = -1) { PowerShell ps = GetPowerShellInstance(); AttachPipeline(ps); ps.AddCommand("Set-AzureStorageBlobContent"); if (!string.IsNullOrEmpty(FileName)) { ps.AddParameter("File", FileName); } if (!string.IsNullOrEmpty(BlobName)) { ps.AddParameter("Blob", BlobName); } ps.AddParameter("Container", ContainerName); if (Type == BlobType.BlockBlob) ps.AddParameter("BlobType", "Block"); else if (Type == BlobType.PageBlob) ps.AddParameter("BlobType", "Page"); if (ConcurrentCount != -1) { ps.AddParameter("ConcurrentCount", ConcurrentCount); } AddCommonParameters(ps, Force); Test.Info(CmdletLogFormat, MethodBase.GetCurrentMethod().Name, GetCommandLine(ps)); ParseBlobCollection(ps.Invoke()); ParseErrorMessages(ps); return !ps.HadErrors; }
internal static void GetBlobTier(BlobType blobType, string blobTierString, out StandardBlobTier?standardBlobTier, out PremiumPageBlobTier?premiumPageBlobTier) { throw new System.NotImplementedException(); }
/// <summary> /// Get a CloudBlob instance with the specified name and type in the given container. /// </summary> /// <param name="containerName">Container name.</param> /// <param name="blobName">Blob name.</param> /// <param name="blobType">Type of blob.</param> /// <returns>A <see cref="Task{T}"/> object of type <see cref="CloudBlob"/> that represents the asynchronous operation.</returns> public static async Task <CloudBlob> GetCloudBlobAsync(string containerName, string blobName, BlobType blobType) { CloudBlobClient client = GetCloudBlobClient(); CloudBlobContainer container = client.GetContainerReference(containerName); await container.CreateIfNotExistsAsync(); CloudBlob cloudBlob; switch (blobType) { case BlobType.AppendBlob: cloudBlob = container.GetAppendBlobReference(blobName); break; case BlobType.BlockBlob: cloudBlob = container.GetBlockBlobReference(blobName); break; case BlobType.PageBlob: cloudBlob = container.GetPageBlobReference(blobName); break; case BlobType.Unspecified: default: throw new ArgumentException(string.Format("Invalid blob type {0}", blobType.ToString()), "blobType"); } return(cloudBlob); }
public IBCBlobKey(uint token, BlobType type) { Token = token; Type = type; }
internal static BlobRequestOptions ApplyDefaults(BlobRequestOptions options, BlobType blobType, CloudBlobClient serviceClient, bool applyExpiry = true) { BlobRequestOptions modifiedOptions = new BlobRequestOptions(options); modifiedOptions.RetryPolicy = modifiedOptions.RetryPolicy ?? serviceClient.DefaultRequestOptions.RetryPolicy ?? BaseDefaultRequestOptions.RetryPolicy; modifiedOptions.AbsorbConditionalErrorsOnRetry = modifiedOptions.AbsorbConditionalErrorsOnRetry ?? serviceClient.DefaultRequestOptions.AbsorbConditionalErrorsOnRetry ?? BaseDefaultRequestOptions.AbsorbConditionalErrorsOnRetry; modifiedOptions.EncryptionPolicy = modifiedOptions.EncryptionPolicy ?? serviceClient.DefaultRequestOptions.EncryptionPolicy ?? BaseDefaultRequestOptions.EncryptionPolicy; modifiedOptions.RequireEncryption = modifiedOptions.RequireEncryption ?? serviceClient.DefaultRequestOptions.RequireEncryption ?? BaseDefaultRequestOptions.RequireEncryption; modifiedOptions.LocationMode = modifiedOptions.LocationMode ?? serviceClient.DefaultRequestOptions.LocationMode ?? BaseDefaultRequestOptions.LocationMode; modifiedOptions.ServerTimeout = modifiedOptions.ServerTimeout ?? serviceClient.DefaultRequestOptions.ServerTimeout ?? BaseDefaultRequestOptions.ServerTimeout; modifiedOptions.MaximumExecutionTime = modifiedOptions.MaximumExecutionTime ?? serviceClient.DefaultRequestOptions.MaximumExecutionTime ?? BaseDefaultRequestOptions.MaximumExecutionTime; modifiedOptions.ParallelOperationThreadCount = modifiedOptions.ParallelOperationThreadCount ?? serviceClient.DefaultRequestOptions.ParallelOperationThreadCount ?? BaseDefaultRequestOptions.ParallelOperationThreadCount; modifiedOptions.SingleBlobUploadThresholdInBytes = modifiedOptions.SingleBlobUploadThresholdInBytes ?? serviceClient.DefaultRequestOptions.SingleBlobUploadThresholdInBytes ?? BaseDefaultRequestOptions.SingleBlobUploadThresholdInBytes; if (applyExpiry && !modifiedOptions.OperationExpiryTime.HasValue && modifiedOptions.MaximumExecutionTime.HasValue) { modifiedOptions.OperationExpiryTime = DateTime.Now + modifiedOptions.MaximumExecutionTime.Value; } #if (WINDOWS_PHONE && WINDOWS_DESKTOP) || PORTABLE modifiedOptions.DisableContentMD5Validation = BaseDefaultRequestOptions.DisableContentMD5Validation; modifiedOptions.StoreBlobContentMD5 = BaseDefaultRequestOptions.StoreBlobContentMD5; modifiedOptions.UseTransactionalMD5 = BaseDefaultRequestOptions.UseTransactionalMD5; #else modifiedOptions.DisableContentMD5Validation = modifiedOptions.DisableContentMD5Validation ?? serviceClient.DefaultRequestOptions.DisableContentMD5Validation ?? BaseDefaultRequestOptions.DisableContentMD5Validation; modifiedOptions.StoreBlobContentMD5 = modifiedOptions.StoreBlobContentMD5 ?? serviceClient.DefaultRequestOptions.StoreBlobContentMD5 ?? (blobType == BlobType.BlockBlob); // must be computed modifiedOptions.UseTransactionalMD5 = modifiedOptions.UseTransactionalMD5 ?? serviceClient.DefaultRequestOptions.UseTransactionalMD5 ?? BaseDefaultRequestOptions.UseTransactionalMD5; #endif return(modifiedOptions); }
private void OnSerializingCallback(StreamingContext context) { cloudBlobUri = null == this.Blob? null : this.Blob.SnapshotQualifiedUri; cloudBlobType = null == this.Blob? BlobType.Unspecified : this.Blob.BlobType; }
/// <summary> /// Constructs a web request to create a new block blob or page blob, or to update the content /// of an existing block blob. /// </summary> /// <param name="uri">The absolute URI to the blob.</param> /// <param name="timeout">The server timeout interval.</param> /// <param name="properties">The properties to set for the blob.</param> /// <param name="blobType">The type of the blob.</param> /// <param name="pageBlobSize">For a page blob, the size of the blob. This parameter is ignored /// for block blobs.</param> /// <param name="accessCondition">The access condition to apply to the request.</param> /// <returns>A web request to use to perform the operation.</returns> public static StorageRequestMessage Put(Uri uri, int?timeout, BlobProperties properties, BlobType blobType, long pageBlobSize, AccessCondition accessCondition, HttpContent content, OperationContext operationContext, ICanonicalizer canonicalizer, StorageCredentials credentials) { if (blobType == BlobType.Unspecified) { throw new InvalidOperationException(SR.UndefinedBlobType); } StorageRequestMessage request = HttpRequestMessageFactory.CreateRequestMessage(HttpMethod.Put, uri, timeout, null /* builder */, content, operationContext, canonicalizer, credentials); if (properties.CacheControl != null) { request.Headers.CacheControl = CacheControlHeaderValue.Parse(properties.CacheControl); } if (content != null) { if (properties.ContentType != null) { content.Headers.ContentType = MediaTypeHeaderValue.Parse(properties.ContentType); } if (properties.ContentMD5 != null) { content.Headers.ContentMD5 = Convert.FromBase64String(properties.ContentMD5); } if (properties.ContentLanguage != null) { content.Headers.ContentLanguage.Add(properties.ContentLanguage); } if (properties.ContentEncoding != null) { content.Headers.ContentEncoding.Add(properties.ContentEncoding); } if (properties.ContentDisposition != null) { content.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse(properties.ContentDisposition); } } if (blobType == BlobType.PageBlob) { request.Headers.Add(Constants.HeaderConstants.BlobType, Constants.HeaderConstants.PageBlob); request.Headers.Add(Constants.HeaderConstants.BlobContentLengthHeader, pageBlobSize.ToString(NumberFormatInfo.InvariantInfo)); properties.Length = pageBlobSize; } else if (blobType == BlobType.BlockBlob) { request.Headers.Add(Constants.HeaderConstants.BlobType, Constants.HeaderConstants.BlockBlob); } else { request.Headers.Add(Constants.HeaderConstants.BlobType, Constants.HeaderConstants.AppendBlob); } request.ApplyAccessCondition(accessCondition); return(request); }
public static CloudBlob GetBlobReference(CloudBlobContainer container, string blobName, BlobType blobType) { switch (blobType) { case BlobType.BlockBlob: return(container.GetBlockBlobReference(blobName)); case BlobType.PageBlob: return(container.GetPageBlobReference(blobName)); case BlobType.AppendBlob: return(container.GetAppendBlobReference(blobName)); default: throw new ArgumentException(String.Format( CultureInfo.CurrentCulture, Resources.InvalidBlobType, blobType, blobName)); } }
public async Task AppPublishedCreateVerifyDeleteTopicTest() { // get the app handle string appHandle = ManageAppsUtils.GetAppHandle(TestConstants.EnvironmentName); if (appHandle == null) { // fail the test Assert.Fail("Failed to lookup appHandle"); } // Set up initial login etc SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl); var user = await TestUtilities.PostGenericUser(client); var auth = AuthHelper.CreateSocialPlusAuth(user.SessionToken); string userHandle = user.UserHandle; // add user as admin bool added = ManageAppsUtils.AddAdmin(TestConstants.EnvironmentName, appHandle, userHandle); if (!added) { // delete the user and fail the test await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth); Assert.Fail("Failed to set user as administrator"); } // create a topic string topicTitle = "My Favorite Topic"; string topicText = "It is all about sports!"; BlobType blobType = BlobType.Image; string blobHandle = "http://myBlobHandle/"; string language = "en-US"; string deepLink = "Sports!"; string categories = "sports, ncurrency"; string group = "mygroup"; PostTopicRequest postTopicRequest = new PostTopicRequest(publisherType: PublisherType.App, text: topicText, title: topicTitle, blobType: blobType, blobHandle: blobHandle, categories: categories, language: language, deepLink: deepLink, group: group); HttpOperationResponse <PostTopicResponse> postTopicOperationResponse = await client.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest, authorization : auth); // if create topic was a success, grab the topic handle, the topic, and delete the topic and user to cleanup string topicHandle = string.Empty; HttpOperationResponse <TopicView> getTopicOperationResponse = null; HttpOperationResponse <object> deleteTopicOperationResponse = null; HttpOperationResponse <object> deleteUserOperationResponse = null; bool?deleteAdminResult = null; if (postTopicOperationResponse.Response.IsSuccessStatusCode) { topicHandle = postTopicOperationResponse.Body.TopicHandle; getTopicOperationResponse = await client.Topics.GetTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth); deleteTopicOperationResponse = await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth); } // otherwise, delete the admin and the user deleteAdminResult = ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle); deleteUserOperationResponse = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth); // check everything went well Assert.IsTrue(postTopicOperationResponse.Response.IsSuccessStatusCode); Assert.IsTrue(getTopicOperationResponse.Response.IsSuccessStatusCode); Assert.IsTrue(deleteTopicOperationResponse.Response.IsSuccessStatusCode); Assert.IsTrue(deleteAdminResult.HasValue); Assert.IsTrue(deleteAdminResult.Value); Assert.IsTrue(deleteUserOperationResponse.Response.IsSuccessStatusCode); TopicView getTopicResponse = getTopicOperationResponse.Body; Assert.AreEqual(getTopicResponse.BlobHandle, blobHandle); Assert.AreEqual(getTopicResponse.BlobType, blobType); if (getTopicResponse.BlobUrl.Contains("images/" + blobHandle) == false) { Assert.Fail(blobHandle + "should be contained in this: " + getTopicResponse.BlobUrl); } Assert.AreEqual(getTopicResponse.Categories, categories); Assert.IsTrue(getTopicResponse.ContentStatus == ContentStatus.Active || getTopicResponse.ContentStatus == ContentStatus.Clean); Assert.AreEqual(getTopicResponse.DeepLink, deepLink); Assert.AreEqual(getTopicResponse.Group, group); Assert.AreEqual(getTopicResponse.Language, language); Assert.AreEqual(getTopicResponse.Liked, false); Assert.AreEqual(getTopicResponse.Pinned, false); Assert.AreEqual(getTopicResponse.PublisherType, PublisherType.App); Assert.AreEqual(getTopicResponse.Text, topicText); Assert.AreEqual(getTopicResponse.Title, topicTitle); Assert.AreEqual(getTopicResponse.TopicHandle, topicHandle); Assert.AreEqual(getTopicResponse.TotalComments, 0); Assert.AreEqual(getTopicResponse.TotalLikes, 0); // for app-published topics, the user is null Assert.AreEqual(getTopicResponse.User, null); }
/// <summary> /// Create blob in blob store and blob metadata in table store /// </summary> /// <param name="appHandle">App handle</param> /// <param name="userHandle">User handle</param> /// <param name="blobHandle">Blob handle</param> /// <param name="stream">Image stream</param> /// <param name="contentType">Content type</param> /// <param name="blobType">Blob type</param> /// <returns>Create blob task</returns> public async Task CreateBlob(string appHandle, string userHandle, string blobHandle, Stream stream, string contentType, BlobType blobType) { await this.blobsStore.InsertBlob(blobHandle, stream, contentType, TimeSpan.FromSeconds(CacheTTLInSec)); await this.blobsMetadataStore.InsertBlobMetadata(StorageConsistencyMode.Strong, appHandle, userHandle, blobHandle, stream.Length, contentType, blobType); }
public static List <string> CreateBlobsTask(CloudBlobContainer container, int count, BlobType type) { string name; List <string> blobs = new List <string>(); for (int i = 0; i < count; i++) { switch (type) { case BlobType.BlockBlob: name = "bb" + Guid.NewGuid().ToString(); CloudBlockBlob blockBlob = container.GetBlockBlobReference(name); blockBlob.PutBlockListAsync(new string[] { }).Wait(); blobs.Add(name); break; case BlobType.PageBlob: name = "pb" + Guid.NewGuid().ToString(); CloudPageBlob pageBlob = container.GetPageBlobReference(name); pageBlob.CreateAsync(0).Wait(); blobs.Add(name); break; case BlobType.AppendBlob: name = "ab" + Guid.NewGuid().ToString(); CloudAppendBlob appendBlob = container.GetAppendBlobReference(name); appendBlob.CreateOrReplaceAsync().Wait(); blobs.Add(name); break; } } return(blobs); }
public static CloudBlob GetBlobReference(CloudBlobContainer container, string blobName, BlobType blobType) { switch(blobType) { case BlobType.BlockBlob: return container.GetBlockBlobReference(blobName); case BlobType.PageBlob: return container.GetPageBlobReference(blobName); case BlobType.AppendBlob: return container.GetAppendBlobReference(blobName); default: throw new ArgumentException(String.Format( CultureInfo.CurrentCulture, Resources.InvalidBlobType, blobType, blobName)); } }
internal static extern bool CryptExportKey([In] IntPtr Key, [In] IntPtr ExpKey, [In] BlobType type, [In] uint Flags, [In] IntPtr Data, [In, Out] ref uint DataLen);
/// <summary> /// Parameters: /// Block: /// true for BlockBlob, false for PageBlob /// ConcurrentCount: /// -1 means use the default value /// </summary> public abstract bool SetAzureStorageBlobContent(string FileName, string ContainerName, BlobType Type, string BlobName = "", bool Force = true, int ConcurrentCount = -1, Hashtable properties = null, Hashtable metadata = null);
public static CloudBlob GetBlobReference(Uri blobUri, StorageCredentials storageCredentials, BlobType blobType) { switch (blobType) { case BlobType.BlockBlob: return(new CloudBlockBlob(blobUri, storageCredentials)); case BlobType.PageBlob: return(new CloudPageBlob(blobUri, storageCredentials)); case BlobType.AppendBlob: return(new CloudAppendBlob(blobUri, storageCredentials)); case BlobType.Unspecified: return(new CloudBlob(blobUri, storageCredentials)); default: throw new ArgumentException(String.Format( CultureInfo.CurrentCulture, Resources.InvalidBlobType, blobType, blobUri)); } }
public override bool SetAzureStorageBlobContent(string FileName, string ContainerName, BlobType Type, string BlobName = "", bool Force = true, int ConcurrentCount = -1, Hashtable properties = null, Hashtable metadata = null) { PowerShell ps = GetPowerShellInstance(); AttachPipeline(ps); ps.AddCommand("Set-AzureStorageBlobContent"); ps.BindParameter("File", FileName); ps.BindParameter("Blob", BlobName); ps.BindParameter("Container", ContainerName); ps.BindParameter("Properties", properties); ps.BindParameter("Metadata", metadata); if (Type == BlobType.BlockBlob) { ps.BindParameter("BlobType", "Block"); } else if (Type == BlobType.PageBlob) { ps.BindParameter("BlobType", "Page"); } if (ConcurrentCount != -1) { ps.BindParameter("ConcurrentCount", ConcurrentCount); } AddCommonParameters(ps, Force); Test.Info(CmdletLogFormat, MethodBase.GetCurrentMethod().Name, GetCommandLine(ps)); ParseBlobCollection(ps.Invoke()); ParseErrorMessages(ps); return(!ps.HadErrors); }
private TransferLocation GetDestinationTransferLocation(TransferLocation dirLocation, TransferEntry entry) { string destRelativePath = this.nameResolver.ResolveName(entry); AzureBlobEntry sourceBlobEntry = entry as AzureBlobEntry; switch (dirLocation.Type) { case TransferLocationType.AzureBlobDirectory: { AzureBlobDirectoryLocation blobDirLocation = dirLocation as AzureBlobDirectoryLocation; BlobType destBlobType = this.BlobType; if (sourceBlobEntry != null) { // if source is Azure blob storage, source and destination blob share the same blob type destBlobType = sourceBlobEntry.Blob.BlobType; } CloudBlob blob = null; switch (destBlobType) { case Blob.BlobType.BlockBlob: case Blob.BlobType.Unspecified: blob = blobDirLocation.BlobDirectory.GetBlockBlobReference(destRelativePath); break; case Blob.BlobType.PageBlob: blob = blobDirLocation.BlobDirectory.GetPageBlobReference(destRelativePath); break; case Blob.BlobType.AppendBlob: blob = blobDirLocation.BlobDirectory.GetAppendBlobReference(destRelativePath); break; } AzureBlobLocation retLocation = new AzureBlobLocation(blob); retLocation.BlobRequestOptions = blobDirLocation.BlobRequestOptions; return(retLocation); } case TransferLocationType.AzureFileDirectory: { AzureFileDirectoryLocation fileDirLocation = dirLocation as AzureFileDirectoryLocation; CloudFile file = fileDirLocation.FileDirectory.GetFileReference(destRelativePath); AzureFileLocation retLocation = new AzureFileLocation(file); retLocation.FileRequestOptions = fileDirLocation.FileRequestOptions; return(retLocation); } case TransferLocationType.LocalDirectory: { DirectoryLocation localDirLocation = dirLocation as DirectoryLocation; string path = Path.Combine(localDirLocation.DirectoryPath, destRelativePath); return(new FileLocation(path, destRelativePath)); } default: throw new ArgumentException("TransferLocationType"); } }
/// <summary> /// Constructs a web request to create a new block blob or page blob, or to update the content /// of an existing block blob. /// </summary> /// <param name="uri">A <see cref="System.Uri"/> specifying the absolute URI to the blob.</param> /// <param name="timeout">An integer specifying the server timeout interval.</param> /// <param name="properties">A <see cref="BlobProperties"/> object.</param> /// <param name="blobType">A <see cref="BlobType"/> enumeration value.</param> /// <param name="pageBlobSize">For a page blob, the size of the blob. This parameter is ignored /// for block blobs.</param> /// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the condition that must be met in order for the request to proceed.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param> /// <returns>A <see cref="System.Net.HttpWebRequest"/> object.</returns> public static HttpWebRequest Put(Uri uri, int?timeout, BlobProperties properties, BlobType blobType, long pageBlobSize, AccessCondition accessCondition, OperationContext operationContext) { CommonUtility.AssertNotNull("properties", properties); if (blobType == BlobType.Unspecified) { throw new InvalidOperationException(SR.UndefinedBlobType); } HttpWebRequest request = HttpWebRequestFactory.CreateWebRequest(WebRequestMethods.Http.Put, uri, timeout, null /* builder */, operationContext); if (properties.CacheControl != null) { request.Headers[HttpRequestHeader.CacheControl] = properties.CacheControl; } if (properties.ContentType != null) { // Setting it using Headers is an exception request.ContentType = properties.ContentType; } if (properties.ContentMD5 != null) { request.Headers[HttpRequestHeader.ContentMd5] = properties.ContentMD5; } if (properties.ContentLanguage != null) { request.Headers[HttpRequestHeader.ContentLanguage] = properties.ContentLanguage; } if (properties.ContentEncoding != null) { request.Headers[HttpRequestHeader.ContentEncoding] = properties.ContentEncoding; } if (properties.ContentDisposition != null) { request.Headers[Constants.HeaderConstants.ContentDispositionRequestHeader] = properties.ContentDisposition; } if (blobType == BlobType.PageBlob) { request.Headers[Constants.HeaderConstants.BlobType] = Constants.HeaderConstants.PageBlob; request.Headers[Constants.HeaderConstants.BlobContentLengthHeader] = pageBlobSize.ToString(NumberFormatInfo.InvariantInfo); properties.Length = pageBlobSize; } else { request.Headers[Constants.HeaderConstants.BlobType] = Constants.HeaderConstants.BlockBlob; } request.ApplyAccessCondition(accessCondition); return(request); }
public static CloudBlob GetBlobReference(Uri blobUri, StorageCredentials storageCredentials, BlobType blobType) { switch (blobType) { case BlobType.BlockBlob: return new CloudBlockBlob(blobUri, storageCredentials); case BlobType.PageBlob: return new CloudPageBlob(blobUri, storageCredentials); case BlobType.AppendBlob: return new CloudAppendBlob(blobUri, storageCredentials); case BlobType.Unspecified: return new CloudBlob(blobUri, storageCredentials); default: throw new ArgumentException(String.Format( CultureInfo.CurrentCulture, Resources.InvalidBlobType, blobType, blobUri)); } }
public void PutBlobScenarioTest(string containerName, string blobName, BlobProperties properties, BlobType blobType, byte[] content, HttpStatusCode? expectedError) { HttpWebRequest request = BlobTests.PutBlobRequest(BlobContext, containerName, blobName, properties, blobType, content, content.Length, null); Assert.IsTrue(request != null, "Failed to create HttpWebRequest"); request.ContentLength = content.Length; if (BlobContext.Credentials != null) { BlobTests.SignRequest(request, BlobContext); } BlobTestUtils.SetRequest(request, BlobContext, content); HttpWebResponse response = BlobTestUtils.GetResponse(request, BlobContext); try { BlobTests.PutBlobResponse(response, BlobContext, expectedError); } finally { response.Close(); } }
private void DoCloudBlobEncryptionWithStrictMode(BlobType type) { CloudBlobContainer container = GetRandomContainerReference(); try { container.Create(); int size = 5 * 1024 * 1024; byte[] buffer = GetRandomBuffer(size); ICloudBlob blob; if (type == BlobType.BlockBlob) { blob = container.GetBlockBlobReference("blob1"); } else { blob = container.GetPageBlobReference("blob1"); } // Create the Key to be used for wrapping. SymmetricKey aesKey = new SymmetricKey("symencryptionkey"); // Create the resolver to be used for unwrapping. DictionaryKeyResolver resolver = new DictionaryKeyResolver(); resolver.Add(aesKey); // Create the encryption policy to be used for upload. BlobEncryptionPolicy uploadPolicy = new BlobEncryptionPolicy(aesKey, null); // Set the encryption policy on the request options. BlobRequestOptions uploadOptions = new BlobRequestOptions() { EncryptionPolicy = uploadPolicy }; // Set RequireEncryption flag to true. uploadOptions.RequireEncryption = true; // Upload an encrypted blob with the policy set. MemoryStream stream = new MemoryStream(buffer); blob.UploadFromStream(stream, size, null, uploadOptions, null); // Upload the blob when RequireEncryption is true and no policy is set. This should throw an error. uploadOptions.EncryptionPolicy = null; stream = new MemoryStream(buffer); TestHelper.ExpectedException<InvalidOperationException>( () => blob.UploadFromStream(stream, size, null, uploadOptions, null), "Not specifying a policy when RequireEnryption is set to true should throw."); // Create the encryption policy to be used for download. BlobEncryptionPolicy downloadPolicy = new BlobEncryptionPolicy(null, resolver); // Set the encryption policy on the request options. BlobRequestOptions downloadOptions = new BlobRequestOptions() { EncryptionPolicy = downloadPolicy }; // Set RequireEncryption flag to true. downloadOptions.RequireEncryption = true; // Download the encrypted blob. MemoryStream outputStream = new MemoryStream(); blob.DownloadToStream(outputStream, null, downloadOptions, null); blob.Metadata.Clear(); // Upload a plain text blob. stream = new MemoryStream(buffer); blob.UploadFromStream(stream, size); // Try to download an encrypted blob with RequireEncryption set to true. This should throw. outputStream = new MemoryStream(); TestHelper.ExpectedException<StorageException>( () => blob.DownloadToStream(outputStream, null, downloadOptions, null), "Downloading with RequireEncryption set to true and no metadata on the service should fail."); // Set RequireEncryption to false and download. downloadOptions.RequireEncryption = false; blob.DownloadToStream(outputStream, null, downloadOptions, null); } finally { container.DeleteIfExists(); } }
public async Task AppPublishedTopicSearchTest() { // create the client SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl); // get the app handle string appHandle = ManageAppsUtils.GetAppHandle(TestConstants.EnvironmentName); if (string.IsNullOrWhiteSpace(appHandle)) { // fail the test Assert.Fail("Failed to lookup appHandle"); } // create a user var user = await TestUtilities.PostGenericUser(client); var auth = AuthHelper.CreateSocialPlusAuth(user.SessionToken); // get the user handle string userHandle = user.UserHandle; if (string.IsNullOrWhiteSpace(userHandle)) { // fail the test Assert.Fail("Failed to get userHandle"); } // elevate the user to admin bool added = ManageAppsUtils.AddAdmin(TestConstants.EnvironmentName, appHandle, userHandle); if (!added) { // delete the user and fail the test await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth); Assert.Fail("Failed to set user as administrator"); } // create a unique string to search on string unique = Guid.NewGuid().ToString().Replace("-", string.Empty); // post a topic published by the app string topicTitle = unique; string topicText = "Something"; BlobType blobType = BlobType.Unknown; string blobHandle = string.Empty; string language = "en-US"; string deepLink = string.Empty; string categories = string.Empty; string friendlyName = string.Empty; string group = string.Empty; PostTopicRequest postTopicRequest = new PostTopicRequest(publisherType: PublisherType.App, text: topicText, title: topicTitle, blobType: blobType, blobHandle: blobHandle, language: language, deepLink: deepLink, categories: categories, friendlyName: friendlyName, group: group); HttpOperationResponse <PostTopicResponse> postTopicOperationResponse = await client.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest, authorization : auth); // If the post topic operation failed, clean up if (postTopicOperationResponse == null || !postTopicOperationResponse.Response.IsSuccessStatusCode || postTopicOperationResponse.Body == null || string.IsNullOrWhiteSpace(postTopicOperationResponse.Body.TopicHandle)) { ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle); await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth); Assert.Fail("Failed to post topic"); } // Delay a bit to allow data to get into the search await Task.Delay(TestConstants.SearchDelay); // search for the single result HttpOperationResponse <FeedResponseTopicView> search = await client.Search.GetTopicsWithHttpMessagesAsync(query : unique, cursor : null, limit : 5, authorization : auth); // Clean up topic HttpOperationResponse <object> deleteTopic = await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : postTopicOperationResponse.Body.TopicHandle, authorization : auth); // Clean up first user bool deleteAdminResult = ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle); HttpOperationResponse <object> deleteUser = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth); // Verify search result Assert.IsNotNull(search); Assert.IsNotNull(search.Body); Assert.IsNotNull(search.Body.Data); Assert.AreEqual(1, search.Body.Data.Count); Assert.AreEqual(postTopicOperationResponse.Body.TopicHandle, search.Body.Data[0].TopicHandle); Assert.AreEqual(unique, search.Body.Data[0].Title); // Verify deletions Assert.IsNotNull(deleteTopic); Assert.IsTrue(deleteTopic.Response.IsSuccessStatusCode); Assert.IsTrue(deleteAdminResult); Assert.IsNotNull(deleteUser); Assert.IsTrue(deleteUser.Response.IsSuccessStatusCode); }
private static void DoCloudBlobEncryptionAPM(BlobType type, bool partial) { CloudBlobContainer container = GetRandomContainerReference(); try { container.Create(); int size = 5 * 1024 * 1024; byte[] buffer = GetRandomBuffer(size); if (partial) { size = 2 * 1024 * 1024; } ICloudBlob blob = GetCloudBlobReference(type, container); // Create the Key to be used for wrapping. SymmetricKey aesKey = new SymmetricKey("symencryptionkey"); // Create the resolver to be used for unwrapping. DictionaryKeyResolver resolver = new DictionaryKeyResolver(); resolver.Add(aesKey); // Create the encryption policy to be used for upload. BlobEncryptionPolicy uploadPolicy = new BlobEncryptionPolicy(aesKey, null); // Set the encryption policy on the request options. BlobRequestOptions uploadOptions = new BlobRequestOptions() { EncryptionPolicy = uploadPolicy }; MemoryStream stream; // Upload the encrypted contents to the blob. using (stream = new MemoryStream(buffer)) { using (AutoResetEvent waitHandle = new AutoResetEvent(false)) { ICancellableAsyncResult result = blob.BeginUploadFromStream( stream, size, null, uploadOptions, null, ar => waitHandle.Set(), null); waitHandle.WaitOne(); blob.EndUploadFromStream(result); } // Ensure that the user stream is open. Assert.IsTrue(stream.CanSeek); } // Download the encrypted blob. // Create the decryption policy to be used for download. There is no need to specify the encryption mode // and the key wrapper when the policy is only going to be used for downloads. BlobEncryptionPolicy downloadPolicy = new BlobEncryptionPolicy(null, resolver); // Set the decryption policy on the request options. BlobRequestOptions downloadOptions = new BlobRequestOptions() { EncryptionPolicy = downloadPolicy }; // Download and decrypt the encrypted contents from the blob. MemoryStream outputStream = new MemoryStream(); using (AutoResetEvent waitHandle = new AutoResetEvent(false)) { ICancellableAsyncResult result = blob.BeginDownloadToStream(outputStream, null, downloadOptions, null, ar => waitHandle.Set(), null); waitHandle.WaitOne(); blob.EndDownloadToStream(result); } // Ensure that the user stream is open. outputStream.Seek(0, SeekOrigin.Begin); // Compare that the decrypted contents match the input data. byte[] outputArray = outputStream.ToArray(); TestHelper.AssertBuffersAreEqualUptoIndex(outputArray, buffer, size - 1); } finally { container.DeleteIfExists(); } }
/// <summary> /// converts Alpha/Unicode values to Blob and vice versa. /// </summary> /// <param name="value"></param> /// <param name="srcAttr"></param> /// <param name="expectedType"></param> /// <returns></returns> internal static String convertArgs(String value, StorageAttribute srcAttr, StorageAttribute expectedType) { int key; object dotNetObj = null; bool invalidArg = false; if (srcAttr != StorageAttribute.DOTNET && expectedType == StorageAttribute.DOTNET) { //Convert Magic To DotNet key = _tempTableKey; dotNetObj = DNConvert.convertMagicToDotNet(value, srcAttr, DNConvert.getDefaultDotNetTypeForMagicType(value, srcAttr)); DNManager.getInstance().DNObjectsCollection.Update(key, dotNetObj); value = BlobType.createDotNetBlobPrefix(key); } else if (srcAttr == StorageAttribute.DOTNET && expectedType != StorageAttribute.DOTNET && expectedType != StorageAttribute.NONE) { //Convert DotNet to Magic key = BlobType.getKey(value); if (key != 0) { dotNetObj = DNManager.getInstance().DNObjectsCollection.GetDNObj(key); value = DNConvert.convertDotNetToMagic(dotNetObj, expectedType); } } else { switch (expectedType) { case StorageAttribute.ALPHA: case StorageAttribute.UNICODE: if (srcAttr == StorageAttribute.BLOB) { if (BlobType.isValidBlob(value)) { value = BlobType.getString(value); } } else if (!StorageAttributeCheck.IsTypeAlphaOrUnicode(srcAttr)) { invalidArg = true; } break; case StorageAttribute.NUMERIC: case StorageAttribute.DATE: case StorageAttribute.TIME: if (!StorageAttributeCheck.isTypeNumeric(srcAttr)) { invalidArg = true; } break; case StorageAttribute.BLOB: if (StorageAttributeCheck.IsTypeAlphaOrUnicode(srcAttr)) { char contentType = srcAttr == StorageAttribute.ALPHA ? BlobType.CONTENT_TYPE_ANSI : BlobType.CONTENT_TYPE_UNICODE; value = BlobType.createFromString(value, contentType); } else if (!StorageAttributeCheck.isTypeBlob(srcAttr)) { invalidArg = true; } break; } //If there is mismatch in attribute, take default value of expectd argument. if (invalidArg) { value = FieldDef.getMagicDefaultValue(expectedType); } } return(value); }
private void DoCloudBlobEncryption(BlobType type, bool partial) { CloudBlobContainer container = GetRandomContainerReference(); try { container.Create(); int size = 5 * 1024 * 1024; byte[] buffer = GetRandomBuffer(size); if (partial) { size = 2 * 1024 * 1024; } ICloudBlob blob; if (type == BlobType.BlockBlob) { blob = container.GetBlockBlobReference("blockblob"); } else if (type == BlobType.PageBlob) { blob = container.GetPageBlobReference("pageblob"); } else { blob = container.GetAppendBlobReference("appendblob"); } // Create the Key to be used for wrapping. SymmetricKey aesKey = new SymmetricKey("symencryptionkey"); // Create the resolver to be used for unwrapping. DictionaryKeyResolver resolver = new DictionaryKeyResolver(); resolver.Add(aesKey); // Create the encryption policy to be used for upload. BlobEncryptionPolicy uploadPolicy = new BlobEncryptionPolicy(aesKey, null); // Set the encryption policy on the request options. BlobRequestOptions uploadOptions = new BlobRequestOptions() { EncryptionPolicy = uploadPolicy }; MemoryStream stream; // Upload the encrypted contents to the blob. using (stream = new MemoryStream(buffer)) { blob.UploadFromStream(stream, size, null, uploadOptions, null); // Ensure that the user stream is open. Assert.IsTrue(stream.CanSeek); } // Download the encrypted blob. // Create the decryption policy to be used for download. There is no need to specify the // key when the policy is only going to be used for downloads. Resolver is sufficient. BlobEncryptionPolicy downloadPolicy = new BlobEncryptionPolicy(null, resolver); // Set the decryption policy on the request options. BlobRequestOptions downloadOptions = new BlobRequestOptions() { EncryptionPolicy = downloadPolicy }; // Download and decrypt the encrypted contents from the blob. MemoryStream outputStream = new MemoryStream(); blob.DownloadToStream(outputStream, null, downloadOptions, null); // Ensure that the user stream is open. outputStream.Seek(0, SeekOrigin.Begin); // Compare that the decrypted contents match the input data. byte[] outputArray = outputStream.ToArray(); TestHelper.AssertBuffersAreEqualUptoIndex(outputArray, buffer, size - 1); } finally { container.DeleteIfExists(); } }
public static async Task <List <string> > CreateBlobsAsync(CloudBlobContainer container, int count, BlobType type) { string name; List <string> blobs = new List <string>(); for (int i = 0; i < count; i++) { switch (type) { case BlobType.BlockBlob: name = "bb" + Guid.NewGuid().ToString(); CloudBlockBlob blockBlob = container.GetBlockBlobReference(name); await blockBlob.PutBlockListAsync(new string[] { }); blobs.Add(name); break; case BlobType.PageBlob: name = "pb" + Guid.NewGuid().ToString(); CloudPageBlob pageBlob = container.GetPageBlobReference(name); await pageBlob.CreateAsync(0); blobs.Add(name); break; } } return(blobs); }
public Web.Data.Blob getBlobById(int id, BlobType type) { return db.blobs .Where(x => x.blobID == id && x.type == type) .FirstOrDefault(); }
public async Task <string> SaveBlobAsync(string containerName, IFormFile file, BlobType blobType) { if (file == null) { return(null); } var fileName = file.FileName; var extension = Path.GetExtension(fileName); ValidateExtension(extension, blobType); var newFileName = $"{Path.GetFileNameWithoutExtension(file.FileName)}_{Guid.NewGuid()}{extension}"; using (var stream = file.OpenReadStream()) { var container = _blobServiceClient.GetBlobContainerClient(containerName); await container.CreateIfNotExistsAsync(); var blob = container.GetBlobClient(newFileName); var blobInfo = await blob.UploadAsync(stream); return($"{_storageAccountOptions.AccountUrl}{containerName}/{newFileName}"); } }
private CloudBlob GetDestBlob(IStorageBlobManagement destChannel, string destContainerName, string destBlobName, BlobType blobType) { NameUtil.ValidateContainerName(destContainerName); NameUtil.ValidateBlobName(destBlobName); CloudBlobContainer container = destChannel.GetContainerReference(destContainerName); CloudBlob destBlob = null; if (BlobType.PageBlob == blobType) { destBlob = container.GetPageBlobReference(destBlobName); } else if (BlobType.BlockBlob == blobType) { destBlob = container.GetBlockBlobReference(destBlobName); } else if (BlobType.AppendBlob == blobType) { destBlob = container.GetAppendBlobReference(destBlobName); } else { throw new ArgumentException(String.Format(Resources.InvalidBlobType, blobType, destBlobName)); } return destBlob; }
private void SetIcon(BlobType blobType) { transform.Find("BlobIcon").GetComponent <Image>().sprite = UiData.blobAssets[blobType].Icon; }
public void PutBlobScenarioTest(string containerName, string blobName, BlobProperties properties, BlobType blobType, byte[] content, HttpStatusCode?expectedError) { HttpWebRequest request = BlobTests.PutBlobRequest(BlobContext, containerName, blobName, properties, blobType, content, content.Length, null); Assert.IsTrue(request != null, "Failed to create HttpWebRequest"); request.ContentLength = content.Length; if (BlobContext.Credentials != null) { BlobTests.SignRequest(request, BlobContext); } BlobTestUtils.SetRequest(request, BlobContext, content); HttpWebResponse response = BlobTestUtils.GetResponse(request, BlobContext); try { BlobTests.PutBlobResponse(response, BlobContext, expectedError); } finally { response.Close(); } }
private CloudBlob GetDestBlob(IStorageBlobManagement destChannel, string destContainerName, string destBlobName, BlobType blobType) { NameUtil.ValidateContainerName(destContainerName); NameUtil.ValidateBlobName(destBlobName); CloudBlobContainer container = destChannel.GetContainerReference(destContainerName); CloudBlob destBlob = null; if (BlobType.PageBlob == blobType) { destBlob = container.GetPageBlobReference(destBlobName); } else if (BlobType.BlockBlob == blobType) { destBlob = container.GetBlockBlobReference(destBlobName); } else if (BlobType.AppendBlob == blobType) { destBlob = container.GetAppendBlobReference(destBlobName); } else { throw new ArgumentException(String.Format(Resources.InvalidBlobType, blobType, destBlobName)); } return(destBlob); }
public CloudBlob GetCloudBlob(string containerName, string dirName, string blobName, BlobType blobType, DateTimeOffset?snapshotTime = null) { using (var azOp = L.Begin("Get Azure Storage blob {0}/{1}/{2}", containerName, dirName, blobName)) { string blobPath = "{0}/{1}".F(dirName, blobName); try { GetCloudBlobClient(); CloudBlobContainer Container = BlobClient.GetContainerReference(containerName); Container.CreateIfNotExists(); CloudBlob cloudBlob; switch (blobType) { case BlobType.AppendBlob: cloudBlob = Container.GetAppendBlobReference(blobPath, snapshotTime); break; case BlobType.BlockBlob: cloudBlob = Container.GetBlockBlobReference(blobPath, snapshotTime); break; case BlobType.PageBlob: cloudBlob = Container.GetPageBlobReference(blobPath, snapshotTime); break; case BlobType.Unspecified: default: throw new ArgumentException(string.Format("Invalid blob type {0}", blobType.ToString()), "blobType"); } azOp.Complete(); return(cloudBlob); } catch (StorageException se) { if (RethrowExceptions) { throw se; } else { L.Error(se, "A storage error occurred getting/creating Azure Storage blob {bp} in container {cn}.", blobPath, containerName); return(null); } } catch (Exception e) { if (RethrowExceptions) { throw e; } else { L.Error(e, "An error occurred getting Azure Storage blob {bp} from container {cn}.", blobPath, containerName); return(null); } } } }
public static CloudBlob GetBlobReference(Uri blobUri, StorageCredentials credentials, BlobType blobType) { switch (blobType) { case BlobType.BlockBlob: return(new CloudBlockBlob(blobUri, credentials)); case BlobType.PageBlob: return(new CloudPageBlob(blobUri, credentials)); case BlobType.AppendBlob: return(new CloudAppendBlob(blobUri, credentials)); default: throw new InvalidOperationException( string.Format( CultureInfo.CurrentCulture, Resources.NotSupportedBlobType, blobType)); } }
public static string ToSerialString(this BlobType value) => value switch {