本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.FetchAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlockBlob.FetchAttributes方法的具体用法?C# CloudBlockBlob.FetchAttributes怎么用?C# CloudBlockBlob.FetchAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob
的用法示例。
在下文中一共展示了CloudBlockBlob.FetchAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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"];
}
示例2: 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());
}
}
示例3: ArchiveOriginalPackageBlob
/// <summary>
/// Creates an archived copy of the original package blob if it doesn't already exist.
/// </summary>
private void ArchiveOriginalPackageBlob(CloudBlockBlob originalPackageBlob, CloudBlockBlob latestPackageBlob)
{
// Copy the blob to backup only if it isn't already successfully copied
if ((!originalPackageBlob.Exists()) || (originalPackageBlob.CopyState != null && originalPackageBlob.CopyState.Status != CopyStatus.Success))
{
if (!WhatIf)
{
Log.Info("Backing up blob: {0} to {1}", latestPackageBlob.Name, originalPackageBlob.Name);
originalPackageBlob.StartCopyFromBlob(latestPackageBlob);
CopyState state = originalPackageBlob.CopyState;
for (int i = 0; (state == null || state.Status == CopyStatus.Pending) && i < SleepTimes.Length; i++)
{
Log.Info("(sleeping for a copy completion)");
Thread.Sleep(SleepTimes[i]);
originalPackageBlob.FetchAttributes(); // To get a refreshed CopyState
//refresh state
state = originalPackageBlob.CopyState;
}
if (state.Status != CopyStatus.Success)
{
string msg = string.Format("Blob copy failed: CopyState={0}", state.StatusDescription);
Log.Error("(error) " + msg);
throw new BlobBackupFailedException(msg);
}
}
}
}
示例4: GetInstanceIndex
protected String GetInstanceIndex(Uri blobURI)
{
//returns the Worker role's index from the Blob metadata
CloudBlockBlob blob = new CloudBlockBlob(blobURI);
blob.FetchAttributes();
return blob.Metadata["InstanceNo"];
}
示例5: GetBlob
public byte[] GetBlob(string containerName, string blobName)
{
CloudBlobContainer container = _blobClient.GetContainerReference(containerName);
_blockBlob = container.GetBlockBlobReference(blobName);
_blockBlob.FetchAttributes();
long fileByteLength = _blockBlob.Properties.Length;
byte[] fileContents = new byte[fileByteLength];
_blockBlob.DownloadToByteArray(fileContents, 0);
return fileContents;
}
示例6: Exists
public static bool Exists(CloudBlockBlob blob)
{
try
{
blob.FetchAttributes();
return true;
}
catch (StorageException)
{
return false;
}
}
示例7: BlobReadExpectLeaseSuccess
/// <summary>
/// Test blob reads, expecting success.
/// </summary>
/// <param name="testBlob">The blob to test.</param>
/// <param name="testAccessCondition">The access condition to use.</param>
private void BlobReadExpectLeaseSuccess(CloudBlockBlob testBlob, AccessCondition testAccessCondition)
{
testBlob.FetchAttributes(testAccessCondition, null /* options */);
testBlob.Snapshot(null /* metadata */, testAccessCondition, null /* options */).Delete();
DownloadText(testBlob, Encoding.UTF8, testAccessCondition, null /* options */);
Stream stream = testBlob.OpenRead(testAccessCondition, null /* options */);
stream.ReadByte();
}
示例8: BlobReadExpectLeaseFailure
/// <summary>
/// Test blob reads, expecting lease failure.
/// </summary>
/// <param name="testBlob">The blob to test.</param>
/// <param name="targetBlob">The blob to use for the target of copy operations.</param>
/// <param name="testAccessCondition">The failing access condition to use.</param>
/// <param name="expectedErrorCode">The expected error code.</param>
/// <param name="description">The reason why these calls should fail.</param>
private void BlobReadExpectLeaseFailure(CloudBlockBlob testBlob, CloudBlockBlob targetBlob, AccessCondition testAccessCondition, HttpStatusCode expectedStatusCode, string expectedErrorCode, string description)
{
// FetchAttributes is a HEAD request with no extended error info, so it returns with the generic ConditionFailed error code.
TestHelper.ExpectedException(
() => testBlob.FetchAttributes(testAccessCondition, null /* options */),
description + "(Fetch Attributes)",
HttpStatusCode.PreconditionFailed);
TestHelper.ExpectedException(
() => testBlob.Snapshot(null /* metadata */, testAccessCondition, null /* options */),
description + " (Create Snapshot)",
expectedStatusCode,
expectedErrorCode);
TestHelper.ExpectedException(
() => DownloadText(testBlob, Encoding.UTF8, testAccessCondition, null /* options */),
description + " (Download Text)",
expectedStatusCode,
expectedErrorCode);
TestHelper.ExpectedException(
() => testBlob.OpenRead(testAccessCondition, null /* options */),
description + " (Read Stream)",
expectedStatusCode/*,
expectedErrorCode*/);
}
示例9: BlobWriteExpectLeaseSuccess
/// <summary>
/// Test blob writing, expecting success.
/// </summary>
/// <param name="testBlob">The blob to test.</param>
/// <param name="sourceBlob">A blob to use as the source of a copy.</param>
/// <param name="testAccessCondition">The access condition to use.</param>
private void BlobWriteExpectLeaseSuccess(CloudBlockBlob testBlob, CloudBlob sourceBlob, AccessCondition testAccessCondition)
{
testBlob.SetMetadata(testAccessCondition, null /* options */);
testBlob.SetProperties(testAccessCondition, null /* options */);
UploadText(testBlob, "No Problem", Encoding.UTF8, testAccessCondition, null /* options */);
testBlob.StartCopy(TestHelper.Defiddler(sourceBlob.Uri), null /* source access condition */, testAccessCondition, null /* options */);
while (testBlob.CopyState.Status == CopyStatus.Pending)
{
Thread.Sleep(1000);
testBlob.FetchAttributes();
}
Stream stream = testBlob.OpenWrite(testAccessCondition, null /* options */);
stream.WriteByte(0);
stream.Flush();
testBlob.Delete(DeleteSnapshotsOption.None, testAccessCondition, null /* options */);
}
示例10: ReadFromMetadata
public AzurePackage ReadFromMetadata(CloudBlockBlob blob)
{
blob.FetchAttributes();
var package = new AzurePackage();
package.Id = blob.Metadata["Id"];
package.Version = new SemanticVersion(blob.Metadata["Version"]);
if (blob.Metadata.ContainsKey("Title"))
{
package.Title = blob.Metadata["Title"];
}
if (blob.Metadata.ContainsKey("Authors"))
{
package.Authors = blob.Metadata["Authors"].Split(',');
}
if (blob.Metadata.ContainsKey("Owners"))
{
package.Owners = blob.Metadata["Owners"].Split(',');
}
if (blob.Metadata.ContainsKey("IconUrl"))
{
package.IconUrl = new Uri(blob.Metadata["IconUrl"]);
}
if (blob.Metadata.ContainsKey("LicenseUrl"))
{
package.LicenseUrl = new Uri(blob.Metadata["LicenseUrl"]);
}
if (blob.Metadata.ContainsKey("ProjectUrl"))
{
package.ProjectUrl = new Uri(blob.Metadata["ProjectUrl"]);
}
package.RequireLicenseAcceptance = blob.Metadata["RequireLicenseAcceptance"].ToBool();
package.DevelopmentDependency = blob.Metadata["DevelopmentDependency"].ToBool();
if (blob.Metadata.ContainsKey("Description"))
{
package.Description = blob.Metadata["Description"];
}
if (blob.Metadata.ContainsKey("Summary"))
{
package.Summary = blob.Metadata["Summary"];
}
if (blob.Metadata.ContainsKey("ReleaseNotes"))
{
package.ReleaseNotes = blob.Metadata["ReleaseNotes"];
}
if (blob.Metadata.ContainsKey("Tags"))
{
package.Tags = blob.Metadata["Tags"];
}
var dependencySetContent = blob.Metadata["Dependencies"];
dependencySetContent = this.Base64Decode(dependencySetContent);
package.DependencySets = dependencySetContent
.FromJson<IEnumerable<AzurePackageDependencySet>>()
.Select(x => new PackageDependencySet(x.TargetFramework, x.Dependencies));
package.IsAbsoluteLatestVersion = blob.Metadata["IsAbsoluteLatestVersion"].ToBool();
package.IsLatestVersion = blob.Metadata["IsLatestVersion"].ToBool();
if (blob.Metadata.ContainsKey("MinClientVersion"))
{
package.MinClientVersion = new Version(blob.Metadata["MinClientVersion"]);
}
package.Listed = blob.Metadata["Listed"].ToBool();
return package;
}
示例11: PrefixEscapingTest
private void PrefixEscapingTest(string prefix, string blobName)
{
CloudBlobClient service = GenerateCloudBlobClient();
CloudBlobContainer container = GetRandomContainerReference();
try
{
container.Create();
string text = Guid.NewGuid().ToString();
// Create from CloudBlobContainer.
CloudBlockBlob originalBlob = container.GetBlockBlobReference(prefix + "/" + blobName);
originalBlob.PutBlockList(new string[] { });
// List blobs from container.
IListBlobItem blobFromContainerListingBlobs = container.ListBlobs(null, true).First();
Assert.AreEqual(originalBlob.Uri, blobFromContainerListingBlobs.Uri);
// Check Name
Assert.AreEqual<string>(prefix + "/" + blobName, originalBlob.Name);
// Absolute URI access from CloudBlockBlob
CloudBlockBlob blobInfo = new CloudBlockBlob(originalBlob.Uri, service.Credentials);
blobInfo.FetchAttributes();
// Access from CloudBlobDirectory
CloudBlobDirectory cloudBlobDirectory = container.GetDirectoryReference(prefix);
CloudBlockBlob blobFromCloudBlobDirectory = cloudBlobDirectory.GetBlockBlobReference(blobName);
Assert.AreEqual(blobInfo.Uri, blobFromCloudBlobDirectory.Uri);
// Copy blob verification.
CloudBlockBlob copyBlob = container.GetBlockBlobReference(prefix + "/" + blobName + "copy");
copyBlob.StartCopyFromBlob(blobInfo.Uri);
copyBlob.FetchAttributes();
}
finally
{
container.Delete();
}
}
示例12: 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);
}
示例13: 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());
}
}
示例14: IsBlobAged
private static bool IsBlobAged(CloudBlockBlob blob, DateTime olderThanUtc)
{
try
{
blob.FetchAttributes();
return blob.Properties.LastModified < olderThanUtc;
}
catch (StorageException e)
{
throw new BlobException(string.Format(CultureInfo.InvariantCulture, "Could not FetchAttributes or examine LastModified from properties for blob named '{0}' to see if it is aged older than '{1}' (UTC). See inner exception for details.", blob.Name, olderThanUtc.ToString()), e);
}
}
示例15: 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);
}
}