| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | // <auto-generated/> |
| | 5 | |
|
| | 6 | | #nullable disable |
| | 7 | |
|
| | 8 | | using System; |
| | 9 | | using System.Collections.Generic; |
| | 10 | | using System.Text.Json; |
| | 11 | | using System.Threading; |
| | 12 | | using System.Threading.Tasks; |
| | 13 | | using Azure; |
| | 14 | | using Azure.Core; |
| | 15 | | using Azure.Core.Pipeline; |
| | 16 | |
|
| | 17 | | namespace Azure.DigitalTwins.Core |
| | 18 | | { |
| | 19 | | internal partial class DigitalTwinsRestClient |
| | 20 | | { |
| | 21 | | private Uri endpoint; |
| | 22 | | private string apiVersion; |
| | 23 | | private ClientDiagnostics _clientDiagnostics; |
| | 24 | | private HttpPipeline _pipeline; |
| | 25 | |
|
| | 26 | | /// <summary> Initializes a new instance of DigitalTwinsRestClient. </summary> |
| | 27 | | /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param> |
| | 28 | | /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param> |
| | 29 | | /// <param name="endpoint"> server parameter. </param> |
| | 30 | | /// <param name="apiVersion"> Api Version. </param> |
| | 31 | | /// <exception cref="ArgumentNullException"> <paramref name="apiVersion"/> is null. </exception> |
| 30 | 32 | | public DigitalTwinsRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null, s |
| | 33 | | { |
| 30 | 34 | | endpoint ??= new Uri("https://digitaltwins-name.digitaltwins.azure.net"); |
| 30 | 35 | | if (apiVersion == null) |
| | 36 | | { |
| 0 | 37 | | throw new ArgumentNullException(nameof(apiVersion)); |
| | 38 | | } |
| | 39 | |
|
| 30 | 40 | | this.endpoint = endpoint; |
| 30 | 41 | | this.apiVersion = apiVersion; |
| 30 | 42 | | _clientDiagnostics = clientDiagnostics; |
| 30 | 43 | | _pipeline = pipeline; |
| 30 | 44 | | } |
| | 45 | |
|
| | 46 | | internal HttpMessage CreateGetByIdRequest(string id) |
| | 47 | | { |
| 27 | 48 | | var message = _pipeline.CreateMessage(); |
| 27 | 49 | | var request = message.Request; |
| 27 | 50 | | request.Method = RequestMethod.Get; |
| 27 | 51 | | var uri = new RawRequestUriBuilder(); |
| 27 | 52 | | uri.Reset(endpoint); |
| 27 | 53 | | uri.AppendPath("/digitaltwins/", false); |
| 27 | 54 | | uri.AppendPath(id, true); |
| 27 | 55 | | uri.AppendQuery("api-version", apiVersion, true); |
| 27 | 56 | | request.Uri = uri; |
| 27 | 57 | | return message; |
| | 58 | | } |
| | 59 | |
|
| | 60 | | internal HttpMessage CreateDeleteRequest(string id, string ifMatch) |
| | 61 | | { |
| 12 | 62 | | var message = _pipeline.CreateMessage(); |
| 12 | 63 | | var request = message.Request; |
| 12 | 64 | | request.Method = RequestMethod.Delete; |
| 12 | 65 | | var uri = new RawRequestUriBuilder(); |
| 12 | 66 | | uri.Reset(endpoint); |
| 12 | 67 | | uri.AppendPath("/digitaltwins/", false); |
| 12 | 68 | | uri.AppendPath(id, true); |
| 12 | 69 | | uri.AppendQuery("api-version", apiVersion, true); |
| 12 | 70 | | request.Uri = uri; |
| 12 | 71 | | if (ifMatch != null) |
| | 72 | | { |
| 0 | 73 | | request.Headers.Add("If-Match", ifMatch); |
| | 74 | | } |
| 12 | 75 | | return message; |
| | 76 | | } |
| | 77 | |
|
| | 78 | | /// <summary> |
| | 79 | | /// Deletes a digital twin. All relationships referencing the digital twin must already be deleted. |
| | 80 | | /// Status codes: |
| | 81 | | /// 200 (OK): Success. |
| | 82 | | /// 400 (Bad Request): The request is invalid. |
| | 83 | | /// 404 (Not Found): There is no digital twin with the provided id. |
| | 84 | | /// </summary> |
| | 85 | | /// <param name="id"> The id of the digital twin. The id is unique within the service and case sensitive. </para |
| | 86 | | /// <param name="ifMatch"> Only perform the operation if the entity's etag matches one of the etags provide |
| | 87 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 88 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 89 | | public async Task<Response> DeleteAsync(string id, string ifMatch = null, CancellationToken cancellationToken = |
| | 90 | | { |
| 6 | 91 | | if (id == null) |
| | 92 | | { |
| 0 | 93 | | throw new ArgumentNullException(nameof(id)); |
| | 94 | | } |
| | 95 | |
|
| 6 | 96 | | using var message = CreateDeleteRequest(id, ifMatch); |
| 6 | 97 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 6 | 98 | | switch (message.Response.Status) |
| | 99 | | { |
| | 100 | | case 204: |
| 6 | 101 | | return message.Response; |
| | 102 | | default: |
| 0 | 103 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 104 | | } |
| 6 | 105 | | } |
| | 106 | |
|
| | 107 | | /// <summary> |
| | 108 | | /// Deletes a digital twin. All relationships referencing the digital twin must already be deleted. |
| | 109 | | /// Status codes: |
| | 110 | | /// 200 (OK): Success. |
| | 111 | | /// 400 (Bad Request): The request is invalid. |
| | 112 | | /// 404 (Not Found): There is no digital twin with the provided id. |
| | 113 | | /// </summary> |
| | 114 | | /// <param name="id"> The id of the digital twin. The id is unique within the service and case sensitive. </para |
| | 115 | | /// <param name="ifMatch"> Only perform the operation if the entity's etag matches one of the etags provide |
| | 116 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 117 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 118 | | public Response Delete(string id, string ifMatch = null, CancellationToken cancellationToken = default) |
| | 119 | | { |
| 6 | 120 | | if (id == null) |
| | 121 | | { |
| 0 | 122 | | throw new ArgumentNullException(nameof(id)); |
| | 123 | | } |
| | 124 | |
|
| 6 | 125 | | using var message = CreateDeleteRequest(id, ifMatch); |
| 6 | 126 | | _pipeline.Send(message, cancellationToken); |
| 6 | 127 | | switch (message.Response.Status) |
| | 128 | | { |
| | 129 | | case 204: |
| 6 | 130 | | return message.Response; |
| | 131 | | default: |
| 0 | 132 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 133 | | } |
| 6 | 134 | | } |
| | 135 | |
|
| | 136 | | internal HttpMessage CreateUpdateRequest(string id, IEnumerable<object> patchDocument, string ifMatch) |
| | 137 | | { |
| 0 | 138 | | var message = _pipeline.CreateMessage(); |
| 0 | 139 | | var request = message.Request; |
| 0 | 140 | | request.Method = RequestMethod.Patch; |
| 0 | 141 | | var uri = new RawRequestUriBuilder(); |
| 0 | 142 | | uri.Reset(endpoint); |
| 0 | 143 | | uri.AppendPath("/digitaltwins/", false); |
| 0 | 144 | | uri.AppendPath(id, true); |
| 0 | 145 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 146 | | request.Uri = uri; |
| 0 | 147 | | if (ifMatch != null) |
| | 148 | | { |
| 0 | 149 | | request.Headers.Add("If-Match", ifMatch); |
| | 150 | | } |
| 0 | 151 | | request.Headers.Add("Content-Type", "application/json-patch+json"); |
| 0 | 152 | | var content = new Utf8JsonRequestContent(); |
| 0 | 153 | | content.JsonWriter.WriteStartArray(); |
| 0 | 154 | | foreach (var item in patchDocument) |
| | 155 | | { |
| 0 | 156 | | content.JsonWriter.WriteObjectValue(item); |
| | 157 | | } |
| 0 | 158 | | content.JsonWriter.WriteEndArray(); |
| 0 | 159 | | request.Content = content; |
| 0 | 160 | | return message; |
| | 161 | | } |
| | 162 | |
|
| | 163 | | internal HttpMessage CreateGetRelationshipByIdRequest(string id, string relationshipId) |
| | 164 | | { |
| 10 | 165 | | var message = _pipeline.CreateMessage(); |
| 10 | 166 | | var request = message.Request; |
| 10 | 167 | | request.Method = RequestMethod.Get; |
| 10 | 168 | | var uri = new RawRequestUriBuilder(); |
| 10 | 169 | | uri.Reset(endpoint); |
| 10 | 170 | | uri.AppendPath("/digitaltwins/", false); |
| 10 | 171 | | uri.AppendPath(id, true); |
| 10 | 172 | | uri.AppendPath("/relationships/", false); |
| 10 | 173 | | uri.AppendPath(relationshipId, true); |
| 10 | 174 | | uri.AppendQuery("api-version", apiVersion, true); |
| 10 | 175 | | request.Uri = uri; |
| 10 | 176 | | return message; |
| | 177 | | } |
| | 178 | |
|
| | 179 | | internal HttpMessage CreateAddRelationshipRequest(string id, string relationshipId, object relationship) |
| | 180 | | { |
| 0 | 181 | | var message = _pipeline.CreateMessage(); |
| 0 | 182 | | var request = message.Request; |
| 0 | 183 | | request.Method = RequestMethod.Put; |
| 0 | 184 | | var uri = new RawRequestUriBuilder(); |
| 0 | 185 | | uri.Reset(endpoint); |
| 0 | 186 | | uri.AppendPath("/digitaltwins/", false); |
| 0 | 187 | | uri.AppendPath(id, true); |
| 0 | 188 | | uri.AppendPath("/relationships/", false); |
| 0 | 189 | | uri.AppendPath(relationshipId, true); |
| 0 | 190 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 191 | | request.Uri = uri; |
| 0 | 192 | | request.Headers.Add("If-None-Match", "*"); |
| 0 | 193 | | request.Headers.Add("Content-Type", "application/json"); |
| 0 | 194 | | if (relationship != null) |
| | 195 | | { |
| 0 | 196 | | var content = new Utf8JsonRequestContent(); |
| 0 | 197 | | content.JsonWriter.WriteObjectValue(relationship); |
| 0 | 198 | | request.Content = content; |
| | 199 | | } |
| 0 | 200 | | return message; |
| | 201 | | } |
| | 202 | |
|
| | 203 | | internal HttpMessage CreateDeleteRelationshipRequest(string id, string relationshipId, string ifMatch) |
| | 204 | | { |
| 8 | 205 | | var message = _pipeline.CreateMessage(); |
| 8 | 206 | | var request = message.Request; |
| 8 | 207 | | request.Method = RequestMethod.Delete; |
| 8 | 208 | | var uri = new RawRequestUriBuilder(); |
| 8 | 209 | | uri.Reset(endpoint); |
| 8 | 210 | | uri.AppendPath("/digitaltwins/", false); |
| 8 | 211 | | uri.AppendPath(id, true); |
| 8 | 212 | | uri.AppendPath("/relationships/", false); |
| 8 | 213 | | uri.AppendPath(relationshipId, true); |
| 8 | 214 | | uri.AppendQuery("api-version", apiVersion, true); |
| 8 | 215 | | request.Uri = uri; |
| 8 | 216 | | if (ifMatch != null) |
| | 217 | | { |
| 0 | 218 | | request.Headers.Add("If-Match", ifMatch); |
| | 219 | | } |
| 8 | 220 | | return message; |
| | 221 | | } |
| | 222 | |
|
| | 223 | | /// <summary> |
| | 224 | | /// Deletes a relationship between two digital twins. |
| | 225 | | /// Status codes: |
| | 226 | | /// 200 (OK): Success. |
| | 227 | | /// 404 (Not Found): There is either no digital twin or relationship with the provided id. |
| | 228 | | /// </summary> |
| | 229 | | /// <param name="id"> The id of the digital twin. The id is unique within the service and case sensitive. </para |
| | 230 | | /// <param name="relationshipId"> The id of the relationship. The id is unique within the digital twin and case |
| | 231 | | /// <param name="ifMatch"> Only perform the operation if the entity's etag matches one of the etags provide |
| | 232 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 233 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> or <paramref name="relationshipId"/> is null. |
| | 234 | | public async Task<Response> DeleteRelationshipAsync(string id, string relationshipId, string ifMatch = null, Can |
| | 235 | | { |
| 4 | 236 | | if (id == null) |
| | 237 | | { |
| 0 | 238 | | throw new ArgumentNullException(nameof(id)); |
| | 239 | | } |
| 4 | 240 | | if (relationshipId == null) |
| | 241 | | { |
| 0 | 242 | | throw new ArgumentNullException(nameof(relationshipId)); |
| | 243 | | } |
| | 244 | |
|
| 4 | 245 | | using var message = CreateDeleteRelationshipRequest(id, relationshipId, ifMatch); |
| 4 | 246 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 4 | 247 | | switch (message.Response.Status) |
| | 248 | | { |
| | 249 | | case 204: |
| 4 | 250 | | return message.Response; |
| | 251 | | default: |
| 0 | 252 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 253 | | } |
| 4 | 254 | | } |
| | 255 | |
|
| | 256 | | /// <summary> |
| | 257 | | /// Deletes a relationship between two digital twins. |
| | 258 | | /// Status codes: |
| | 259 | | /// 200 (OK): Success. |
| | 260 | | /// 404 (Not Found): There is either no digital twin or relationship with the provided id. |
| | 261 | | /// </summary> |
| | 262 | | /// <param name="id"> The id of the digital twin. The id is unique within the service and case sensitive. </para |
| | 263 | | /// <param name="relationshipId"> The id of the relationship. The id is unique within the digital twin and case |
| | 264 | | /// <param name="ifMatch"> Only perform the operation if the entity's etag matches one of the etags provide |
| | 265 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 266 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> or <paramref name="relationshipId"/> is null. |
| | 267 | | public Response DeleteRelationship(string id, string relationshipId, string ifMatch = null, CancellationToken ca |
| | 268 | | { |
| 4 | 269 | | if (id == null) |
| | 270 | | { |
| 0 | 271 | | throw new ArgumentNullException(nameof(id)); |
| | 272 | | } |
| 4 | 273 | | if (relationshipId == null) |
| | 274 | | { |
| 0 | 275 | | throw new ArgumentNullException(nameof(relationshipId)); |
| | 276 | | } |
| | 277 | |
|
| 4 | 278 | | using var message = CreateDeleteRelationshipRequest(id, relationshipId, ifMatch); |
| 4 | 279 | | _pipeline.Send(message, cancellationToken); |
| 4 | 280 | | switch (message.Response.Status) |
| | 281 | | { |
| | 282 | | case 204: |
| 4 | 283 | | return message.Response; |
| | 284 | | default: |
| 0 | 285 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 286 | | } |
| 4 | 287 | | } |
| | 288 | |
|
| | 289 | | internal HttpMessage CreateUpdateRelationshipRequest(string id, string relationshipId, string ifMatch, IEnumerab |
| | 290 | | { |
| 0 | 291 | | var message = _pipeline.CreateMessage(); |
| 0 | 292 | | var request = message.Request; |
| 0 | 293 | | request.Method = RequestMethod.Patch; |
| 0 | 294 | | var uri = new RawRequestUriBuilder(); |
| 0 | 295 | | uri.Reset(endpoint); |
| 0 | 296 | | uri.AppendPath("/digitaltwins/", false); |
| 0 | 297 | | uri.AppendPath(id, true); |
| 0 | 298 | | uri.AppendPath("/relationships/", false); |
| 0 | 299 | | uri.AppendPath(relationshipId, true); |
| 0 | 300 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 301 | | request.Uri = uri; |
| 0 | 302 | | if (ifMatch != null) |
| | 303 | | { |
| 0 | 304 | | request.Headers.Add("If-Match", ifMatch); |
| | 305 | | } |
| 0 | 306 | | request.Headers.Add("Content-Type", "application/json-patch+json"); |
| 0 | 307 | | if (patchDocument != null) |
| | 308 | | { |
| 0 | 309 | | var content = new Utf8JsonRequestContent(); |
| 0 | 310 | | content.JsonWriter.WriteStartArray(); |
| 0 | 311 | | foreach (var item in patchDocument) |
| | 312 | | { |
| 0 | 313 | | content.JsonWriter.WriteObjectValue(item); |
| | 314 | | } |
| 0 | 315 | | content.JsonWriter.WriteEndArray(); |
| 0 | 316 | | request.Content = content; |
| | 317 | | } |
| 0 | 318 | | return message; |
| | 319 | | } |
| | 320 | |
|
| | 321 | | internal HttpMessage CreateListRelationshipsRequest(string id, string relationshipName) |
| | 322 | | { |
| 4 | 323 | | var message = _pipeline.CreateMessage(); |
| 4 | 324 | | var request = message.Request; |
| 4 | 325 | | request.Method = RequestMethod.Get; |
| 4 | 326 | | var uri = new RawRequestUriBuilder(); |
| 4 | 327 | | uri.Reset(endpoint); |
| 4 | 328 | | uri.AppendPath("/digitaltwins/", false); |
| 4 | 329 | | uri.AppendPath(id, true); |
| 4 | 330 | | uri.AppendPath("/relationships", false); |
| 4 | 331 | | if (relationshipName != null) |
| | 332 | | { |
| 2 | 333 | | uri.AppendQuery("relationshipName", relationshipName, true); |
| | 334 | | } |
| 4 | 335 | | uri.AppendQuery("api-version", apiVersion, true); |
| 4 | 336 | | request.Uri = uri; |
| 4 | 337 | | return message; |
| | 338 | | } |
| | 339 | |
|
| | 340 | | /// <summary> |
| | 341 | | /// Retrieves the relationships from a digital twin. |
| | 342 | | /// Status codes: |
| | 343 | | /// 200 (OK): Success. |
| | 344 | | /// 400 (Bad Request): The request is invalid. |
| | 345 | | /// 404 (Not Found): There is no digital twin with the provided id. |
| | 346 | | /// </summary> |
| | 347 | | /// <param name="id"> The id of the digital twin. The id is unique within the service and case sensitive. </para |
| | 348 | | /// <param name="relationshipName"> The name of the relationship. </param> |
| | 349 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 350 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 351 | | public async Task<Response<RelationshipCollection>> ListRelationshipsAsync(string id, string relationshipName = |
| | 352 | | { |
| 2 | 353 | | if (id == null) |
| | 354 | | { |
| 0 | 355 | | throw new ArgumentNullException(nameof(id)); |
| | 356 | | } |
| | 357 | |
|
| 2 | 358 | | using var message = CreateListRelationshipsRequest(id, relationshipName); |
| 2 | 359 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 2 | 360 | | switch (message.Response.Status) |
| | 361 | | { |
| | 362 | | case 200: |
| | 363 | | { |
| | 364 | | RelationshipCollection value = default; |
| 2 | 365 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 2 | 366 | | value = RelationshipCollection.DeserializeRelationshipCollection(document.RootElement); |
| 2 | 367 | | return Response.FromValue(value, message.Response); |
| | 368 | | } |
| | 369 | | default: |
| 0 | 370 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 371 | | } |
| 2 | 372 | | } |
| | 373 | |
|
| | 374 | | /// <summary> |
| | 375 | | /// Retrieves the relationships from a digital twin. |
| | 376 | | /// Status codes: |
| | 377 | | /// 200 (OK): Success. |
| | 378 | | /// 400 (Bad Request): The request is invalid. |
| | 379 | | /// 404 (Not Found): There is no digital twin with the provided id. |
| | 380 | | /// </summary> |
| | 381 | | /// <param name="id"> The id of the digital twin. The id is unique within the service and case sensitive. </para |
| | 382 | | /// <param name="relationshipName"> The name of the relationship. </param> |
| | 383 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 384 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 385 | | public Response<RelationshipCollection> ListRelationships(string id, string relationshipName = null, Cancellatio |
| | 386 | | { |
| 2 | 387 | | if (id == null) |
| | 388 | | { |
| 0 | 389 | | throw new ArgumentNullException(nameof(id)); |
| | 390 | | } |
| | 391 | |
|
| 2 | 392 | | using var message = CreateListRelationshipsRequest(id, relationshipName); |
| 2 | 393 | | _pipeline.Send(message, cancellationToken); |
| 2 | 394 | | switch (message.Response.Status) |
| | 395 | | { |
| | 396 | | case 200: |
| | 397 | | { |
| | 398 | | RelationshipCollection value = default; |
| 2 | 399 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 2 | 400 | | value = RelationshipCollection.DeserializeRelationshipCollection(document.RootElement); |
| 2 | 401 | | return Response.FromValue(value, message.Response); |
| | 402 | | } |
| | 403 | | default: |
| 0 | 404 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 405 | | } |
| 2 | 406 | | } |
| | 407 | |
|
| | 408 | | internal HttpMessage CreateListIncomingRelationshipsRequest(string id) |
| | 409 | | { |
| 2 | 410 | | var message = _pipeline.CreateMessage(); |
| 2 | 411 | | var request = message.Request; |
| 2 | 412 | | request.Method = RequestMethod.Get; |
| 2 | 413 | | var uri = new RawRequestUriBuilder(); |
| 2 | 414 | | uri.Reset(endpoint); |
| 2 | 415 | | uri.AppendPath("/digitaltwins/", false); |
| 2 | 416 | | uri.AppendPath(id, true); |
| 2 | 417 | | uri.AppendPath("/incomingrelationships", false); |
| 2 | 418 | | uri.AppendQuery("api-version", apiVersion, true); |
| 2 | 419 | | request.Uri = uri; |
| 2 | 420 | | return message; |
| | 421 | | } |
| | 422 | |
|
| | 423 | | /// <summary> |
| | 424 | | /// Retrieves all incoming relationship for a digital twin. |
| | 425 | | /// Status codes: |
| | 426 | | /// 200 (OK): Success. |
| | 427 | | /// 400 (Bad Request): The request is invalid. |
| | 428 | | /// 404 (Not Found): There is no digital twin with the provided id. |
| | 429 | | /// </summary> |
| | 430 | | /// <param name="id"> The id of the digital twin. The id is unique within the service and case sensitive. </para |
| | 431 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 432 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 433 | | public async Task<Response<IncomingRelationshipCollection>> ListIncomingRelationshipsAsync(string id, Cancellati |
| | 434 | | { |
| 1 | 435 | | if (id == null) |
| | 436 | | { |
| 0 | 437 | | throw new ArgumentNullException(nameof(id)); |
| | 438 | | } |
| | 439 | |
|
| 1 | 440 | | using var message = CreateListIncomingRelationshipsRequest(id); |
| 1 | 441 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 1 | 442 | | switch (message.Response.Status) |
| | 443 | | { |
| | 444 | | case 200: |
| | 445 | | { |
| | 446 | | IncomingRelationshipCollection value = default; |
| 1 | 447 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 1 | 448 | | value = IncomingRelationshipCollection.DeserializeIncomingRelationshipCollection(document.RootEl |
| 1 | 449 | | return Response.FromValue(value, message.Response); |
| | 450 | | } |
| | 451 | | default: |
| 0 | 452 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 453 | | } |
| 1 | 454 | | } |
| | 455 | |
|
| | 456 | | /// <summary> |
| | 457 | | /// Retrieves all incoming relationship for a digital twin. |
| | 458 | | /// Status codes: |
| | 459 | | /// 200 (OK): Success. |
| | 460 | | /// 400 (Bad Request): The request is invalid. |
| | 461 | | /// 404 (Not Found): There is no digital twin with the provided id. |
| | 462 | | /// </summary> |
| | 463 | | /// <param name="id"> The id of the digital twin. The id is unique within the service and case sensitive. </para |
| | 464 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 465 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 466 | | public Response<IncomingRelationshipCollection> ListIncomingRelationships(string id, CancellationToken cancellat |
| | 467 | | { |
| 1 | 468 | | if (id == null) |
| | 469 | | { |
| 0 | 470 | | throw new ArgumentNullException(nameof(id)); |
| | 471 | | } |
| | 472 | |
|
| 1 | 473 | | using var message = CreateListIncomingRelationshipsRequest(id); |
| 1 | 474 | | _pipeline.Send(message, cancellationToken); |
| 1 | 475 | | switch (message.Response.Status) |
| | 476 | | { |
| | 477 | | case 200: |
| | 478 | | { |
| | 479 | | IncomingRelationshipCollection value = default; |
| 1 | 480 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 1 | 481 | | value = IncomingRelationshipCollection.DeserializeIncomingRelationshipCollection(document.RootEl |
| 1 | 482 | | return Response.FromValue(value, message.Response); |
| | 483 | | } |
| | 484 | | default: |
| 0 | 485 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 486 | | } |
| 1 | 487 | | } |
| | 488 | |
|
| | 489 | | internal HttpMessage CreateSendTelemetryRequest(string id, string dtId, object telemetry, string dtTimestamp) |
| | 490 | | { |
| 0 | 491 | | var message = _pipeline.CreateMessage(); |
| 0 | 492 | | var request = message.Request; |
| 0 | 493 | | request.Method = RequestMethod.Post; |
| 0 | 494 | | var uri = new RawRequestUriBuilder(); |
| 0 | 495 | | uri.Reset(endpoint); |
| 0 | 496 | | uri.AppendPath("/digitaltwins/", false); |
| 0 | 497 | | uri.AppendPath(id, true); |
| 0 | 498 | | uri.AppendPath("/telemetry", false); |
| 0 | 499 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 500 | | request.Uri = uri; |
| 0 | 501 | | request.Headers.Add("dt-id", dtId); |
| 0 | 502 | | if (dtTimestamp != null) |
| | 503 | | { |
| 0 | 504 | | request.Headers.Add("dt-timestamp", dtTimestamp); |
| | 505 | | } |
| 0 | 506 | | request.Headers.Add("Content-Type", "application/json"); |
| 0 | 507 | | var content = new Utf8JsonRequestContent(); |
| 0 | 508 | | content.JsonWriter.WriteObjectValue(telemetry); |
| 0 | 509 | | request.Content = content; |
| 0 | 510 | | return message; |
| | 511 | | } |
| | 512 | |
|
| | 513 | | internal HttpMessage CreateSendComponentTelemetryRequest(string id, string componentPath, string dtId, object te |
| | 514 | | { |
| 0 | 515 | | var message = _pipeline.CreateMessage(); |
| 0 | 516 | | var request = message.Request; |
| 0 | 517 | | request.Method = RequestMethod.Post; |
| 0 | 518 | | var uri = new RawRequestUriBuilder(); |
| 0 | 519 | | uri.Reset(endpoint); |
| 0 | 520 | | uri.AppendPath("/digitaltwins/", false); |
| 0 | 521 | | uri.AppendPath(id, true); |
| 0 | 522 | | uri.AppendPath("/components/", false); |
| 0 | 523 | | uri.AppendPath(componentPath, true); |
| 0 | 524 | | uri.AppendPath("/telemetry", false); |
| 0 | 525 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 526 | | request.Uri = uri; |
| 0 | 527 | | request.Headers.Add("dt-id", dtId); |
| 0 | 528 | | if (dtTimestamp != null) |
| | 529 | | { |
| 0 | 530 | | request.Headers.Add("dt-timestamp", dtTimestamp); |
| | 531 | | } |
| 0 | 532 | | request.Headers.Add("Content-Type", "application/json"); |
| 0 | 533 | | var content = new Utf8JsonRequestContent(); |
| 0 | 534 | | content.JsonWriter.WriteObjectValue(telemetry); |
| 0 | 535 | | request.Content = content; |
| 0 | 536 | | return message; |
| | 537 | | } |
| | 538 | |
|
| | 539 | | internal HttpMessage CreateGetComponentRequest(string id, string componentPath) |
| | 540 | | { |
| 2 | 541 | | var message = _pipeline.CreateMessage(); |
| 2 | 542 | | var request = message.Request; |
| 2 | 543 | | request.Method = RequestMethod.Get; |
| 2 | 544 | | var uri = new RawRequestUriBuilder(); |
| 2 | 545 | | uri.Reset(endpoint); |
| 2 | 546 | | uri.AppendPath("/digitaltwins/", false); |
| 2 | 547 | | uri.AppendPath(id, true); |
| 2 | 548 | | uri.AppendPath("/components/", false); |
| 2 | 549 | | uri.AppendPath(componentPath, true); |
| 2 | 550 | | uri.AppendQuery("api-version", apiVersion, true); |
| 2 | 551 | | request.Uri = uri; |
| 2 | 552 | | return message; |
| | 553 | | } |
| | 554 | |
|
| | 555 | | internal HttpMessage CreateUpdateComponentRequest(string id, string componentPath, string ifMatch, IEnumerable<o |
| | 556 | | { |
| 0 | 557 | | var message = _pipeline.CreateMessage(); |
| 0 | 558 | | var request = message.Request; |
| 0 | 559 | | request.Method = RequestMethod.Patch; |
| 0 | 560 | | var uri = new RawRequestUriBuilder(); |
| 0 | 561 | | uri.Reset(endpoint); |
| 0 | 562 | | uri.AppendPath("/digitaltwins/", false); |
| 0 | 563 | | uri.AppendPath(id, true); |
| 0 | 564 | | uri.AppendPath("/components/", false); |
| 0 | 565 | | uri.AppendPath(componentPath, true); |
| 0 | 566 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 567 | | request.Uri = uri; |
| 0 | 568 | | if (ifMatch != null) |
| | 569 | | { |
| 0 | 570 | | request.Headers.Add("If-Match", ifMatch); |
| | 571 | | } |
| 0 | 572 | | request.Headers.Add("Content-Type", "application/json-patch+json"); |
| 0 | 573 | | if (patchDocument != null) |
| | 574 | | { |
| 0 | 575 | | var content = new Utf8JsonRequestContent(); |
| 0 | 576 | | content.JsonWriter.WriteStartArray(); |
| 0 | 577 | | foreach (var item in patchDocument) |
| | 578 | | { |
| 0 | 579 | | content.JsonWriter.WriteObjectValue(item); |
| | 580 | | } |
| 0 | 581 | | content.JsonWriter.WriteEndArray(); |
| 0 | 582 | | request.Content = content; |
| | 583 | | } |
| 0 | 584 | | return message; |
| | 585 | | } |
| | 586 | |
|
| | 587 | | internal HttpMessage CreateListRelationshipsNextPageRequest(string nextLink, string id, string relationshipName) |
| | 588 | | { |
| 0 | 589 | | var message = _pipeline.CreateMessage(); |
| 0 | 590 | | var request = message.Request; |
| 0 | 591 | | request.Method = RequestMethod.Get; |
| 0 | 592 | | var uri = new RawRequestUriBuilder(); |
| 0 | 593 | | uri.Reset(endpoint); |
| 0 | 594 | | uri.AppendRawNextLink(nextLink, false); |
| 0 | 595 | | request.Uri = uri; |
| 0 | 596 | | return message; |
| | 597 | | } |
| | 598 | |
|
| | 599 | | /// <summary> |
| | 600 | | /// Retrieves the relationships from a digital twin. |
| | 601 | | /// Status codes: |
| | 602 | | /// 200 (OK): Success. |
| | 603 | | /// 400 (Bad Request): The request is invalid. |
| | 604 | | /// 404 (Not Found): There is no digital twin with the provided id. |
| | 605 | | /// </summary> |
| | 606 | | /// <param name="nextLink"> The URL to the next page of results. </param> |
| | 607 | | /// <param name="id"> The id of the digital twin. The id is unique within the service and case sensitive. </para |
| | 608 | | /// <param name="relationshipName"> The name of the relationship. </param> |
| | 609 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 610 | | /// <exception cref="ArgumentNullException"> <paramref name="nextLink"/> or <paramref name="id"/> is null. </exc |
| | 611 | | public async Task<Response<RelationshipCollection>> ListRelationshipsNextPageAsync(string nextLink, string id, s |
| | 612 | | { |
| 0 | 613 | | if (nextLink == null) |
| | 614 | | { |
| 0 | 615 | | throw new ArgumentNullException(nameof(nextLink)); |
| | 616 | | } |
| 0 | 617 | | if (id == null) |
| | 618 | | { |
| 0 | 619 | | throw new ArgumentNullException(nameof(id)); |
| | 620 | | } |
| | 621 | |
|
| 0 | 622 | | using var message = CreateListRelationshipsNextPageRequest(nextLink, id, relationshipName); |
| 0 | 623 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 624 | | switch (message.Response.Status) |
| | 625 | | { |
| | 626 | | case 200: |
| | 627 | | { |
| | 628 | | RelationshipCollection value = default; |
| 0 | 629 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 630 | | value = RelationshipCollection.DeserializeRelationshipCollection(document.RootElement); |
| 0 | 631 | | return Response.FromValue(value, message.Response); |
| | 632 | | } |
| | 633 | | default: |
| 0 | 634 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 635 | | } |
| 0 | 636 | | } |
| | 637 | |
|
| | 638 | | /// <summary> |
| | 639 | | /// Retrieves the relationships from a digital twin. |
| | 640 | | /// Status codes: |
| | 641 | | /// 200 (OK): Success. |
| | 642 | | /// 400 (Bad Request): The request is invalid. |
| | 643 | | /// 404 (Not Found): There is no digital twin with the provided id. |
| | 644 | | /// </summary> |
| | 645 | | /// <param name="nextLink"> The URL to the next page of results. </param> |
| | 646 | | /// <param name="id"> The id of the digital twin. The id is unique within the service and case sensitive. </para |
| | 647 | | /// <param name="relationshipName"> The name of the relationship. </param> |
| | 648 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 649 | | /// <exception cref="ArgumentNullException"> <paramref name="nextLink"/> or <paramref name="id"/> is null. </exc |
| | 650 | | public Response<RelationshipCollection> ListRelationshipsNextPage(string nextLink, string id, string relationshi |
| | 651 | | { |
| 0 | 652 | | if (nextLink == null) |
| | 653 | | { |
| 0 | 654 | | throw new ArgumentNullException(nameof(nextLink)); |
| | 655 | | } |
| 0 | 656 | | if (id == null) |
| | 657 | | { |
| 0 | 658 | | throw new ArgumentNullException(nameof(id)); |
| | 659 | | } |
| | 660 | |
|
| 0 | 661 | | using var message = CreateListRelationshipsNextPageRequest(nextLink, id, relationshipName); |
| 0 | 662 | | _pipeline.Send(message, cancellationToken); |
| 0 | 663 | | switch (message.Response.Status) |
| | 664 | | { |
| | 665 | | case 200: |
| | 666 | | { |
| | 667 | | RelationshipCollection value = default; |
| 0 | 668 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 669 | | value = RelationshipCollection.DeserializeRelationshipCollection(document.RootElement); |
| 0 | 670 | | return Response.FromValue(value, message.Response); |
| | 671 | | } |
| | 672 | | default: |
| 0 | 673 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 674 | | } |
| 0 | 675 | | } |
| | 676 | |
|
| | 677 | | internal HttpMessage CreateListIncomingRelationshipsNextPageRequest(string nextLink, string id) |
| | 678 | | { |
| 0 | 679 | | var message = _pipeline.CreateMessage(); |
| 0 | 680 | | var request = message.Request; |
| 0 | 681 | | request.Method = RequestMethod.Get; |
| 0 | 682 | | var uri = new RawRequestUriBuilder(); |
| 0 | 683 | | uri.Reset(endpoint); |
| 0 | 684 | | uri.AppendRawNextLink(nextLink, false); |
| 0 | 685 | | request.Uri = uri; |
| 0 | 686 | | return message; |
| | 687 | | } |
| | 688 | |
|
| | 689 | | /// <summary> |
| | 690 | | /// Retrieves all incoming relationship for a digital twin. |
| | 691 | | /// Status codes: |
| | 692 | | /// 200 (OK): Success. |
| | 693 | | /// 400 (Bad Request): The request is invalid. |
| | 694 | | /// 404 (Not Found): There is no digital twin with the provided id. |
| | 695 | | /// </summary> |
| | 696 | | /// <param name="nextLink"> The URL to the next page of results. </param> |
| | 697 | | /// <param name="id"> The id of the digital twin. The id is unique within the service and case sensitive. </para |
| | 698 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 699 | | /// <exception cref="ArgumentNullException"> <paramref name="nextLink"/> or <paramref name="id"/> is null. </exc |
| | 700 | | public async Task<Response<IncomingRelationshipCollection>> ListIncomingRelationshipsNextPageAsync(string nextLi |
| | 701 | | { |
| 0 | 702 | | if (nextLink == null) |
| | 703 | | { |
| 0 | 704 | | throw new ArgumentNullException(nameof(nextLink)); |
| | 705 | | } |
| 0 | 706 | | if (id == null) |
| | 707 | | { |
| 0 | 708 | | throw new ArgumentNullException(nameof(id)); |
| | 709 | | } |
| | 710 | |
|
| 0 | 711 | | using var message = CreateListIncomingRelationshipsNextPageRequest(nextLink, id); |
| 0 | 712 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 713 | | switch (message.Response.Status) |
| | 714 | | { |
| | 715 | | case 200: |
| | 716 | | { |
| | 717 | | IncomingRelationshipCollection value = default; |
| 0 | 718 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 719 | | value = IncomingRelationshipCollection.DeserializeIncomingRelationshipCollection(document.RootEl |
| 0 | 720 | | return Response.FromValue(value, message.Response); |
| | 721 | | } |
| | 722 | | default: |
| 0 | 723 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 724 | | } |
| 0 | 725 | | } |
| | 726 | |
|
| | 727 | | /// <summary> |
| | 728 | | /// Retrieves all incoming relationship for a digital twin. |
| | 729 | | /// Status codes: |
| | 730 | | /// 200 (OK): Success. |
| | 731 | | /// 400 (Bad Request): The request is invalid. |
| | 732 | | /// 404 (Not Found): There is no digital twin with the provided id. |
| | 733 | | /// </summary> |
| | 734 | | /// <param name="nextLink"> The URL to the next page of results. </param> |
| | 735 | | /// <param name="id"> The id of the digital twin. The id is unique within the service and case sensitive. </para |
| | 736 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 737 | | /// <exception cref="ArgumentNullException"> <paramref name="nextLink"/> or <paramref name="id"/> is null. </exc |
| | 738 | | public Response<IncomingRelationshipCollection> ListIncomingRelationshipsNextPage(string nextLink, string id, Ca |
| | 739 | | { |
| 0 | 740 | | if (nextLink == null) |
| | 741 | | { |
| 0 | 742 | | throw new ArgumentNullException(nameof(nextLink)); |
| | 743 | | } |
| 0 | 744 | | if (id == null) |
| | 745 | | { |
| 0 | 746 | | throw new ArgumentNullException(nameof(id)); |
| | 747 | | } |
| | 748 | |
|
| 0 | 749 | | using var message = CreateListIncomingRelationshipsNextPageRequest(nextLink, id); |
| 0 | 750 | | _pipeline.Send(message, cancellationToken); |
| 0 | 751 | | switch (message.Response.Status) |
| | 752 | | { |
| | 753 | | case 200: |
| | 754 | | { |
| | 755 | | IncomingRelationshipCollection value = default; |
| 0 | 756 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 757 | | value = IncomingRelationshipCollection.DeserializeIncomingRelationshipCollection(document.RootEl |
| 0 | 758 | | return Response.FromValue(value, message.Response); |
| | 759 | | } |
| | 760 | | default: |
| 0 | 761 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 762 | | } |
| 0 | 763 | | } |
| | 764 | | } |
| | 765 | | } |