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


C# CloudBlockBlob.DownloadToStreamAsync方法代码示例

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


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

示例1: Download

        public async Task<Stream> Download(string containerName, string path)
        {
            CloudBlobContainer container = _blobClient.GetContainerReference(containerName);

            container.CreateIfNotExists();
            container.SetPermissions(new BlobContainerPermissions
            {
                PublicAccess = BlobContainerPublicAccessType.Blob
            });

            _blockBlob = container.GetBlockBlobReference(path);

            var ms = new MemoryStream();
            await _blockBlob.DownloadToStreamAsync(ms);
            return ms;


        }
开发者ID:Lejdholt,项目名称:Muztache,代码行数:18,代码来源:BlobService.cs

示例2: LoadBlobTelemetrySummaryModelsAsync

        private async static Task<List<DeviceTelemetrySummaryModel>> LoadBlobTelemetrySummaryModelsAsync(
            CloudBlockBlob blob)
        {
            Debug.Assert(blob != null, "blob is a null reference.");

            var models = new List<DeviceTelemetrySummaryModel>();

            TextReader reader = null;
            MemoryStream stream = null;
            try
            {
                stream = new MemoryStream();
                await blob.DownloadToStreamAsync(stream);
                stream.Position = 0;
                reader = new StreamReader(stream);

                IEnumerable<StrDict> strdicts = ParsingHelper.ParseCsv(reader).ToDictionaries();
                DeviceTelemetrySummaryModel model;
                double number;
                string str;
                foreach (StrDict strdict in strdicts)
                {
                    model = new DeviceTelemetrySummaryModel();

                    if (strdict.TryGetValue("deviceid", out str))
                    {
                        model.DeviceId = str;
                    }

                    if (strdict.TryGetValue("averagehumidity", out str) &&
                       double.TryParse(
                            str,
                            NumberStyles.Float,
                            CultureInfo.InvariantCulture,
                            out number))
                    {
                        model.AverageHumidity = number;
                    }

                    if (strdict.TryGetValue("maxhumidity", out str) &&
                       double.TryParse(
                            str,
                            NumberStyles.Float,
                            CultureInfo.InvariantCulture,
                            out number))
                    {
                        model.MaximumHumidity = number;
                    }

                    if (strdict.TryGetValue("minimumhumidity", out str) &&
                       double.TryParse(
                            str,
                            NumberStyles.Float,
                            CultureInfo.InvariantCulture,
                            out number))
                    {
                        model.MinimumHumidity = number;
                    }

                    if (strdict.TryGetValue("timeframeminutes", out str) &&
                       double.TryParse(
                            str,
                            NumberStyles.Float,
                            CultureInfo.InvariantCulture,
                            out number))
                    {
                        model.TimeFrameMinutes = number;
                    }

                    // Translate LastModified to local time zone.  DateTimeOffsets 
                    // don't do this automatically.  This is for equivalent behavior 
                    // with parsed DateTimes.
                    if ((blob.Properties != null) &&
                        blob.Properties.LastModified.HasValue)
                    {
                        model.Timestamp = blob.Properties.LastModified.Value.LocalDateTime;
                    }

                    models.Add(model);
                }
            }
            finally
            {
                IDisposable disp;
                if ((disp = stream) != null)
                {
                    disp.Dispose();
                }

                if ((disp = reader) != null)
                {
                    disp.Dispose();
                }
            }

            return models;
        }
开发者ID:selam99,项目名称:azure-iot-remote-monitoring,代码行数:97,代码来源:DeviceTelemetryRepository.cs

示例3: RunAsync

        /// <summary>
        /// Runs the mapper task.
        /// </summary>
        public async Task RunAsync()
        {
            CloudBlockBlob blob = new CloudBlockBlob(new Uri(this.blobSas));
            Console.WriteLine("Matches in blob: {0}/{1}", blob.Container.Name, blob.Name);

            using (Stream memoryStream = new MemoryStream())
            {
                //Download the blob.
                await blob.DownloadToStreamAsync(memoryStream);
                memoryStream.Seek(0, SeekOrigin.Begin);

                using (StreamReader streamReader = new StreamReader(memoryStream))
                {
                    Regex regex = new Regex(this.configurationSettings.RegularExpression);

                    int lineCount = 0;

                    //Read the file content.
                    while (!streamReader.EndOfStream)
                    {
                        ++lineCount;
                        string textLine = await streamReader.ReadLineAsync();

                        //If the line matches the search parameters, then print it out.
                        if (textLine.Length > 0)
                        {
                            if (regex.Match(textLine).Success)
                            {
                                Console.WriteLine("Match: \"{0}\" -- line: {1}", textLine, lineCount);
                            }
                        }
                    }
                }
            }
        }
