本文整理汇总了C#中Microsoft.WindowsAzure.StorageClient.CloudBlob类的典型用法代码示例。如果您正苦于以下问题:C# CloudBlob类的具体用法?C# CloudBlob怎么用?C# CloudBlob使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CloudBlob类属于Microsoft.WindowsAzure.StorageClient命名空间,在下文中一共展示了CloudBlob类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
}
开发者ID:fashaikh,项目名称:ChronoZoom,代码行数:35,代码来源:Common.cs
示例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();
}
}
}
开发者ID:robertogg,项目名称:Demos,代码行数:28,代码来源:LogFetcher.cs
示例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));
}
}
开发者ID:smonteil,项目名称:azuremongospare,代码行数:35,代码来源:Program.cs
示例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();
}
}
开发者ID:nghead,项目名称:NServiceBus,代码行数:27,代码来源:AutoRenewLease.cs
示例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);
}
}
开发者ID:sushant2517,项目名称:WazStorageExtensions,代码行数:28,代码来源:AutoRenewLease.cs
示例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);
}
}
开发者ID:higheredgrowth,项目名称:lokad-cqrs,代码行数:35,代码来源:BlobStorageUtil.cs
示例7: BlobTreeNode
public BlobTreeNode(CloudBlob blob)
{
Blob = blob;
ImageKey = "Blob";
SelectedImageKey = "Blob";
Text = blob.Name;
}
开发者ID:caseywatson,项目名称:AzureStorageDemo,代码行数:8,代码来源:BlobTreeNode.cs
示例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();
}
开发者ID:MRCollective,项目名称:AzureWebFarm,代码行数:8,代码来源:LeaseBlobExtensions.cs
示例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>();
}
开发者ID:bunkermachine,项目名称:nimbus,代码行数:8,代码来源:Project.cs
示例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;
}
开发者ID:kallex,项目名称:Caloom,代码行数:8,代码来源:InformationSource.cs
示例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();
}
开发者ID:rhayesbite,项目名称:Examine,代码行数:8,代码来源:LeaseBlobExtensions.cs
示例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);
}
开发者ID:valkiria88,项目名称:Astoria,代码行数:19,代码来源:BlobLibrary.cs
示例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>();
}
开发者ID:bunkermachine,项目名称:nimbus,代码行数:9,代码来源:Task.cs
示例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()));
}
开发者ID:smarx,项目名称:Things,代码行数:56,代码来源:HomeController.cs
示例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);
}
}
开发者ID:kallex,项目名称:Caloom,代码行数:10,代码来源:InformationSourceCollection.cs
示例16: Delete
/// <summary>
/// Удаляет файл.
/// </summary>
/// <param name="localUri"> Адрес файла </param>
public void Delete(string localUri)
{
CloudBlob blob = new CloudBlob(localUri, _client);
blob.DeleteIfExists(new BlobRequestOptions()
{
RetryPolicy = RetryPolicies.RetryExponential(
RetryPolicies.DefaultClientRetryCount,
RetryPolicies.DefaultClientBackoff)
});
}
开发者ID:retran,项目名称:old-projects-backup,代码行数:14,代码来源:BlobServiceImplementor.cs
示例17: CreateUpdateModifiedDateTaskRunner
public TaskRunner CreateUpdateModifiedDateTaskRunner(CloudBlob blob, FileInformation fileInfo)
{
this._statistics.UpdatedModifiedDateCount++;
return new SingleActionTaskRunner(() =>
{
_messageBus.Publish(new FileProgressedMessage(fileInfo.FullPath, 0));
blob.SetFileLastModifiedUtc(fileInfo.LastWriteTimeUtc, true);
_messageBus.Publish(new FileProgressedMessage(fileInfo.FullPath, 1));
});
}
开发者ID:devsda0,项目名称:AzureBackup,代码行数:10,代码来源:UploadSyncronizationProvider.cs
示例18: CreateUpdateTaskRunner
public TaskRunner CreateUpdateTaskRunner(CloudBlob blob, FileInformation fileInfo)
{
this._statistics.UpdatedCount++;
return new SingleActionTaskRunner(() =>
{
_messageBus.Publish(new FileProgressedMessage(fileInfo.FullPath, 0));
blob.DownloadToFile(fileInfo.FullPath);
_fileSystem.SetLastWriteTimeUtc(fileInfo.FullPath, blob.GetFileLastModifiedUtc());
_messageBus.Publish(new FileProgressedMessage(fileInfo.FullPath, 1));
});
}
开发者ID:devsda0,项目名称:AzureBackup,代码行数:11,代码来源:DownloadKeepSyncronizationProvider.cs
示例19: DoLeaseOperationAsync
private static async Task DoLeaseOperationAsync(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, 90, action, leaseId);
creds.SignRequest(req);
using (var response = await req.GetResponseAsync())
{
response.Close();
}
}
开发者ID:bytenik,项目名称:CloudServiceHost,代码行数:11,代码来源:CloudBlobExtensions.cs
示例20: AzureTapeStream
public AzureTapeStream(string name, string connectionString, string containerName, ITapeStreamSerializer serializer)
{
_serializer = serializer;
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
blobClient = storageAccount.CreateCloudBlobClient();
container = blobClient.GetContainerReference(containerName);
container.CreateIfNotExist();
_blob = container.GetBlobReference(name);
}
开发者ID:stemarie,项目名称:CqrsSiteEngine,代码行数:11,代码来源:AzureTapeStream.cs
注:本文中的Microsoft.WindowsAzure.StorageClient.CloudBlob类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论