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


C# CloudBlob.DownloadToStream方法代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.StorageClient.CloudBlob.DownloadToStream方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlob.DownloadToStream方法的具体用法?C# CloudBlob.DownloadToStream怎么用?C# CloudBlob.DownloadToStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.WindowsAzure.StorageClient.CloudBlob的用法示例。


在下文中一共展示了CloudBlob.DownloadToStream方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Get

        /// <summary>
        /// Возвращает поток с файлом из хранилища.
        /// </summary>
        /// <param name="localUri"> Адрес файла </param>
        /// <returns> Поток </returns>
        public Stream Get(string localUri)
        {
            CloudBlob blob = new CloudBlob(localUri, _client);

            MemoryStream stream = new MemoryStream();
            blob.DownloadToStream(stream, new BlobRequestOptions()
            {
                RetryPolicy = RetryPolicies.RetryExponential(
                    RetryPolicies.DefaultClientRetryCount,
                    RetryPolicies.DefaultClientBackoff)
            });
            stream.Seek(0, SeekOrigin.Begin);

            return stream;
        }
开发者ID:retran,项目名称:old-projects-backup,代码行数:20,代码来源:BlobServiceImplementor.cs

示例2: RetrieveInformationWithBlob

 public static IInformationObject RetrieveInformationWithBlob(string relativeLocation, Type typeToRetrieve, out CloudBlob blob, string eTag = null, IContainerOwner owner = null)
 {
     if (owner != null)
         relativeLocation = GetBlobOwnerAddress(owner, relativeLocation);
     blob = CurrActiveContainer.GetBlobReference(relativeLocation);
     MemoryStream memoryStream = new MemoryStream();
     string blobEtag = null;
     try
     {
         BlobRequestOptions options = new BlobRequestOptions();
         options.RetryPolicy = RetryPolicies.Retry(10, TimeSpan.FromSeconds(3));
         if (eTag != null)
             options.AccessCondition = AccessCondition.IfMatch(eTag);
         blob.DownloadToStream(memoryStream, options);
         blobEtag = blob.Properties.ETag;
     }
     catch (StorageClientException stEx)
     {
         if (stEx.ErrorCode == StorageErrorCode.BlobNotFound)
             return null;
         throw;
     }
     //if (memoryStream.Length == 0)
     //    return null;
     memoryStream.Seek(0, SeekOrigin.Begin);
     DataContractSerializer serializer = new DataContractSerializer(typeToRetrieve);
     IInformationObject informationObject = (IInformationObject)serializer.ReadObject(memoryStream);
     informationObject.ETag = blobEtag;
     //informationObject.RelativeLocation = blob.Attributes.Metadata["RelativeLocation"];
     informationObject.SetInstanceTreeValuesAsUnmodified();
     Debug.WriteLine(String.Format("Read: {0} ID {1}", informationObject.GetType().Name,
         informationObject.ID));
     return informationObject;
 }
开发者ID:rodmjay,项目名称:TheBallOnAzure,代码行数:34,代码来源:StorageSupport.cs

示例3: HandlePublicBlobRequestWithCacheSupport

 private static void HandlePublicBlobRequestWithCacheSupport(HttpContext context, CloudBlob blob, HttpResponse response)
 {
     // Set the cache request properties as IIS will include them regardless for now
     // even when we wouldn't want them on 304 response...
     response.Cache.SetMaxAge(TimeSpan.FromMinutes(0));
     response.Cache.SetCacheability(HttpCacheability.Private);
     var request = context.Request;
     blob.FetchAttributes();
     string ifNoneMatch = request.Headers["If-None-Match"];
     string ifModifiedSince = request.Headers["If-Modified-Since"];
     if (ifNoneMatch != null)
     {
         if (ifNoneMatch == blob.Properties.ETag)
         {
             response.ClearContent();
             response.StatusCode = 304;
             return;
         }
     }
     else if (ifModifiedSince != null)
     {
         DateTime ifModifiedSinceValue;
         if (DateTime.TryParse(ifModifiedSince, out ifModifiedSinceValue))
         {
             ifModifiedSinceValue = ifModifiedSinceValue.ToUniversalTime();
             if (blob.Properties.LastModifiedUtc <= ifModifiedSinceValue)
             {
                 response.ClearContent();
                 response.StatusCode = 304;
                 return;
             }
         }
     }
     var fileName = blob.Name.Contains("/MediaContent/") ?
         request.Path : blob.Name;
     response.ContentType = StorageSupport.GetMimeType(fileName);
     //response.Cache.SetETag(blob.Properties.ETag);
     response.Headers.Add("ETag", blob.Properties.ETag);
     response.Cache.SetLastModified(blob.Properties.LastModifiedUtc);
     blob.DownloadToStream(response.OutputStream);
 }
