|
9 | 9 | using System.Net; |
10 | 10 | using System.Threading.Tasks; |
11 | 11 | using Azure; |
| 12 | +using Azure.Core; |
12 | 13 | using Azure.Storage; |
13 | 14 | using Azure.Storage.Blobs; |
14 | 15 | using Azure.Storage.Blobs.Models; |
@@ -51,6 +52,22 @@ public BlobsTranscriptStore(string dataConnectionString, string containerName, J |
51 | 52 | { |
52 | 53 | } |
53 | 54 |
|
| 55 | + /// <summary> |
| 56 | + /// Initializes a new instance of the <see cref="BlobsTranscriptStore"/> class. |
| 57 | + /// </summary> |
| 58 | + /// <param name="blobServiceUri">A Uri referencing the blob container that includes the name of the account and the name of the container.</param> |
| 59 | + /// <param name="tokenCredential">The token credential to authenticate to the Azure storage.</param> |
| 60 | + /// <param name="containerName">Name of the Blob container where entities will be stored.</param> |
| 61 | + /// <param name="jsonSerializer">If passing in a custom JsonSerializer, we recommend the following settings: |
| 62 | + /// <para>jsonSerializer.TypeNameHandling = TypeNameHandling.None.</para> |
| 63 | + /// <para>jsonSerializer.NullValueHandling = NullValueHandling.Include.</para> |
| 64 | + /// <para>jsonSerializer.ContractResolver = new DefaultContractResolver().</para> |
| 65 | + /// </param> |
| 66 | + public BlobsTranscriptStore(Uri blobServiceUri, TokenCredential tokenCredential, string containerName, JsonSerializer jsonSerializer = null) |
| 67 | + : this(blobServiceUri, tokenCredential, containerName, default, jsonSerializer) |
| 68 | + { |
| 69 | + } |
| 70 | + |
54 | 71 | /// <summary> |
55 | 72 | /// Initializes a new instance of the <see cref="BlobsTranscriptStore"/> class. |
56 | 73 | /// </summary> |
@@ -99,6 +116,59 @@ public BlobsTranscriptStore(string dataConnectionString, string containerName, S |
99 | 116 | }, isThreadSafe: true); |
100 | 117 | } |
101 | 118 |
|
| 119 | + /// <summary> |
| 120 | + /// Initializes a new instance of the <see cref="BlobsTranscriptStore"/> class. |
| 121 | + /// </summary> |
| 122 | + /// <param name="blobServiceUri">A Uri referencing the blob container that includes the name of the account and the name of the container.</param> |
| 123 | + /// <param name="tokenCredential">The token credential to authenticate to the Azure storage.</param> |
| 124 | + /// <param name="containerName">Name of the Blob container where entities will be stored.</param> |
| 125 | + /// <param name="storageTransferOptions">Used for providing options for parallel transfers <see cref="StorageTransferOptions"/>.</param> |
| 126 | + /// <param name="jsonSerializer">If passing in a custom JsonSerializer, we recommend the following settings: |
| 127 | + /// <para>jsonSerializer.TypeNameHandling = TypeNameHandling.None.</para> |
| 128 | + /// <para>jsonSerializer.NullValueHandling = NullValueHandling.Include.</para> |
| 129 | + /// <para>jsonSerializer.ContractResolver = new DefaultContractResolver().</para> |
| 130 | + /// </param> |
| 131 | + public BlobsTranscriptStore(Uri blobServiceUri, TokenCredential tokenCredential, string containerName, StorageTransferOptions storageTransferOptions, JsonSerializer jsonSerializer = null) |
| 132 | + { |
| 133 | + if (blobServiceUri == null) |
| 134 | + { |
| 135 | + throw new ArgumentNullException(nameof(blobServiceUri)); |
| 136 | + } |
| 137 | + |
| 138 | + if (tokenCredential == null) |
| 139 | + { |
| 140 | + throw new ArgumentNullException(nameof(tokenCredential)); |
| 141 | + } |
| 142 | + |
| 143 | + if (string.IsNullOrEmpty(containerName)) |
| 144 | + { |
| 145 | + throw new ArgumentNullException(nameof(containerName)); |
| 146 | + } |
| 147 | + |
| 148 | + _storageTransferOptions = storageTransferOptions; |
| 149 | + |
| 150 | + _jsonSerializer = jsonSerializer ?? JsonSerializer.Create(new JsonSerializerSettings |
| 151 | + { |
| 152 | + NullValueHandling = NullValueHandling.Ignore, |
| 153 | + Formatting = Formatting.Indented, |
| 154 | + MaxDepth = null, |
| 155 | + }); |
| 156 | + |
| 157 | + // Triggers a check for the existance of the container |
| 158 | + _containerClient = new Lazy<BlobContainerClient>( |
| 159 | + () => |
| 160 | + { |
| 161 | + var containerClient = new BlobContainerClient(blobServiceUri, tokenCredential); |
| 162 | + if (!_checkedContainers.Contains(containerName)) |
| 163 | + { |
| 164 | + containerClient.CreateIfNotExistsAsync().Wait(); |
| 165 | + _checkedContainers.Add(containerName); |
| 166 | + } |
| 167 | + |
| 168 | + return containerClient; |
| 169 | + }, isThreadSafe: true); |
| 170 | + } |
| 171 | + |
102 | 172 | /// <summary> |
103 | 173 | /// Initializes a new instance of the <see cref="BlobsTranscriptStore"/> class. |
104 | 174 | /// </summary> |
|
0 commit comments