当前位置: 首页>>代码示例>>C#>>正文


C# ICloudBlob.OpenRead方法代码示例

本文整理汇总了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;
            }
        }
开发者ID:Gajendra-Bahakar,项目名称:azure-storage-net,代码行数:47,代码来源:BlobReadStreamTest.cs

示例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;
        }
开发者ID:rafaelmtz,项目名称:azure-webjobs-sdk,代码行数:41,代码来源:HostVersionReader.cs


注:本文中的ICloudBlob.OpenRead方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。