本文整理汇总了C#中Microsoft.WindowsAzure.StorageClient.CloudBlob类的典型用法代码示例。如果您正苦于以下问题:C# CloudBlob类的具体用法?C# CloudBlob怎么用?C# CloudBlob使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CloudBlob类属于Microsoft.WindowsAzure.StorageClient命名空间,在下文中一共展示了CloudBlob类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BlobExists
/// <summary>
/// Check whether the specified blob exists
/// </summary>
/// <param name="blob">Blob to check</param>
/// <returns>true if specified blob exists, and false if it doesn't</returns>
private static bool BlobExists(CloudBlob blob)
{
try
{
// try fetching Attributes
blob.FetchAttributes();
return true;
}
catch (StorageClientException e)
{
if (e.ErrorCode == StorageErrorCode.ResourceNotFound)
{
// if failed with ResourceNotFound error code, then the blob doesn't exist
return false;
}
else
{
// something else went wrong
//throw;
Console.Write(e);
return false;
}
}
catch (Exception e)
{
Console.Write(e);
return false;
}
}
示例2: CopyContents
/// <summary>
/// Copies the full binary contents of the given blob to the given HTTP response.
/// </summary>
private static void CopyContents(CloudBlob blob, HttpResponseBase response, long offset = 0)
{
blob.FetchAttributes();
response.BufferOutput = false;
response.AddHeader("Content-Length", blob.Attributes.Properties.Length.ToString());
response.Flush();
using (var reader = blob.OpenRead())
{
reader.Seek(offset, System.IO.SeekOrigin.Begin);
byte[] buffer = new byte[1024 * 4]; // 4KB buffer
while (reader.CanRead)
{
int numBytes = reader.Read(buffer, 0, buffer.Length);
if (numBytes <= 0)
break;
response.BinaryWrite(buffer);
response.Flush();
}
}
}
示例3: Main
static void Main(string[] args)
{
try
{
string BlobURL = "deploy/Testdrivesnapshot.vhd";
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=http;AccountName=mongodbwest2;AccountKey=wZcR60wAy+zltHPV7CXJsvBo/rnZHV2FIqg+UA+H1pIhkYl4j0qRZ+GgI5V8IJhngh2DOxI+sS46KddPFWg0Xw==");
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
//Get a reference to a blob.
CloudBlob blob = blobClient.GetBlobReference(BlobURL);
//Take a snapshot of the blob.
CloudBlob snapshot = blob.CreateSnapshot();
//Get the snapshot timestamp.
DateTime timestamp = (DateTime)snapshot.Attributes.Snapshot;
//Use the timestamp to get a second reference to the snapshot.
CloudBlob snapshot2 = new CloudBlob(BlobURL, timestamp, blobClient);
CloudDrive Snapshotdrive = new CloudDrive(snapshot2.Uri, storageAccount.Credentials);
string path = Snapshotdrive.Mount(0, DriveMountOptions.None);
Console.WriteLine("Mounted on " + path);
Console.ReadLine();
Snapshotdrive.Unmount();
}
catch (Exception ex)
{
Console.WriteLine(string.Format("Exception : {0} ({1}) at {2}", ex.Message, ex.InnerException == null ? "" : ex.InnerException.Message, ex.StackTrace));
}
}
示例4: AutoRenewLease
public AutoRenewLease(CloudBlob blob)
{
this.blob = blob;
blob.Container.CreateIfNotExist();
try
{
blob.UploadByteArray(new byte[0], new BlobRequestOptions { AccessCondition = AccessCondition.IfNoneMatch("*") });
}
catch (StorageClientException e)
{
if (e.ErrorCode != StorageErrorCode.BlobAlreadyExists
&& e.StatusCode != HttpStatusCode.PreconditionFailed) // 412 from trying to modify a blob that's leased
{
throw;
}
}
leaseId = blob.TryAcquireLease();
if (HasLease)
{
renewalThread = new Thread(() =>
{
Thread.Sleep(TimeSpan.FromSeconds(40));
blob.RenewLease(leaseId);
});
renewalThread.Start();
}
}
示例5: DoEvery
public static void DoEvery(CloudBlob blob, TimeSpan interval, Action action)
{
while (true)
{
var lastPerformed = DateTimeOffset.MinValue;
using (var arl = new AutoRenewLease(blob))
{
if (arl.HasLease)
{
blob.FetchAttributes();
DateTimeOffset.TryParseExact(blob.Metadata["lastPerformed"], "R", CultureInfo.CurrentCulture, DateTimeStyles.AdjustToUniversal, out lastPerformed);
if (DateTimeOffset.UtcNow >= lastPerformed + interval)
{
action();
lastPerformed = DateTimeOffset.UtcNow;
blob.Metadata["lastPerformed"] = lastPerformed.ToString("R");
blob.SetMetadata(arl.leaseId);
}
}
}
var timeLeft = (lastPerformed + interval) - DateTimeOffset.UtcNow;
var minimum = TimeSpan.FromSeconds(5); // so we're not polling the leased blob too fast
Thread.Sleep(
timeLeft > minimum
? timeLeft
: minimum);
}
}
示例6: Read
public static void Read(BlobRequestOptions mapped, CloudBlob blob, ReaderDelegate reader)
{
blob.FetchAttributes(mapped);
var props = MapFetchedAttrbitues(blob);
var compression = blob.Properties.ContentEncoding ?? "";
var md5 = blob.Metadata[LokadHashFieldName];
switch (compression)
{
case "gzip":
using (var stream = blob.OpenRead(mapped))
{
ReadAndVerifyHash(stream, s =>
{
// important is not to flush the decompression stream
using (var decompress = new GZipStream(s, CompressionMode.Decompress, true))
{
reader(props, decompress);
}
}, md5);
}
break;
case "":
using (var stream = blob.OpenRead(mapped))
{
ReadAndVerifyHash(stream, s => reader(props, s), md5);
}
break;
default:
var error = string.Format("Unsupported ContentEncoding '{0}'", compression);
throw new InvalidOperationException(error);
}
}
示例7: BlobTreeNode
public BlobTreeNode(CloudBlob blob)
{
Blob = blob;
ImageKey = "Blob";
SelectedImageKey = "Blob";
Text = blob.Name;
}
示例8: DoLeaseOperation
private static void DoLeaseOperation(CloudBlob blob, string leaseId, LeaseAction action)
{
var credentials = blob.ServiceClient.Credentials;
var request = BlobRequest.Lease(new Uri(credentials.TransformUri(blob.Uri.AbsoluteUri)), 90,
action, leaseId);
credentials.SignRequest(request);
request.GetResponse().Close();
}
示例9: Project
public Project(string projectName, string projectDummyFile, CloudBlob projectDummyFileBlob)
{
this.projectName = projectName;
this.projectDummyFile = projectDummyFile;
this.projectDummyFileBlob = projectDummyFileBlob;
tasksMap = new Dictionary<string, Task>();
projectMetadata = new Dictionary<string, string>();
}
示例10: SetBlobValuesToSource
public void SetBlobValuesToSource(CloudBlob blob)
{
SourceLocation = blob.Name;
SourceETag = blob.Properties.ETag;
SourceType = blob.GetBlobInformationType();
SourceMD5 = blob.Properties.ContentMD5;
SourceLastModified = blob.Properties.LastModifiedUtc;
}
示例11: DoLeaseOperation
private static void DoLeaseOperation(CloudBlob blob, string leaseId, LeaseAction action)
{
var creds = blob.ServiceClient.Credentials;
var transformedUri = new Uri(creds.TransformUri(blob.Uri.ToString()));
var req = BlobRequest.Lease(transformedUri, 60, action, leaseId);
creds.SignRequest(req);
req.GetResponse().Close();
}
示例12: appendToBlob
private const string MimeTypeName = "text/plain"; // since these are assumed to
#endregion Fields
#region Methods
/// <summary>
/// ugliness of downloading and reuploading whole blob.
/// </summary>
/// <param name="blob"></param>
/// <param name="toAdd"></param>
public static void appendToBlob(CloudBlob blob, string toAdd)
{
string oldLogData = "";
if (Exists(blob))
oldLogData = blob.DownloadText();
blob.DeleteIfExists();
blob.UploadText(oldLogData + "\r\n" + toAdd);
}
示例13: Task
public Task(string taskName, string taskDummyFile, CloudBlob taskDummyFileBlob)
{
this.taskName = taskName;
this.taskDummyFile = taskDummyFile;
this.taskDummyFileBlob = taskDummyFileBlob;
this.exes = new List<string>();
this.dataFiles = new List<string>();
taskMetadata = new Dictionary<string, string>();
}
示例14: Pygmentize
Tuple<string, IHtmlString> Pygmentize(CloudBlob blob)
{
var filename = Uri.UnescapeDataString(blob.Uri.Segments.Last());
var extension = Path.GetExtension(filename).ToLower();
if (extension == ".mdown")
{
return new Tuple<string, IHtmlString>(null, new MvcHtmlString(new Markdown().Transform(blob.DownloadText())));
}
var formatters = new Dictionary<string, string>()
{
{ ".cscfg", "xml" },
{ ".csdef", "xml" },
{ ".config", "xml" },
{ ".xml", "xml" },
{ ".cmd", "bat" },
{ ".rb", "ruby" },
{ ".cs", "csharp" },
{ ".html", "html" },
{ ".cshtml", "html" },
{ ".css", "css" },
{ ".erb", "erb" },
{ ".haml", "haml" },
{ ".js", "javascript" },
{ ".php", "php" },
{ ".py", "python" },
{ ".yaml", "yaml" },
{ ".yml", "yaml" },
{ ".txt", "text" }
};
var executable = "pygmentize";
if (RoleEnvironment.IsAvailable)
{
executable = Path.Combine(RoleEnvironment.GetLocalResource("Python").RootPath, @"scripts\pygmentize.exe");
}
if (!formatters.ContainsKey(extension))
{
extension = ".txt";
}
var startInfo = new ProcessStartInfo(executable, string.Format("-f html -l {0}", formatters[extension]))
{
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
};
var proc = Process.Start(startInfo);
proc.StandardInput.Write(blob.DownloadText().Trim(new char[]{'\uFEFF'}));
proc.StandardInput.Close();
return new Tuple<string, IHtmlString>(filename, new MvcHtmlString(proc.StandardOutput.ReadToEnd()));
}
示例15: SubscribeTargetToSourceChanges
public void SubscribeTargetToSourceChanges(CloudBlob subscriber)
{
if(subscriber.CanContainExternalMetadata() == false)
throw new InvalidDataException("Subscriber candidate cannot contain metadata: " + subscriber.Name);
foreach(var source in CollectionContent.Where(src => src.IsInformationObjectSource))
{
SubscribeSupport.AddSubscriptionToObject(source.SourceLocation, subscriber.Name,
SubscribeSupport.SubscribeType_WebPageToSource);
}
}