Пример #1
0
        private string GetStorageCatalog(string storageSetting, string containerName)
        {
            CloudStorageAccount storageAccount = RoleEnvironment.IsEmulated
                                                     ? CloudStorageAccount.DevelopmentStorageAccount
                                                     : CloudStorageAccount.Parse(storageSetting);
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            var location = new Uri(storageAccount.BlobEndpoint + "/" + containerName);

            var blobContainer = new CloudBlobContainer(location, blobClient.Credentials);

            IEnumerable<IListBlobItem> blobs = blobContainer.ListBlobs(useFlatBlobListing: true, blobListingDetails: BlobListingDetails.All);

            foreach (IListBlobItem item in blobs)
            {
                string fileAbsPath = item.Uri.AbsolutePath.ToLower();
                fileAbsPath = fileAbsPath.Substring(fileAbsPath.LastIndexOf('/') + 1);

                try
                {
                    var blob = new CloudPageBlob(item.Uri);
                    blob.DownloadToFile(ModuleService.CacheFolder + fileAbsPath, FileMode.Create);
                }
                catch (Exception e)
                {
                    // Ignore exceptions, if we can't write it's because we've already got the file, move on
                }
            }

            return ModuleService.CacheFolder;
        }