本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob类的典型用法代码示例。如果您正苦于以下问题:C# CloudBlockBlob类的具体用法?C# CloudBlockBlob怎么用?C# CloudBlockBlob使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CloudBlockBlob类属于Microsoft.WindowsAzure.Storage.Blob命名空间,在下文中一共展示了CloudBlockBlob类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
}
示例2: JobLogBlob
public JobLogBlob(CloudBlockBlob blob)
{
Blob = blob;
// Parse the name
var parsed = BlobNameParser.Match(blob.Name);
if (!parsed.Success)
{
throw new ArgumentException("Job Log Blob name is invalid Bob! Expected [jobname].[yyyy-MM-dd].json or [jobname].json. Got: " + blob.Name, "blob");
}
// Grab the chunks we care about
JobName = parsed.Groups["job"].Value;
string format = DayTimeStamp;
if (parsed.Groups[1].Success)
{
// Has an hour portion!
format = HourTimeStamp;
}
ArchiveTimestamp = DateTime.ParseExact(
parsed.Groups["timestamp"].Value,
format,
CultureInfo.InvariantCulture);
}
示例3: uploadfromFilesystem
public void uploadfromFilesystem(CloudBlockBlob blob, string localFilePath, string eventType)
{
if (eventType.Equals("create") || eventType.Equals("signUpStart"))
{
Program.ClientForm.addtoConsole("Upload started[create || signUpStart]:" + localFilePath);
blob.UploadFromFile(localFilePath, FileMode.Open);
Program.ClientForm.addtoConsole("Uploaded");
Program.ClientForm.ballon("Uploaded:"+ localFilePath);
}
else
{
try
{
Program.ClientForm.addtoConsole("Upload started[change,etc]:" + localFilePath);
string leaseId = Guid.NewGuid().ToString();
blob.AcquireLease(TimeSpan.FromMilliseconds(16000), leaseId);
blob.UploadFromFile(localFilePath, FileMode.Open, AccessCondition.GenerateLeaseCondition(leaseId));
blob.ReleaseLease(AccessCondition.GenerateLeaseCondition(leaseId));
Program.ClientForm.addtoConsole("Uploaded");
Program.ClientForm.ballon("Uploaded:" + localFilePath);
}
catch (Exception ex)
{
Program.ClientForm.addtoConsole("Upload: second attempt");
Thread.Sleep(5000);
string leaseId = Guid.NewGuid().ToString();
blob.AcquireLease(TimeSpan.FromMilliseconds(16000), leaseId);
blob.UploadFromFile(localFilePath, FileMode.Open, AccessCondition.GenerateLeaseCondition(leaseId));
blob.ReleaseLease(AccessCondition.GenerateLeaseCondition(leaseId));
Program.ClientForm.addtoConsole("Uploaded");
Program.ClientForm.ballon("Uploaded:" + localFilePath);
}
}
}
示例4: WaitForBlobAsync
public static async Task WaitForBlobAsync(CloudBlockBlob blob)
{
await TestHelpers.Await(() =>
{
return blob.Exists();
});
}
示例5: BlobFileSinkStreamProvider
public BlobFileSinkStreamProvider(CloudBlockBlob blob, bool overwrite)
{
Guard.NotNull("blob", blob);
this.blob = blob;
this.overwrite = overwrite;
}
示例6: revertFromSnapshot
public void revertFromSnapshot(CloudBlockBlob blobRef, CloudBlockBlob snapshot)
{
try
{
blobRef.StartCopyFromBlob(snapshot);
DateTime timestamp = DateTime.Now;
blobRef.FetchAttributes();
snapshot.FetchAttributes();
string time = snapshot.Metadata["timestamp"];
blobRef.Metadata["timestamp"] = timestamp.ToUniversalTime().ToString("MM/dd/yyyy HH:mm:ss");
blobRef.SetMetadata();
blobRef.CreateSnapshot();
//System.Windows.Forms.MessageBox.Show("revert success");
Program.ClientForm.addtoConsole("Successfully Reverted with time: " + time);
Program.ClientForm.ballon("Successfully Reverted! ");
}
catch (Exception e)
{
Program.ClientForm.addtoConsole("Exception:" + e.Message);
//System.Windows.Forms.MessageBox.Show(e.ToString());
}
}
示例7: deleteSnapshot
public void deleteSnapshot(CloudBlockBlob blobRef)
{
string blobPrefix = null;
bool useFlatBlobListing = true;
var snapshots = container.ListBlobs(blobPrefix, useFlatBlobListing,
BlobListingDetails.Snapshots).Where(item => ((CloudBlockBlob)item).SnapshotTime.HasValue && item.Uri.Equals(blobRef.Uri)).ToList<IListBlobItem>();
if (snapshots.Count < 1)
{
Console.WriteLine("snapshot was not created");
}
else
{
foreach (IListBlobItem item in snapshots)
{
CloudBlockBlob blob = (CloudBlockBlob)item;
blob.DeleteIfExists();
Console.WriteLine("Delete Name: {0}, Timestamp: {1}", blob.Name, blob.SnapshotTime);
Console.WriteLine("success");
}
//snapshots.ForEach(item => Console.WriteLine(String.Format("{0} {1} ", ((CloudBlockBlob)item).Name, ((CloudBlockBlob)item).Metadata["timestamp"])));
}
}
示例8: JobLogBlob
public JobLogBlob(CloudBlockBlob blob)
{
Blob = blob;
// Parse the name
var parsed = BlobNameParser.Match(blob.Name);
if (!parsed.Success)
{
throw new ArgumentException(string.Format(NuGetGallery.Strings.JobLogBlobNameInvalid, blob.Name), nameof(blob));
}
// Grab the chunks we care about
JobName = parsed.Groups["job"].Value;
string format = DayTimeStamp;
if (parsed.Groups[1].Success)
{
// Has an hour portion!
format = HourTimeStamp;
}
ArchiveTimestamp = DateTime.ParseExact(
parsed.Groups["timestamp"].Value,
format,
CultureInfo.InvariantCulture);
}
示例9: ValidatePipelineICloudBlobSuccessfullyTest
public void ValidatePipelineICloudBlobSuccessfullyTest()
{
AddTestBlobs();
CloudBlockBlob blob = new CloudBlockBlob(new Uri("http://127.0.0.1/account/container1/blob0"));
command.ValidatePipelineICloudBlob(blob);
}
示例10: EndpointToHost
public EndpointToHost(CloudBlockBlob blob)
{
this.blob = blob;
this.blob.FetchAttributes();
EndpointName = Path.GetFileNameWithoutExtension(blob.Uri.AbsolutePath);
LastUpdated = blob.Properties.LastModified.HasValue ? blob.Properties.LastModified.Value.DateTime : default(DateTime);
}
示例11: AddContainerMetadata
public static void AddContainerMetadata(CloudBlockBlob blob, object fileUploadObj)
{
var obj = ((BlobStorage.Models.UploadDataModel)fileUploadObj);
//Add some metadata to the container.
if (IsNotNull(obj.Category))
blob.Metadata["category"] = obj.Category;
else
blob.Metadata["category"] = "Other";
if (IsNotNull(obj.Name))
blob.Metadata["name"] = obj.Name;
else
blob.Metadata["name"] = "Null";
if (IsNotNull(obj.Number))
blob.Metadata["number"] = obj.Number;
else
blob.Metadata["number"] = "Null";
if (IsNotNull(obj.Email))
blob.Metadata["email"] = obj.Email;
else
blob.Metadata["email"] = "Null";
if (IsNotNull(obj.Comments))
blob.Metadata["comments"] = obj.Comments;
else
blob.Metadata["comments"] = "Null";
//Set the container's metadata.
blob.SetMetadata();
}
示例12: 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);
}
}
}
}
}
}
示例13: GetTitle
protected String GetTitle(Uri blobURI)
{
//returns the title of the file from the Blob metadata
CloudBlockBlob blob = new CloudBlockBlob(blobURI);
blob.FetchAttributes();
return blob.Metadata["Title"];
}
示例14: Main
public static void Main(string[] args)
{
Console.WriteLine("Press any key to run sample...");
Console.ReadKey();
// Make sure the endpoint matches with the web role's endpoint.
var tokenServiceEndpoint = ConfigurationManager.AppSettings["serviceEndpointUrl"];
try
{
var blobSas = GetBlobSas(new Uri(tokenServiceEndpoint)).Result;
// Create storage credentials object based on SAS
var credentials = new StorageCredentials(blobSas.Credentials);
// Using the returned SAS credentials and BLOB Uri create a block blob instance to upload
var blob = new CloudBlockBlob(blobSas.BlobUri, credentials);
using (var stream = GetFileToUpload(10))
{
blob.UploadFromStream(stream);
}
Console.WriteLine("Blob uplodad successful: {0}", blobSas.Name);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.WriteLine();
Console.WriteLine("Done. Press any key to exit...");
Console.ReadKey();
}
示例15: 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();
}
}
}