本文整理汇总了C#中IStorageBlobManagement.GetContainerReference方法的典型用法代码示例。如果您正苦于以下问题:C# IStorageBlobManagement.GetContainerReference方法的具体用法?C# IStorageBlobManagement.GetContainerReference怎么用?C# IStorageBlobManagement.GetContainerReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IStorageBlobManagement
的用法示例。
在下文中一共展示了IStorageBlobManagement.GetContainerReference方法的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: 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);
}
}
示例3: 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;
}
示例4: 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);
}
}
示例5: 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);
}
示例6: 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;
}
示例7: StartCopyBlob
/// <summary>
/// Start copy operation by source uri
/// </summary>
/// <param name="srcCloudBlob">Source uri</param>
/// <param name="destContainer">Destinaion container name</param>
/// <param name="destBlobName">Destination blob name</param>
/// <returns>Destination CloudBlob object</returns>
private void StartCopyBlob(IStorageBlobManagement destChannel, string srcUri, string destContainer, string destBlobName, AzureStorageContext context)
{
if (context != null)
{
Uri sourceUri = new Uri(srcUri);
Uri contextUri = new Uri(context.BlobEndPoint);
if (sourceUri.Host.ToLower() == contextUri.Host.ToLower())
{
CloudBlobClient blobClient = context.StorageAccount.CreateCloudBlobClient();
CloudBlob blobReference = null;
try
{
blobReference = Util.GetBlobReferenceFromServer(blobClient, sourceUri);
}
catch (InvalidOperationException)
{
blobReference = null;
}
if (null == blobReference)
{
throw new ResourceNotFoundException(String.Format(Resources.BlobUriNotFound, sourceUri.ToString()));
}
StartCopyBlob(destChannel, blobReference, destContainer, destBlobName);
}
else
{
WriteWarning(String.Format(Resources.StartCopySourceContextMismatch, srcUri, context.BlobEndPoint));
}
}
else
{
CloudBlobContainer container = destChannel.GetContainerReference(destContainer);
Func<long, Task> taskGenerator = (taskId) => StartCopyAsync(taskId, destChannel, new Uri(srcUri), container, destBlobName);
RunTask(taskGenerator);
}
}
示例8: GetPoliciesAsync
internal async Task<SharedAccessBlobPolicies> GetPoliciesAsync(IStorageBlobManagement localChannel, string containerName, string policyName)
{
CloudBlobContainer container = localChannel.GetContainerReference(containerName);
BlobContainerPermissions blobContainerPermissions = await localChannel.GetContainerPermissionsAsync(container, null, null, null, CmdletCancellationToken);
return blobContainerPermissions.SharedAccessPolicies;
}
示例9: 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;
}
示例10: StartCopyBlob
/// <summary>
/// Start copy operation by source uri
/// </summary>
/// <param name="srcICloudBlob">Source uri</param>
/// <param name="destContainer">Destinaion container name</param>
/// <param name="destBlobName">Destination blob name</param>
/// <returns>Destination ICloudBlob object</returns>
private void StartCopyBlob(IStorageBlobManagement destChannel, string srcUri, string destContainer, string destBlobName, AzureStorageContext context)
{
if (context != null)
{
Uri sourceUri = new Uri(srcUri);
Uri contextUri = new Uri(context.BlobEndPoint);
if (sourceUri.Host.ToLower() == contextUri.Host.ToLower())
{
CloudBlobClient blobClient = context.StorageAccount.CreateCloudBlobClient();
ICloudBlob blobReference = blobClient.GetBlobReferenceFromServer(sourceUri);
StartCopyBlob(destChannel, blobReference, destContainer, destBlobName);
}
else
{
WriteWarning(String.Format(Resources.StartCopySourceContextMismatch, srcUri, context.BlobEndPoint));
}
}
CloudBlobContainer container = destChannel.GetContainerReference(destContainer);
Func<long, Task> taskGenerator = (taskId) => StartCopyInTransferManager(taskId, destChannel, new Uri(srcUri), container, destBlobName);
RunTask(taskGenerator);
}
示例11: 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;
}
示例12: RemoveAzureBlob
/// <summary>
/// remove azure blob
/// </summary>
/// <param name="containerName">container name</param>
/// <param name="blobName">blob name</param>
/// <returns>true if the blob is removed successfully, false if user cancel the remove operation</returns>
internal async Task RemoveAzureBlob(long taskId, IStorageBlobManagement localChannel, string containerName, string blobName)
{
CloudBlobContainer container = localChannel.GetContainerReference(containerName);
await RemoveAzureBlob(taskId, localChannel, container, blobName);
}
示例13: StartCopyBlob
/// <summary>
/// Start copy operation by source ICloudBlob object
/// </summary>
/// <param name="srcICloudBlob">Source ICloudBlob object</param>
/// <param name="destContainer">Destinaion container name</param>
/// <param name="destBlobName">Destination blob name</param>
/// <returns>Destination ICloudBlob object</returns>
private void StartCopyBlob(IStorageBlobManagement destChannel, ICloudBlob srcICloudBlob, string destContainer, string destBlobName)
{
if (string.IsNullOrEmpty(destBlobName))
{
destBlobName = srcICloudBlob.Name;
}
ValidateBlobName(destBlobName);
CloudBlobContainer container = destChannel.GetContainerReference(destContainer);
ICloudBlob destBlob = null;
if (BlobType.PageBlob == srcICloudBlob.BlobType)
{
destBlob = container.GetPageBlobReference(destBlobName);
}
else if (BlobType.BlockBlob == srcICloudBlob.BlobType)
{
destBlob = container.GetBlockBlobReference(destBlobName);
}
else
{
throw new ArgumentException(String.Format(Resources.InvalidBlobType, srcICloudBlob.Name));
}
this.StartCopyBlob(destChannel, srcICloudBlob, destBlob);
}
示例14: StopCopyBlob
/// <summary>
/// Stop copy operation by name
/// </summary>
/// <param name="containerName">Container name</param>
/// <param name="blobName">Blob name</param>
/// <param name="copyId">copy id</param>
private async Task StopCopyBlob(long taskId, IStorageBlobManagement localChannel, string containerName, string blobName, string copyId)
{
CloudBlobContainer container = localChannel.GetContainerReference(containerName);
await StopCopyBlob(taskId, localChannel, container, blobName, copyId);
}
示例15: 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);
}
}