开发者ID:Wahesh,项目名称:azure-batch-samples,代码行数:38,代码来源:MapperTask.cs

示例4: LoadBlobAsync

		public async Task<Stream> LoadBlobAsync (Uri location)
		{
			// The container is setup for public read access
			// do not need to generate credentials
			var cloudBlob = new CloudBlockBlob(location);

			MemoryStream imageStream = new MemoryStream ();

			await cloudBlob.DownloadToStreamAsync (imageStream);

			return imageStream;
		}
开发者ID:codemillmatt,项目名称:CheesedStorage,代码行数:12,代码来源:CheeseStorageService.cs

示例5: TestBlobSASAsync

        /// <summary>
        /// Tests a blob SAS to determine which operations it allows.
        /// </summary>
        /// <param name="sasUri">A string containing a URI with a SAS appended.</param>
        /// <param name="blobContent">A string content content to write to the blob.</param>
        /// <returns>A Task object.</returns>
        private static async Task TestBlobSASAsync(string sasUri, string blobContent)
        {
            // Try performing blob operations using the SAS provided.

            // Return a reference to the blob using the SAS URI.
            CloudBlockBlob blob = new CloudBlockBlob(new Uri(sasUri));

            // Create operation: Upload a blob with the specified name to the container.
            // If the blob does not exist, it will be created. If it does exist, it will be overwritten.
            try
            {
                MemoryStream msWrite = new MemoryStream(Encoding.UTF8.GetBytes(blobContent));
                msWrite.Position = 0;
                using (msWrite)
                {
                    await blob.UploadFromStreamAsync(msWrite);
                }

                Console.WriteLine("Create operation succeeded for SAS {0}", sasUri);
                Console.WriteLine();
            }
            catch (StorageException e)
            {
                if (e.RequestInformation.HttpStatusCode == 403)
                {
                    Console.WriteLine("Create operation failed for SAS {0}", sasUri);
                    Console.WriteLine("Additional error information: " + e.Message);
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine(e.Message);
                    Console.ReadLine();
                    throw;
                }
            }

            // Write operation: Add metadata to the blob
            try
            {
                await blob.FetchAttributesAsync();
                string rnd = new Random().Next().ToString();
                string metadataName = "name";
                string metadataValue = "value";
                blob.Metadata.Add(metadataName, metadataValue);
                await blob.SetMetadataAsync();

                Console.WriteLine("Write operation succeeded for SAS {0}", sasUri);
                Console.WriteLine();
            }
            catch (StorageException e)
            {
                if (e.RequestInformation.HttpStatusCode == 403)
                {
                    Console.WriteLine("Write operation failed for SAS {0}", sasUri);
                    Console.WriteLine("Additional error information: " + e.Message);
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine(e.Message);
                    Console.ReadLine();
                    throw;
                }
            }

            // Read operation: Read the contents of the blob.
            try
            {
                MemoryStream msRead = new MemoryStream();
                using (msRead)
                {
                    await blob.DownloadToStreamAsync(msRead);
                    msRead.Position = 0;
                    using (StreamReader reader = new StreamReader(msRead, true))
                    {
                        string line;
                        while ((line = reader.ReadLine()) != null)
                        {
                            Console.WriteLine(line);
                        }
                    }

                    Console.WriteLine();
                }

                Console.WriteLine("Read operation succeeded for SAS {0}", sasUri);
                Console.WriteLine();
            }
            catch (StorageException e)
            {
                if (e.RequestInformation.HttpStatusCode == 403)
                {
                    Console.WriteLine("Read operation failed for SAS {0}", sasUri);
//.........这里部分代码省略.........
开发者ID:tamram,项目名称:storage-blob-dotnet-getting-started,代码行数:101,代码来源:Advanced.cs

示例6: FetchMetricValuesFromBlob

        private async Task<Dictionary<string, List<MetricValueBlob>>> FetchMetricValuesFromBlob(BlobInfo blobInfo, MetricFilter filter)
        {
            if (blobInfo.EndTime < filter.StartTime || blobInfo.StartTime >= filter.EndTime)
            {
                return new Dictionary<string, List<MetricValueBlob>>();
            }

            var blob = new CloudBlockBlob(new Uri(blobInfo.BlobUri));

            using (var memoryStream = new MemoryStream())
            {
                try
                {
                    await blob.DownloadToStreamAsync(memoryStream);
                }
                catch (StorageException ex)
                {
                    if (ex.RequestInformation.HttpStatusCode == 404)
                    {
                        return new Dictionary<string, List<MetricValueBlob>>();
                    }

                    throw;
                }
                
                memoryStream.Seek(0, 0);
                using (var streamReader = new StreamReader(memoryStream))
                {
                    string content = await streamReader.ReadToEndAsync();
                    var metricBlob = JsonConvert.DeserializeObject<MetricBlob>(content);
                    var metricValues = metricBlob.records;

                    var metricsPerName = new Dictionary<string, List<MetricValueBlob>>();
                    foreach (var metric in metricValues)
                    {
                        if (metric.time < filter.StartTime || metric.time >= filter.EndTime)
                        {
                            continue;
                        }

                        List<MetricValueBlob> metrics;
                        if (!metricsPerName.TryGetValue(metric.metricName, out metrics))
                        {
                            metrics = new List<MetricValueBlob>();
                            metricsPerName.Add(metric.metricName, metrics);
                        }

                        metrics.Add(metric);
                    }

                    return metricsPerName;
                }
            }
        }
开发者ID:Azure,项目名称:azure-powershell,代码行数:54,代码来源:BlobShoeboxMetricRetriever.cs

示例7: LoadFile

        public static async Task<Stream> LoadFile(string location, string storagePrimary)
        {
            CloudStorageAccount account = CloudStorageAccount.Parse(storagePrimary);

            CloudBlockBlob blob = new CloudBlockBlob(new Uri(location), account.Credentials);
            MemoryStream stream = new MemoryStream();
            await blob.DownloadToStreamAsync(stream);
            stream.Seek(0, SeekOrigin.Begin);

            return stream;
        }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:11,代码来源:Artifacts.cs

示例8: WrapDownloadToStreamAsync

		//Source: http://stackoverflow.com/questions/18050836/getting-return-value-from-task-run
		private async Task<MemoryStream> WrapDownloadToStreamAsync(CloudBlockBlob ccb, MemoryStream ms, CancellationToken ct)
		{
			await Task.Run(() => ccb.DownloadToStreamAsync(ms, ct));
			return ms;
		}
开发者ID:CUAHSI,项目名称:HydroClient,代码行数:6,代码来源:AzureContext.cs

示例9: DownloadPictureFromCloud

 public async Task<MemoryStream> DownloadPictureFromCloud(PictureViewModel pictureViewModel)
 {
     try
     {
         var blob = new CloudBlockBlob(new Uri(pictureViewModel.PictureUrl), App.credentials);
         var ims = new MemoryStream();
         await blob.DownloadToStreamAsync(ims);
         return ims;
     }
     catch (Exception)
     {
         throw;
     }
 }
开发者ID:BerndtHamboeck,项目名称:AzureHomeSecurity,代码行数:14,代码来源:PictureDataSource.cs

示例10: FetchLogFromBlob

        private async Task<Log> FetchLogFromBlob(string blobUri, MetricFilter filter, LocalizableString category)
        {
            var blob = new CloudBlockBlob(new Uri(blobUri));

            using (var memoryStream = new MemoryStream())
            {
                try
                {
                    await blob.DownloadToStreamAsync(memoryStream);
                }
                catch (StorageException ex)
                {
                    if (ex.RequestInformation.HttpStatusCode == 404)
                    {
                        return new Log
                        {
                            Category = new LocalizableString
                            {
                                LocalizedValue = category.LocalizedValue,
                                Value = category.Value
                            },
                            StartTime = filter.StartTime,
                            EndTime = filter.EndTime,
                            Value = new List<LogValue>()
                        };
                    }

                    throw;
                }

                memoryStream.Seek(0, 0);
                using (var streamReader = new StreamReader(memoryStream))
                {
                    string content = await streamReader.ReadToEndAsync();
                    var logBlob = JsonConvert.DeserializeObject<LogBlob>(content);
                    var logValues = logBlob.records.Where(x => x.Time >= filter.StartTime && x.Time < filter.EndTime).ToList();

                    return new Log
                    {
                        Category = category,
                        StartTime = filter.StartTime,
                        EndTime = filter.EndTime,
                        Value = logValues
                    };
                }
            }
        }
开发者ID:RossMerr,项目名称:azure-sdk-for-net,代码行数:47,代码来源:LogOperations.Customization.cs

示例11: ProduceAlertHistoryItemsAsync

        private async static Task<List<AlertHistoryItemModel>> ProduceAlertHistoryItemsAsync(
            CloudBlockBlob blob)
        {
            IDisposable disp;
            IEnumerable<ExpandoObject> expandos;
            AlertHistoryItemModel model;
            List<AlertHistoryItemModel> models;
            TextReader reader;
            MemoryStream stream;

            Debug.Assert(blob != null, "blob is a null reference.");

            models = new List<AlertHistoryItemModel>();

            reader = null;
            stream = null;
            try
            {
                stream = new MemoryStream();
                await blob.DownloadToStreamAsync(stream);
                stream.Position = 0;
                reader = new StreamReader(stream);

                expandos = ParsingHelper.ParseCsv(reader).ToExpandoObjects();
                foreach (ExpandoObject expando in expandos)
                {
                    model =
                        ProduceAlertHistoryItem(
                            expando,
                            "temperatureruleoutput");

                    if (model != null)
                    {
                        models.Add(model);
                    }

                    model =
                        ProduceAlertHistoryItem(expando, "humidityruleoutput");

                    if (model != null)
                    {
                        models.Add(model);
                    }
                }
            }
            finally
            {
                if ((disp = stream) != null)
                {
                    disp.Dispose();
                }

                if ((disp = reader) != null)
                {
                    disp.Dispose();
                }
            }

            return models;
        }
开发者ID:smartpcr,项目名称:azure-iot-remote-monitoring,代码行数:60,代码来源:AlertsRepository.cs

示例12: LoadBlobTelemetrySummaryModelsAsync

        private async static Task<List<DeviceTelemetrySummaryModel>> LoadBlobTelemetrySummaryModelsAsync(
            CloudBlockBlob blob)
        {
            IDisposable disp;
            IEnumerable<StrDict> strdicts;
            DeviceTelemetrySummaryModel model;
            List<DeviceTelemetrySummaryModel> models;
            double number;
            TextReader reader;
            string str;
            MemoryStream stream;

            Debug.Assert(blob != null, "blob is a null reference.");

            models = new List<DeviceTelemetrySummaryModel>();

            reader = null;
            stream = null;
            try
            {
                stream = new MemoryStream();
                await blob.DownloadToStreamAsync(stream);
                stream.Position = 0;
                reader = new StreamReader(stream);

                strdicts = ParsingHelper.ParseCsv(reader).ToDictionaries();
                foreach (StrDict strdict in strdicts)
                {
                    model = new DeviceTelemetrySummaryModel();

                    if (strdict.TryGetValue("deviceid", out str))
                    {
                        model.DeviceId = str;
                    }

                    if (strdict.TryGetValue("averagehumidity", out str) &&
                       double.TryParse(str, out number))
                    {
                        model.AverageHumidity = number;
                    }

                    if (strdict.TryGetValue("maxhumidity", out str) &&
                       double.TryParse(str, out number))
                    {
                        model.MaximumHumidity = number;
                    }

                    if (strdict.TryGetValue("minimumhumidity", out str) &&
                       double.TryParse(str, out number))
                    {
                        model.MinimumHumidity = number;
                    }

                    if (strdict.TryGetValue("timeframeminutes", out str) &&
                       double.TryParse(str, out number))
                    {
                        model.TimeFrameMinutes = number;
                    }

                    if ((blob.Properties != null) &&
                        blob.Properties.LastModified.HasValue)
                    {
                        model.Timestamp =
                            blob.Properties.LastModified.Value.UtcDateTime;
                    }

                    models.Add(model);
                }
            }
            finally
            {
                if ((disp = stream) != null)
                {
                    disp.Dispose();
                }

                if ((disp = reader) != null)
                {
                    disp.Dispose();
                }
            }

            return models;
        }
开发者ID:smartpcr,项目名称:azure-iot-remote-monitoring,代码行数:84,代码来源:DeviceTelemetryRepository.cs

示例13: LoadBlobTelemetryModelsAsync

        private async static Task<List<DeviceTelemetryModel>> LoadBlobTelemetryModelsAsync(
            CloudBlockBlob blob)
        {
            DateTime date;
            IDisposable disp;
            DeviceTelemetryModel model;
            List<DeviceTelemetryModel> models;
            double number;
            TextReader reader;
            string str;
            IEnumerable<StrDict> strdicts;
            MemoryStream stream;

            Debug.Assert(blob != null, "blob is a null reference.");

            models = new List<DeviceTelemetryModel>();

            reader = null;
            stream = null;
            try
            {
                stream = new MemoryStream();
                await blob.DownloadToStreamAsync(stream);
                stream.Position = 0;
                reader = new StreamReader(stream);

                strdicts = ParsingHelper.ParseCsv(reader).ToDictionaries();
                foreach (StrDict strdict in strdicts)
                {
                    model = new DeviceTelemetryModel();

                    if (strdict.TryGetValue("DeviceId", out str))
                    {
                        model.DeviceId = str;
                    }

                    if (strdict.TryGetValue("ExternalTemperature", out str) &&
                        double.TryParse(str, out number))
                    {
                        model.ExternalTemperature = number;
                    }

                    if (strdict.TryGetValue("Humidity", out str) &&
                        double.TryParse(str, out number))
                    {
                        model.Humidity = number;
                    }

                    if (strdict.TryGetValue("Temperature", out str) &&
                        double.TryParse(str, out number))
                    {
                        model.Temperature = number;
                    }

                    if (strdict.TryGetValue("EventEnqueuedUtcTime", out str) &&
                        DateTime.TryParse(str, out date))
                    {
                        model.Timestamp = date;
                    }

                    models.Add(model);
                }
            }
            finally
            {
                if ((disp = stream) != null)
                {
                    disp.Dispose();
                }

                if ((disp = reader) != null)
                {
                    disp.Dispose();
                }
            }

            return models;
        }
开发者ID:smartpcr,项目名称:azure-iot-remote-monitoring,代码行数:78,代码来源:DeviceTelemetryRepository.cs

示例14: ProduceAlertHistoryItemsAsync

        private async static Task<List<AlertHistoryItemModel>> ProduceAlertHistoryItemsAsync(CloudBlockBlob blob)
        {
            Debug.Assert(blob != null, "blob is a null reference.");

            var models = new List<AlertHistoryItemModel>();
            var stream = new MemoryStream();
            TextReader reader = null;
            try
            {
                await blob.DownloadToStreamAsync(stream);
                stream.Position = 0;
                reader = new StreamReader(stream);

                IEnumerable<ExpandoObject> expandos = ParsingHelper.ParseCsv(reader).ToExpandoObjects();
                foreach (ExpandoObject expando in expandos)
                {
                    AlertHistoryItemModel model = ProduceAlertHistoryItem(expando);

                    if (model != null)
                    {
                        models.Add(model);
                    }
                }
            }
            finally
            {
                IDisposable dispStream = stream as IDisposable;
                if (dispStream != null)
                {
                    dispStream.Dispose();
                }

                IDisposable dispReader = reader as IDisposable;
                if (dispReader != null)
                {
                    dispReader.Dispose();
                }
            }

            return models;
        }
开发者ID:selam99,项目名称:azure-iot-remote-monitoring,代码行数:41,代码来源:AlertsRepository.cs


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