本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.DownloadToStream方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlockBlob.DownloadToStream方法的具体用法?C# CloudBlockBlob.DownloadToStream怎么用?C# CloudBlockBlob.DownloadToStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob
的用法示例。
在下文中一共展示了CloudBlockBlob.DownloadToStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: init
private void init(CloudBlockBlob blob)
{
if (blob == null)
throw new ArgumentNullException("blob");
_server_ref = blob;
Stream = new MemoryStream();
_server_ref.DownloadToStream(Stream);
Stream.Seek(0, SeekOrigin.Begin);
//Automatic Fetches Attributes on DownloadToStream.
ETag = _server_ref.Properties.ETag;
Length = _server_ref.Properties.Length;
}
示例2: TaskMain
public static void TaskMain(string[] args)
{
if (args == null || args.Length != 5)
{
throw new Exception("Usage: TopNWordsSample.exe --Task <blobpath> <numtopwords> <storageAccountName> <storageAccountKey>");
}
string blobName = args[1];
int numTopN = int.Parse(args[2]);
string storageAccountName = args[3];
string storageAccountKey = args[4];
// open the cloud blob that contains the book
var storageCred = new StorageCredentials(storageAccountName, storageAccountKey);
CloudBlockBlob blob = new CloudBlockBlob(new Uri(blobName), storageCred);
using (Stream memoryStream = new MemoryStream())
{
blob.DownloadToStream(memoryStream);
memoryStream.Position = 0; //Reset the stream
var sr = new StreamReader(memoryStream);
var myStr = sr.ReadToEnd();
string[] words = myStr.Split(' ');
var topNWords =
words.
Where(word => word.Length > 0).
GroupBy(word => word, (key, group) => new KeyValuePair<String, long>(key, group.LongCount())).
OrderByDescending(x => x.Value).
Take(numTopN).
ToList();
foreach (var pair in topNWords)
{
Console.WriteLine("{0} {1}", pair.Key, pair.Value);
}
}
}
示例3: DownloadBlob
private static string DownloadBlob(CloudBlockBlob blob)
{
using (var stream = new MemoryStream())
{
StreamReader reader;
try
{
blob.DownloadToStream(stream, options: new BlobRequestOptions()
{
RetryPolicy = new LinearRetry(TimeSpan.FromSeconds(5), 3)
});
}
catch (StorageException se)
{
return "";
}
try
{
stream.Seek(0, 0);
reader = new StreamReader(new GZipStream(stream, CompressionMode.Decompress));
return reader.ReadToEnd();
}
catch
{
stream.Seek(0, 0);
reader = new StreamReader(stream);
return reader.ReadToEnd();
}
}
}
示例4: DownloadIfExists
private void DownloadIfExists(CloudBlockBlob blob)
{
string target = Path.Combine(Root, blob.Name);
if (blob.Exists())
{
if (!Directory.Exists(Root))
{
Directory.CreateDirectory(Root);
}
using (var file = File.OpenWrite(target))
{
blob.DownloadToStream(file);
}
}
}
示例5: OnExecuting
protected override void OnExecuting(CloudBlockBlob workItem)
{
if (workItem == null)
throw new ArgumentNullException("workItem");
if (workItem.Metadata.ContainsKey(CompressedFlag))
return;
using (var blobStream = new MemoryStream())
{
workItem.DownloadToStream(blobStream);
using (var compressedStream = new MemoryStream())
{
CompressStream(compressedStream, blobStream);
SetCompressedFlag(workItem);
workItem.UploadFromStream(compressedStream);
}
}
}
示例6: DownloadBlob
/// <summary>
/// Downloads the BLOB.
/// </summary>
/// <param name="blob">The BLOB.</param>
/// <param name="fetchAttribute">if set to <c>true</c> [fetch attribute].</param>
/// <param name="metaData">The meta data.</param>
/// <returns>System.Byte[].</returns>
public static byte[] DownloadBlob(CloudBlockBlob blob, bool fetchAttribute, out IDictionary<string, string> metaData)
{
try
{
blob.CheckNullObject("blob");
if (fetchAttribute)
{
blob.FetchAttributes();
metaData = blob.Metadata;
}
else
{
metaData = null;
}
var msRead = new MemoryStream { Position = 0 };
using (msRead)
{
blob.DownloadToStream(msRead);
return msRead.ToBytes();
}
}
catch (Exception ex)
{
throw ex.Handle("DownloadBlob", blob.Uri.ToString());
}
}
示例7: DownloadBlobInParallel
private void DownloadBlobInParallel(CloudBlockBlob blob, Stream stream)
{
try
{
blob.FetchAttributes();
blob.ServiceClient.ParallelOperationThreadCount = NumberOfIOThreads;
blob.DownloadToStream(stream);
stream.Seek(0, SeekOrigin.Begin);
}
catch (StorageException ex)
{
logger.Warn(ex.Message);
}
}
示例8: GetNetworkSecurityGroupRuleCounters
/// <summary>
/// Down loads JSON log files between 2 dates from the blob storage
/// and exports them into one .CSV file.
/// </summary>
/// <param name="logStart">Begin date and time of the log.</param>
/// <param name="logEnd">End date and time of the log.</param>
private static void GetNetworkSecurityGroupRuleCounters(DateTime logStart, DateTime logEnd)
{
// Creates client.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(BlobStorageConnectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
Console.WriteLine($"Getting reference to container {CounterContainerName}");
CloudBlobContainer container = blobClient.GetContainerReference(CounterContainerName);
// Instantiate the URL generator.
StorageURL storageUrl = new StorageURL(container.Uri, SubscriptionID, ResrouceGroupsName, ProviderName, ResrouceTypeName);
List<Log> logs = new List<Log>();
int itemPosition = 0;
// Using the date and time as arguments download all logs from the storage blob.
for (DateTime logTimeStamp = logStart; logTimeStamp <= logEnd; logTimeStamp = logTimeStamp.AddHours(1))
{
Console.WriteLine(logTimeStamp);
Uri storageBlogUrl = storageUrl.GetURL(logTimeStamp);
CloudBlockBlob blockBlob = new CloudBlockBlob(storageBlogUrl, storageAccount.Credentials);
MemoryStream memstream = new MemoryStream();
try
{
blockBlob.DownloadToStream(memstream);
memstream.Position = 0;
JsonSerializer serializer = new JsonSerializer();
using (StreamReader sr = new StreamReader(memstream))
using (JsonTextReader jsonTextReader = new JsonTextReader(sr))
{
// Deserialize JSON.
LogRecords logRecords = serializer.Deserialize<LogRecords>(jsonTextReader);
itemPosition = 0;
foreach (Log logItem in logRecords.records)
{
// Add deserialized logs.
logs.Add(logItem);
itemPosition++;
}
}
}
catch (Exception ex)
{
Console.WriteLine($"{ex.Message} - {storageBlogUrl}");
}
}
// Dump everything in the logs list into a file.
using (StreamWriter file = new StreamWriter(CounterCSVExportNamePath))
{
file.WriteLine("time,systemId,resourceId,operationName,properties.vnetResourceGuid,properties.subnetPrefix"
+ ",properties.macAddress,properties.ruleName,properties.direction,properties.type,properties.matchedConnections");
foreach (Log log in logs)
{
file.WriteLine($"{DateTime.Parse(log.time).ToUniversalTime()}, {log.systemId}, {log.resourceId}, {log.operationName}"
+ $", {log.properties.vnetResourceGuid}, {log.properties.subnetPrefix}, {log.properties.macAddress}"
+ $", {log.properties.ruleName}, {log.properties.direction}, {log.properties.type}, {log.properties.matchedConnections}");
}
}
}
示例9: InitFormBlob
private void InitFormBlob(CloudBlockBlob blob, bool withFileData)
{
if (blob == null || !blob.Exists())
return;
BlobKey = blob.Name;
FileName = Uri.UnescapeDataString(blob.Metadata["FileName"]);
ContentType = Uri.UnescapeDataString(blob.Metadata["ContentType"]);
int contentLength;
if (int.TryParse(Uri.UnescapeDataString(blob.Metadata["ContentLength"]), out contentLength))
ContentLength = contentLength;
BlobFileType type;
if (Enum.TryParse<BlobFileType>(Uri.UnescapeDataString(blob.Metadata["BlobFileType"]), true, out type))
BlobFileType = type;
DateTime dtUploaded;
if (DateTime.TryParse(Uri.UnescapeDataString(blob.Metadata["DtUploaded"]), out dtUploaded))
UploadedDate = dtUploaded;
if (withFileData)
{
Data = new MemoryStream();
blob.DownloadToStream(Data);
Data.Position = 0;
}
}
示例10: DownloadBlob
public MemoryStream DownloadBlob(CloudBlockBlob blob)
{
var memorystream = new MemoryStream { Position = 0 };
blob.DownloadToStream(memorystream);
return memorystream;
}
示例11: TaskMain
public static void TaskMain(string[] args)
{
if (args == null || args.Length != 4)
{
throw new Exception("Usage: ImageBlur.exe --Task <blobpath> <storageAccountName> <storageAccountKey>");
}
string blobName = args[1];
string storageAccountName = args[2];
string storageAccountKey = args[3];
string workingDirectory = Environment.GetEnvironmentVariable("AZ_BATCH_TASK_WORKING_DIR");
int numberToBlur = 3;
Console.WriteLine();
Console.WriteLine(" blobName: <{0}>", blobName);
Console.WriteLine(" storageAccountName: <{0}>", storageAccountName);
Console.WriteLine(" number to blur: <{0}>", numberToBlur);
Console.WriteLine();
// get source image from cloud blob
var storageCred = new StorageCredentials(storageAccountName, storageAccountKey);
CloudBlockBlob blob = new CloudBlockBlob(new Uri(blobName), storageCred);
using (MemoryStream inStream = new MemoryStream())
{
blob.DownloadToStream(inStream);
Image img = Image.FromStream(inStream);
int imgWidth = img.Width;
int imgHeight = img.Height;
Size size = new Size(imgWidth, imgHeight);
ISupportedImageFormat format = new JpegFormat { Quality = 70 };
// Print image properties to stdout
Console.WriteLine(" Image Properties:");
Console.WriteLine(" Format: {0}", FormatUtilities.GetFormat(inStream));
Console.WriteLine(" Size: {0}", size.ToString());
Console.WriteLine();
for (var i = 0; i < numberToBlur; i++)
{
using (ImageFactory imageFactory = new ImageFactory(preserveExifData: true))
{
int blurIndex = (i * 5) + 10;
imageFactory.Load(inStream);
imageFactory.Resize(size)
.Format(format)
.GaussianBlur(blurIndex)
.Save(workingDirectory + "/resultimage" + i + ".Jpeg");
//.Save(@"C:/Users/jiata/Desktop/imageblur/results/resultimage" + i + ".Jpeg");
}
}
}
// TODO - not working
for (var i = 0; i < numberToBlur; i++)
{
blob.UploadFromFile(workingDirectory + "/resultimage" + i + ".Jpeg", FileMode.Open);
}
Environment.Exit(1);
}
示例12: CloudBlockBlobGenerateSASForSnapshot
public void CloudBlockBlobGenerateSASForSnapshot()
{
// Client with shared key access.
CloudBlobClient blobClient = GenerateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(GetRandomContainerName());
MemoryStream memoryStream = new MemoryStream();
try
{
container.Create();
CloudBlockBlob blob = container.GetBlockBlobReference("Testing");
blob.UploadFromStream(new MemoryStream(GetRandomBuffer(10)));
SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy()
{
SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write,
};
CloudBlockBlob snapshot = blob.CreateSnapshot();
string sas = snapshot.GetSharedAccessSignature(policy);
Assert.IsNotNull(sas);
StorageCredentials credentials = new StorageCredentials(sas);
Uri snapshotUri = snapshot.SnapshotQualifiedUri;
CloudBlockBlob blob1 = new CloudBlockBlob(snapshotUri, credentials);
blob1.DownloadToStream(memoryStream);
Assert.IsNotNull(memoryStream);
}
finally
{
container.DeleteIfExists();
memoryStream.Close();
}
}
示例13: UploadBlobStream
/// <summary>
/// Uploads Memory Stream to Blob
/// </summary>
/// <param name="outputBlob"></param>
/// <param name="line"></param>
private static void UploadBlobStream(CloudBlockBlob outputBlob, string line)
{
using (MemoryStream ms = new MemoryStream())
{
if (outputBlob.Exists())
{
outputBlob.DownloadToStream(ms);
}
byte[] dataToWrite = Encoding.UTF8.GetBytes(line + "\r\n");
ms.Write(dataToWrite, 0, dataToWrite.Length);
ms.Position = 0;
outputBlob.UploadFromStream(ms);
}
}
示例14: DownloadBlobInParallel
void DownloadBlobInParallel(CloudBlockBlob blob, Stream stream)
{
blob.FetchAttributes();
blob.ServiceClient.ParallelOperationThreadCount = NumberOfIOThreads;
container.ServiceClient.RetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(BackOffInterval), MaxRetries);
blob.DownloadToStream(stream);
stream.Seek(0, SeekOrigin.Begin);
}
示例15: GetLoadBalancerEvents
private static void GetLoadBalancerEvents(DateTime logStart, DateTime logEnd)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(BlobStorageConnectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
Console.WriteLine($"Getting reference to container {EventContainerName}");
CloudBlobContainer container = blobClient.GetContainerReference(EventContainerName);
StorageURL storageUrl = new StorageURL(container.Uri, SubscriptionID, ResrouceGroupsName, ProviderName, ResrouceTypeName, ResourceType.LOADBALANCERS);
List<Log> logs = new List<Log>();
int itemPosition = 0;
// Using the date and time as arguments download all logs from the storage blob.
for (DateTime logTimeStamp = logStart; logTimeStamp <= logEnd; logTimeStamp = logTimeStamp.AddHours(1))
{
Console.WriteLine(logTimeStamp);
Uri storageBlobUrl = storageUrl.GetURL(logTimeStamp);
CloudBlockBlob blockBlob = new CloudBlockBlob(storageBlobUrl, storageAccount.Credentials);
MemoryStream memstream = new MemoryStream();
try
{
blockBlob.DownloadToStream(memstream);
memstream.Position = 0;
JsonSerializer serializer = new JsonSerializer();
using (StreamReader sr = new StreamReader(memstream))
{
using (JsonTextReader jsonTextReader = new JsonTextReader(sr))
{
LogRecords logRecords = serializer.Deserialize<LogRecords>(jsonTextReader);
itemPosition = 0;
foreach (Log logItem in logRecords.records)
{
logs.Add(logItem);
itemPosition++;
}
}
}
}
catch (Exception ex)
{
Console.WriteLine($"{ex.Message} - {storageBlobUrl}");
}
}
using (System.IO.StreamWriter file = new System.IO.StreamWriter(EventCSVExportNamePath))
{
file.WriteLine("time,systemId,category,resourceId,operationName,properties.publicIpAddress"
+ ",properties.port,properties.totalDipCount,properties.dipDownCount,properties.healthPercentage");
foreach (Log log in logs)
{
file.WriteLine($"{DateTime.Parse(log.time).ToUniversalTime()}, {log.systemId}, {log.category}, {log.resourceId}, {log.operationName}"
+ $", {log.properties.publicIpAddress }, {log.properties.port}, {log.properties.totalDipCount}"
+ $", {log.properties.dipDownCount}, {log.properties.healthPercentage}");
}
}
}