本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.GetAppendBlobReference方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlobContainer.GetAppendBlobReference方法的具体用法?C# CloudBlobContainer.GetAppendBlobReference怎么用?C# CloudBlobContainer.GetAppendBlobReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer
的用法示例。
在下文中一共展示了CloudBlobContainer.GetAppendBlobReference方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestAccess
private static void TestAccess(string sasToken, SharedAccessBlobPermissions permissions, SharedAccessBlobHeaders headers, CloudBlobContainer container, CloudBlob blob)
{
CloudBlob SASblob;
StorageCredentials credentials = string.IsNullOrEmpty(sasToken) ?
new StorageCredentials() :
new StorageCredentials(sasToken);
if (container != null)
{
container = new CloudBlobContainer(credentials.TransformUri(container.Uri));
if (blob.BlobType == BlobType.BlockBlob)
{
SASblob = container.GetBlockBlobReference(blob.Name);
}
else if (blob.BlobType == BlobType.PageBlob)
{
SASblob = container.GetPageBlobReference(blob.Name);
}
else
{
SASblob = container.GetAppendBlobReference(blob.Name);
}
}
else
{
if (blob.BlobType == BlobType.BlockBlob)
{
SASblob = new CloudBlockBlob(credentials.TransformUri(blob.Uri));
}
else if (blob.BlobType == BlobType.PageBlob)
{
SASblob = new CloudPageBlob(credentials.TransformUri(blob.Uri));
}
else
{
SASblob = new CloudAppendBlob(credentials.TransformUri(blob.Uri));
}
}
HttpStatusCode failureCode = sasToken == null ? HttpStatusCode.NotFound : HttpStatusCode.Forbidden;
// We want to ensure that 'create', 'add', and 'write' permissions all allow for correct writing of blobs, as is reasonable.
if (((permissions & SharedAccessBlobPermissions.Create) == SharedAccessBlobPermissions.Create) || ((permissions & SharedAccessBlobPermissions.Write) == SharedAccessBlobPermissions.Write))
{
if (blob.BlobType == BlobType.PageBlob)
{
CloudPageBlob SASpageBlob = (CloudPageBlob)SASblob;
SASpageBlob.Create(512);
CloudPageBlob pageBlob = (CloudPageBlob)blob;
byte[] buffer = new byte[512];
buffer[0] = 2; // random data
if (((permissions & SharedAccessBlobPermissions.Write) == SharedAccessBlobPermissions.Write))
{
SASpageBlob.UploadFromByteArray(buffer, 0, 512);
}
else
{
TestHelper.ExpectedException(
() => SASpageBlob.UploadFromByteArray(buffer, 0, 512),
"pageBlob SAS token without Write perms should not allow for writing/adding",
failureCode);
pageBlob.UploadFromByteArray(buffer, 0, 512);
}
}
else if (blob.BlobType == BlobType.BlockBlob)
{
if ((permissions & SharedAccessBlobPermissions.Write) == SharedAccessBlobPermissions.Write)
{
UploadText(SASblob, "blob", Encoding.UTF8);
}
else
{
TestHelper.ExpectedException(
() => UploadText(SASblob, "blob", Encoding.UTF8),
"Block blob SAS token without Write or perms should not allow for writing",
failureCode);
UploadText(blob, "blob", Encoding.UTF8);
}
}
else // append blob
{
// If the sas token contains Feb 2012, append won't be accepted
if (sasToken.Contains(Constants.VersionConstants.February2012))
{
UploadText(blob, "blob", Encoding.UTF8);
}
else
{
CloudAppendBlob SASAppendBlob = SASblob as CloudAppendBlob;
SASAppendBlob.CreateOrReplace();
byte[] textAsBytes = Encoding.UTF8.GetBytes("blob");
using (MemoryStream stream = new MemoryStream())
{
stream.Write(textAsBytes, 0, textAsBytes.Length);
stream.Seek(0, SeekOrigin.Begin);
if (((permissions & SharedAccessBlobPermissions.Add) == SharedAccessBlobPermissions.Add) || ((permissions & SharedAccessBlobPermissions.Write) == SharedAccessBlobPermissions.Write))
{
//.........这里部分代码省略.........
示例2: CreateBlobsAsync
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;
}
示例3: TestAccess
private static void TestAccess(string sasToken, SharedAccessBlobPermissions permissions, SharedAccessBlobHeaders headers, CloudBlobContainer container, CloudBlob blob)
{
StorageCredentials credentials = string.IsNullOrEmpty(sasToken) ?
new StorageCredentials() :
new StorageCredentials(sasToken);
if (container != null)
{
container = new CloudBlobContainer(credentials.TransformUri(container.Uri));
if (blob.BlobType == BlobType.BlockBlob)
{
blob = container.GetBlockBlobReference(blob.Name);
}
else if (blob.BlobType == BlobType.PageBlob)
{
blob = container.GetPageBlobReference(blob.Name);
}
else
{
blob = container.GetAppendBlobReference(blob.Name);
}
}
else
{
if (blob.BlobType == BlobType.BlockBlob)
{
blob = new CloudBlockBlob(credentials.TransformUri(blob.Uri));
}
else if (blob.BlobType == BlobType.PageBlob)
{
blob = new CloudPageBlob(credentials.TransformUri(blob.Uri));
}
else
{
blob = new CloudAppendBlob(credentials.TransformUri(blob.Uri));
}
}
if (container != null)
{
if ((permissions & SharedAccessBlobPermissions.List) == SharedAccessBlobPermissions.List)
{
container.ListBlobs().ToArray();
}
else
{
TestHelper.ExpectedException(
() => container.ListBlobs().ToArray(),
"List blobs while SAS does not allow for listing",
HttpStatusCode.NotFound);
}
}
if ((permissions & SharedAccessBlobPermissions.Read) == SharedAccessBlobPermissions.Read)
{
blob.FetchAttributes();
// Test headers
if (headers != null)
{
if (headers.CacheControl != null)
{
Assert.AreEqual(headers.CacheControl, blob.Properties.CacheControl);
}
if (headers.ContentDisposition != null)
{
Assert.AreEqual(headers.ContentDisposition, blob.Properties.ContentDisposition);
}
if (headers.ContentEncoding != null)
{
Assert.AreEqual(headers.ContentEncoding, blob.Properties.ContentEncoding);
}
if (headers.ContentLanguage != null)
{
Assert.AreEqual(headers.ContentLanguage, blob.Properties.ContentLanguage);
}
if (headers.ContentType != null)
{
Assert.AreEqual(headers.ContentType, blob.Properties.ContentType);
}
}
}
else
{
TestHelper.ExpectedException(
() => blob.FetchAttributes(),
"Fetch blob attributes while SAS does not allow for reading",
HttpStatusCode.NotFound);
}
if ((permissions & SharedAccessBlobPermissions.Write) == SharedAccessBlobPermissions.Write)
{
blob.SetMetadata();
}
else
{
//.........这里部分代码省略.........
示例4: GetCloudBlobReference
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;
}
示例5: CloudAppendBlobUploadFromStreamAsync
private async Task CloudAppendBlobUploadFromStreamAsync(CloudBlobContainer container, int size, AccessCondition accessCondition, OperationContext operationContext, int startOffset)
{
byte[] buffer = GetRandomBuffer(size);
CloudAppendBlob blob = container.GetAppendBlobReference("blob1");
await blob.CreateOrReplaceAsync();
using (MemoryStream originalBlobStream = new MemoryStream())
{
originalBlobStream.Write(buffer, startOffset, buffer.Length - startOffset);
using (MemoryStream sourceStream = new MemoryStream(buffer))
{
sourceStream.Seek(startOffset, SeekOrigin.Begin);
await blob.AppendBlockAsync(sourceStream, null, accessCondition, null, operationContext);
}
using (MemoryStream downloadedBlobStream = new MemoryStream())
{
await blob.DownloadToStreamAsync(downloadedBlobStream);
TestHelper.AssertStreamsAreEqualAtIndex(
originalBlobStream,
downloadedBlobStream,
0,
0,
(int)originalBlobStream.Length);
}
}
}
示例6: GetBlobReference
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));
}
}
示例7: CloudAppendBlobUploadFromStream
private void CloudAppendBlobUploadFromStream(CloudBlobContainer container, int size, long? copyLength, AccessCondition accessCondition, bool seekableSourceStream, bool allowSinglePut, int startOffset, bool isAsync, bool testMd5)
{
byte[] buffer = GetRandomBuffer(size);
MD5 hasher = MD5.Create();
string md5 = string.Empty;
if (testMd5)
{
md5 = Convert.ToBase64String(hasher.ComputeHash(buffer, startOffset, copyLength.HasValue ? (int)copyLength : buffer.Length - startOffset));
}
CloudAppendBlob blob = container.GetAppendBlobReference("blob1");
blob.StreamWriteSizeInBytes = 1 * 1024 * 1024;
using (MemoryStream originalBlobStream = new MemoryStream())
{
originalBlobStream.Write(buffer, startOffset, buffer.Length - startOffset);
Stream sourceStream;
if (seekableSourceStream)
{
MemoryStream stream = new MemoryStream(buffer);
stream.Seek(startOffset, SeekOrigin.Begin);
sourceStream = stream;
}
else
{
NonSeekableMemoryStream stream = new NonSeekableMemoryStream(buffer);
stream.ForceSeek(startOffset, SeekOrigin.Begin);
sourceStream = stream;
}
using (sourceStream)
{
BlobRequestOptions options = new BlobRequestOptions()
{
StoreBlobContentMD5 = true,
};
if (isAsync)
{
using (ManualResetEvent waitHandle = new ManualResetEvent(false))
{
if (copyLength.HasValue)
{
ICancellableAsyncResult result = blob.BeginUploadFromStream(
sourceStream, copyLength.Value, accessCondition, options, null, ar => waitHandle.Set(), null);
waitHandle.WaitOne();
blob.EndUploadFromStream(result);
}
else
{
ICancellableAsyncResult result = blob.BeginUploadFromStream(
sourceStream, accessCondition, options, null, ar => waitHandle.Set(), null);
waitHandle.WaitOne();
blob.EndUploadFromStream(result);
}
}
}
else
{
if (copyLength.HasValue)
{
blob.UploadFromStream(sourceStream, copyLength.Value, accessCondition, options);
}
else
{
blob.UploadFromStream(sourceStream, accessCondition, options);
}
}
}
blob.FetchAttributes();
if (testMd5)
{
Assert.AreEqual(md5, blob.Properties.ContentMD5);
}
using (MemoryStream downloadedBlobStream = new MemoryStream())
{
if (isAsync)
{
using (ManualResetEvent waitHandle = new ManualResetEvent(false))
{
ICancellableAsyncResult result = blob.BeginDownloadToStream(
downloadedBlobStream, ar => waitHandle.Set(), null);
waitHandle.WaitOne();
blob.EndDownloadToStream(result);
}
}
else
{
blob.DownloadToStream(downloadedBlobStream);
}
Assert.AreEqual(copyLength ?? originalBlobStream.Length, downloadedBlobStream.Length);
TestHelper.AssertStreamsAreEqualAtIndex(
originalBlobStream,
downloadedBlobStream,
//.........这里部分代码省略.........
示例8: CloudAppendBlockTask
private void CloudAppendBlockTask(CloudBlobContainer container, int size, AccessCondition accessCondition, int startOffset)
{
try
{
byte[] buffer = GetRandomBuffer(size);
CloudAppendBlob blob = container.GetAppendBlobReference("blob1");
blob.CreateOrReplaceAsync().Wait();
using (MemoryStream originalBlob = new MemoryStream())
{
originalBlob.Write(buffer, startOffset, buffer.Length - startOffset);
using (MemoryStream sourceStream = new MemoryStream(buffer))
{
sourceStream.Seek(startOffset, SeekOrigin.Begin);
BlobRequestOptions options = new BlobRequestOptions()
{
UseTransactionalMD5 = true,
};
blob.AppendBlockAsync(sourceStream, null, accessCondition, options, null).Wait();
}
blob.FetchAttributesAsync().Wait();
using (MemoryStream downloadedBlob = new MemoryStream())
{
blob.DownloadToStreamAsync(downloadedBlob).Wait();
TestHelper.AssertStreamsAreEqualAtIndex(
originalBlob,
downloadedBlob,
0,
0,
(int)originalBlob.Length);
}
}
}
catch (AggregateException ex)
{
throw ex.InnerException;
}
}
示例9: CloudAppendBlock
private void CloudAppendBlock(CloudBlobContainer container, int size, AccessCondition accessCondition, int startOffset, bool isAsync)
{
byte[] buffer = GetRandomBuffer(size);
CloudAppendBlob blob = container.GetAppendBlobReference("blob1");
blob.CreateOrReplace();
using (MemoryStream originalBlob = new MemoryStream())
{
originalBlob.Write(buffer, startOffset, buffer.Length - startOffset);
using (MemoryStream sourceStream = new MemoryStream(buffer))
{
sourceStream.Seek(startOffset, SeekOrigin.Begin);
BlobRequestOptions options = new BlobRequestOptions()
{
UseTransactionalMD5 = true,
};
if (isAsync)
{
using (ManualResetEvent waitHandle = new ManualResetEvent(false))
{
ICancellableAsyncResult result = blob.BeginAppendBlock(
sourceStream, null, accessCondition, options, null, ar => waitHandle.Set(), null);
waitHandle.WaitOne();
blob.EndAppendBlock(result);
}
}
else
{
blob.AppendBlock(sourceStream, null, accessCondition, options);
}
}
blob.FetchAttributes();
using (MemoryStream downloadedBlob = new MemoryStream())
{
if (isAsync)
{
using (ManualResetEvent waitHandle = new ManualResetEvent(false))
{
ICancellableAsyncResult result = blob.BeginDownloadToStream(downloadedBlob,
ar => waitHandle.Set(),
null);
waitHandle.WaitOne();
blob.EndDownloadToStream(result);
}
}
else
{
blob.DownloadToStream(downloadedBlob);
}
TestHelper.AssertStreamsAreEqualAtIndex(
originalBlob,
downloadedBlob,
0,
0,
(int)originalBlob.Length);
}
}
}
示例10: GetAppendBlob
private static CloudAppendBlob GetAppendBlob(CloudBlobContainer container, string extension, string partitionId)
{
var now = DateTime.UtcNow;
var blobPath = string.Format("{0:0000}/{1:00}/{2:00}/{3}p{4}.{5}", now.Year, now.Month, now.Day, now.ToString("yyyyMMddHH"), partitionId, extension);
var blob = container.GetAppendBlobReference(blobPath);
if (!blob.Exists())
blob.CreateOrReplace();
return blob;
}