本文整理汇总了C#中IStorageBlobManagement类的典型用法代码示例。如果您正苦于以下问题:C# IStorageBlobManagement类的具体用法?C# IStorageBlobManagement怎么用?C# IStorageBlobManagement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IStorageBlobManagement类属于命名空间,在下文中一共展示了IStorageBlobManagement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAzureContainerStoredAccessPolicy
internal string CreateAzureContainerStoredAccessPolicy(IStorageBlobManagement localChannel, string containerName, string policyName, DateTime? startTime, DateTime? expiryTime, string permission)
{
if (!NameUtil.IsValidStoredAccessPolicyName(policyName))
{
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.InvalidAccessPolicyName, policyName));
}
//Get existing permissions
CloudBlobContainer container = localChannel.GetContainerReference(containerName);
BlobContainerPermissions blobContainerPermissions = localChannel.GetContainerPermissions(container);
//Add new policy
if (blobContainerPermissions.SharedAccessPolicies.Keys.Contains(policyName))
{
throw new ResourceAlreadyExistException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyAlreadyExists, policyName));
}
SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy();
AccessPolicyHelper.SetupAccessPolicy<SharedAccessBlobPolicy>(policy, startTime, expiryTime, permission);
blobContainerPermissions.SharedAccessPolicies.Add(policyName, policy);
//Set permissions back to container
localChannel.SetContainerPermissions(container, blobContainerPermissions);
return policyName;
}
示例2: SetContainerAcl
/// <summary>
/// set the access level of specified container
/// </summary>
/// <param name="name">container name</param>
/// <param name="accessLevel">access level in ("off", "blob", "container")</param>
internal async Task SetContainerAcl(long taskId, IStorageBlobManagement localChannel, string name, BlobContainerPublicAccessType accessLevel)
{
if (!NameUtil.IsValidContainerName(name))
{
throw new ArgumentException(String.Format(Resources.InvalidContainerName, name));
}
BlobContainerPermissions permissions = new BlobContainerPermissions();
permissions.PublicAccess = accessLevel;
BlobRequestOptions requestOptions = RequestOptions;
AccessCondition accessCondition = null;
CloudBlobContainer container = localChannel.GetContainerReference(name);
if (!await localChannel.DoesContainerExistAsync(container, requestOptions, OperationContext, CmdletCancellationToken))
{
throw new ResourceNotFoundException(String.Format(Resources.ContainerNotFound, name));
}
await localChannel.SetContainerPermissionsAsync(container, permissions, accessCondition, requestOptions, OperationContext, CmdletCancellationToken);
if (PassThru)
{
WriteCloudContainerObject(taskId, localChannel, container, permissions);
}
}
示例3: SetDestinationContainer
public void SetDestinationContainer(IStorageBlobManagement channel, string containerName)
{
if (Container == null)
{
if (!NameUtil.IsValidContainerName(containerName))
{
throw new ArgumentException(String.Format(Resources.InvalidContainerName, containerName));
}
Container = channel.GetContainerReference(containerName);
}
}
示例4: SetAzureContainerStoredAccessPolicy
internal string SetAzureContainerStoredAccessPolicy(IStorageBlobManagement localChannel, string containerName, string policyName, DateTime? startTime, DateTime? expiryTime, string permission, bool noStartTime, bool noExpiryTime)
{
//Get existing permissions
CloudBlobContainer container = localChannel.GetContainerReference(containerName);
BlobContainerPermissions blobContainerPermissions = localChannel.GetContainerPermissions(container);
//Set the policy with new value
if (!blobContainerPermissions.SharedAccessPolicies.Keys.Contains(policyName))
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName));
}
SharedAccessBlobPolicy policy = blobContainerPermissions.SharedAccessPolicies[policyName];
AccessPolicyHelper.SetupAccessPolicy<SharedAccessBlobPolicy>(policy, startTime, expiryTime, permission, noStartTime, noExpiryTime);
blobContainerPermissions.SharedAccessPolicies[policyName] = policy;
//Set permission back to container
localChannel.SetContainerPermissions(container, blobContainerPermissions);
WriteObject(AccessPolicyHelper.ConstructPolicyOutputPSObject<SharedAccessBlobPolicy>(blobContainerPermissions.SharedAccessPolicies, policyName));
return policyName;
}
示例5: RemoveAzureContainer
/// <summary>
/// remove azure container by container name
/// </summary>
/// <param name="name">container name</param>
internal async Task RemoveAzureContainer(long taskId, IStorageBlobManagement localChannel, string name)
{
if (!NameUtil.IsValidContainerName(name))
{
throw new ArgumentException(String.Format(Resources.InvalidContainerName, name));
}
BlobRequestOptions requestOptions = RequestOptions;
AccessCondition accessCondition = null;
CloudBlobContainer container = localChannel.GetContainerReference(name);
if (!await localChannel.DoesContainerExistAsync(container, requestOptions, OperationContext, CmdletCancellationToken))
{
throw new ResourceNotFoundException(String.Format(Resources.ContainerNotFound, name));
}
string result = string.Empty;
bool removed = false;
if (force || await OutputStream.ConfirmAsync(name))
{
await localChannel.DeleteContainerAsync(container, accessCondition, requestOptions, OperationContext, CmdletCancellationToken);
result = String.Format(Resources.RemoveContainerSuccessfully, name);
removed = true;
}
else
{
result = String.Format(Resources.RemoveContainerCancelled, name);
}
OutputStream.WriteVerbose(taskId, result);
if (PassThru)
{
OutputStream.WriteObject(taskId, removed);
}
}
示例6: CreateAzureContainer
/// <summary>
/// create a new azure container
/// </summary>
/// <param name="name">container name</param>
internal async Task CreateAzureContainer(long taskId, IStorageBlobManagement localChannel, string name, BlobContainerPublicAccessType accesslevel)
{
if (!NameUtil.IsValidContainerName(name))
{
throw new ArgumentException(String.Format(Resources.InvalidContainerName, name));
}
BlobRequestOptions requestOptions = RequestOptions;
CloudBlobContainer container = localChannel.GetContainerReference(name);
BlobContainerPermissions permissions = new BlobContainerPermissions();
permissions.PublicAccess = accesslevel;
bool created = await localChannel.CreateContainerIfNotExistsAsync(container, permissions.PublicAccess, requestOptions, OperationContext, CmdletCancellationToken);
if (!created)
{
throw new ResourceAlreadyExistException(String.Format(Resources.ContainerAlreadyExists, name));
}
WriteCloudContainerObject(taskId, localChannel, container, permissions);
}
示例7: GetAzureContainerStoredAccessPolicyAsync
internal async Task GetAzureContainerStoredAccessPolicyAsync(long taskId, IStorageBlobManagement localChannel, string containerName, string policyName)
{
SharedAccessBlobPolicies shareAccessPolicies = await GetPoliciesAsync(localChannel, containerName, policyName);
if (!String.IsNullOrEmpty(policyName))
{
if (shareAccessPolicies.Keys.Contains(policyName))
{
OutputStream.WriteObject(taskId, AccessPolicyHelper.ConstructPolicyOutputPSObject<SharedAccessBlobPolicy>(shareAccessPolicies, policyName));
}
else
{
throw new ResourceNotFoundException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName));
}
}
else
{
foreach (string key in shareAccessPolicies.Keys)
{
OutputStream.WriteObject(taskId, AccessPolicyHelper.ConstructPolicyOutputPSObject<SharedAccessBlobPolicy>(shareAccessPolicies, key));
}
}
}
示例8: RemoveAzureContainerStoredAccessPolicy
internal bool RemoveAzureContainerStoredAccessPolicy(IStorageBlobManagement localChannel, string containerName, string policyName)
{
bool success = false;
string result = string.Empty;
//Get existing permissions
CloudBlobContainer container = localChannel.GetContainerReference(containerName);
BlobContainerPermissions blobContainerPermissions = localChannel.GetContainerPermissions(container);
//remove the specified policy
if (!blobContainerPermissions.SharedAccessPolicies.Keys.Contains(policyName))
{
throw new ResourceNotFoundException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName));
}
if (this.Force || ConfirmRemove(policyName))
{
blobContainerPermissions.SharedAccessPolicies.Remove(policyName);
localChannel.SetContainerPermissions(container, blobContainerPermissions);
success = true;
}
return success;
}
示例9: NewAzureStorageBlobSasTokenCommand
/// <summary>
/// Initializes a new instance of the NewAzureStorageBlobSasCommand class.
/// </summary>
/// <param name="channel">IStorageBlobManagement channel</param>
public NewAzureStorageBlobSasTokenCommand(IStorageBlobManagement channel)
{
Channel = channel;
EnableMultiThread = false;
}
示例10: FakeSetAzureBlobContentCommand
public FakeSetAzureBlobContentCommand(IStorageBlobManagement channel)
{
Channel = channel;
}
示例11: ListBlobsByPrefix
/// <summary>
/// list blobs by blob prefix and container name
/// </summary>
/// <param name="containerName">container name</param>
/// <param name="prefix">blob preifx</param>
/// <returns>An enumerable collection of IListBlobItem</returns>
internal async Task ListBlobsByPrefix(long taskId, IStorageBlobManagement localChannel, string containerName, string prefix, Func<CloudBlob, bool> blobFilter = null)
{
CloudBlobContainer container = await GetCloudBlobContainerByName(localChannel, containerName);
BlobRequestOptions requestOptions = RequestOptions;
bool useFlatBlobListing = true;
BlobListingDetails details = BlobListingDetails.Snapshots | BlobListingDetails.Metadata | BlobListingDetails.Copy;
int listCount = InternalMaxCount;
int MaxListCount = 5000;
int requestCount = MaxListCount;
int realListCount = 0;
BlobContinuationToken continuationToken = ContinuationToken;
do
{
requestCount = Math.Min(listCount, MaxListCount);
realListCount = 0;
BlobResultSegment blobResult = await localChannel.ListBlobsSegmentedAsync(container, prefix, useFlatBlobListing,
details, requestCount, continuationToken, requestOptions, OperationContext, CmdletCancellationToken);
foreach (IListBlobItem blobItem in blobResult.Results)
{
CloudBlob blob = blobItem as CloudBlob;
if (blob == null)
{
continue;
}
if (blobFilter == null || blobFilter(blob))
{
WriteCloudBlobObject(taskId, localChannel, blob, blobResult.ContinuationToken);
realListCount++;
}
}
if (InternalMaxCount != int.MaxValue)
{
listCount -= realListCount;
}
continuationToken = blobResult.ContinuationToken;
}
while (listCount > 0 && continuationToken != null);
}
示例12: GetCloudBlobContainerByName
/// <summary>
/// get the CloudBlobContainer object by name if container exists
/// </summary>
/// <param name="containerName">container name</param>
/// <returns>return CloudBlobContianer object if specified container exists, otherwise throw an exception</returns>
internal async Task<CloudBlobContainer> GetCloudBlobContainerByName(IStorageBlobManagement localChannel, string containerName, bool skipCheckExists = false)
{
if (!NameUtil.IsValidContainerName(containerName))
{
throw new ArgumentException(String.Format(Resources.InvalidContainerName, containerName));
}
BlobRequestOptions requestOptions = RequestOptions;
CloudBlobContainer container = localChannel.GetContainerReference(containerName);
if (!skipCheckExists && container.ServiceClient.Credentials.IsSharedKey
&& !await localChannel.DoesContainerExistAsync(container, requestOptions, OperationContext, CmdletCancellationToken))
{
throw new ArgumentException(String.Format(Resources.ContainerNotFound, containerName));
}
return container;
}
示例13: StartCopyAsync
/// <summary>
/// Start copy using transfer mangager by source uri
/// </summary>
/// <param name="uri">source uri</param>
/// <param name="destContainer">Destination CloudBlobContainer object</param>
/// <param name="destBlobName">Destination blob name</param>
/// <returns>Destination CloudBlob object</returns>
private async Task StartCopyAsync(long taskId, IStorageBlobManagement destChannel, Uri uri, CloudBlobContainer destContainer, string destBlobName)
{
NameUtil.ValidateContainerName(destContainer.Name);
NameUtil.ValidateBlobName(destBlobName);
await this.StartCopyFromUri(taskId, destChannel, uri, destContainer.GetBlockBlobReference(destBlobName));
}
示例14: GetDestBlob
private CloudBlob GetDestBlob(IStorageBlobManagement destChannel, string destContainerName, string destBlobName, BlobType blobType)
{
NameUtil.ValidateContainerName(destContainerName);
NameUtil.ValidateBlobName(destBlobName);
CloudBlobContainer container = destChannel.GetContainerReference(destContainerName);
CloudBlob destBlob = null;
if (BlobType.PageBlob == blobType)
{
destBlob = container.GetPageBlobReference(destBlobName);
}
else if (BlobType.BlockBlob == blobType)
{
destBlob = container.GetBlockBlobReference(destBlobName);
}
else if (BlobType.AppendBlob == blobType)
{
destBlob = container.GetAppendBlobReference(destBlobName);
}
else
{
throw new ArgumentException(String.Format(Resources.InvalidBlobType, blobType, destBlobName));
}
return destBlob;
}
示例15: GetDestinationBlobWithCopyId
/// <summary>
/// Get DestinationBlob with specified copy id
/// </summary>
/// <param name="container">CloudBlobContainer object</param>
/// <param name="blobName">Blob name</param>
/// <param name="copyId">Current CopyId</param>
/// <returns>Destination ICloudBlob object</returns>
private ICloudBlob GetDestinationBlobWithCopyId(IStorageBlobManagement destChannel, CloudBlobContainer container, string blobName)
{
AccessCondition accessCondition = null;
BlobRequestOptions options = RequestOptions;
ICloudBlob blob = destChannel.GetBlobReferenceFromServer(container, blobName, accessCondition, options, OperationContext);
return blob;
}