| | 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.Linq; |
| | 7 | | using System.Threading; |
| | 8 | | using System.Threading.Tasks; |
| | 9 | | using Azure.Core; |
| | 10 | | using Azure.Core.Pipeline; |
| | 11 | |
|
| | 12 | | namespace Azure.DigitalTwins.Core |
| | 13 | | { |
| | 14 | | /// <summary> |
| | 15 | | /// The Digital Twins Service Client contains methods to retrieve digital twin information, like models, components, |
| | 16 | | /// </summary> |
| | 17 | | public class DigitalTwinsClient |
| | 18 | | { |
| | 19 | | private const bool IncludeModelDefinition = true; |
| | 20 | | private const string DateTimeOffsetFormat = "MM/dd/yy H:mm:ss zzz"; |
| | 21 | |
|
| | 22 | | private readonly HttpPipeline _httpPipeline; |
| | 23 | | private readonly ClientDiagnostics _clientDiagnostics; |
| | 24 | |
|
| | 25 | | private readonly DigitalTwinsRestClient _dtRestClient; |
| | 26 | | private readonly DigitalTwinModelsRestClient _dtModelsRestClient; |
| | 27 | | private readonly EventRoutesRestClient _eventRoutesRestClient; |
| | 28 | | private readonly QueryRestClient _queryClient; |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// Creates a new instance of the <see cref="DigitalTwinsClient"/> class. |
| | 32 | | /// </summary> |
| | 33 | | /// <param name='endpoint'>The Azure digital twins service instance URI to connect to.</param> |
| | 34 | | /// <param name="credential">The <see cref="TokenCredential"/> implementation which will be used to request for |
| | 35 | | /// <seealso cref="DigitalTwinsClient(Uri, TokenCredential)"> |
| | 36 | | /// This other constructor provides an opportunity to override default behavior, including specifying API versio |
| | 37 | | /// overriding <see href="https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Pip |
| | 38 | | /// enabling <see href="https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Diagn |
| | 39 | | /// and controlling <see href="https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/sample |
| | 40 | | /// </seealso> |
| | 41 | | /// <remarks> |
| | 42 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 43 | | /// </remarks> |
| | 44 | | /// <example> |
| | 45 | | /// <code snippet="Snippet:DigitalTwinsSampleCreateServiceClientWithClientSecret"> |
| | 46 | | /// // DefaultAzureCredential supports different authentication mechanisms and determines the appropriate creden |
| | 47 | | /// // It attempts to use multiple credential types in an order until it finds a working credential. |
| | 48 | | /// var tokenCredential = new DefaultAzureCredential(); |
| | 49 | | /// |
| | 50 | | /// var client = new DigitalTwinsClient( |
| | 51 | | /// new Uri(adtEndpoint), |
| | 52 | | /// tokenCredential); |
| | 53 | | /// </code> |
| | 54 | | /// </example> |
| | 55 | | public DigitalTwinsClient(Uri endpoint, TokenCredential credential) |
| 0 | 56 | | : this(endpoint, credential, new DigitalTwinsClientOptions()) |
| | 57 | | { |
| 0 | 58 | | } |
| | 59 | |
|
| | 60 | | /// <summary> |
| | 61 | | /// Creates a new instance of the <see cref="DigitalTwinsClient"/> class, with options. |
| | 62 | | /// </summary> |
| | 63 | | /// <param name='endpoint'>The Azure digital twins service instance URI to connect to.</param> |
| | 64 | | /// <param name="credential">The <see cref="TokenCredential"/> implementation which will be used to request for |
| | 65 | | /// <param name="options">Options that allow configuration of requests sent to the digital twins service.</param |
| | 66 | | /// <remarks> |
| | 67 | | /// <para> |
| | 68 | | /// The options parameter provides an opportunity to override default behavior, including specifying API version |
| | 69 | | /// overriding <see href="https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Pip |
| | 70 | | /// enabling <see href="https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Diagn |
| | 71 | | /// and controlling <see href="https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/sample |
| | 72 | | /// </para> |
| | 73 | | /// <para> |
| | 74 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 75 | | /// </para> |
| | 76 | | /// </remarks> |
| 60 | 77 | | public DigitalTwinsClient(Uri endpoint, TokenCredential credential, DigitalTwinsClientOptions options) |
| | 78 | | { |
| 60 | 79 | | Argument.AssertNotNull(options, nameof(options)); |
| | 80 | |
|
| 60 | 81 | | _clientDiagnostics = new ClientDiagnostics(options); |
| | 82 | |
|
| 60 | 83 | | options.AddPolicy(new BearerTokenAuthenticationPolicy(credential, GetAuthorizationScopes(endpoint)), HttpPip |
| 60 | 84 | | _httpPipeline = HttpPipelineBuilder.Build(options); |
| | 85 | |
|
| 60 | 86 | | _dtRestClient = new DigitalTwinsRestClient(_clientDiagnostics, _httpPipeline, endpoint, options.GetVersionSt |
| 60 | 87 | | _dtModelsRestClient = new DigitalTwinModelsRestClient(_clientDiagnostics, _httpPipeline, endpoint, options.G |
| 60 | 88 | | _eventRoutesRestClient = new EventRoutesRestClient(_clientDiagnostics, _httpPipeline, endpoint, options.GetV |
| 60 | 89 | | _queryClient = new QueryRestClient(_clientDiagnostics, _httpPipeline, endpoint); |
| 60 | 90 | | } |
| | 91 | |
|
| | 92 | | /// <summary> |
| | 93 | | /// Creates a new instance of the <see cref="DigitalTwinsClient"/> class, provided for unit testing purposes onl |
| | 94 | | /// </summary> |
| 60 | 95 | | protected DigitalTwinsClient() |
| | 96 | | { |
| | 97 | | // This constructor only exists for mocking purposes in unit tests. It should not be used otherwise. |
| 60 | 98 | | } |
| | 99 | |
|
| | 100 | | /// <summary> |
| | 101 | | /// Gets a digital twin asynchronously. |
| | 102 | | /// </summary> |
| | 103 | | /// <remarks> |
| | 104 | | /// <para> |
| | 105 | | /// The returned application/json string can always be deserialized into an instance of <see cref="Serialization |
| | 106 | | /// It may also be deserialized into custom digital twin types that extend the <see cref="Serialization.BasicDig |
| | 107 | | /// strongly typed properties provided that you know the definition of the retrieved digital twin prior to deser |
| | 108 | | /// </para> |
| | 109 | | /// <para> |
| | 110 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 111 | | /// </para> |
| | 112 | | /// </remarks> |
| | 113 | | /// <param name="digitalTwinId">The Id of the digital twin.</param> |
| | 114 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 115 | | /// <returns>The application/json digital twin and the http response <see cref="Response{T}"/>.</returns> |
| | 116 | | /// <exception cref="RequestFailedException"> |
| | 117 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 118 | | /// </exception> |
| | 119 | | /// <exception cref="ArgumentNullException"> |
| | 120 | | /// The exception is thrown when <paramref name="digitalTwinId"/> is <c>null</c>. |
| | 121 | | /// </exception> |
| | 122 | | /// <example> |
| | 123 | | /// This sample demonstrates getting and deserializing a digital twin into a custom data type. |
| | 124 | | /// |
| | 125 | | /// <code snippet="Snippet:DigitalTwinsSampleGetCustomDigitalTwin"> |
| | 126 | | /// Response<string> getCustomDtResponse = await client.GetDigitalTwinAsync(customDtId); |
| | 127 | | /// CustomDigitalTwin customDt = JsonSerializer.Deserialize<CustomDigitalTwin>(getCustomDtResponse.Value); |
| | 128 | | /// Console.WriteLine($"Retrieved and deserialized digital twin {customDt.Id}:\n\t" + |
| | 129 | | /// $"ETag: {customDt.ETag}\n\t" + |
| | 130 | | /// $"Prop1: {customDt.Prop1}\n\t" + |
| | 131 | | /// $"Prop2: {customDt.Prop2}\n\t" + |
| | 132 | | /// $"ComponentProp1: {customDt.Component1.ComponentProp1}\n\t" + |
| | 133 | | /// $"ComponentProp2: {customDt.Component1.ComponentProp2}"); |
| | 134 | | /// </code> |
| | 135 | | /// </example> |
| | 136 | | public virtual Task<Response<string>> GetDigitalTwinAsync(string digitalTwinId, CancellationToken cancellationTo |
| | 137 | | { |
| 28 | 138 | | return _dtRestClient.GetByIdAsync(digitalTwinId, cancellationToken); |
| | 139 | | } |
| | 140 | |
|
| | 141 | | /// <summary> |
| | 142 | | /// Gets a digital twin synchronously. |
| | 143 | | /// </summary> |
| | 144 | | /// <remarks> |
| | 145 | | /// <para> |
| | 146 | | /// The returned application/json string can always be deserialized into an instance of <see cref="Serialization |
| | 147 | | /// It may also be deserialized into custom digital twin types that extend the <see cref="Serialization.BasicDig |
| | 148 | | /// strongly typed properties provided that you know the definition of the retrieved digital twin prior to deser |
| | 149 | | /// </para> |
| | 150 | | /// <para> |
| | 151 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 152 | | /// </para> |
| | 153 | | /// </remarks> |
| | 154 | | /// <param name="digitalTwinId">The Id of the digital twin.</param> |
| | 155 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 156 | | /// <returns>The application/json digital twin and the http response <see cref="Response{T}"/>.</returns> |
| | 157 | | /// <exception cref="RequestFailedException"> |
| | 158 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 159 | | /// </exception> |
| | 160 | | /// <exception cref="ArgumentNullException"> |
| | 161 | | /// The exception is thrown when <paramref name="digitalTwinId"/> is <c>null</c>. |
| | 162 | | /// </exception> |
| | 163 | | public virtual Response<string> GetDigitalTwin(string digitalTwinId, CancellationToken cancellationToken = defau |
| | 164 | | { |
| 26 | 165 | | return _dtRestClient.GetById(digitalTwinId, cancellationToken); |
| | 166 | | } |
| | 167 | |
|
| | 168 | | /// <summary> |
| | 169 | | /// Creates a digital twin asynchronously. |
| | 170 | | /// </summary> |
| | 171 | | /// <param name="digitalTwinId">The Id of the digital twin.</param> |
| | 172 | | /// <param name="digitalTwin">The application/json digital twin to create.</param> |
| | 173 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 174 | | /// <returns>The created application/json digital twin and the http response <see cref="Response{T}"/>.</returns |
| | 175 | | /// <remarks> |
| | 176 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 177 | | /// </remarks> |
| | 178 | | /// <exception cref="RequestFailedException"> |
| | 179 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 180 | | /// </exception> |
| | 181 | | /// <exception cref="ArgumentNullException"> |
| | 182 | | /// The exception is thrown when <paramref name="digitalTwinId"/> or <paramref name="digitalTwin"/> is <c>null</ |
| | 183 | | /// </exception> |
| | 184 | | /// <example> |
| | 185 | | /// <code snippet="Snippet:DigitalTwinsSampleCreateCustomTwin"> |
| | 186 | | /// var customTwin = new CustomDigitalTwin |
| | 187 | | /// { |
| | 188 | | /// Id = customDtId, |
| | 189 | | /// Metadata = { ModelId = modelId }, |
| | 190 | | /// Prop1 = "Prop1 val", |
| | 191 | | /// Prop2 = 987, |
| | 192 | | /// Component1 = new Component1 |
| | 193 | | /// { |
| | 194 | | /// ComponentProp1 = "Component prop1 val", |
| | 195 | | /// ComponentProp2 = 123, |
| | 196 | | /// } |
| | 197 | | /// }; |
| | 198 | | /// string dt2Payload = JsonSerializer.Serialize(customTwin); |
| | 199 | | /// |
| | 200 | | /// await client.CreateDigitalTwinAsync(customDtId, dt2Payload); |
| | 201 | | /// Console.WriteLine($"Created digital twin '{customDtId}'."); |
| | 202 | | /// </code> |
| | 203 | | /// </example> |
| | 204 | | public virtual Task<Response<string>> CreateDigitalTwinAsync(string digitalTwinId, string digitalTwin, Cancellat |
| | 205 | | { |
| 14 | 206 | | return _dtRestClient.AddAsync(digitalTwinId, digitalTwin, cancellationToken); |
| | 207 | | } |
| | 208 | |
|
| | 209 | | /// <summary> |
| | 210 | | /// Creates a digital twin synchronously. |
| | 211 | | /// </summary> |
| | 212 | | /// <param name="digitalTwinId">The Id of the digital twin.</param> |
| | 213 | | /// <param name="digitalTwin">The application/json digital twin to create.</param> |
| | 214 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 215 | | /// <returns>The created application/json digital twin and the http response <see cref="Response{T}"/>.</returns |
| | 216 | | /// <remarks> |
| | 217 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 218 | | /// </remarks> |
| | 219 | | /// <exception cref="RequestFailedException"> |
| | 220 | | /// <exception cref="ArgumentNullException"> |
| | 221 | | /// The exception is thrown when <paramref name="digitalTwinId"/> or <paramref name="digitalTwin"/> is <c>null</ |
| | 222 | | /// </exception> |
| | 223 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 224 | | /// </exception> |
| | 225 | | public virtual Response<string> CreateDigitalTwin(string digitalTwinId, string digitalTwin, CancellationToken ca |
| | 226 | | { |
| 14 | 227 | | return _dtRestClient.Add(digitalTwinId, digitalTwin, cancellationToken); |
| | 228 | | } |
| | 229 | |
|
| | 230 | | /// <summary> |
| | 231 | | /// Deletes a digital twin asynchronously. |
| | 232 | | /// </summary> |
| | 233 | | /// <param name="digitalTwinId">The Id of the digital twin to delete.</param> |
| | 234 | | /// <param name="requestOptions">The optional settings for this request.</param> |
| | 235 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 236 | | /// <returns>The http response <see cref="Response"/>.</returns> |
| | 237 | | /// <remarks> |
| | 238 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 239 | | /// </remarks> |
| | 240 | | /// <exception cref="RequestFailedException"> |
| | 241 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 242 | | /// </exception> |
| | 243 | | /// <exception cref="ArgumentNullException"> |
| | 244 | | /// The exception is thrown when <paramref name="digitalTwinId"/> is <c>null</c>. |
| | 245 | | /// </exception> |
| | 246 | | /// <remarks> |
| | 247 | | /// To delete a digital twin, any relationships referencing it must be deleted first. |
| | 248 | | /// </remarks> |
| | 249 | | /// <example> |
| | 250 | | /// <code snippet="Snippet:DigitalTwinsSampleDeleteTwin"> |
| | 251 | | /// await client.DeleteDigitalTwinAsync(digitalTwinId); |
| | 252 | | /// Console.WriteLine($"Deleted digital twin '{digitalTwinId}'."); |
| | 253 | | /// </code> |
| | 254 | | /// </example> |
| | 255 | | public virtual Task<Response> DeleteDigitalTwinAsync(string digitalTwinId, RequestOptions requestOptions = defau |
| | 256 | | { |
| 12 | 257 | | return _dtRestClient.DeleteAsync(digitalTwinId, requestOptions?.IfMatch, cancellationToken); |
| | 258 | | } |
| | 259 | |
|
| | 260 | | /// <summary> |
| | 261 | | /// Deletes a digital twin synchronously. |
| | 262 | | /// </summary> |
| | 263 | | /// <param name="digitalTwinId">The Id of the digital twin to delete.</param> |
| | 264 | | /// <param name="requestOptions">The optional settings for this request.</param> |
| | 265 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 266 | | /// <returns>The http response <see cref="Response"/>.</returns> |
| | 267 | | /// <remarks> |
| | 268 | | /// <para> |
| | 269 | | /// To delete a digital twin, any relationships referencing it must be deleted first. |
| | 270 | | /// </para> |
| | 271 | | /// <para> |
| | 272 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 273 | | /// </para> |
| | 274 | | /// </remarks> |
| | 275 | | /// <exception cref="RequestFailedException"> |
| | 276 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 277 | | /// </exception> |
| | 278 | | /// <exception cref="ArgumentNullException"> |
| | 279 | | /// The exception is thrown when <paramref name="digitalTwinId"/> is <c>null</c>. |
| | 280 | | /// </exception> |
| | 281 | | public virtual Response DeleteDigitalTwin(string digitalTwinId, RequestOptions requestOptions = default, Cancell |
| | 282 | | { |
| 12 | 283 | | return _dtRestClient.Delete(digitalTwinId, requestOptions?.IfMatch, cancellationToken); |
| | 284 | | } |
| | 285 | |
|
| | 286 | | /// <summary> |
| | 287 | | /// Updates a digital twin asynchronously. |
| | 288 | | /// </summary> |
| | 289 | | /// <param name="digitalTwinId">The Id of the digital twin to update.</param> |
| | 290 | | /// <param name="digitalTwinUpdateOperations">The application/json-patch+json operations to be performed on the |
| | 291 | | /// <param name="requestOptions">The optional settings for this request.</param> |
| | 292 | | /// <param name="cancellationToken">The cancellationToken.</param> |
| | 293 | | /// <returns>The http response <see cref="Response{T}"/>.</returns> |
| | 294 | | /// <remarks> |
| | 295 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 296 | | /// </remarks> |
| | 297 | | /// <exception cref="RequestFailedException"> |
| | 298 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 299 | | /// </exception> |
| | 300 | | /// <exception cref="ArgumentNullException"> |
| | 301 | | /// The exception is thrown when <paramref name="digitalTwinId"/> or <paramref name="digitalTwinUpdateOperations |
| | 302 | | /// </exception> |
| | 303 | | public virtual Task<Response<string>> UpdateDigitalTwinAsync(string digitalTwinId, string digitalTwinUpdateOpera |
| | 304 | | { |
| 2 | 305 | | return _dtRestClient.UpdateAsync(digitalTwinId, digitalTwinUpdateOperations, requestOptions?.IfMatch, cancel |
| | 306 | | } |
| | 307 | |
|
| | 308 | | /// <summary> |
| | 309 | | /// Updates a digital twin synchronously. |
| | 310 | | /// </summary> |
| | 311 | | /// <param name="digitalTwinId">The Id of the digital twin to update.</param> |
| | 312 | | /// <param name="digitalTwinUpdateOperations">The application/json-patch+json operations to be performed on the |
| | 313 | | /// <param name="requestOptions">The optional settings for this request.</param> |
| | 314 | | /// <param name="cancellationToken">The cancellationToken.</param> |
| | 315 | | /// <returns>The http response <see cref="Response{T}"/>.</returns> |
| | 316 | | /// <remarks> |
| | 317 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 318 | | /// </remarks> |
| | 319 | | /// <exception cref="RequestFailedException"> |
| | 320 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 321 | | /// </exception> |
| | 322 | | /// <exception cref="ArgumentNullException"> |
| | 323 | | /// The exception is thrown when <paramref name="digitalTwinId"/> or <paramref name="digitalTwinUpdateOperations |
| | 324 | | /// </exception> |
| | 325 | | /// <seealso cref="UpdateDigitalTwinAsync(string, string, RequestOptions, CancellationToken)"> |
| | 326 | | /// See the asynchronous version of this method for examples. |
| | 327 | | /// </seealso> |
| | 328 | | public virtual Response<string> UpdateDigitalTwin(string digitalTwinId, string digitalTwinUpdateOperations, Requ |
| | 329 | | { |
| 2 | 330 | | return _dtRestClient.Update(digitalTwinId, digitalTwinUpdateOperations, requestOptions?.IfMatch, cancellatio |
| | 331 | | } |
| | 332 | |
|
| | 333 | | /// <summary> |
| | 334 | | /// Gets a component on a digital twin asynchronously. |
| | 335 | | /// </summary> |
| | 336 | | /// <param name="digitalTwinId">The Id of the digital twin.</param> |
| | 337 | | /// <param name="componentPath">The component being retrieved.</param> |
| | 338 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 339 | | /// <returns>Json string representation of the component corresponding to the provided componentPath and the HTT |
| | 340 | | /// <remarks> |
| | 341 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 342 | | /// </remarks> |
| | 343 | | /// <exception cref="RequestFailedException"> |
| | 344 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 345 | | /// </exception> |
| | 346 | | /// <exception cref="ArgumentNullException"> |
| | 347 | | /// The exception is thrown when <paramref name="digitalTwinId"/> or <paramref name="componentPath"/> is <c>null |
| | 348 | | /// </exception> |
| | 349 | | /// <example> |
| | 350 | | /// <code snippet="Snippet:DigitalTwinsSampleGetComponent"> |
| | 351 | | /// await client.GetComponentAsync(basicDtId, SamplesConstants.ComponentPath); |
| | 352 | | /// Console.WriteLine($"Retrieved component for digital twin '{basicDtId}'."); |
| | 353 | | /// </code> |
| | 354 | | /// </example> |
| | 355 | | public virtual Task<Response<string>> GetComponentAsync(string digitalTwinId, string componentPath, Cancellation |
| | 356 | | { |
| 2 | 357 | | return _dtRestClient.GetComponentAsync(digitalTwinId, componentPath, cancellationToken); |
| | 358 | | } |
| | 359 | |
|
| | 360 | | /// <summary> |
| | 361 | | /// Gets a component on a digital twin synchronously. |
| | 362 | | /// </summary> |
| | 363 | | /// <param name="digitalTwinId">The Id of the digital twin.</param> |
| | 364 | | /// <param name="componentPath">The component being retrieved.</param> |
| | 365 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 366 | | /// <returns>Json string representation of the component corresponding to the provided componentPath and the HTT |
| | 367 | | /// <remarks> |
| | 368 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 369 | | /// </remarks> |
| | 370 | | /// <exception cref="RequestFailedException"> |
| | 371 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 372 | | /// </exception> |
| | 373 | | /// <exception cref="ArgumentNullException"> |
| | 374 | | /// The exception is thrown when <paramref name="digitalTwinId"/> or <paramref name="componentPath"/> is <c>null |
| | 375 | | /// </exception> |
| | 376 | | /// <seealso cref="GetComponentAsync(string, string, CancellationToken)"> |
| | 377 | | /// See the asynchronous version of this method for examples. |
| | 378 | | /// </seealso> |
| | 379 | | public virtual Response<string> GetComponent(string digitalTwinId, string componentPath, CancellationToken cance |
| | 380 | | { |
| 2 | 381 | | return _dtRestClient.GetComponent(digitalTwinId, componentPath, cancellationToken); |
| | 382 | | } |
| | 383 | |
|
| | 384 | | /// <summary> |
| | 385 | | /// Updates properties of a component on a digital twin asynchronously. |
| | 386 | | /// </summary> |
| | 387 | | /// <param name="digitalTwinId">The Id of the digital twin.</param> |
| | 388 | | /// <param name="componentPath">The component being modified.</param> |
| | 389 | | /// <param name="componentUpdateOperations">The application/json-patch+json operations to be performed on the sp |
| | 390 | | /// <param name="requestOptions">The optional settings for this request.</param> |
| | 391 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 392 | | /// <returns>The HTTP response <see cref="Response{T}"/>.</returns> |
| | 393 | | /// <remarks> |
| | 394 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 395 | | /// </remarks> |
| | 396 | | /// <exception cref="RequestFailedException"> |
| | 397 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 398 | | /// </exception> |
| | 399 | | /// <example> |
| | 400 | | /// <exception cref="ArgumentNullException"> |
| | 401 | | /// The exception is thrown when <paramref name="digitalTwinId"/> or <paramref name="componentPath"/> is <c>null |
| | 402 | | /// </exception> |
| | 403 | | /// <code snippet="Snippet:DigitalTwinsSampleUpdateComponent"> |
| | 404 | | /// // Update Component1 by replacing the property ComponentProp1 value, |
| | 405 | | /// // using an optional utility to build the payload. |
| | 406 | | /// var componentUpdateUtility = new UpdateOperationsUtility(); |
| | 407 | | /// componentUpdateUtility.AppendReplaceOp("/ComponentProp1", "Some new value"); |
| | 408 | | /// string updatePayload = componentUpdateUtility.Serialize(); |
| | 409 | | /// await client.UpdateComponentAsync(basicDtId, "Component1", updatePayload); |
| | 410 | | /// Console.WriteLine($"Updated component for digital twin '{basicDtId}'."); |
| | 411 | | /// </code> |
| | 412 | | /// </example> |
| | 413 | | public virtual Task<Response<string>> UpdateComponentAsync(string digitalTwinId, string componentPath, string co |
| | 414 | | { |
| | 415 | | // TODO how can we make this patch easier to construct? |
| 2 | 416 | | return _dtRestClient.UpdateComponentAsync(digitalTwinId, componentPath, componentUpdateOperations, requestOp |
| | 417 | | } |
| | 418 | |
|
| | 419 | | /// <summary> |
| | 420 | | /// Updates properties of a component on a digital twin synchronously. |
| | 421 | | /// </summary> |
| | 422 | | /// <param name="digitalTwinId">The Id of the digital twin.</param> |
| | 423 | | /// <param name="componentPath">The component being modified.</param> |
| | 424 | | /// <param name="componentUpdateOperations">The application/json-patch+json operations to be performed on the sp |
| | 425 | | /// <param name="requestOptions">The optional settings for this request.</param> |
| | 426 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 427 | | /// <returns>The HTTP response <see cref="Response{T}"/>.</returns> |
| | 428 | | /// <remarks> |
| | 429 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 430 | | /// </remarks> |
| | 431 | | /// <exception cref="RequestFailedException"> |
| | 432 | | /// <exception cref="ArgumentNullException"> |
| | 433 | | /// The exception is thrown when <paramref name="digitalTwinId"/> or <paramref name="componentPath"/> is <c>null |
| | 434 | | /// </exception> |
| | 435 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 436 | | /// </exception> |
| | 437 | | /// <seealso cref="UpdateComponentAsync(string, string, string, RequestOptions, CancellationToken)"> |
| | 438 | | /// See the asynchronous version of this method for examples. |
| | 439 | | /// </seealso> |
| | 440 | | public virtual Response<string> UpdateComponent(string digitalTwinId, string componentPath, string componentUpda |
| | 441 | | { |
| 2 | 442 | | return _dtRestClient.UpdateComponent(digitalTwinId, componentPath, componentUpdateOperations, requestOptions |
| | 443 | | } |
| | 444 | |
|
| | 445 | | /// <summary> |
| | 446 | | /// Gets all the relationships on a digital twin by iterating through a collection asynchronously. |
| | 447 | | /// </summary> |
| | 448 | | /// <param name="digitalTwinId">The Id of the source digital twin.</param> |
| | 449 | | /// <param name="relationshipName">The name of a relationship to filter to. If null, all relationships for the d |
| | 450 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 451 | | /// <returns>The pageable list <see cref="AsyncPageable{T}"/> of application/json relationships belonging to the |
| | 452 | | /// <remarks> |
| | 453 | | /// <para> |
| | 454 | | /// String relationships that are returned as part of the pageable list can always be deserialized into an instn |
| | 455 | | /// You may also deserialize the relationship into custom type that extend the <see cref="Serialization.BasicRel |
| | 456 | | /// </para> |
| | 457 | | /// <para> |
| | 458 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 459 | | /// </para> |
| | 460 | | /// </remarks> |
| | 461 | | /// <exception cref="RequestFailedException"> |
| | 462 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 463 | | /// </exception> |
| | 464 | | /// <exception cref="ArgumentNullException"> |
| | 465 | | /// The exception is thrown when <paramref name="digitalTwinId"/> is <c>null</c>. |
| | 466 | | /// </exception> |
| | 467 | | /// <example> |
| | 468 | | /// This sample demonstrates iterating over outgoing relationships and deserializing relationship strings into B |
| | 469 | | /// <code snippet="Snippet:DigitalTwinsSampleGetAllRelationships"> |
| | 470 | | /// AsyncPageable<string> relationships = client.GetRelationshipsAsync("buildingTwinId"); |
| | 471 | | /// await foreach (var relationshipJson in relationships) |
| | 472 | | /// { |
| | 473 | | /// BasicRelationship relationship = JsonSerializer.Deserialize<BasicRelationship>(relationshipJson); |
| | 474 | | /// Console.WriteLine($"Retrieved relationship '{relationship.Id}' with source {relationship. |
| | 475 | | /// $"target {relationship.TargetId}.\n\t" + |
| | 476 | | /// $"Prop1: {relationship.CustomProperties["Prop1"]}\n\t" + |
| | 477 | | /// $"Prop2: {relationship.CustomProperties["Prop2"]}"); |
| | 478 | | /// } |
| | 479 | | /// </code> |
| | 480 | | /// </example> |
| | 481 | | public virtual AsyncPageable<string> GetRelationshipsAsync(string digitalTwinId, string relationshipName = null, |
| | 482 | | { |
| 4 | 483 | | if (digitalTwinId == null) |
| | 484 | | { |
| 0 | 485 | | throw new ArgumentNullException(nameof(digitalTwinId)); |
| | 486 | | } |
| | 487 | |
|
| | 488 | | async Task<Page<string>> FirstPageFunc(int? pageSizeHint) |
| | 489 | | { |
| 4 | 490 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DigitalTwinsClient)}.{nameof(GetR |
| 4 | 491 | | scope.Start(); |
| | 492 | | try |
| | 493 | | { |
| 4 | 494 | | Response<RelationshipCollection> response = await _dtRestClient.ListRelationshipsAsync(digitalTwinId |
| 4 | 495 | | return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); |
| | 496 | | } |
| 0 | 497 | | catch (Exception ex) |
| | 498 | | { |
| 0 | 499 | | scope.Failed(ex); |
| 0 | 500 | | throw; |
| | 501 | | } |
| 4 | 502 | | } |
| | 503 | |
|
| | 504 | | async Task<Page<string>> NextPageFunc(string nextLink, int? pageSizeHint) |
| | 505 | | { |
| 0 | 506 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DigitalTwinsClient)}.{nameof(GetR |
| 0 | 507 | | scope.Start(); |
| | 508 | | try |
| | 509 | | { |
| 0 | 510 | | Response<RelationshipCollection> response = await _dtRestClient.ListRelationshipsNextPageAsync(nextL |
| 0 | 511 | | return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); |
| | 512 | | } |
| 0 | 513 | | catch (Exception ex) |
| | 514 | | { |
| 0 | 515 | | scope.Failed(ex); |
| 0 | 516 | | throw; |
| | 517 | | } |
| 0 | 518 | | } |
| | 519 | |
|
| 4 | 520 | | return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); |
| | 521 | | } |
| | 522 | |
|
| | 523 | | /// <summary> |
| | 524 | | /// Gets all the relationships on a digital twin by iterating through a collection synchronously. |
| | 525 | | /// </summary> |
| | 526 | | /// <param name="digitalTwinId">The Id of the source digital twin.</param> |
| | 527 | | /// <param name="relationshipName">The name of a relationship to filter to. If null, all relationships for the d |
| | 528 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 529 | | /// <returns>The pageable list <see cref="Pageable{T}"/> of application/json relationships belonging to the spec |
| | 530 | | /// <remarks> |
| | 531 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 532 | | /// </remarks> |
| | 533 | | /// <exception cref="RequestFailedException"> |
| | 534 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 535 | | /// </exception> |
| | 536 | | /// <exception cref="ArgumentNullException"> |
| | 537 | | /// The exception is thrown when <paramref name="digitalTwinId"/> is <c>null</c>. |
| | 538 | | /// </exception> |
| | 539 | | /// <seealso cref="GetRelationshipsAsync(string, string, CancellationToken)"> |
| | 540 | | /// See the asynchronous version of this method for examples. |
| | 541 | | /// </seealso> |
| | 542 | | public virtual Pageable<string> GetRelationships(string digitalTwinId, string relationshipName = null, Cancellat |
| | 543 | | { |
| 4 | 544 | | if (digitalTwinId == null) |
| | 545 | | { |
| 0 | 546 | | throw new ArgumentNullException(nameof(digitalTwinId)); |
| | 547 | | } |
| | 548 | |
|
| | 549 | | Page<string> FirstPageFunc(int? pageSizeHint) |
| | 550 | | { |
| 4 | 551 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DigitalTwinsClient)}.{nameof(GetR |
| 4 | 552 | | scope.Start(); |
| | 553 | | try |
| | 554 | | { |
| 4 | 555 | | Response<RelationshipCollection> response = _dtRestClient.ListRelationships(digitalTwinId, relations |
| 4 | 556 | | return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); |
| | 557 | | } |
| 0 | 558 | | catch (Exception ex) |
| | 559 | | { |
| 0 | 560 | | scope.Failed(ex); |
| 0 | 561 | | throw; |
| | 562 | | } |
| 4 | 563 | | } |
| | 564 | |
|
| | 565 | | Page<string> NextPageFunc(string nextLink, int? pageSizeHint) |
| | 566 | | { |
| 0 | 567 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DigitalTwinsClient)}.{nameof(GetR |
| 0 | 568 | | scope.Start(); |
| | 569 | | try |
| | 570 | | { |
| 0 | 571 | | Response<RelationshipCollection> response = _dtRestClient.ListRelationshipsNextPage(nextLink, digita |
| 0 | 572 | | return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); |
| | 573 | | } |
| 0 | 574 | | catch (Exception ex) |
| | 575 | | { |
| 0 | 576 | | scope.Failed(ex); |
| 0 | 577 | | throw; |
| | 578 | | } |
| 0 | 579 | | } |
| | 580 | |
|
| 4 | 581 | | return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); |
| | 582 | | } |
| | 583 | |
|
| | 584 | | /// <summary> |
| | 585 | | /// Gets all the relationships referencing a digital twin as a target by iterating through a collection asynchro |
| | 586 | | /// </summary> |
| | 587 | | /// <param name="digitalTwinId">The Id of the target digital twin.</param> |
| | 588 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 589 | | /// <returns>The pageable list <see cref="AsyncPageable{T}"/> of application/json relationships directed towards |
| | 590 | | /// <remarks> |
| | 591 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 592 | | /// </remarks> |
| | 593 | | /// <exception cref="RequestFailedException"> |
| | 594 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 595 | | /// </exception> |
| | 596 | | /// <exception cref="ArgumentNullException"> |
| | 597 | | /// The exception is thrown when <paramref name="digitalTwinId"/> is <c>null</c>. |
| | 598 | | /// </exception> |
| | 599 | | /// <example> |
| | 600 | | /// <code snippet="Snippet:DigitalTwinsSampleGetIncomingRelationships"> |
| | 601 | | /// AsyncPageable<IncomingRelationship> incomingRelationships = client.GetIncomingRelationshipsAsync(" |
| | 602 | | /// |
| | 603 | | /// await foreach (IncomingRelationship incomingRelationship in incomingRelationships) |
| | 604 | | /// { |
| | 605 | | /// Console.WriteLine($"Found an incoming relationship '{incomingRelationship.RelationshipId}&apos |
| | 606 | | /// } |
| | 607 | | /// </code> |
| | 608 | | /// </example> |
| | 609 | | public virtual AsyncPageable<IncomingRelationship> GetIncomingRelationshipsAsync(string digitalTwinId, Cancellat |
| | 610 | | { |
| | 611 | | async Task<Page<IncomingRelationship>> FirstPageFunc(int? pageSizeHint) |
| | 612 | | { |
| 2 | 613 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DigitalTwinsClient)}.{nameof(GetI |
| 2 | 614 | | scope.Start(); |
| | 615 | | try |
| | 616 | | { |
| 2 | 617 | | Response<IncomingRelationshipCollection> response = await _dtRestClient.ListIncomingRelationshipsAsy |
| 2 | 618 | | return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); |
| | 619 | | } |
| 0 | 620 | | catch (Exception ex) |
| | 621 | | { |
| 0 | 622 | | scope.Failed(ex); |
| 0 | 623 | | throw; |
| | 624 | | } |
| 2 | 625 | | } |
| | 626 | |
|
| | 627 | | async Task<Page<IncomingRelationship>> NextPageFunc(string nextLink, int? pageSizeHint) |
| | 628 | | { |
| 0 | 629 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DigitalTwinsClient)}.{nameof(GetI |
| 0 | 630 | | scope.Start(); |
| | 631 | | try |
| | 632 | | { |
| 0 | 633 | | Response<IncomingRelationshipCollection> response = await _dtRestClient.ListIncomingRelationshipsNex |
| 0 | 634 | | return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); |
| | 635 | | } |
| 0 | 636 | | catch (Exception ex) |
| | 637 | | { |
| 0 | 638 | | scope.Failed(ex); |
| 0 | 639 | | throw; |
| | 640 | | } |
| 0 | 641 | | } |
| | 642 | |
|
| 2 | 643 | | return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); |
| | 644 | | } |
| | 645 | |
|
| | 646 | | /// <summary> |
| | 647 | | /// Gets all the relationships referencing a digital twin as a target by iterating through a collection synchron |
| | 648 | | /// </summary> |
| | 649 | | /// <param name="digitalTwinId">The Id of the target digital twin.</param> |
| | 650 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 651 | | /// <returns>The pageable list <see cref="Pageable{T}"/> of application/json relationships directed towards the |
| | 652 | | /// <remarks> |
| | 653 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 654 | | /// </remarks> |
| | 655 | | /// <exception cref="RequestFailedException"> |
| | 656 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 657 | | /// </exception> |
| | 658 | | /// <exception cref="ArgumentNullException"> |
| | 659 | | /// The exception is thrown when <paramref name="digitalTwinId"/> is <c>null</c>. |
| | 660 | | /// </exception> |
| | 661 | | /// <seealso cref="GetIncomingRelationshipsAsync(string, CancellationToken)"> |
| | 662 | | /// See the asynchronous version of this method for examples. |
| | 663 | | /// </seealso> |
| | 664 | | public virtual Pageable<IncomingRelationship> GetIncomingRelationships(string digitalTwinId, CancellationToken c |
| | 665 | | { |
| | 666 | | Page<IncomingRelationship> FirstPageFunc(int? pageSizeHint) |
| | 667 | | { |
| 2 | 668 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope("DigitalTwinsGeneratedClient.ListIncomingRe |
| 2 | 669 | | scope.Start(); |
| | 670 | | try |
| | 671 | | { |
| 2 | 672 | | Response<IncomingRelationshipCollection> response = _dtRestClient.ListIncomingRelationships(digitalT |
| 2 | 673 | | return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); |
| | 674 | | } |
| 0 | 675 | | catch (Exception e) |
| | 676 | | { |
| 0 | 677 | | scope.Failed(e); |
| 0 | 678 | | throw; |
| | 679 | | } |
| 2 | 680 | | } |
| | 681 | |
|
| | 682 | | Page<IncomingRelationship> NextPageFunc(string nextLink, int? pageSizeHint) |
| | 683 | | { |
| 0 | 684 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope("DigitalTwinsGeneratedClient.ListIncomingRe |
| 0 | 685 | | scope.Start(); |
| | 686 | | try |
| | 687 | | { |
| 0 | 688 | | Response<IncomingRelationshipCollection> response = _dtRestClient.ListIncomingRelationshipsNextPage( |
| 0 | 689 | | return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); |
| | 690 | | } |
| 0 | 691 | | catch (Exception e) |
| | 692 | | { |
| 0 | 693 | | scope.Failed(e); |
| 0 | 694 | | throw; |
| | 695 | | } |
| 0 | 696 | | } |
| | 697 | |
|
| 2 | 698 | | return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); |
| | 699 | | } |
| | 700 | |
|
| | 701 | | /// <summary> |
| | 702 | | /// Gets a relationship on a digital twin asynchronously. |
| | 703 | | /// </summary> |
| | 704 | | /// <param name="digitalTwinId">The Id of the source digital twin.</param> |
| | 705 | | /// <param name="relationshipId">The Id of the relationship to retrieve.</param> |
| | 706 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 707 | | /// <returns>The application/json relationship corresponding to the provided relationshipId and the http respons |
| | 708 | | /// <remarks> |
| | 709 | | /// <para> |
| | 710 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 711 | | /// </para> |
| | 712 | | /// </remarks> |
| | 713 | | /// <exception cref="RequestFailedException"> |
| | 714 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 715 | | /// </exception> |
| | 716 | | /// <exception cref="ArgumentNullException"> |
| | 717 | | /// The exception is thrown when <paramref name="digitalTwinId"/> or <paramref name="relationshipId"/> is <c>nul |
| | 718 | | /// </exception> |
| | 719 | | /// <example> |
| | 720 | | /// This sample demonstrates getting and deserializing a digital twin relationship into a custom data type. |
| | 721 | | /// <code snippet="Snippet:DigitalTwinsSampleGetCustomRelationship"> |
| | 722 | | /// Response<string> getCustomRelationshipResponse = await client.GetRelationshipAsync("floorTwinId&q |
| | 723 | | /// CustomRelationship getCustomRelationship = JsonSerializer.Deserialize<CustomRelationship>(getCustomRel |
| | 724 | | /// Console.WriteLine($"Retrieved and deserialized relationship '{getCustomRelationship.Id}' from |
| | 725 | | /// $"Prop1: {getCustomRelationship.Prop1}\n\t" + |
| | 726 | | /// $"Prop2: {getCustomRelationship.Prop2}"); |
| | 727 | | /// </code> |
| | 728 | | /// </example> |
| | 729 | | public virtual Task<Response<string>> GetRelationshipAsync(string digitalTwinId, string relationshipId, Cancella |
| | 730 | | { |
| 10 | 731 | | return _dtRestClient.GetRelationshipByIdAsync(digitalTwinId, relationshipId, cancellationToken); |
| | 732 | | } |
| | 733 | |
|
| | 734 | | /// <summary> |
| | 735 | | /// Gets a relationship on a digital twin synchronously. |
| | 736 | | /// </summary> |
| | 737 | | /// <param name="digitalTwinId">The Id of the source digital twin.</param> |
| | 738 | | /// <param name="relationshipId">The Id of the relationship to retrieve.</param> |
| | 739 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 740 | | /// <returns>The application/json relationship corresponding to the provided relationshipId and the http respons |
| | 741 | | /// <remarks> |
| | 742 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 743 | | /// </remarks> |
| | 744 | | /// <exception cref="RequestFailedException"> |
| | 745 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 746 | | /// </exception> |
| | 747 | | /// <exception cref="ArgumentNullException"> |
| | 748 | | /// The exception is thrown when <paramref name="digitalTwinId"/> or <paramref name="relationshipId"/> is <c>nul |
| | 749 | | /// </exception> |
| | 750 | | /// <seealso cref="GetRelationshipAsync(string, string, CancellationToken)"> |
| | 751 | | /// See the asynchronous version of this method for examples. |
| | 752 | | /// </seealso> |
| | 753 | | public virtual Response<string> GetRelationship(string digitalTwinId, string relationshipId, CancellationToken c |
| | 754 | | { |
| 10 | 755 | | return _dtRestClient.GetRelationshipById(digitalTwinId, relationshipId, cancellationToken); |
| | 756 | | } |
| | 757 | |
|
| | 758 | | /// <summary> |
| | 759 | | /// Deletes a relationship on a digital twin asynchronously. |
| | 760 | | /// </summary> |
| | 761 | | /// <param name="digitalTwinId">The Id of the source digital twin.</param> |
| | 762 | | /// <param name="relationshipId">The Id of the relationship to delete.</param> |
| | 763 | | /// <param name="requestOptions">The optional settings for this request.</param> |
| | 764 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 765 | | /// <returns>The http response <see cref="Response"/>.</returns> |
| | 766 | | /// <remarks> |
| | 767 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 768 | | /// </remarks> |
| | 769 | | /// <exception cref="RequestFailedException"> |
| | 770 | | /// <exception cref="ArgumentNullException"> |
| | 771 | | /// The exception is thrown when <paramref name="digitalTwinId"/> or <paramref name="relationshipId"/> is <c>nul |
| | 772 | | /// </exception> |
| | 773 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 774 | | /// </exception> |
| | 775 | | public virtual Task<Response> DeleteRelationshipAsync(string digitalTwinId, string relationshipId, RequestOption |
| | 776 | | { |
| 8 | 777 | | return _dtRestClient.DeleteRelationshipAsync(digitalTwinId, relationshipId, requestOptions?.IfMatch, cancell |
| | 778 | | } |
| | 779 | |
|
| | 780 | | /// <summary> |
| | 781 | | /// Deletes a relationship on a digital twin synchronously. |
| | 782 | | /// </summary> |
| | 783 | | /// <param name="digitalTwinId">The Id of the source digital twin.</param> |
| | 784 | | /// <param name="relationshipId">The Id of the relationship to delete.</param> |
| | 785 | | /// <param name="requestOptions">The optional settings for this request.</param> |
| | 786 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 787 | | /// <returns>The http response <see cref="Response"/>.</returns> |
| | 788 | | /// <remarks> |
| | 789 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 790 | | /// </remarks> |
| | 791 | | /// <exception cref="RequestFailedException"> |
| | 792 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 793 | | /// </exception> |
| | 794 | | /// <exception cref="ArgumentNullException"> |
| | 795 | | /// The exception is thrown when <paramref name="digitalTwinId"/> or <paramref name="relationshipId"/> is <c>nul |
| | 796 | | /// </exception> |
| | 797 | | /// <seealso cref="DeleteRelationshipAsync(string, string, RequestOptions, CancellationToken)"> |
| | 798 | | /// See the asynchronous version of this method for examples. |
| | 799 | | /// </seealso> |
| | 800 | | public virtual Response DeleteRelationship(string digitalTwinId, string relationshipId, RequestOptions requestOp |
| | 801 | | { |
| 8 | 802 | | return _dtRestClient.DeleteRelationship(digitalTwinId, relationshipId, requestOptions?.IfMatch, cancellation |
| | 803 | | } |
| | 804 | |
|
| | 805 | | /// <summary> |
| | 806 | | /// Creates a relationship on a digital twin asynchronously. |
| | 807 | | /// </summary> |
| | 808 | | /// <param name="digitalTwinId">The Id of the source digital twin.</param> |
| | 809 | | /// <param name="relationshipId">The Id of the relationship which is being created.</param> |
| | 810 | | /// <param name="relationship">The application/json relationship to be created.</param> |
| | 811 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 812 | | /// <returns>The http response <see cref="Response{T}"/>.</returns> |
| | 813 | | /// <remarks> |
| | 814 | | /// <para> |
| | 815 | | /// Relationships are a one-way link from a source digital twin to another, as described at creation time of the |
| | 816 | | /// </para> |
| | 817 | | /// <para> |
| | 818 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 819 | | /// </para> |
| | 820 | | /// </remarks> |
| | 821 | | /// <exception cref="RequestFailedException"> |
| | 822 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 823 | | /// </exception> |
| | 824 | | /// <exception cref="ArgumentNullException"> |
| | 825 | | /// The exception is thrown when <paramref name="digitalTwinId"/> or <paramref name="relationshipId"/> is <c>nul |
| | 826 | | /// </exception> |
| | 827 | | /// <example> |
| | 828 | | /// <code snippet="Snippet:DigitalTwinsSampleCreateCustomRelationship"> |
| | 829 | | /// var floorBuildingRelationshipPayload = new CustomRelationship |
| | 830 | | /// { |
| | 831 | | /// Id = "floorBuildingRelationshipId", |
| | 832 | | /// SourceId = "floorTwinId", |
| | 833 | | /// TargetId = "buildingTwinId", |
| | 834 | | /// Name = "containedIn", |
| | 835 | | /// Prop1 = "Prop1 val", |
| | 836 | | /// Prop2 = 4 |
| | 837 | | /// }; |
| | 838 | | /// string serializedCustomRelationship = JsonSerializer.Serialize(floorBuildingRelationshipPayload); |
| | 839 | | /// |
| | 840 | | /// Response<string> createCustomRelationshipResponse = await client.CreateRelationshipAsync("floorTw |
| | 841 | | /// Console.WriteLine($"Created a digital twin relationship 'floorBuildingRelationshipId' from tw |
| | 842 | | /// </code> |
| | 843 | | /// </example> |
| | 844 | | public virtual Task<Response<string>> CreateRelationshipAsync(string digitalTwinId, string relationshipId, strin |
| | 845 | | { |
| 8 | 846 | | return _dtRestClient.AddRelationshipAsync(digitalTwinId, relationshipId, relationship, cancellationToken); |
| | 847 | | } |
| | 848 | |
|
| | 849 | | /// <summary> |
| | 850 | | /// Creates a relationship on a digital twin synchronously. |
| | 851 | | /// </summary> |
| | 852 | | /// <param name="digitalTwinId">The Id of the source digital twin.</param> |
| | 853 | | /// <param name="relationshipId">The Id of the relationship to delete.</param> |
| | 854 | | /// <param name="relationship">The application/json relationship to be created.</param> |
| | 855 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 856 | | /// <returns>The http response <see cref="Response{T}"/>.</returns> |
| | 857 | | /// <remarks> |
| | 858 | | /// <para> |
| | 859 | | /// Relationships are a one-way link from a source digital twin to another, as described at creation time of the |
| | 860 | | /// </para> |
| | 861 | | /// <para> |
| | 862 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 863 | | /// </para> |
| | 864 | | /// </remarks> |
| | 865 | | /// <exception cref="RequestFailedException"> |
| | 866 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 867 | | /// </exception> |
| | 868 | | /// <exception cref="ArgumentNullException"> |
| | 869 | | /// The exception is thrown when <paramref name="digitalTwinId"/> or <paramref name="relationshipId"/> is <c>nul |
| | 870 | | /// </exception> |
| | 871 | | /// <seealso cref="CreateRelationshipAsync(string, string, string, CancellationToken)"> |
| | 872 | | /// See the asynchronous version of this method for examples. |
| | 873 | | /// </seealso> |
| | 874 | | public virtual Response<string> CreateRelationship(string digitalTwinId, string relationshipId, string relations |
| | 875 | | { |
| 8 | 876 | | return _dtRestClient.AddRelationship(digitalTwinId, relationshipId, relationship, cancellationToken); |
| | 877 | | } |
| | 878 | |
|
| | 879 | | /// <summary> |
| | 880 | | /// Updates the properties of a relationship on a digital twin asynchronously. |
| | 881 | | /// </summary> |
| | 882 | | /// <param name="digitalTwinId">The Id of the source digital twin.</param> |
| | 883 | | /// <param name="relationshipId">The Id of the relationship to be updated.</param> |
| | 884 | | /// <param name="relationshipUpdateOperations">The application/json-patch+json operations to be performed on the |
| | 885 | | /// <param name="requestOptions">The optional settings for this request.</param> |
| | 886 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 887 | | /// <returns>The http response <see cref="Response"/>.</returns> |
| | 888 | | /// <remarks> |
| | 889 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 890 | | /// </remarks> |
| | 891 | | /// <exception cref="RequestFailedException"> |
| | 892 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 893 | | /// </exception> |
| | 894 | | /// <exception cref="ArgumentNullException"> |
| | 895 | | /// The exception is thrown when <paramref name="digitalTwinId"/> or <paramref name="relationshipId"/> is <c>nul |
| | 896 | | /// </exception> |
| | 897 | | public virtual Task<Response> UpdateRelationshipAsync(string digitalTwinId, string relationshipId, string relati |
| | 898 | | { |
| | 899 | | // TODO how can we make this patch easier to construct? |
| 2 | 900 | | return _dtRestClient.UpdateRelationshipAsync(digitalTwinId, relationshipId, relationshipUpdateOperations, re |
| | 901 | | } |
| | 902 | |
|
| | 903 | | /// <summary> |
| | 904 | | /// Updates the properties of a relationship on a digital twin synchronously. |
| | 905 | | /// </summary> |
| | 906 | | /// <param name="digitalTwinId">The Id of the source digital twin.</param> |
| | 907 | | /// <param name="relationshipId">The Id of the relationship to be updated.</param> |
| | 908 | | /// <param name="relationshipUpdateOperations">The application/json-patch+json operations to be performed on the |
| | 909 | | /// <param name="requestOptions">The optional settings for this request.</param> |
| | 910 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 911 | | /// <returns>The http response <see cref="Response"/>.</returns> |
| | 912 | | /// <remarks> |
| | 913 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 914 | | /// </remarks> |
| | 915 | | /// <exception cref="RequestFailedException"> |
| | 916 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 917 | | /// </exception> |
| | 918 | | /// <exception cref="ArgumentNullException"> |
| | 919 | | /// The exception is thrown when <paramref name="digitalTwinId"/> or <paramref name="relationshipId"/> is <c>nul |
| | 920 | | /// </exception> |
| | 921 | | /// <seealso cref="UpdateRelationshipAsync(string, string, string, RequestOptions, CancellationToken)"> |
| | 922 | | /// See the asynchronous version of this method for examples. |
| | 923 | | /// </seealso> |
| | 924 | | public virtual Response UpdateRelationship(string digitalTwinId, string relationshipId, string relationshipUpdat |
| | 925 | | { |
| 2 | 926 | | return _dtRestClient.UpdateRelationship(digitalTwinId, relationshipId, relationshipUpdateOperations, request |
| | 927 | | } |
| | 928 | |
|
| | 929 | | /// <summary> |
| | 930 | | /// Gets the list of models by iterating through a collection asynchronously. |
| | 931 | | /// </summary> |
| | 932 | | /// <param name="dependenciesFor">The model Ids to have dependencies retrieved.</param> |
| | 933 | | /// <param name="includeModelDefinition">Whether to include the model definition in the result. If false, only t |
| | 934 | | /// <param name="options">The options to follow when listing the models. For example, the page size hint can be |
| | 935 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 936 | | /// <returns>The pageable list <see cref="AsyncPageable{T}"/> of application/json models and the http response.< |
| | 937 | | /// <remarks> |
| | 938 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 939 | | /// </remarks> |
| | 940 | | /// <exception cref="RequestFailedException"> |
| | 941 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 942 | | /// </exception> |
| | 943 | | /// <example> |
| | 944 | | /// <code snippet="Snippet:DigitalTwinsSampleGetModels"> |
| | 945 | | /// AsyncPageable<ModelData> allModels = client.GetModelsAsync(); |
| | 946 | | /// await foreach (ModelData model in allModels) |
| | 947 | | /// { |
| | 948 | | /// Console.WriteLine($"Retrieved model '{model.Id}', " + |
| | 949 | | /// $"display name '{model.DisplayName["en"]}', " + |
| | 950 | | /// $"upload time '{model.UploadTime}', " + |
| | 951 | | /// $"and decommissioned '{model.Decommissioned}'"); |
| | 952 | | /// } |
| | 953 | | /// </code> |
| | 954 | | /// </example> |
| | 955 | | public virtual AsyncPageable<ModelData> GetModelsAsync(IEnumerable<string> dependenciesFor = default, bool inclu |
| | 956 | | { |
| | 957 | | async Task<Page<ModelData>> FirstPageFunc(int? pageSizeHint) |
| | 958 | | { |
| 2 | 959 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope("DigitalTwinModelsClient.List"); |
| 2 | 960 | | scope.Start(); |
| | 961 | | try |
| | 962 | | { |
| 2 | 963 | | Response<PagedModelDataCollection> response = await _dtModelsRestClient.ListAsync(dependenciesFor, i |
| 2 | 964 | | return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); |
| | 965 | | } |
| 0 | 966 | | catch (Exception e) |
| | 967 | | { |
| 0 | 968 | | scope.Failed(e); |
| 0 | 969 | | throw; |
| | 970 | | } |
| 2 | 971 | | } |
| | 972 | |
|
| | 973 | | async Task<Page<ModelData>> NextPageFunc(string nextLink, int? pageSizeHint) |
| | 974 | | { |
| 0 | 975 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope("DigitalTwinModelsClient.List"); |
| 0 | 976 | | scope.Start(); |
| | 977 | | try |
| | 978 | | { |
| 0 | 979 | | Response<PagedModelDataCollection> response = await _dtModelsRestClient.ListNextPageAsync(nextLink, |
| 0 | 980 | | return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); |
| | 981 | | } |
| 0 | 982 | | catch (Exception e) |
| | 983 | | { |
| 0 | 984 | | scope.Failed(e); |
| 0 | 985 | | throw; |
| | 986 | | } |
| 0 | 987 | | } |
| | 988 | |
|
| 2 | 989 | | return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); |
| | 990 | | } |
| | 991 | |
|
| | 992 | | /// <summary> |
| | 993 | | /// Gets the list of models by iterating through a collection synchronously. |
| | 994 | | /// </summary> |
| | 995 | | /// <param name="dependenciesFor">The model Ids to have dependencies retrieved.</param> |
| | 996 | | /// <param name="includeModelDefinition">Whether to include the model definition in the result. If false, only t |
| | 997 | | /// <param name="options">The options to follow when listing the models. For example, the page size hint can be |
| | 998 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 999 | | /// <returns>The pageable list <see cref="Pageable{T}"/> of application/json models and the http response.</retu |
| | 1000 | | /// <remarks> |
| | 1001 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1002 | | /// </remarks> |
| | 1003 | | /// <exception cref="RequestFailedException"> |
| | 1004 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1005 | | /// </exception> |
| | 1006 | | /// <seealso cref="GetModelsAsync(IEnumerable{string}, bool, GetModelsOptions, CancellationToken)"> |
| | 1007 | | /// See the asynchronous version of this method for examples. |
| | 1008 | | /// </seealso> |
| | 1009 | | public virtual Pageable<ModelData> GetModels(IEnumerable<string> dependenciesFor = default, bool includeModelDef |
| | 1010 | | { |
| | 1011 | | Page<ModelData> FirstPageFunc(int? pageSizeHint) |
| | 1012 | | { |
| 2 | 1013 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope("DigitalTwinModelsClient.List"); |
| 2 | 1014 | | scope.Start(); |
| | 1015 | | try |
| | 1016 | | { |
| 2 | 1017 | | Response<PagedModelDataCollection> response = _dtModelsRestClient.List(dependenciesFor, includeModel |
| 2 | 1018 | | return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); |
| | 1019 | | } |
| 0 | 1020 | | catch (Exception e) |
| | 1021 | | { |
| 0 | 1022 | | scope.Failed(e); |
| 0 | 1023 | | throw; |
| | 1024 | | } |
| 2 | 1025 | | } |
| | 1026 | |
|
| | 1027 | | Page<ModelData> NextPageFunc(string nextLink, int? pageSizeHint) |
| | 1028 | | { |
| 0 | 1029 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope("DigitalTwinModelsClient.List"); |
| 0 | 1030 | | scope.Start(); |
| | 1031 | | try |
| | 1032 | | { |
| 0 | 1033 | | Response<PagedModelDataCollection> response = _dtModelsRestClient.ListNextPage(nextLink, dependencie |
| 0 | 1034 | | return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); |
| | 1035 | | } |
| 0 | 1036 | | catch (Exception e) |
| | 1037 | | { |
| 0 | 1038 | | scope.Failed(e); |
| 0 | 1039 | | throw; |
| | 1040 | | } |
| 0 | 1041 | | } |
| | 1042 | |
|
| 2 | 1043 | | return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); |
| | 1044 | | } |
| | 1045 | |
|
| | 1046 | | /// <summary> |
| | 1047 | | /// Gets a model, including the model metadata and the model definition asynchronously. |
| | 1048 | | /// </summary> |
| | 1049 | | /// <param name="modelId">The Id of the model.</param> |
| | 1050 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 1051 | | /// <returns>The application/json model and the http response <see cref="Response{T}"/>.</returns> |
| | 1052 | | /// <remarks> |
| | 1053 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1054 | | /// </remarks> |
| | 1055 | | /// <exception cref="RequestFailedException"> |
| | 1056 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1057 | | /// </exception> |
| | 1058 | | /// <exception cref="ArgumentNullException"> |
| | 1059 | | /// The exception is thrown when <paramref name="modelId"/> is <c>null</c>. |
| | 1060 | | /// </exception> |
| | 1061 | | /// <example> |
| | 1062 | | /// <code snippet="Snippet:DigitalTwinsSampleGetModel"> |
| | 1063 | | /// Response<ModelData> sampleModelResponse = await client.GetModelAsync(sampleModelId); |
| | 1064 | | /// Console.WriteLine($"Retrieved model '{sampleModelResponse.Value.Id}'."); |
| | 1065 | | /// </code> |
| | 1066 | | /// </example> |
| | 1067 | | public virtual Task<Response<ModelData>> GetModelAsync(string modelId, CancellationToken cancellationToken = def |
| | 1068 | | { |
| | 1069 | | // The GetModel API will include the model definition in its response by default. |
| 48 | 1070 | | return _dtModelsRestClient.GetByIdAsync(modelId, IncludeModelDefinition, cancellationToken); |
| | 1071 | | } |
| | 1072 | |
|
| | 1073 | | /// <summary> |
| | 1074 | | /// Gets a model, including the model metadata and the model definition synchronously. |
| | 1075 | | /// </summary> |
| | 1076 | | /// <param name="modelId">The Id of the model.</param> |
| | 1077 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 1078 | | /// <returns>The application/json model and the http response <see cref="Response{T}"/>.</returns> |
| | 1079 | | /// <remarks> |
| | 1080 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1081 | | /// </remarks> |
| | 1082 | | /// <exception cref="RequestFailedException"> |
| | 1083 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1084 | | /// </exception> |
| | 1085 | | /// <exception cref="ArgumentNullException"> |
| | 1086 | | /// The exception is thrown when <paramref name="modelId"/> is <c>null</c>. |
| | 1087 | | /// </exception> |
| | 1088 | | /// <seealso cref="GetModelAsync(string, CancellationToken)"> |
| | 1089 | | /// See the asynchronous version of this method for examples. |
| | 1090 | | /// </seealso> |
| | 1091 | | public virtual Response<ModelData> GetModel(string modelId, CancellationToken cancellationToken = default) |
| | 1092 | | { |
| | 1093 | | // The GetModel API will include the model definition in its response by default. |
| 48 | 1094 | | return _dtModelsRestClient.GetById(modelId, IncludeModelDefinition, cancellationToken); |
| | 1095 | | } |
| | 1096 | |
|
| | 1097 | | /// <summary> |
| | 1098 | | /// Decommissions a model asynchronously. |
| | 1099 | | /// </summary> |
| | 1100 | | /// <param name="modelId">The Id of the model to decommission.</param> |
| | 1101 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 1102 | | /// <returns>The http response <see cref="Response"/>.</returns> |
| | 1103 | | /// <remarks> |
| | 1104 | | /// <para> |
| | 1105 | | /// When a model is decomissioned, new digital twins will no longer be able to be defined by this model. |
| | 1106 | | /// However, existing digital twins may continue to use this model. |
| | 1107 | | /// Once a model is decomissioned, it may not be recommissioned. |
| | 1108 | | /// </para> |
| | 1109 | | /// <para> |
| | 1110 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1111 | | /// </para> |
| | 1112 | | /// </remarks> |
| | 1113 | | /// <exception cref="RequestFailedException"> |
| | 1114 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1115 | | /// </exception> |
| | 1116 | | /// <exception cref="ArgumentNullException"> |
| | 1117 | | /// The exception is thrown when <paramref name="modelId"/> is <c>null</c>. |
| | 1118 | | /// </exception> |
| | 1119 | | /// <example> |
| | 1120 | | /// <code snippet="Snippet:DigitalTwinsSampleDecommisionModel"> |
| | 1121 | | /// try |
| | 1122 | | /// { |
| | 1123 | | /// await client.DecommissionModelAsync(sampleModelId); |
| | 1124 | | /// Console.WriteLine($"Decommissioned model '{sampleModelId}'."); |
| | 1125 | | /// } |
| | 1126 | | /// catch (RequestFailedException ex) |
| | 1127 | | /// { |
| | 1128 | | /// FatalError($"Failed to decommision model '{sampleModelId}' due to:\n{ex}"); |
| | 1129 | | /// } |
| | 1130 | | /// </code> |
| | 1131 | | /// </example> |
| | 1132 | | public virtual Task<Response> DecommissionModelAsync(string modelId, CancellationToken cancellationToken = defau |
| | 1133 | | { |
| 2 | 1134 | | return _dtModelsRestClient.UpdateAsync(modelId, ModelsConstants.DecommissionModelOperationList, cancellation |
| | 1135 | | } |
| | 1136 | |
|
| | 1137 | | /// <summary> |
| | 1138 | | /// Decommissions a model synchronously. |
| | 1139 | | /// </summary> |
| | 1140 | | /// <param name="modelId">The Id of the model to decommission.</param> |
| | 1141 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 1142 | | /// <returns>The http response <see cref="Response"/>.</returns> |
| | 1143 | | /// <remarks> |
| | 1144 | | /// <para> |
| | 1145 | | /// When a model is decomissioned, new digital twins will no longer be able to be defined by this model. |
| | 1146 | | /// However, existing digital twins may continue to use this model. |
| | 1147 | | /// Once a model is decomissioned, it may not be recommissioned. |
| | 1148 | | /// </para> |
| | 1149 | | /// <para> |
| | 1150 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1151 | | /// </para> |
| | 1152 | | /// </remarks> |
| | 1153 | | /// <exception cref="RequestFailedException"> |
| | 1154 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1155 | | /// </exception> |
| | 1156 | | /// <exception cref="ArgumentNullException"> |
| | 1157 | | /// The exception is thrown when <paramref name="modelId"/> is <c>null</c>. |
| | 1158 | | /// </exception> |
| | 1159 | | /// <seealso cref="DecommissionModelAsync(string, CancellationToken)"> |
| | 1160 | | /// See the asynchronous version of this method for examples. |
| | 1161 | | /// </seealso> |
| | 1162 | | public virtual Response DecommissionModel(string modelId, CancellationToken cancellationToken = default) |
| | 1163 | | { |
| 2 | 1164 | | return _dtModelsRestClient.Update(modelId, ModelsConstants.DecommissionModelOperationList, cancellationToken |
| | 1165 | | } |
| | 1166 | |
|
| | 1167 | | /// <summary> |
| | 1168 | | /// Creates one or many models asynchronously. |
| | 1169 | | /// </summary> |
| | 1170 | | /// <param name="models">The set of models to create. Each string corresponds to exactly one model.</param> |
| | 1171 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 1172 | | /// <returns>The created models and the http response <see cref="Response{T}"/>.</returns> |
| | 1173 | | /// <exception cref="RequestFailedException"> |
| | 1174 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1175 | | /// </exception> |
| | 1176 | | /// <remarks> |
| | 1177 | | /// <para> |
| | 1178 | | /// Bulk model creation is useful when several models have references to each other. |
| | 1179 | | /// It simplifies creation for the client because otherwise the models would have to be created in a very specif |
| | 1180 | | /// The service evaluates all models to ensure all references are satisfied, and then accepts or rejects the set |
| | 1181 | | /// So using this method, model creation is transactional. |
| | 1182 | | /// </para> |
| | 1183 | | /// <para> |
| | 1184 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1185 | | /// </para> |
| | 1186 | | /// </remarks> |
| | 1187 | | /// <example> |
| | 1188 | | /// <code snippet="Snippet:DigitalTwinsSampleCreateModels"> |
| | 1189 | | /// await client.CreateModelsAsync(new[] { newComponentModelPayload, newModelPayload }); |
| | 1190 | | /// Console.WriteLine($"Created models '{componentModelId}' and '{sampleModelId}'." |
| | 1191 | | /// </code> |
| | 1192 | | /// </example> |
| | 1193 | | public virtual async Task<Response<ModelData[]>> CreateModelsAsync(IEnumerable<string> models, CancellationToken |
| | 1194 | | { |
| 18 | 1195 | | Response<IReadOnlyList<ModelData>> response = await _dtModelsRestClient.AddAsync(models, cancellationToken). |
| 16 | 1196 | | return Response.FromValue(response.Value.ToArray(), response.GetRawResponse()); |
| 16 | 1197 | | } |
| | 1198 | |
|
| | 1199 | | /// <summary> |
| | 1200 | | /// Creates one or many models synchronously. |
| | 1201 | | /// </summary> |
| | 1202 | | /// <param name="models">The set of models to create. Each string corresponds to exactly one model.</param> |
| | 1203 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 1204 | | /// <returns>The created models and the http response <see cref="Response{T}"/>.</returns> |
| | 1205 | | /// <remarks> |
| | 1206 | | /// <para> |
| | 1207 | | /// Bulk model creation is useful when several models have references to each other. |
| | 1208 | | /// It simplifies creation for the client because otherwise the models would have to be created in a very specif |
| | 1209 | | /// The service evaluates all models to ensure all references are satisfied, and then accepts or rejects the set |
| | 1210 | | /// So using this method, model creation is transactional. |
| | 1211 | | /// </para> |
| | 1212 | | /// <para> |
| | 1213 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1214 | | /// </para> |
| | 1215 | | /// </remarks> |
| | 1216 | | /// <exception cref="RequestFailedException"> |
| | 1217 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1218 | | /// </exception> |
| | 1219 | | /// <seealso cref="CreateModelsAsync(IEnumerable{string}, CancellationToken)"> |
| | 1220 | | /// See the asynchronous version of this method for examples. |
| | 1221 | | /// </seealso> |
| | 1222 | | public virtual Response<ModelData[]> CreateModels(IEnumerable<string> models, CancellationToken cancellationToke |
| | 1223 | | { |
| 18 | 1224 | | Response<IReadOnlyList<ModelData>> response = _dtModelsRestClient.Add(models, cancellationToken); |
| 16 | 1225 | | return Response.FromValue(response.Value.ToArray(), response.GetRawResponse()); |
| | 1226 | | } |
| | 1227 | |
|
| | 1228 | | /// <summary> |
| | 1229 | | /// Deletes a model asynchronously. |
| | 1230 | | /// </summary> |
| | 1231 | | /// <param name="modelId"> The id for the model. The id is globally unique and case sensitive. </param> |
| | 1232 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 1233 | | /// <returns>The http response <see cref="Response"/>.</returns> |
| | 1234 | | /// <remarks> |
| | 1235 | | /// <para> |
| | 1236 | | /// A model can only be deleted if no other models reference it. |
| | 1237 | | /// Status codes: |
| | 1238 | | /// 204 (No Content): Success. |
| | 1239 | | /// 400 (Bad Request): The request is invalid. |
| | 1240 | | /// 404 (Not Found): There is no model with the provided id. |
| | 1241 | | /// 409 (Conflict): There are dependencies on the model that prevent it from being deleted. |
| | 1242 | | /// </para> |
| | 1243 | | /// <para> |
| | 1244 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1245 | | /// </para> |
| | 1246 | | /// </remarks> |
| | 1247 | | /// <exception cref="RequestFailedException"> |
| | 1248 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1249 | | /// </exception> |
| | 1250 | | /// <exception cref="ArgumentNullException"> |
| | 1251 | | /// The exception is thrown when <paramref name="modelId"/> is <c>null</c>. |
| | 1252 | | /// </exception> |
| | 1253 | | /// <example> |
| | 1254 | | /// <code snippet="Snippet:DigitalTwinsSampleDeleteModel"> |
| | 1255 | | /// try |
| | 1256 | | /// { |
| | 1257 | | /// await client.DeleteModelAsync(sampleModelId); |
| | 1258 | | /// Console.WriteLine($"Deleted model '{sampleModelId}'."); |
| | 1259 | | /// } |
| | 1260 | | /// catch (Exception ex) |
| | 1261 | | /// { |
| | 1262 | | /// FatalError($"Failed to delete model '{sampleModelId}' due to:\n{ex}"); |
| | 1263 | | /// } |
| | 1264 | | /// </code> |
| | 1265 | | /// </example> |
| | 1266 | | public virtual Task<Response> DeleteModelAsync(string modelId, CancellationToken cancellationToken = default) |
| | 1267 | | { |
| 24 | 1268 | | return _dtModelsRestClient.DeleteAsync(modelId, cancellationToken); |
| | 1269 | | } |
| | 1270 | |
|
| | 1271 | | /// <summary> |
| | 1272 | | /// Deletes a model synchronously. |
| | 1273 | | /// </summary> |
| | 1274 | | /// <param name="modelId"> The id for the model. The id is globally unique and case sensitive. </param> |
| | 1275 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 1276 | | /// <returns>The http response <see cref="Response"/>.</returns> |
| | 1277 | | /// <remarks> |
| | 1278 | | /// <para> |
| | 1279 | | /// A model can only be deleted if no other models reference it. |
| | 1280 | | /// Status codes: |
| | 1281 | | /// 204 (No Content): Success. |
| | 1282 | | /// 400 (Bad Request): The request is invalid. |
| | 1283 | | /// 404 (Not Found): There is no model with the provided id. |
| | 1284 | | /// 409 (Conflict): There are dependencies on the model that prevent it from being deleted. |
| | 1285 | | /// </para> |
| | 1286 | | /// <para> |
| | 1287 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1288 | | /// </para> |
| | 1289 | | /// </remarks> |
| | 1290 | | /// <exception cref="RequestFailedException"> |
| | 1291 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1292 | | /// </exception> |
| | 1293 | | /// <exception cref="ArgumentNullException"> |
| | 1294 | | /// The exception is thrown when <paramref name="modelId"/> is <c>null</c>. |
| | 1295 | | /// </exception> |
| | 1296 | | /// <seealso cref="DeleteModelAsync(string, CancellationToken)"> |
| | 1297 | | /// See the asynchronous version of this method for examples. |
| | 1298 | | /// </seealso> |
| | 1299 | | public virtual Response DeleteModel(string modelId, CancellationToken cancellationToken = default) |
| | 1300 | | { |
| 24 | 1301 | | return _dtModelsRestClient.Delete(modelId, cancellationToken); |
| | 1302 | | } |
| | 1303 | |
|
| | 1304 | | /// <summary> |
| | 1305 | | /// Queries for digital twins by iterating through a collection asynchronously. |
| | 1306 | | /// </summary> |
| | 1307 | | /// <param name="query">The query string, in SQL-like syntax.</param> |
| | 1308 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 1309 | | /// <returns>The pageable list <see cref="AsyncPageable{T}"/> of query results.</returns> |
| | 1310 | | /// <remarks> |
| | 1311 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1312 | | /// </remarks> |
| | 1313 | | /// <exception cref="RequestFailedException"> |
| | 1314 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1315 | | /// </exception> |
| | 1316 | | /// <example> |
| | 1317 | | /// <code snippet="Snippet:DigitalTwinsSampleQueryTwins"> |
| | 1318 | | /// // This code snippet demonstrates the simplest way to iterate over the digital twin results, where paging |
| | 1319 | | /// // happens under the covers. |
| | 1320 | | /// AsyncPageable<string> asyncPageableResponse = client.QueryAsync("SELECT * FROM digitaltwins" |
| | 1321 | | /// |
| | 1322 | | /// // Iterate over the twin instances in the pageable response. |
| | 1323 | | /// // The "await" keyword here is required because new pages will be fetched when necessary, |
| | 1324 | | /// // which involves a request to the service. |
| | 1325 | | /// await foreach (string response in asyncPageableResponse) |
| | 1326 | | /// { |
| | 1327 | | /// BasicDigitalTwin twin = JsonSerializer.Deserialize<BasicDigitalTwin>(response); |
| | 1328 | | /// Console.WriteLine($"Found digital twin '{twin.Id}'"); |
| | 1329 | | /// } |
| | 1330 | | /// </code> |
| | 1331 | | /// </example> |
| | 1332 | | public virtual AsyncPageable<string> QueryAsync(string query, CancellationToken cancellationToken = default) |
| | 1333 | | { |
| | 1334 | | // Note: pageSizeHint is not supported as a parameter in the service for query API, so ignoring it. |
| | 1335 | | // Cannot remove the parameter as the function signature in Azure.Core helper needs it. |
| | 1336 | | async Task<Page<string>> FirstPageFunc(int? pageSizeHint) |
| | 1337 | | { |
| 2 | 1338 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DigitalTwinsClient)}.{nameof(Quer |
| 2 | 1339 | | scope.Start(); |
| | 1340 | | try |
| | 1341 | | { |
| 2 | 1342 | | var querySpecification = new QuerySpecification |
| 2 | 1343 | | { |
| 2 | 1344 | | Query = query |
| 2 | 1345 | | }; |
| 2 | 1346 | | Response<QueryResult> response = await _queryClient.QueryTwinsAsync(querySpecification, cancellation |
| 2 | 1347 | | return Page.FromValues(response.Value.Items, response.Value.ContinuationToken, response.GetRawRespon |
| | 1348 | | } |
| 0 | 1349 | | catch (Exception ex) |
| | 1350 | | { |
| 0 | 1351 | | scope.Failed(ex); |
| 0 | 1352 | | throw; |
| | 1353 | | } |
| 2 | 1354 | | } |
| | 1355 | |
|
| | 1356 | | async Task<Page<string>> NextPageFunc(string nextLink, int? pageSizeHint) |
| | 1357 | | { |
| 0 | 1358 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DigitalTwinsClient)}.{nameof(Quer |
| 0 | 1359 | | scope.Start(); |
| | 1360 | | try |
| | 1361 | | { |
| 0 | 1362 | | var querySpecification = new QuerySpecification |
| 0 | 1363 | | { |
| 0 | 1364 | | ContinuationToken = nextLink |
| 0 | 1365 | | }; |
| 0 | 1366 | | Response<QueryResult> response = await _queryClient.QueryTwinsAsync(querySpecification, cancellation |
| 0 | 1367 | | return Page.FromValues(response.Value.Items, response.Value.ContinuationToken, response.GetRawRespon |
| | 1368 | | } |
| 0 | 1369 | | catch (Exception ex) |
| | 1370 | | { |
| 0 | 1371 | | scope.Failed(ex); |
| 0 | 1372 | | throw; |
| | 1373 | | } |
| 0 | 1374 | | } |
| | 1375 | |
|
| 2 | 1376 | | return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); |
| | 1377 | | } |
| | 1378 | |
|
| | 1379 | | /// <summary> |
| | 1380 | | /// Queries for digital twins by iterating through a collection synchronously. |
| | 1381 | | /// </summary> |
| | 1382 | | /// <param name="query">The query string, in SQL-like syntax.</param> |
| | 1383 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 1384 | | /// <returns>The pageable list <see cref="Pageable{T}"/> of query results.</returns> |
| | 1385 | | /// <remarks> |
| | 1386 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1387 | | /// </remarks> |
| | 1388 | | /// <exception cref="RequestFailedException"> |
| | 1389 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1390 | | /// </exception> |
| | 1391 | | /// <example> |
| | 1392 | | /// A basic query for all digital twins: SELECT * FROM digitalTwins. |
| | 1393 | | /// </example> |
| | 1394 | | /// <seealso cref="QueryAsync(string, CancellationToken)"> |
| | 1395 | | /// See the asynchronous version of this method for examples. |
| | 1396 | | /// </seealso> |
| | 1397 | | public virtual Pageable<string> Query(string query, CancellationToken cancellationToken = default) |
| | 1398 | | { |
| | 1399 | | // Note: pageSizeHint is not supported as a parameter in the service for query API, so ignoring it. |
| | 1400 | | // Cannot remove the parameter as the function signature in Azure.Core helper needs it. |
| | 1401 | | Page<string> FirstPageFunc(int? pageSizeHint) |
| | 1402 | | { |
| 2 | 1403 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DigitalTwinsClient)}.{nameof(Quer |
| 2 | 1404 | | scope.Start(); |
| | 1405 | | try |
| | 1406 | | { |
| 2 | 1407 | | var querySpecification = new QuerySpecification |
| 2 | 1408 | | { |
| 2 | 1409 | | Query = query |
| 2 | 1410 | | }; |
| 2 | 1411 | | Response<QueryResult> response = _queryClient.QueryTwins(querySpecification, cancellationToken); |
| 2 | 1412 | | return Page.FromValues(response.Value.Items, response.Value.ContinuationToken, response.GetRawRespon |
| | 1413 | | } |
| 0 | 1414 | | catch (Exception ex) |
| | 1415 | | { |
| 0 | 1416 | | scope.Failed(ex); |
| 0 | 1417 | | throw; |
| | 1418 | | } |
| 2 | 1419 | | } |
| | 1420 | |
|
| | 1421 | | Page<string> NextPageFunc(string nextLink, int? pageSizeHint) |
| | 1422 | | { |
| 0 | 1423 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DigitalTwinsClient)}.{nameof(Quer |
| 0 | 1424 | | scope.Start(); |
| | 1425 | | try |
| | 1426 | | { |
| 0 | 1427 | | var querySpecification = new QuerySpecification |
| 0 | 1428 | | { |
| 0 | 1429 | | ContinuationToken = nextLink |
| 0 | 1430 | | }; |
| 0 | 1431 | | Response<QueryResult> response = _queryClient.QueryTwins(querySpecification, cancellationToken); |
| 0 | 1432 | | return Page.FromValues(response.Value.Items, response.Value.ContinuationToken, response.GetRawRespon |
| | 1433 | | } |
| 0 | 1434 | | catch (Exception ex) |
| | 1435 | | { |
| 0 | 1436 | | scope.Failed(ex); |
| 0 | 1437 | | throw; |
| | 1438 | | } |
| 0 | 1439 | | } |
| | 1440 | |
|
| 2 | 1441 | | return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); |
| | 1442 | | } |
| | 1443 | |
|
| | 1444 | | /// <summary>. |
| | 1445 | | /// Lists the event routes in a digital twins instance by iterating through a collection asynchronously. |
| | 1446 | | /// </summary> |
| | 1447 | | /// <param name="options">The options to use when listing the event routes. One can set the maximum number of it |
| | 1448 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 1449 | | /// <returns>The pageable list <see cref="AsyncPageable{T}"/> of application/json event routes and the http resp |
| | 1450 | | /// <remarks> |
| | 1451 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1452 | | /// </remarks> |
| | 1453 | | /// <exception cref="RequestFailedException"> |
| | 1454 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1455 | | /// </exception> |
| | 1456 | | /// <example> |
| | 1457 | | /// <code snippet="Snippet:DigitalTwinsSampleGetEventRoutes"> |
| | 1458 | | /// AsyncPageable<EventRoute> response = client.GetEventRoutesAsync(); |
| | 1459 | | /// await foreach (EventRoute er in response) |
| | 1460 | | /// { |
| | 1461 | | /// Console.WriteLine($"Event route '{er.Id}', endpoint name '{er.EndpointName}'&qu |
| | 1462 | | /// } |
| | 1463 | | /// </code> |
| | 1464 | | /// </example> |
| | 1465 | | public virtual AsyncPageable<EventRoute> GetEventRoutesAsync(EventRoutesListOptions options = default, Cancellat |
| | 1466 | | { |
| | 1467 | | async Task<Page<EventRoute>> FirstPageFunc(int? pageSizeHint) |
| | 1468 | | { |
| 2 | 1469 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope("EventRoutesClient.List"); |
| 2 | 1470 | | scope.Start(); |
| | 1471 | | try |
| | 1472 | | { |
| 2 | 1473 | | Response<EventRouteCollection> response = await _eventRoutesRestClient.ListAsync(options, cancellati |
| 2 | 1474 | | return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); |
| | 1475 | | } |
| 0 | 1476 | | catch (Exception e) |
| | 1477 | | { |
| 0 | 1478 | | scope.Failed(e); |
| 0 | 1479 | | throw; |
| | 1480 | | } |
| 2 | 1481 | | } |
| | 1482 | |
|
| | 1483 | | async Task<Page<EventRoute>> NextPageFunc(string nextLink, int? pageSizeHint) |
| | 1484 | | { |
| 0 | 1485 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope("EventRoutesClient.List"); |
| 0 | 1486 | | scope.Start(); |
| | 1487 | | try |
| | 1488 | | { |
| 0 | 1489 | | Response<EventRouteCollection> response = await _eventRoutesRestClient.ListNextPageAsync(nextLink, o |
| 0 | 1490 | | return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); |
| | 1491 | | } |
| 0 | 1492 | | catch (Exception e) |
| | 1493 | | { |
| 0 | 1494 | | scope.Failed(e); |
| 0 | 1495 | | throw; |
| | 1496 | | } |
| 0 | 1497 | | } |
| | 1498 | |
|
| 2 | 1499 | | return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); |
| | 1500 | | } |
| | 1501 | |
|
| | 1502 | | /// <summary>. |
| | 1503 | | /// Lists the event routes in a digital twins instance by iterating through a collection synchronously. |
| | 1504 | | /// </summary> |
| | 1505 | | /// <param name="options">The options to use when listing the event routes. One can set the maximum number of it |
| | 1506 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 1507 | | /// <returns>The pageable list <see cref="Pageable{T}"/> of application/json event routes and the http response. |
| | 1508 | | /// <remarks> |
| | 1509 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1510 | | /// </remarks> |
| | 1511 | | /// <exception cref="RequestFailedException"> |
| | 1512 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1513 | | /// </exception> |
| | 1514 | | /// <seealso cref="GetEventRoutesAsync(EventRoutesListOptions, CancellationToken)"> |
| | 1515 | | /// See the asynchronous version of this method for examples. |
| | 1516 | | /// </seealso> |
| | 1517 | | public virtual Pageable<EventRoute> GetEventRoutes(EventRoutesListOptions options = default, CancellationToken c |
| | 1518 | | { |
| | 1519 | | Page<EventRoute> FirstPageFunc(int? pageSizeHint) |
| | 1520 | | { |
| 2 | 1521 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope("EventRoutesClient.List"); |
| 2 | 1522 | | scope.Start(); |
| | 1523 | | try |
| | 1524 | | { |
| 2 | 1525 | | Response<EventRouteCollection> response = _eventRoutesRestClient.List(options, cancellationToken); |
| 2 | 1526 | | return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); |
| | 1527 | | } |
| 0 | 1528 | | catch (Exception e) |
| | 1529 | | { |
| 0 | 1530 | | scope.Failed(e); |
| 0 | 1531 | | throw; |
| | 1532 | | } |
| 2 | 1533 | | } |
| | 1534 | |
|
| | 1535 | | Page<EventRoute> NextPageFunc(string nextLink, int? pageSizeHint) |
| | 1536 | | { |
| 0 | 1537 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope("EventRoutesClient.List"); |
| 0 | 1538 | | scope.Start(); |
| | 1539 | | try |
| | 1540 | | { |
| 0 | 1541 | | Response<EventRouteCollection> response = _eventRoutesRestClient.ListNextPage(nextLink, options, can |
| 0 | 1542 | | return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); |
| | 1543 | | } |
| 0 | 1544 | | catch (Exception e) |
| | 1545 | | { |
| 0 | 1546 | | scope.Failed(e); |
| 0 | 1547 | | throw; |
| | 1548 | | } |
| 0 | 1549 | | } |
| | 1550 | |
|
| 2 | 1551 | | return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); |
| | 1552 | | } |
| | 1553 | |
|
| | 1554 | | /// <summary> |
| | 1555 | | /// Gets an event route by Id asynchronously. |
| | 1556 | | /// </summary> |
| | 1557 | | /// <param name="eventRouteId">The Id of the event route.</param> |
| | 1558 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 1559 | | /// <returns>The application/json event routes and the http response <see cref="Response{T}"/>.</returns> |
| | 1560 | | /// <remarks> |
| | 1561 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1562 | | /// </remarks> |
| | 1563 | | /// <exception cref="RequestFailedException"> |
| | 1564 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1565 | | /// </exception> |
| | 1566 | | /// <exception cref="ArgumentNullException"> |
| | 1567 | | /// The exception is thrown when <paramref name="eventRouteId"/> is <c>null</c>. |
| | 1568 | | /// </exception> |
| | 1569 | | public virtual Task<Response<EventRoute>> GetEventRouteAsync(string eventRouteId, CancellationToken cancellation |
| | 1570 | | { |
| 6 | 1571 | | return _eventRoutesRestClient.GetByIdAsync(eventRouteId, cancellationToken); |
| | 1572 | | } |
| | 1573 | |
|
| | 1574 | | /// <summary> |
| | 1575 | | /// Gets an event route by Id synchronously. |
| | 1576 | | /// </summary> |
| | 1577 | | /// <param name="eventRouteId">The Id of the event route.</param> |
| | 1578 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 1579 | | /// <returns>The application/json event routes and the http response <see cref="Response{T}"/>.</returns> |
| | 1580 | | /// <remarks> |
| | 1581 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1582 | | /// </remarks> |
| | 1583 | | /// <exception cref="RequestFailedException"> |
| | 1584 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1585 | | /// </exception> |
| | 1586 | | /// <exception cref="ArgumentNullException"> |
| | 1587 | | /// The exception is thrown when <paramref name="eventRouteId"/> is <c>null</c>. |
| | 1588 | | /// </exception> |
| | 1589 | | /// <seealso cref="GetEventRouteAsync(string, CancellationToken)"> |
| | 1590 | | /// See the asynchronous version of this method for examples. |
| | 1591 | | /// </seealso> |
| | 1592 | | public virtual Response<EventRoute> GetEventRoute(string eventRouteId, CancellationToken cancellationToken = def |
| | 1593 | | { |
| 6 | 1594 | | return _eventRoutesRestClient.GetById(eventRouteId, cancellationToken); |
| | 1595 | | } |
| | 1596 | |
|
| | 1597 | | /// <summary> |
| | 1598 | | /// Creates an event route asynchronously. |
| | 1599 | | /// </summary> |
| | 1600 | | /// <param name="eventRouteId">The Id of the event route to create.</param> |
| | 1601 | | /// <param name="eventRoute">The event route data containing the endpoint and optional filter.</param> |
| | 1602 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 1603 | | /// <returns>The http response <see cref="Response"/>.</returns> |
| | 1604 | | /// <remarks> |
| | 1605 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1606 | | /// </remarks> |
| | 1607 | | /// <exception cref="RequestFailedException"> |
| | 1608 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1609 | | /// </exception> |
| | 1610 | | /// <exception cref="ArgumentNullException"> |
| | 1611 | | /// The exception is thrown when <paramref name="eventRouteId"/> is <c>null</c>. |
| | 1612 | | /// </exception> |
| | 1613 | | /// <example> |
| | 1614 | | /// <code snippet="Snippet:DigitalTwinsSampleCreateEventRoute"> |
| | 1615 | | /// string eventFilter = "$eventType = 'DigitalTwinTelemetryMessages' or $eventType = 'Digit |
| | 1616 | | /// var eventRoute = new EventRoute(eventhubEndpointName) |
| | 1617 | | /// { |
| | 1618 | | /// Filter = eventFilter |
| | 1619 | | /// }; |
| | 1620 | | /// |
| | 1621 | | /// await client.CreateEventRouteAsync(_eventRouteId, eventRoute); |
| | 1622 | | /// Console.WriteLine($"Created event route '{_eventRouteId}'."); |
| | 1623 | | /// </code> |
| | 1624 | | /// </example> |
| | 1625 | | public virtual Task<Response> CreateEventRouteAsync(string eventRouteId, EventRoute eventRoute, CancellationToke |
| | 1626 | | { |
| 6 | 1627 | | return _eventRoutesRestClient.AddAsync(eventRouteId, eventRoute, cancellationToken); |
| | 1628 | | } |
| | 1629 | |
|
| | 1630 | | /// <summary> |
| | 1631 | | /// Creates an event route synchronously. |
| | 1632 | | /// </summary> |
| | 1633 | | /// <param name="eventRouteId">The Id of the event route to create.</param> |
| | 1634 | | /// <param name="eventRoute">The event route data containing the endpoint and optional filter.</param> |
| | 1635 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 1636 | | /// <returns>The http response <see cref="Response"/>.</returns> |
| | 1637 | | /// <remarks> |
| | 1638 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1639 | | /// </remarks> |
| | 1640 | | /// <exception cref="RequestFailedException"> |
| | 1641 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1642 | | /// </exception> |
| | 1643 | | /// <exception cref="ArgumentNullException"> |
| | 1644 | | /// The exception is thrown when <paramref name="eventRouteId"/> is <c>null</c>. |
| | 1645 | | /// </exception> |
| | 1646 | | /// <seealso cref="CreateEventRouteAsync(string, EventRoute, CancellationToken)"> |
| | 1647 | | /// See the asynchronous version of this method for examples. |
| | 1648 | | /// </seealso> |
| | 1649 | | public virtual Response CreateEventRoute(string eventRouteId, EventRoute eventRoute, CancellationToken cancellat |
| | 1650 | | { |
| 6 | 1651 | | return _eventRoutesRestClient.Add(eventRouteId, eventRoute, cancellationToken); |
| | 1652 | | } |
| | 1653 | |
|
| | 1654 | | /// <summary> |
| | 1655 | | /// Deletes an event route asynchronously. |
| | 1656 | | /// </summary> |
| | 1657 | | /// <param name="eventRouteId">The Id of the event route to delete.</param> |
| | 1658 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 1659 | | /// <returns>The http response <see cref="Response"/>.</returns> |
| | 1660 | | /// <remarks> |
| | 1661 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1662 | | /// </remarks> |
| | 1663 | | /// <exception cref="RequestFailedException"> |
| | 1664 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1665 | | /// </exception> |
| | 1666 | | /// <exception cref="ArgumentNullException"> |
| | 1667 | | /// The exception is thrown when <paramref name="eventRouteId"/> is <c>null</c>. |
| | 1668 | | /// </exception> |
| | 1669 | | /// <example> |
| | 1670 | | /// <code snippet="Snippet:DigitalTwinsSampleDeleteEventRoute"> |
| | 1671 | | /// await client.DeleteEventRouteAsync(_eventRouteId); |
| | 1672 | | /// Console.WriteLine($"Deleted event route '{_eventRouteId}'."); |
| | 1673 | | /// </code> |
| | 1674 | | /// </example> |
| | 1675 | | public virtual Task<Response> DeleteEventRouteAsync(string eventRouteId, CancellationToken cancellationToken = d |
| | 1676 | | { |
| 4 | 1677 | | return _eventRoutesRestClient.DeleteAsync(eventRouteId, cancellationToken); |
| | 1678 | | } |
| | 1679 | |
|
| | 1680 | | /// <summary> |
| | 1681 | | /// Deletes an event route synchronously. |
| | 1682 | | /// </summary> |
| | 1683 | | /// <param name="eventRouteId">The Id of the event route to delete.</param> |
| | 1684 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 1685 | | /// <returns>The http response <see cref="Response"/>.</returns> |
| | 1686 | | /// <remarks> |
| | 1687 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1688 | | /// </remarks> |
| | 1689 | | /// <exception cref="RequestFailedException"> |
| | 1690 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1691 | | /// </exception> |
| | 1692 | | /// <exception cref="ArgumentNullException"> |
| | 1693 | | /// The exception is thrown when <paramref name="eventRouteId"/> is <c>null</c>. |
| | 1694 | | /// </exception> |
| | 1695 | | /// <seealso cref="DeleteEventRouteAsync(string, CancellationToken)"> |
| | 1696 | | /// See the asynchronous version of this method for examples. |
| | 1697 | | /// </seealso> |
| | 1698 | | public virtual Response DeleteEventRoute(string eventRouteId, CancellationToken cancellationToken = default) |
| | 1699 | | { |
| 4 | 1700 | | return _eventRoutesRestClient.Delete(eventRouteId, cancellationToken); |
| | 1701 | | } |
| | 1702 | |
|
| | 1703 | | /// <summary> |
| | 1704 | | /// Publishes telemetry from a digital twin asynchronously. |
| | 1705 | | /// The result is then consumed by one or many destination endpoints (subscribers) defined under <see cref="Even |
| | 1706 | | /// These event routes need to be set before publishing a telemetry message, in order for the telemetry message |
| | 1707 | | /// </summary> |
| | 1708 | | /// <param name="digitalTwinId">The Id of the digital twin.</param> |
| | 1709 | | /// <param name="payload">The application/json telemetry payload to be sent.</param> |
| | 1710 | | /// <param name="options">The additional information to be used when processing a telemetry request.</param> |
| | 1711 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 1712 | | /// <returns>The http response <see cref="Response"/>.</returns> |
| | 1713 | | /// <remarks> |
| | 1714 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1715 | | /// </remarks> |
| | 1716 | | /// <exception cref="RequestFailedException"> |
| | 1717 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1718 | | /// </exception> |
| | 1719 | | /// <exception cref="ArgumentNullException"> |
| | 1720 | | /// The exception is thrown when <paramref name="digitalTwinId"/> or <paramref name="payload"/> is <c>null</c>. |
| | 1721 | | /// </exception> |
| | 1722 | | /// <example> |
| | 1723 | | /// <code snippet="Snippet:DigitalTwinsSamplePublishTelemetry"> |
| | 1724 | | /// // construct your json telemetry payload by hand. |
| | 1725 | | /// await client.PublishTelemetryAsync(twinId, "{\"Telemetry1\": 5}"); |
| | 1726 | | /// Console.WriteLine($"Published telemetry message to twin '{twinId}'."); |
| | 1727 | | /// </code> |
| | 1728 | | /// </example> |
| | 1729 | | public virtual Task<Response> PublishTelemetryAsync(string digitalTwinId, string payload, TelemetryOptions optio |
| | 1730 | | { |
| 2 | 1731 | | TelemetryOptions telemetryOptions = options ?? new TelemetryOptions(); |
| 2 | 1732 | | var dateTimeInString = TypeFormatters.ToString(telemetryOptions.TimeStamp, DateTimeOffsetFormat); |
| | 1733 | |
|
| 2 | 1734 | | return _dtRestClient |
| 2 | 1735 | | .SendTelemetryAsync(digitalTwinId, telemetryOptions.MessageId, payload, dateTimeInString, cancellationTo |
| | 1736 | | } |
| | 1737 | |
|
| | 1738 | | /// <summary> |
| | 1739 | | /// Publishes telemetry from a digital twin synchronously. |
| | 1740 | | /// The result is then consumed by one or many destination endpoints (subscribers) defined under <see cref="Even |
| | 1741 | | /// These event routes need to be set before publishing a telemetry message, in order for the telemetry message |
| | 1742 | | /// </summary> |
| | 1743 | | /// <param name="digitalTwinId">The Id of the digital twin.</param> |
| | 1744 | | /// <param name="payload">The application/json telemetry payload to be sent.</param> |
| | 1745 | | /// <param name="options">The additional information to be used when processing a telemetry request.</param> |
| | 1746 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 1747 | | /// <returns>The http response <see cref="Response"/>.</returns> |
| | 1748 | | /// <remarks> |
| | 1749 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1750 | | /// </remarks> |
| | 1751 | | /// <exception cref="RequestFailedException"> |
| | 1752 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1753 | | /// </exception> |
| | 1754 | | /// <exception cref="ArgumentNullException"> |
| | 1755 | | /// The exception is thrown when <paramref name="digitalTwinId"/> or <paramref name="payload"/> is <c>null</c>. |
| | 1756 | | /// </exception> |
| | 1757 | | /// <seealso cref="PublishTelemetryAsync(string, string, TelemetryOptions, CancellationToken)"> |
| | 1758 | | /// See the asynchronous version of this method for examples. |
| | 1759 | | /// </seealso> |
| | 1760 | | public virtual Response PublishTelemetry(string digitalTwinId, string payload, TelemetryOptions options = defaul |
| | 1761 | | { |
| 2 | 1762 | | TelemetryOptions telemetryOptions = options ?? new TelemetryOptions(); |
| 2 | 1763 | | var dateTimeInString = TypeFormatters.ToString(telemetryOptions.TimeStamp, DateTimeOffsetFormat); |
| | 1764 | |
|
| 2 | 1765 | | return _dtRestClient.SendTelemetry(digitalTwinId, telemetryOptions.MessageId, payload, dateTimeInString, can |
| | 1766 | | } |
| | 1767 | |
|
| | 1768 | | /// <summary> |
| | 1769 | | /// Publishes telemetry from a digital twin's component asynchronously. |
| | 1770 | | /// The result is then consumed by one or many destination endpoints (subscribers) defined under <see cref="Even |
| | 1771 | | /// These event routes need to be set before publishing a telemetry message, in order for the telemetry message |
| | 1772 | | /// </summary> |
| | 1773 | | /// <param name="digitalTwinId">The Id of the digital twin.</param> |
| | 1774 | | /// <param name="componentName">The name of the DTDL component.</param> |
| | 1775 | | /// <param name="payload">The application/json telemetry payload to be sent.</param> |
| | 1776 | | /// <param name="options">The additional information to be used when processing a telemetry request.</param> |
| | 1777 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 1778 | | /// <returns>The http response <see cref="Response"/>.</returns> |
| | 1779 | | /// <remarks> |
| | 1780 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1781 | | /// </remarks> |
| | 1782 | | /// <exception cref="RequestFailedException"> |
| | 1783 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1784 | | /// </exception> |
| | 1785 | | /// <exception cref="ArgumentNullException"> |
| | 1786 | | /// The exception is thrown when <paramref name="digitalTwinId"/> or <paramref name="componentName"/> or <paramr |
| | 1787 | | /// </exception> |
| | 1788 | | /// <example> |
| | 1789 | | /// <code snippet="Snippet:DigitalTwinsSamplePublishComponentTelemetry"> |
| | 1790 | | /// // construct your json telemetry payload by serializing a dictionary. |
| | 1791 | | /// var telemetryPayload = new Dictionary<string, int> |
| | 1792 | | /// { |
| | 1793 | | /// { "ComponentTelemetry1", 9 } |
| | 1794 | | /// }; |
| | 1795 | | /// await client.PublishComponentTelemetryAsync( |
| | 1796 | | /// twinId, |
| | 1797 | | /// "Component1", |
| | 1798 | | /// JsonSerializer.Serialize(telemetryPayload)); |
| | 1799 | | /// Console.WriteLine($"Published component telemetry message to twin '{twinId}'."); |
| | 1800 | | /// </code> |
| | 1801 | | /// </example> |
| | 1802 | | public virtual Task<Response> PublishComponentTelemetryAsync(string digitalTwinId, string componentName, string |
| | 1803 | | { |
| 2 | 1804 | | TelemetryOptions telemetryOptions = options ?? new TelemetryOptions(); |
| 2 | 1805 | | var dateTimeInString = TypeFormatters.ToString(telemetryOptions.TimeStamp, DateTimeOffsetFormat); |
| | 1806 | |
|
| 2 | 1807 | | return _dtRestClient |
| 2 | 1808 | | .SendComponentTelemetryAsync(digitalTwinId, componentName, telemetryOptions.MessageId, payload, dateTime |
| | 1809 | | } |
| | 1810 | |
|
| | 1811 | | /// <summary> |
| | 1812 | | /// Publishes telemetry from a digital twin's component synchronously. |
| | 1813 | | /// The result is then consumed by one or many destination endpoints (subscribers) defined under <see cref="Even |
| | 1814 | | /// These event routes need to be set before publishing a telemetry message, in order for the telemetry message |
| | 1815 | | /// </summary> |
| | 1816 | | /// <param name="digitalTwinId">The Id of the digital twin.</param> |
| | 1817 | | /// <param name="componentName">The name of the DTDL component.</param> |
| | 1818 | | /// <param name="payload">The application/json telemetry payload to be sent.</param> |
| | 1819 | | /// <param name="options">The additional information to be used when processing a telemetry request.</param> |
| | 1820 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | 1821 | | /// <returns>The http response <see cref="Response"/>.</returns> |
| | 1822 | | /// <remarks> |
| | 1823 | | /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azu |
| | 1824 | | /// </remarks> |
| | 1825 | | /// <exception cref="RequestFailedException"> |
| | 1826 | | /// The exception that captures the errors from the service. Check the <see cref="RequestFailedException.ErrorCo |
| | 1827 | | /// </exception> |
| | 1828 | | /// <exception cref="ArgumentNullException"> |
| | 1829 | | /// The exception is thrown when <paramref name="digitalTwinId"/> or <paramref name="componentName"/> or <paramr |
| | 1830 | | /// </exception> |
| | 1831 | | /// <seealso cref="PublishComponentTelemetryAsync(string, string, string, TelemetryOptions, CancellationToken)"> |
| | 1832 | | /// See the asynchronous version of this method for examples. |
| | 1833 | | /// </seealso> |
| | 1834 | | public virtual Response PublishComponentTelemetry(string digitalTwinId, string componentName, string payload, Te |
| | 1835 | | { |
| 2 | 1836 | | TelemetryOptions telemetryOptions = options ?? new TelemetryOptions(); |
| 2 | 1837 | | var dateTimeInString = TypeFormatters.ToString(telemetryOptions.TimeStamp, DateTimeOffsetFormat); |
| | 1838 | |
|
| 2 | 1839 | | return _dtRestClient.SendComponentTelemetry(digitalTwinId, componentName, telemetryOptions.MessageId, payloa |
| | 1840 | | } |
| | 1841 | |
|
| | 1842 | | /// <summary> |
| | 1843 | | /// Gets the scope for authentication/authorization policy. |
| | 1844 | | /// </summary> |
| | 1845 | | /// <param name="endpoint">Azure digital twins instance Uri.</param> |
| | 1846 | | /// <returns>List of scopes for the specified endpoint.</returns> |
| | 1847 | | internal static string[] GetAuthorizationScopes(Uri endpoint) |
| | 1848 | | { |
| 68 | 1849 | | Argument.AssertNotNull(endpoint, nameof(endpoint)); |
| 66 | 1850 | | Argument.AssertNotNullOrEmpty(endpoint.AbsoluteUri, nameof(endpoint.AbsoluteUri)); |
| | 1851 | |
|
| | 1852 | | // Uri representation for azure digital twin app Id "0b07f429-9f4b-4714-9392-cc5e8e80c8b0" in the public clo |
| | 1853 | | const string adtPublicCloudAppId = "https://digitaltwins.azure.net"; |
| | 1854 | | const string defaultPermissionConsent = "/.default"; |
| | 1855 | |
|
| | 1856 | | // If the endpoint is in Azure public cloud, the suffix will have "azure.net" or "ppe.net". |
| | 1857 | | // Once ADT becomes available in other clouds, their corresponding scope has to be matched and set. |
| 66 | 1858 | | if (endpoint.AbsoluteUri.IndexOf("azure.net", StringComparison.OrdinalIgnoreCase) > 0 |
| 66 | 1859 | | || endpoint.AbsoluteUri.IndexOf("ppe.net", StringComparison.OrdinalIgnoreCase) > 0) |
| | 1860 | | { |
| 64 | 1861 | | return new[] { adtPublicCloudAppId + defaultPermissionConsent }; |
| | 1862 | | } |
| | 1863 | |
|
| 2 | 1864 | | throw new InvalidOperationException($"Azure digital twins instance endpoint '{endpoint.AbsoluteUri}' is not |
| | 1865 | | } |
| | 1866 | | } |
| | 1867 | | } |