本文整理汇总了C#中ICloudBlob.OpenRead方法的典型用法代码示例。如果您正苦于以下问题:C# ICloudBlob.OpenRead方法的具体用法?C# ICloudBlob.OpenRead怎么用?C# ICloudBlob.OpenRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICloudBlob
的用法示例。
在下文中一共展示了ICloudBlob.OpenRead方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BlobReadStreamReadSizeTest
private void BlobReadStreamReadSizeTest(ICloudBlob blob)
{
byte[] buffer = GetRandomBuffer(5 * 1024 * 1024);
using (MemoryStream wholeBlob = new MemoryStream(buffer))
{
blob.UploadFromStream(wholeBlob);
}
TestHelper.ExpectedException<ArgumentOutOfRangeException>(
() => blob.StreamMinimumReadSizeInBytes = 16 * 1024 - 1,
"StreamMinimumReadSizeInBytes should not accept values smaller than 16KB");
blob.StreamMinimumReadSizeInBytes = 4 * 1024 * 1024 + 1;
BlobRequestOptions options = new BlobRequestOptions() { UseTransactionalMD5 = true };
TestHelper.ExpectedException<ArgumentOutOfRangeException>(
() => blob.OpenRead(null, options, null),
"StreamMinimumReadSizeInBytes should be smaller than 4MB if UseTransactionalMD5 is true");
string range = null;
OperationContext context = new OperationContext();
context.SendingRequest += (sender, e) => range = range ?? e.Request.Headers["x-ms-range"];
blob.StreamMinimumReadSizeInBytes = 4 * 1024 * 1024;
using (Stream blobStream = blob.OpenRead(null, options, context))
{
blobStream.ReadByte();
Assert.AreEqual("bytes=0-" + (blob.StreamMinimumReadSizeInBytes - 1).ToString(), range);
range = null;
}
blob.StreamMinimumReadSizeInBytes = 6 * 1024 * 1024;
options.UseTransactionalMD5 = false;
using (Stream blobStream = blob.OpenRead(null, options, context))
{
blobStream.ReadByte();
Assert.AreEqual("bytes=0-" + (buffer.Length - 1).ToString(), range);
range = null;
}
blob.StreamMinimumReadSizeInBytes = 16 * 1024;
using (Stream blobStream = blob.OpenRead(null, options, context))
{
blobStream.ReadByte();
Assert.AreEqual("bytes=0-" + (blob.StreamMinimumReadSizeInBytes - 1).ToString(), range);
range = null;
}
}
示例2: GetHostVersion
private static HostVersion GetHostVersion(ICloudBlob blob)
{
// Use the blob name as the HostVersion.Name; any HostVersion will have this property set.
HostVersion version = new HostVersion
{
Label = blob.Name
};
// Try to get the link property from the blob contents.
// HostVersion.Link will only be set when the blob matches this schema.
if (blob.Properties.ContentType == "application/json")
{
Encoding utf8 = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);
string value;
Stream stream = blob.OpenRead();
try
{
using (TextReader textReader = new StreamReader(stream, utf8))
{
stream = null;
value = textReader.ReadToEnd();
}
}
finally
{
if (stream != null)
{
stream.Dispose();
}
}
string link;
if (TryReadLink(value, out link))
{
version.Link = link;
}
}
return version;
}