| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | #pragma warning disable SA1402 // File may only contain a single type |
| | 5 | |
|
| | 6 | | using System.Collections.Generic; |
| | 7 | |
|
| | 8 | | namespace Azure.Storage.Blobs.Models |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// Contains blob page range information returned from the PageBlobClient.GetPageRanges operations. |
| | 12 | | /// </summary> |
| | 13 | | public class PageRangesInfo |
| | 14 | | { |
| | 15 | | /// <summary> |
| | 16 | | /// Model type expected by the protocol layer. |
| | 17 | | /// </summary> |
| | 18 | | private readonly PageRangesInfoInternal _pageRangesInfo; |
| | 19 | |
|
| | 20 | | /// <summary> |
| | 21 | | /// Returns the date and time the container was last modified. Any operation that modifies the blob, including a |
| | 22 | | /// </summary> |
| 0 | 23 | | public System.DateTimeOffset LastModified => _pageRangesInfo.LastModified; |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// The ETag contains a value that you can use to perform operations conditionally. If the request version is 20 |
| | 27 | | /// </summary> |
| 0 | 28 | | public ETag ETag => _pageRangesInfo.ETag; |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// The size of the blob in bytes. |
| | 32 | | /// </summary> |
| 0 | 33 | | public long BlobContentLength => _pageRangesInfo.BlobContentLength; |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// Page ranges for the blob. |
| | 37 | | /// </summary> |
| 224 | 38 | | public IEnumerable<HttpRange> PageRanges { get; internal set; } |
| | 39 | |
|
| | 40 | | /// <summary> |
| | 41 | | /// Clear ranges for the blob. |
| | 42 | | /// </summary> |
| 112 | 43 | | public IEnumerable<HttpRange> ClearRanges { get; internal set; } |
| | 44 | |
|
| | 45 | | /// <summary> |
| | 46 | | /// Creates a new PageRangesInfo instance |
| | 47 | | /// </summary> |
| 104 | 48 | | internal PageRangesInfo(PageRangesInfoInternal rangesInfoInternal) |
| | 49 | | { |
| 104 | 50 | | _pageRangesInfo = rangesInfoInternal; |
| | 51 | |
|
| | 52 | | // convert from PageRange to HttpRange |
| 104 | 53 | | var pageRange = new List<HttpRange>(); |
| 288 | 54 | | foreach (PageRange range in _pageRangesInfo.Body.PageRange) |
| | 55 | | { |
| 40 | 56 | | pageRange.Add(new HttpRange(range.Start, range.End - range.Start + 1)); |
| | 57 | | } |
| 104 | 58 | | PageRanges = pageRange; |
| | 59 | |
|
| | 60 | | // convert from ClearRange to HttpRange |
| 104 | 61 | | var clearRange = new List<HttpRange>(); |
| 216 | 62 | | foreach (ClearRange range in _pageRangesInfo.Body.ClearRange) |
| | 63 | | { |
| 4 | 64 | | clearRange.Add(new HttpRange(range.Start, range.End - range.Start + 1)); |
| | 65 | | } |
| 104 | 66 | | ClearRanges = clearRange; |
| 104 | 67 | | } |
| | 68 | | } |
| | 69 | |
|
| | 70 | | /// <summary> |
| | 71 | | /// BlobsModelFactory provides utilities for mocking. |
| | 72 | | /// </summary> |
| | 73 | | public static partial class BlobsModelFactory |
| | 74 | | { |
| | 75 | | /// <summary> |
| | 76 | | /// Creates a new PageRangesInfo instance for mocking. |
| | 77 | | /// </summary> |
| | 78 | | public static PageRangesInfo PageRangesInfo( |
| | 79 | | System.DateTimeOffset lastModified, |
| | 80 | | ETag eTag, |
| | 81 | | long blobContentLength, |
| | 82 | | IEnumerable<HttpRange> pageRanges, |
| | 83 | | IEnumerable<HttpRange> clearRanges) |
| | 84 | | { |
| | 85 | | var pageRangesInfo = |
| | 86 | | new PageRangesInfo( |
| | 87 | | new PageRangesInfoInternal() |
| | 88 | | { |
| | 89 | | LastModified = lastModified, |
| | 90 | | ETag = eTag, |
| | 91 | | BlobContentLength = blobContentLength, |
| | 92 | | } |
| | 93 | | ) |
| | 94 | | { |
| | 95 | | PageRanges = pageRanges, |
| | 96 | | ClearRanges = clearRanges |
| | 97 | | }; |
| | 98 | | return pageRangesInfo; |
| | 99 | | } |
| | 100 | | } |
| | 101 | | } |