本文整理汇总了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;
}
示例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;
}
示例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);
}
}
}
}
}
}
示例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;
}
示例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);
//.........这里部分代码省略.........
示例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;
}
}
}
示例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;
}
示例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;
}
示例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;
}
}
示例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
};
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}