| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.Globalization; |
| | 7 | | using System.Text; |
| | 8 | | using Azure.Storage.Blobs.Models; |
| | 9 | |
|
| | 10 | | namespace Azure.Storage.Blobs |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// Quick Query extensions. |
| | 14 | | /// </summary> |
| | 15 | | internal static class QuickQueryExtensions |
| | 16 | | { |
| | 17 | | internal static QuerySerialization ToQuickQuerySerialization( |
| | 18 | | this IBlobQueryTextOptions textConfiguration) |
| | 19 | | { |
| 224 | 20 | | if (textConfiguration == default) |
| | 21 | | { |
| 224 | 22 | | return default; |
| | 23 | | } |
| | 24 | |
|
| 0 | 25 | | QuerySerialization serialization = new QuerySerialization |
| 0 | 26 | | { |
| 0 | 27 | | Format = new QueryFormat() |
| 0 | 28 | | }; |
| | 29 | |
|
| 0 | 30 | | serialization.Format.DelimitedTextConfiguration = default; |
| 0 | 31 | | serialization.Format.JsonTextConfiguration = default; |
| | 32 | |
|
| 0 | 33 | | if (textConfiguration.GetType() == typeof(BlobQueryCsvTextOptions)) |
| | 34 | | { |
| 0 | 35 | | BlobQueryCsvTextOptions cvsTextConfiguration = textConfiguration as BlobQueryCsvTextOptions; |
| 0 | 36 | | serialization.Format.Type = QueryFormatType.Delimited; |
| 0 | 37 | | serialization.Format.DelimitedTextConfiguration = new DelimitedTextConfigurationInternal |
| 0 | 38 | | { |
| 0 | 39 | | ColumnSeparator = cvsTextConfiguration.ColumnSeparator?.ToString(CultureInfo.InvariantCulture), |
| 0 | 40 | | FieldQuote = cvsTextConfiguration.QuotationCharacter?.ToString(CultureInfo.InvariantCulture), |
| 0 | 41 | | RecordSeparator = cvsTextConfiguration.RecordSeparator?.ToString(CultureInfo.InvariantCulture), |
| 0 | 42 | | EscapeChar = cvsTextConfiguration.EscapeCharacter?.ToString(CultureInfo.InvariantCulture), |
| 0 | 43 | | HeadersPresent = cvsTextConfiguration.HasHeaders |
| 0 | 44 | | }; |
| | 45 | | } |
| 0 | 46 | | else if (textConfiguration.GetType() == typeof(BlobQueryJsonTextOptions)) |
| | 47 | | { |
| 0 | 48 | | BlobQueryJsonTextOptions jsonTextConfiguration = textConfiguration as BlobQueryJsonTextOptions; |
| 0 | 49 | | serialization.Format.Type = QueryFormatType.Json; |
| 0 | 50 | | serialization.Format.JsonTextConfiguration = new JsonTextConfigurationInternal |
| 0 | 51 | | { |
| 0 | 52 | | RecordSeparator = jsonTextConfiguration.RecordSeparator?.ToString(CultureInfo.InvariantCulture) |
| 0 | 53 | | }; |
| | 54 | | } |
| | 55 | | else |
| | 56 | | { |
| 0 | 57 | | throw new ArgumentException(Constants.QuickQuery.Errors.InvalidTextConfigurationType); |
| | 58 | | } |
| | 59 | |
|
| 0 | 60 | | return serialization; |
| | 61 | | } |
| | 62 | |
|
| | 63 | | internal static BlobDownloadInfo ToBlobDownloadInfo(this BlobQueryResult quickQueryResult) |
| 88 | 64 | | => BlobsModelFactory.BlobDownloadInfo( |
| 88 | 65 | | lastModified: quickQueryResult.LastModified, |
| 88 | 66 | | blobSequenceNumber: quickQueryResult.BlobSequenceNumber, |
| 88 | 67 | | blobType: quickQueryResult.BlobType, |
| 88 | 68 | | contentCrc64: quickQueryResult.ContentCrc64, |
| 88 | 69 | | contentLanguage: quickQueryResult.ContentLanguage, |
| 88 | 70 | | copyStatusDescription: quickQueryResult.CopyStatusDescription, |
| 88 | 71 | | copyId: quickQueryResult.CopyId, |
| 88 | 72 | | copyProgress: quickQueryResult.CopyProgress, |
| 88 | 73 | | copySource: quickQueryResult.CopySource != default ? new Uri(quickQueryResult.CopySource) : default, |
| 88 | 74 | | copyStatus: quickQueryResult.CopyStatus, |
| 88 | 75 | | contentDisposition: quickQueryResult.ContentDisposition, |
| 88 | 76 | | leaseDuration: quickQueryResult.LeaseDuration, |
| 88 | 77 | | cacheControl: quickQueryResult.CacheControl, |
| 88 | 78 | | leaseState: quickQueryResult.LeaseState, |
| 88 | 79 | | contentEncoding: quickQueryResult.ContentEncoding, |
| 88 | 80 | | leaseStatus: quickQueryResult.LeaseStatus, |
| 88 | 81 | | contentHash: quickQueryResult.ContentHash, |
| 88 | 82 | | acceptRanges: quickQueryResult.AcceptRanges, |
| 88 | 83 | | eTag: quickQueryResult.ETag, |
| 88 | 84 | | blobCommittedBlockCount: quickQueryResult.BlobCommittedBlockCount, |
| 88 | 85 | | contentRange: quickQueryResult.ContentRange, |
| 88 | 86 | | isServerEncrypted: quickQueryResult.IsServerEncrypted, |
| 88 | 87 | | contentType: quickQueryResult.ContentType, |
| 88 | 88 | | encryptionKeySha256: quickQueryResult.EncryptionKeySha256, |
| 88 | 89 | | encryptionScope: quickQueryResult.EncryptionScope, |
| 88 | 90 | | contentLength: quickQueryResult.ContentLength, |
| 88 | 91 | | blobContentHash: quickQueryResult.BlobContentMD5, |
| 88 | 92 | | metadata: quickQueryResult.Metadata, |
| 88 | 93 | | content: quickQueryResult.Body, |
| 88 | 94 | | copyCompletionTime: quickQueryResult.CopyCompletionTime); |
| | 95 | | } |
| | 96 | | } |