本文整理汇总了C#中Agent.GetAzureStorageBlobContent方法的典型用法代码示例。如果您正苦于以下问题:C# Agent.GetAzureStorageBlobContent方法的具体用法?C# Agent.GetAzureStorageBlobContent怎么用?C# Agent.GetAzureStorageBlobContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Agent
的用法示例。
在下文中一共展示了Agent.GetAzureStorageBlobContent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DownloadBlobTest
/// <summary>
/// Parameters:
/// Block:
/// True for BlockBlob, false for PageBlob
/// </summary>
internal void DownloadBlobTest(Agent agent, string UploadFilePath, string DownloadDirPath, Microsoft.WindowsAzure.Storage.Blob.BlobType Type)
{
string NEW_CONTAINER_NAME = Utility.GenNameString("upload-");
string blobName = Path.GetFileName(UploadFilePath);
Collection<Dictionary<string, object>> comp = new Collection<Dictionary<string, object>>();
Dictionary<string, object> dic = Utility.GenComparisonData(StorageObjectType.Blob, blobName);
dic["BlobType"] = Type;
comp.Add(dic);
// create the container
CloudBlobContainer container = CommonStorageAccount.CreateCloudBlobClient().GetContainerReference(NEW_CONTAINER_NAME);
container.CreateIfNotExists();
try
{
bool bSuccess = false;
// upload the blob file
if (Type == Microsoft.WindowsAzure.Storage.Blob.BlobType.BlockBlob)
bSuccess = CommonBlobHelper.UploadFileToBlockBlob(NEW_CONTAINER_NAME, blobName, UploadFilePath);
else if (Type == Microsoft.WindowsAzure.Storage.Blob.BlobType.PageBlob)
bSuccess = CommonBlobHelper.UploadFileToPageBlob(NEW_CONTAINER_NAME, blobName, UploadFilePath);
Test.Assert(bSuccess, "upload file {0} to container {1} should succeed", UploadFilePath, NEW_CONTAINER_NAME);
//--------------Download operation--------------
string downloadFilePath = Path.Combine(DownloadDirPath, blobName);
Test.Assert(agent.GetAzureStorageBlobContent(blobName, downloadFilePath, NEW_CONTAINER_NAME),
Utility.GenComparisonData("GetAzureStorageBlobContent", true));
ICloudBlob blob = CommonBlobHelper.QueryBlob(NEW_CONTAINER_NAME, blobName);
CloudBlobUtil.PackBlobCompareData(blob, dic);
// Verification for returned values
agent.OutputValidation(comp);
Test.Assert(Helper.CompareTwoFiles(downloadFilePath, UploadFilePath),
String.Format("File '{0}' should be bit-wise identicial to '{1}'", downloadFilePath, UploadFilePath));
}
finally
{
// cleanup
container.DeleteIfExists();
}
}
示例2: DownloadBlobTestGB
internal void DownloadBlobTestGB(Agent agent, StorageBlob.BlobType blobType)
{
string uploadFilePath = @".\" + Utility.GenNameString("gbupload");
string downloadFilePath = @".\" + Utility.GenNameString("gbdownload");
string containerName = Utility.GenNameString("gbupload-");
string blobName = Path.GetFileName(uploadFilePath);
// create the container
StorageBlob.CloudBlobContainer container = blobUtil.CreateContainer(containerName);
// Generate a 512 bytes file which contains GB18030 characters
File.WriteAllText(uploadFilePath, GB18030String);
try
{
// create source blob
StorageBlob.ICloudBlob blob = CloudBlobUtil.GetBlob(container, blobName, blobType);
// upload file data
using (var fileStream = System.IO.File.OpenRead(uploadFilePath))
{
blob.UploadFromStream(fileStream);
}
//--------------Download operation--------------
Test.Assert(agent.GetAzureStorageBlobContent(blobName, downloadFilePath, containerName, true), "download blob should be successful");
// Check MD5
string localMd5 = Helper.GetFileContentMD5(downloadFilePath);
string uploadMd5 = Helper.GetFileContentMD5(uploadFilePath);
blob.FetchAttributes();
Test.Assert(localMd5 == uploadMd5, string.Format("blob content md5 should be {0}, and actualy it's {1}", localMd5, uploadMd5));
}
finally
{
// cleanup
container.DeleteIfExists();
File.Delete(uploadFilePath);
File.Delete(downloadFilePath);
}
}