本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlob类的典型用法代码示例。如果您正苦于以下问题:C# CloudBlob类的具体用法?C# CloudBlob怎么用?C# CloudBlob使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CloudBlob类属于Microsoft.WindowsAzure.Storage.Blob命名空间,在下文中一共展示了CloudBlob类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestAccess
private static void TestAccess(string sasToken, SharedAccessBlobPermissions permissions, SharedAccessBlobHeaders headers, CloudBlobContainer container, CloudBlob blob)
{
CloudBlob SASblob;
StorageCredentials credentials = string.IsNullOrEmpty(sasToken) ?
new StorageCredentials() :
new StorageCredentials(sasToken);
if (container != null)
{
container = new CloudBlobContainer(credentials.TransformUri(container.Uri));
if (blob.BlobType == BlobType.BlockBlob)
{
SASblob = container.GetBlockBlobReference(blob.Name);
}
else if (blob.BlobType == BlobType.PageBlob)
{
SASblob = container.GetPageBlobReference(blob.Name);
}
else
{
SASblob = container.GetAppendBlobReference(blob.Name);
}
}
else
{
if (blob.BlobType == BlobType.BlockBlob)
{
SASblob = new CloudBlockBlob(credentials.TransformUri(blob.Uri));
}
else if (blob.BlobType == BlobType.PageBlob)
{
SASblob = new CloudPageBlob(credentials.TransformUri(blob.Uri));
}
else
{
SASblob = new CloudAppendBlob(credentials.TransformUri(blob.Uri));
}
}
HttpStatusCode failureCode = sasToken == null ? HttpStatusCode.NotFound : HttpStatusCode.Forbidden;
// We want to ensure that 'create', 'add', and 'write' permissions all allow for correct writing of blobs, as is reasonable.
if (((permissions & SharedAccessBlobPermissions.Create) == SharedAccessBlobPermissions.Create) || ((permissions & SharedAccessBlobPermissions.Write) == SharedAccessBlobPermissions.Write))
{
if (blob.BlobType == BlobType.PageBlob)
{
CloudPageBlob SASpageBlob = (CloudPageBlob)SASblob;
SASpageBlob.Create(512);
CloudPageBlob pageBlob = (CloudPageBlob)blob;
byte[] buffer = new byte[512];
buffer[0] = 2; // random data
if (((permissions & SharedAccessBlobPermissions.Write) == SharedAccessBlobPermissions.Write))
{
SASpageBlob.UploadFromByteArray(buffer, 0, 512);
}
else
{
TestHelper.ExpectedException(
() => SASpageBlob.UploadFromByteArray(buffer, 0, 512),
"pageBlob SAS token without Write perms should not allow for writing/adding",
failureCode);
pageBlob.UploadFromByteArray(buffer, 0, 512);
}
}
else if (blob.BlobType == BlobType.BlockBlob)
{
if ((permissions & SharedAccessBlobPermissions.Write) == SharedAccessBlobPermissions.Write)
{
UploadText(SASblob, "blob", Encoding.UTF8);
}
else
{
TestHelper.ExpectedException(
() => UploadText(SASblob, "blob", Encoding.UTF8),
"Block blob SAS token without Write or perms should not allow for writing",
failureCode);
UploadText(blob, "blob", Encoding.UTF8);
}
}
else // append blob
{
// If the sas token contains Feb 2012, append won't be accepted
if (sasToken.Contains(Constants.VersionConstants.February2012))
{
UploadText(blob, "blob", Encoding.UTF8);
}
else
{
CloudAppendBlob SASAppendBlob = SASblob as CloudAppendBlob;
SASAppendBlob.CreateOrReplace();
byte[] textAsBytes = Encoding.UTF8.GetBytes("blob");
using (MemoryStream stream = new MemoryStream())
{
stream.Write(textAsBytes, 0, textAsBytes.Length);
stream.Seek(0, SeekOrigin.Begin);
if (((permissions & SharedAccessBlobPermissions.Add) == SharedAccessBlobPermissions.Add) || ((permissions & SharedAccessBlobPermissions.Write) == SharedAccessBlobPermissions.Write))
{
//.........这里部分代码省略.........
示例2: AzureBlobLocation
/// <summary>
/// Initializes a new instance of the <see cref="AzureBlobLocation"/> class.
/// </summary>
/// <param name="blob">CloudBlob instance as a location in a transfer job.
/// It could be a source, a destination.</param>
public AzureBlobLocation(CloudBlob blob)
{
if (null == blob)
{
throw new ArgumentNullException("blob");
}
this.Blob = blob;
}
示例3: PutNextEntry
protected override void PutNextEntry(CloudBlob blob)
{
var entry = TarEntry.CreateTarEntry(GetEntryName(blob));
entry.Size = blob.Properties.Length;
entry.ModTime = (blob.Properties.LastModified ?? new DateTimeOffset(2000, 01, 01, 00, 00, 00, TimeSpan.Zero)).UtcDateTime;
_archiveStream.PutNextEntry(entry);
}
示例4: WaitForCopyAsync
public static async Task WaitForCopyAsync(CloudBlob blob)
{
bool copyInProgress = true;
while (copyInProgress)
{
await Task.Delay(1000);
await blob.FetchAttributesAsync();
copyInProgress = (blob.CopyState.Status == CopyStatus.Pending);
}
}
示例5: AzureStorageBlob
/// <summary>
/// Azure storage blob constructor
/// </summary>
/// <param name="blob">ICloud blob object</param>
public AzureStorageBlob(CloudBlob blob)
{
Name = blob.Name;
ICloudBlob = blob;
BlobType = blob.BlobType;
Length = blob.Properties.Length;
ContentType = blob.Properties.ContentType;
LastModified = blob.Properties.LastModified;
SnapshotTime = blob.SnapshotTime;
}
示例6: WaitForCopyTask
public static void WaitForCopyTask(CloudBlob blob)
{
bool copyInProgress = true;
while (copyInProgress)
{
Thread.Sleep(1000);
blob.FetchAttributesAsync().Wait();
copyInProgress = (blob.CopyState.Status == CopyStatus.Pending);
}
}
示例7: LoadBlobBytesAsync
public async Task<byte[]> LoadBlobBytesAsync(Uri location)
{
var blob = new CloudBlob (location);
await blob.FetchAttributesAsync ();
byte[] target = new byte[blob.Properties.Length];
await blob.DownloadToByteArrayAsync (target, 0);
return target;
}
示例8: TestAccessTask
private static void TestAccessTask(BlobContainerPublicAccessType accessType, CloudBlobContainer container, CloudBlob inputBlob)
{
StorageCredentials credentials = new StorageCredentials();
container = new CloudBlobContainer(container.Uri, credentials);
CloudPageBlob blob = new CloudPageBlob(inputBlob.Uri, credentials);
if (accessType.Equals(BlobContainerPublicAccessType.Container))
{
blob.FetchAttributesAsync().Wait();
BlobContinuationToken token = null;
do
{
BlobResultSegment results = container.ListBlobsSegmented(token);
results.Results.ToArray();
token = results.ContinuationToken;
}
while (token != null);
container.FetchAttributesAsync().Wait();
}
else if (accessType.Equals(BlobContainerPublicAccessType.Blob))
{
blob.FetchAttributesAsync().Wait();
TestHelper.ExpectedExceptionTask(
container.ListBlobsSegmentedAsync(null),
"List blobs while public access does not allow for listing",
HttpStatusCode.NotFound);
TestHelper.ExpectedExceptionTask(
container.FetchAttributesAsync(),
"Fetch container attributes while public access does not allow",
HttpStatusCode.NotFound);
}
else
{
TestHelper.ExpectedExceptionTask(
blob.FetchAttributesAsync(),
"Fetch blob attributes while public access does not allow",
HttpStatusCode.NotFound);
TestHelper.ExpectedExceptionTask(
container.ListBlobsSegmentedAsync(null),
"List blobs while public access does not allow for listing",
HttpStatusCode.NotFound);
TestHelper.ExpectedExceptionTask(
container.FetchAttributesAsync(),
"Fetch container attributes while public access does not allow",
HttpStatusCode.NotFound);
}
}
示例9: TestAccessAsync
private static async Task TestAccessAsync(BlobContainerPublicAccessType accessType, CloudBlobContainer container, CloudBlob inputBlob)
{
StorageCredentials credentials = new StorageCredentials();
container = new CloudBlobContainer(container.Uri, credentials);
CloudPageBlob blob = new CloudPageBlob(inputBlob.Uri, credentials);
OperationContext context = new OperationContext();
BlobRequestOptions options = new BlobRequestOptions();
if (accessType.Equals(BlobContainerPublicAccessType.Container))
{
await blob.FetchAttributesAsync();
await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.All, null, null, options, context);
await container.FetchAttributesAsync();
}
else if (accessType.Equals(BlobContainerPublicAccessType.Blob))
{
await blob.FetchAttributesAsync();
await TestHelper.ExpectedExceptionAsync(
async () => await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.All, null, null, options, context),
context,
"List blobs while public access does not allow for listing",
HttpStatusCode.NotFound);
await TestHelper.ExpectedExceptionAsync(
async () => await container.FetchAttributesAsync(null, options, context),
context,
"Fetch container attributes while public access does not allow",
HttpStatusCode.NotFound);
}
else
{
await TestHelper.ExpectedExceptionAsync(
async () => await blob.FetchAttributesAsync(null, options, context),
context,
"Fetch blob attributes while public access does not allow",
HttpStatusCode.NotFound);
await TestHelper.ExpectedExceptionAsync(
async () => await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.All, null, null, options, context),
context,
"List blobs while public access does not allow for listing",
HttpStatusCode.NotFound);
await TestHelper.ExpectedExceptionAsync(
async () => await container.FetchAttributesAsync(null, options, context),
context,
"Fetch container attributes while public access does not allow",
HttpStatusCode.NotFound);
}
}
示例10: Equals
/// <summary>
/// Determines whether two blobs have the same Uri and SnapshotTime.
/// </summary>
/// <param name="blob">Blob to compare.</param>
/// <param name="comparand">Comparand object.</param>
/// <returns>True if the two blobs have the same Uri and SnapshotTime; otherwise, false.</returns>
internal static bool Equals(
CloudBlob blob,
CloudBlob comparand)
{
if (blob == comparand)
{
return true;
}
if (null == blob || null == comparand)
{
return false;
}
return blob.Uri.Equals(comparand.Uri) &&
blob.SnapshotTime.Equals(comparand.SnapshotTime);
}
示例11: CreateVideo
private Video CreateVideo(CloudBlob blob)
{
if (blob == null)
{
return null;
}
blob.FetchAttributes();
return new Video
{
Title = blob.Metadata[NameField],
Name = blob.Name,
StorageUrl = blob.Uri.ToString(),
ContentDeliveryNetworkUrl = $"https://{_config.CdnEndpointName}.vo.msecnd.net/{ContainerName}/{blob.Name}"
};
}
示例12: BlobReadStreamBase
/// <summary>
/// Initializes a new instance of the BlobReadStreamBase class.
/// </summary>
/// <param name="blob">Blob reference to read from</param>
/// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the condition that must be met in order for the request to proceed. If <c>null</c>, no condition is used.</param>
/// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies additional options for the request.</param>
/// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
protected BlobReadStreamBase(CloudBlob blob, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
{
if (options.UseTransactionalMD5.Value)
{
CommonUtility.AssertInBounds("StreamMinimumReadSizeInBytes", blob.StreamMinimumReadSizeInBytes, 1, Constants.MaxRangeGetContentMD5Size);
}
this.blob = blob;
this.blobProperties = new BlobProperties(blob.Properties);
this.currentOffset = 0;
this.streamMinimumReadSizeInBytes = this.blob.StreamMinimumReadSizeInBytes;
this.internalBuffer = new MultiBufferMemoryStream(blob.ServiceClient.BufferManager);
this.accessCondition = accessCondition;
this.options = options;
this.operationContext = operationContext;
this.blobMD5 = (this.options.DisableContentMD5Validation.Value || string.IsNullOrEmpty(this.blobProperties.ContentMD5)) ? null : new MD5Wrapper();
this.lastException = null;
}
示例13: AssertAreEqual
public static void AssertAreEqual(CloudBlob expected, CloudBlob actual)
{
if (expected == null)
{
Assert.IsNull(actual);
}
else
{
Assert.IsNotNull(actual);
Assert.AreEqual(expected.BlobType, actual.BlobType);
Assert.AreEqual(expected.Uri, actual.Uri);
Assert.AreEqual(expected.StorageUri, actual.StorageUri);
Assert.AreEqual(expected.SnapshotTime, actual.SnapshotTime);
Assert.AreEqual(expected.IsSnapshot, actual.IsSnapshot);
Assert.AreEqual(expected.SnapshotQualifiedUri, actual.SnapshotQualifiedUri);
AssertAreEqual(expected.Properties, actual.Properties);
AssertAreEqual(expected.CopyState, actual.CopyState);
}
}
示例14: TestAccess
private static void TestAccess(BlobContainerPublicAccessType accessType, CloudBlobContainer container, CloudBlob inputBlob)
{
StorageCredentials credentials = new StorageCredentials();
container = new CloudBlobContainer(container.Uri, credentials);
CloudPageBlob blob = new CloudPageBlob(inputBlob.Uri, credentials);
if (accessType.Equals(BlobContainerPublicAccessType.Container))
{
blob.FetchAttributes();
container.ListBlobs().ToArray();
container.FetchAttributes();
}
else if (accessType.Equals(BlobContainerPublicAccessType.Blob))
{
blob.FetchAttributes();
TestHelper.ExpectedException(
() => container.ListBlobs().ToArray(),
"List blobs while public access does not allow for listing",
HttpStatusCode.NotFound);
TestHelper.ExpectedException(
() => container.FetchAttributes(),
"Fetch container attributes while public access does not allow",
HttpStatusCode.NotFound);
}
else
{
TestHelper.ExpectedException(
() => blob.FetchAttributes(),
"Fetch blob attributes while public access does not allow",
HttpStatusCode.NotFound);
TestHelper.ExpectedException(
() => container.ListBlobs().ToArray(),
"List blobs while public access does not allow for listing",
HttpStatusCode.NotFound);
TestHelper.ExpectedException(
() => container.FetchAttributes(),
"Fetch container attributes while public access does not allow",
HttpStatusCode.NotFound);
}
}
示例15: BlobAsyncCopyController
public BlobAsyncCopyController(
TransferScheduler transferScheduler,
TransferJob transferJob,
CancellationToken cancellationToken)
: base(transferScheduler, transferJob, cancellationToken)
{
this.destLocation = transferJob.Destination as AzureBlobLocation;
CloudBlob transferDestBlob = this.destLocation.Blob;
if (null == transferDestBlob)
{
throw new ArgumentException(
string.Format(
CultureInfo.CurrentCulture,
Resources.ParameterCannotBeNullException,
"Dest.Blob"),
"transferJob");
}
if (transferDestBlob.IsSnapshot)
{
throw new ArgumentException(Resources.DestinationMustBeBaseBlob, "transferJob");
}
AzureBlobLocation sourceBlobLocation = transferJob.Source as AzureBlobLocation;
if (sourceBlobLocation != null)
{
if (sourceBlobLocation.Blob.BlobType != transferDestBlob.BlobType)
{
throw new ArgumentException(Resources.SourceAndDestinationBlobTypeDifferent, "transferJob");
}
if (StorageExtensions.Equals(sourceBlobLocation.Blob, transferDestBlob))
{
throw new InvalidOperationException(Resources.SourceAndDestinationLocationCannotBeEqualException);
}
}
this.destBlob = transferDestBlob;
}