| | 1 | | // Copyright (c) Microsoft and contributors. All rights reserved. |
| | 2 | | // |
| | 3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
| | 4 | | // you may not use this file except in compliance with the License. |
| | 5 | | // You may obtain a copy of the License at |
| | 6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
| | 7 | | // |
| | 8 | | // Unless required by applicable law or agreed to in writing, software |
| | 9 | | // distributed under the License is distributed on an "AS IS" BASIS, |
| | 10 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | 11 | | // |
| | 12 | | // See the License for the specific language governing permissions and |
| | 13 | | // limitations under the License. |
| | 14 | |
|
| | 15 | | using Microsoft.WindowsAzure.Storage; |
| | 16 | | using Microsoft.WindowsAzure.Storage.Blob; |
| | 17 | | using System; |
| | 18 | | using System.Collections.Generic; |
| | 19 | |
|
| | 20 | | namespace Microsoft.Azure.Batch.Conventions.Files.Utilities |
| | 21 | | { |
| | 22 | | internal static class CloudBlobContainerUtils |
| | 23 | | { |
| | 24 | | internal static CloudBlobContainer GetContainerReference(Uri jobOutputContainerUri) |
| | 25 | | { |
| 35 | 26 | | if (jobOutputContainerUri == null) |
| | 27 | | { |
| 0 | 28 | | throw new ArgumentNullException(nameof(jobOutputContainerUri)); |
| | 29 | | } |
| | 30 | |
|
| 35 | 31 | | return new CloudBlobContainer(jobOutputContainerUri); |
| | 32 | | } |
| | 33 | |
|
| | 34 | | internal static CloudBlobContainer GetContainerReference(CloudStorageAccount storageAccount, string jobId) |
| | 35 | | { |
| 0 | 36 | | if (storageAccount == null) |
| | 37 | | { |
| 0 | 38 | | throw new ArgumentNullException(nameof(storageAccount)); |
| | 39 | | } |
| | 40 | |
|
| 0 | 41 | | Validate.IsNotNullOrEmpty(jobId, nameof(jobId)); |
| | 42 | |
|
| 0 | 43 | | var jobOutputContainerName = ContainerNameUtils.GetSafeContainerName(jobId); |
| 0 | 44 | | return storageAccount.CreateCloudBlobClient().GetContainerReference(jobOutputContainerName); |
| | 45 | | } |
| | 46 | |
|
| | 47 | | internal static IEnumerable<IListBlobItem> ListBlobs(this CloudBlobContainer container, string prefix, bool useF |
| | 48 | | { |
| 0 | 49 | | BlobContinuationToken continuationToken = null; |
| | 50 | | do |
| | 51 | | { |
| 0 | 52 | | BlobResultSegment segment = container |
| 0 | 53 | | .ListBlobsSegmentedAsync(prefix, useFlatBlobListing, BlobListingDetails.None, null, continuationToke |
| 0 | 54 | | .GetAwaiter() |
| 0 | 55 | | .GetResult(); |
| 0 | 56 | | foreach (var result in segment.Results) |
| | 57 | | { |
| 0 | 58 | | yield return result; |
| | 59 | | } |
| 0 | 60 | | continuationToken = segment.ContinuationToken; |
| 0 | 61 | | } while (continuationToken != null); |
| | 62 | |
|
| 0 | 63 | | } |
| | 64 | | } |
| | 65 | | } |