本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.Exists方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlobContainer.Exists方法的具体用法?C# CloudBlobContainer.Exists怎么用?C# CloudBlobContainer.Exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer
的用法示例。
在下文中一共展示了CloudBlobContainer.Exists方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BlobContainer
public BlobContainer(string name)
{
// hämta connectionsträngen från config // RoleEnviroment bestämmer settingvalue runtime
//var connectionString = RoleEnvironment.GetConfigurationSettingValue("PhotoAppStorage");
//var connectionString = CloudConfigurationManager.GetSetting("CloudStorageApp");
// hämtar kontot utfrån connectionsträngens värde
//var account = CloudStorageAccount.Parse(connectionString);
//var account = CloudStorageAccount.DevelopmentStorageAccount;
var cred = new StorageCredentials("jholm",
"/bVipQ2JxjWwYrZQfHmzhaBx1p1s8BoD/wX6VWOmg4/gpVo/aALrjsDUKqzXsFtc9utepPqe65NposrXt9YsyA==");
var account = new CloudStorageAccount(cred, true);
// skapar en blobclient
_client = account.CreateCloudBlobClient();
m_BlobContainer = _client.GetContainerReference(name);
// Om det inte finns någon container med det namnet
if (!m_BlobContainer.Exists())
{
// Skapa containern
m_BlobContainer.Create();
var permissions = new BlobContainerPermissions()
{
PublicAccess = BlobContainerPublicAccessType.Blob
};
// Sätter public access till blobs
m_BlobContainer.SetPermissions(permissions);
}
}
示例2: InstanciateStorageContainer
private void InstanciateStorageContainer(string formattedStorageContainerName)
{
if ((_blobContainer == null) || (_blobContainer.Name != formattedStorageContainerName))
{
var cloudStorageAccount = CloudStorageAccount.Parse(StorageConnectionString);
var cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
_blobContainer = cloudBlobClient.GetContainerReference(formattedStorageContainerName);
if (!_blobContainer.Exists())
{
try
{
_blobContainer.Create();
while (!_blobContainer.Exists())
Thread.Sleep(100);
}
catch (StorageException storageException)
{
WriteDebugError(String.Format("NLog.AzureStorage - Failed to create Azure Storage Blob Container '{0}' - Storage Exception: {1} {2}", formattedStorageContainerName, storageException.Message, GetStorageExceptionHttpStatusMessage(storageException)));
throw;
}
}
}
}
示例3: BaseStorage
/// <summary>Constructor establishes the connection</summary>
/// <param name="containerName">The name of the container inside Azure</param>
protected BaseStorage(string containerName)
{
var cloudStorageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting(BlobStorageConnectionStringKey));
var cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
_cloudBlobContainer = cloudBlobClient.GetContainerReference(containerName);
if (!_cloudBlobContainer.Exists()) _cloudBlobContainer.CreateIfNotExists();
}
示例4: BlobTriggerTests
public BlobTriggerTests()
{
_timesProcessed = 0;
RandomNameResolver nameResolver = new RandomNameResolver();
_hostConfiguration = new JobHostConfiguration()
{
NameResolver = nameResolver,
TypeLocator = new FakeTypeLocator(typeof(BlobTriggerTests)),
};
_storageAccount = CloudStorageAccount.Parse(_hostConfiguration.StorageConnectionString);
CloudBlobClient blobClient = _storageAccount.CreateCloudBlobClient();
_testContainer = blobClient.GetContainerReference(nameResolver.ResolveInString(ContainerName));
Assert.False(_testContainer.Exists());
_testContainer.Create();
}
示例5: DoesContainerExist
/// <summary>
/// Whether the container exists or not
/// </summary>
/// <param name="container">A cloudblobcontainer object</param>
/// <param name="options">Blob request option</param>
/// <param name="operationContext">Operation context</param>
/// <returns>True if the specific container exists, otherwise return false</returns>
public bool DoesContainerExist(CloudBlobContainer container, BlobRequestOptions options, OperationContext operationContext)
{
if (null == container)
{
return false;
}
else
{
return container.Exists(options, operationContext);
}
}
示例6: ResetContainer
private void ResetContainer(CloudBlobContainer container)
{
if (!container.Exists()) return;
Trace.WriteLine($"Ready to parse {container.Name} container");
Trace.WriteLine("------------------------------------------------");
var blobs = container.ListBlobs().ToList();
var total = blobs.Count;
var counter = 1;
foreach (var blob in blobs)
{
if (blob is CloudBlobDirectory) continue;
var cloudBlob = (CloudBlob)blob;
var extension = Path.GetExtension(cloudBlob.Uri.AbsoluteUri);
string contentType;
_contentTypes.TryGetValue(extension, out contentType);
if (string.IsNullOrEmpty(contentType)) continue;
Trace.Write($"{counter++} of {total} : {cloudBlob.Name}");
if (cloudBlob.Properties.ContentType == contentType)
{
Trace.WriteLine($" ({cloudBlob.Properties.ContentType}) (skipped)");
continue;
}
cloudBlob.Properties.ContentType = contentType;
cloudBlob.SetProperties();
Trace.WriteLine($" ({cloudBlob.Properties.ContentType}) (reset)");
}
}