当前位置: 首页>>代码示例>>C#>>正文


C# CloudBlobClient.ListContainers方法代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.StorageClient.CloudBlobClient.ListContainers方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlobClient.ListContainers方法的具体用法?C# CloudBlobClient.ListContainers怎么用?C# CloudBlobClient.ListContainers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.WindowsAzure.StorageClient.CloudBlobClient的用法示例。


在下文中一共展示了CloudBlobClient.ListContainers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnInitialize

        private void OnInitialize()
        {
            var selfInstance = InstanceEnumerator.EnumerateInstances().First(i => i.IsSelf);

            cloudStorageAccount     = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(ConfigurationSettingsKeys.StorageConnectionString));
            log.Info("Storage account selected: {0}",cloudStorageAccount.BlobEndpoint);
            
            cloudBlobClient         = cloudStorageAccount.CreateCloudBlobClient();
            log.Info("Storage client created");

            var containerName       = ConfigurationProvider.GetSetting(ConfigurationSettingsKeys.StorageContainerName,"ravendb");

            // In order to force a connection we just enumerate all available containers:
            var availableContainers = cloudBlobClient.ListContainers().ToArray();

            foreach (var container in availableContainers)
            {
                log.Info("Available container: {0}",container.Name);
            }

            if (!availableContainers.Any(c => c.Name.Equals(containerName)))
            {
                log.Info("Container {0} does not exist, creating",containerName);

                // Container does not exist:
                cloudBlobClient.GetContainerReference(containerName).Create();
            }

            cloudBlobContainer      = cloudBlobClient.GetContainerReference(containerName);
            log.Info("Container {0} selected",cloudBlobContainer.Name);

            localCache              = RoleEnvironment.GetLocalResource(ConfigurationSettingsKeys.StorageCacheResource);
            log.Info("Cache resource retrieved: {0}, path: {1}",localCache.Name,localCache.RootPath);
            CloudDrive.InitializeCache(localCache.RootPath, localCache.MaximumSizeInMegabytes);
            log.Info("Cache initialized: {0} mb",localCache.MaximumSizeInMegabytes);

            var driveName           = string.Format("{0}{1}.vhd", selfInstance.InstanceType, selfInstance.InstanceIndex).ToLowerInvariant();
            log.Info("Virtual drive name: {0}",driveName);
            
            var pageBlob            = cloudBlobContainer.GetPageBlobReference(driveName);
            log.Info("Virtual drive blob: {0}",pageBlob.Uri);

            cloudDrive              = cloudStorageAccount.CreateCloudDrive(pageBlob.Uri.ToString());
            log.Info("Virtual drive created: {0}",cloudDrive.Uri);

            var storageSize         = ConfigurationProvider.GetSetting(ConfigurationSettingsKeys.StorageSize, 50000);
            log.Info("Storage size: {0} mb",storageSize);

            cloudDrive.CreateIfNotExist(storageSize);
            log.Info("Virtual drive initialized: {0}",cloudDrive.Uri);

            var mountedDirectoryPath = cloudDrive.Mount(storageSize, DriveMountOptions.None);
            log.Info("Virtual drive mounted at: {0}",mountedDirectoryPath);

            mountedDirectory = new DirectoryInfo(mountedDirectoryPath);

            log.Info("Ensuring drive is available: {0}",mountedDirectoryPath);
            UpdateTestFile();

            log.Info("Storage initialization succeeded");
        }
开发者ID:jalchr,项目名称:RavenDb.Azure,代码行数:61,代码来源:CloudStorageProvider.cs


注:本文中的Microsoft.WindowsAzure.StorageClient.CloudBlobClient.ListContainers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。