开发者ID:kallex,项目名称:Caloom,代码行数:41,代码来源:AnonymousBlobStorageHandler.cs

示例4: DeserializeNameValueCollectionFromBlob

        // Deserialize NameValueCollection from Blob
        private static NameValueCollection DeserializeNameValueCollectionFromBlob(CloudBlob blob)
        {
            NameValueCollection collection = null;
            try
            {
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    SoapFormatter ser = new SoapFormatter();
                    blob.DownloadToStream(memoryStream);
                    memoryStream.Seek(0, SeekOrigin.Begin);
                    collection = ser.Deserialize(memoryStream) as NameValueCollection;
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("Failed to DeserializeNameValueCollectionFromBlob. Error: {0}", ex.Message);
            }

            return collection;
        }
开发者ID:MikeOrtiz,项目名称:dynovader,代码行数:21,代码来源:WindowsAzureVMManager.cs

示例5: AzureIndexInput

        public AzureIndexInput(AzureDirectory azuredirectory, CloudBlob blob)
        {
            _name = blob.Uri.Segments[blob.Uri.Segments.Length - 1];

            #if FULLDEBUG
            Debug.WriteLine(String.Format("opening {0} ", _name));
            #endif
            _fileMutex = new Mutex(false, _name);
            _fileMutex.WaitOne();
            try
            {
                _azureDirectory = azuredirectory;
                _blobContainer = azuredirectory.BlobContainer;
                _blob = blob;

                string fileName = _name;

                bool fFileNeeded = false;
                if (!CacheDirectory.FileExists(fileName))
                {
                    fFileNeeded = true;
                }
                else
                {
                    long cachedLength = CacheDirectory.FileLength(fileName);
                    long blobLength = blob.Properties.Length;
                    long.TryParse(blob.Metadata["CachedLength"], out blobLength);

                    long longLastModified = 0;
                    DateTime blobLastModifiedUTC = blob.Properties.LastModifiedUtc;
                    if (long.TryParse(blob.Metadata["CachedLastModified"], out longLastModified))
                        blobLastModifiedUTC = new DateTime(longLastModified).ToUniversalTime();

                    if (cachedLength != blobLength)
                        fFileNeeded = true;
                    else
                    {
                        // there seems to be an error of 1 tick which happens every once in a while
                        // for now we will say that if they are within 1 tick of each other and same length
                        DateTime cachedLastModifiedUTC = new DateTime(CacheDirectory.FileModified(fileName), DateTimeKind.Local).ToUniversalTime();
                        if (cachedLastModifiedUTC != blobLastModifiedUTC)
                        {
                            TimeSpan timeSpan = blobLastModifiedUTC.Subtract(cachedLastModifiedUTC);
                            if (timeSpan.TotalSeconds > 1)
                                fFileNeeded = true;
                            else
                            {
            #if FULLDEBUG
                                Debug.WriteLine(timeSpan.TotalSeconds);
            #endif
                                // file not needed
                            }
                        }
                    }
                }

                // if the file does not exist
                // or if it exists and it is older then the lastmodified time in the blobproperties (which always comes from the blob storage)
                if (fFileNeeded)
                {
            #if COMPRESSBLOBS
                    if (_azureDirectory.ShouldCompressFile(_name))
                    {
                        // then we will get it fresh into local deflatedName
                        // StreamOutput deflatedStream = new StreamOutput(CacheDirectory.CreateOutput(deflatedName));
                        MemoryStream deflatedStream = new MemoryStream();

                        // get the deflated blob
                        _blob.DownloadToStream(deflatedStream);

                        Debug.WriteLine(string.Format("GET {0} RETREIVED {1} bytes", _name, deflatedStream.Length));

                        // seek back to begininng
                        deflatedStream.Seek(0, SeekOrigin.Begin);

                        // open output file for uncompressed contents
                        StreamOutput fileStream = _azureDirectory.CreateCachedOutputAsStream(fileName);

                        // create decompressor
                        DeflateStream decompressor = new DeflateStream(deflatedStream, CompressionMode.Decompress);

                        byte[] bytes = new byte[65535];
                        int nRead = 0;
                        do
                        {
                            nRead = decompressor.Read(bytes, 0, 65535);
                            if (nRead > 0)
                                fileStream.Write(bytes, 0, nRead);
                        } while (nRead == 65535);
                        decompressor.Close(); // this should close the deflatedFileStream too

                        fileStream.Close();

                    }
                    else
            #endif
                    {
                        StreamOutput fileStream = _azureDirectory.CreateCachedOutputAsStream(fileName);

                        // get the blob
//.........这里部分代码省略.........
开发者ID:remiolivier,项目名称:Openturf,代码行数:101,代码来源:AzureIndexInput.cs


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