| | 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 DigitalTwinModelsRestClient |
| | 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 DigitalTwinModelsRestClient. </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 DigitalTwinModelsRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = nu |
| | 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 CreateListRequest(IEnumerable<string> dependenciesFor, bool? includeModelDefinition, GetMod |
| | 47 | | { |
| 2 | 48 | | var message = _pipeline.CreateMessage(); |
| 2 | 49 | | var request = message.Request; |
| 2 | 50 | | request.Method = RequestMethod.Get; |
| 2 | 51 | | var uri = new RawRequestUriBuilder(); |
| 2 | 52 | | uri.Reset(endpoint); |
| 2 | 53 | | uri.AppendPath("/models", false); |
| 2 | 54 | | if (dependenciesFor != null) |
| | 55 | | { |
| 0 | 56 | | uri.AppendQueryDelimited("dependenciesFor", dependenciesFor, ",", true); |
| | 57 | | } |
| 2 | 58 | | if (includeModelDefinition != null) |
| | 59 | | { |
| 2 | 60 | | uri.AppendQuery("includeModelDefinition", includeModelDefinition.Value, true); |
| | 61 | | } |
| 2 | 62 | | uri.AppendQuery("api-version", apiVersion, true); |
| 2 | 63 | | request.Uri = uri; |
| 2 | 64 | | if (digitalTwinModelsListOptions?.MaxItemCount != null) |
| | 65 | | { |
| 0 | 66 | | request.Headers.Add("x-ms-max-item-count", digitalTwinModelsListOptions.MaxItemCount.Value); |
| | 67 | | } |
| 2 | 68 | | return message; |
| | 69 | | } |
| | 70 | |
|
| | 71 | | /// <summary> |
| | 72 | | /// Retrieves model metadata and, optionally, model definitions. |
| | 73 | | /// Status codes: |
| | 74 | | /// 200 (OK): Success. |
| | 75 | | /// 400 (Bad Request): The request is invalid. |
| | 76 | | /// </summary> |
| | 77 | | /// <param name="dependenciesFor"> The set of the models which will have their dependencies retrieved. If omitte |
| | 78 | | /// <param name="includeModelDefinition"> When true the model definition will be returned as part of the result. |
| | 79 | | /// <param name="digitalTwinModelsListOptions"> Parameter group. </param> |
| | 80 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 81 | | public async Task<Response<PagedModelDataCollection>> ListAsync(IEnumerable<string> dependenciesFor = null, bool |
| | 82 | | { |
| 1 | 83 | | using var message = CreateListRequest(dependenciesFor, includeModelDefinition, digitalTwinModelsListOptions) |
| 1 | 84 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 1 | 85 | | switch (message.Response.Status) |
| | 86 | | { |
| | 87 | | case 200: |
| | 88 | | { |
| | 89 | | PagedModelDataCollection value = default; |
| 1 | 90 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 1 | 91 | | value = PagedModelDataCollection.DeserializePagedModelDataCollection(document.RootElement); |
| 1 | 92 | | return Response.FromValue(value, message.Response); |
| | 93 | | } |
| | 94 | | default: |
| 0 | 95 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 96 | | } |
| 1 | 97 | | } |
| | 98 | |
|
| | 99 | | /// <summary> |
| | 100 | | /// Retrieves model metadata and, optionally, model definitions. |
| | 101 | | /// Status codes: |
| | 102 | | /// 200 (OK): Success. |
| | 103 | | /// 400 (Bad Request): The request is invalid. |
| | 104 | | /// </summary> |
| | 105 | | /// <param name="dependenciesFor"> The set of the models which will have their dependencies retrieved. If omitte |
| | 106 | | /// <param name="includeModelDefinition"> When true the model definition will be returned as part of the result. |
| | 107 | | /// <param name="digitalTwinModelsListOptions"> Parameter group. </param> |
| | 108 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 109 | | public Response<PagedModelDataCollection> List(IEnumerable<string> dependenciesFor = null, bool? includeModelDef |
| | 110 | | { |
| 1 | 111 | | using var message = CreateListRequest(dependenciesFor, includeModelDefinition, digitalTwinModelsListOptions) |
| 1 | 112 | | _pipeline.Send(message, cancellationToken); |
| 1 | 113 | | switch (message.Response.Status) |
| | 114 | | { |
| | 115 | | case 200: |
| | 116 | | { |
| | 117 | | PagedModelDataCollection value = default; |
| 1 | 118 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 1 | 119 | | value = PagedModelDataCollection.DeserializePagedModelDataCollection(document.RootElement); |
| 1 | 120 | | return Response.FromValue(value, message.Response); |
| | 121 | | } |
| | 122 | | default: |
| 0 | 123 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 124 | | } |
| 1 | 125 | | } |
| | 126 | |
|
| | 127 | | internal HttpMessage CreateGetByIdRequest(string id, bool? includeModelDefinition) |
| | 128 | | { |
| 48 | 129 | | var message = _pipeline.CreateMessage(); |
| 48 | 130 | | var request = message.Request; |
| 48 | 131 | | request.Method = RequestMethod.Get; |
| 48 | 132 | | var uri = new RawRequestUriBuilder(); |
| 48 | 133 | | uri.Reset(endpoint); |
| 48 | 134 | | uri.AppendPath("/models/", false); |
| 48 | 135 | | uri.AppendPath(id, true); |
| 48 | 136 | | if (includeModelDefinition != null) |
| | 137 | | { |
| 48 | 138 | | uri.AppendQuery("includeModelDefinition", includeModelDefinition.Value, true); |
| | 139 | | } |
| 48 | 140 | | uri.AppendQuery("api-version", apiVersion, true); |
| 48 | 141 | | request.Uri = uri; |
| 48 | 142 | | return message; |
| | 143 | | } |
| | 144 | |
|
| | 145 | | /// <summary> |
| | 146 | | /// Retrieves model metadata and optionally the model definition. |
| | 147 | | /// Status codes: |
| | 148 | | /// 200 (OK): Success. |
| | 149 | | /// 404 (Not Found): There is no model with the provided id. |
| | 150 | | /// </summary> |
| | 151 | | /// <param name="id"> The id for the model. The id is globally unique and case sensitive. </param> |
| | 152 | | /// <param name="includeModelDefinition"> When true the model definition will be returned as part of the result. |
| | 153 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 154 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 155 | | public async Task<Response<ModelData>> GetByIdAsync(string id, bool? includeModelDefinition = null, Cancellation |
| | 156 | | { |
| 24 | 157 | | if (id == null) |
| | 158 | | { |
| 0 | 159 | | throw new ArgumentNullException(nameof(id)); |
| | 160 | | } |
| | 161 | |
|
| 24 | 162 | | using var message = CreateGetByIdRequest(id, includeModelDefinition); |
| 24 | 163 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 24 | 164 | | switch (message.Response.Status) |
| | 165 | | { |
| | 166 | | case 200: |
| | 167 | | { |
| | 168 | | ModelData value = default; |
| 6 | 169 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 6 | 170 | | value = ModelData.DeserializeModelData(document.RootElement); |
| 6 | 171 | | return Response.FromValue(value, message.Response); |
| | 172 | | } |
| | 173 | | default: |
| 18 | 174 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 175 | | } |
| 6 | 176 | | } |
| | 177 | |
|
| | 178 | | /// <summary> |
| | 179 | | /// Retrieves model metadata and optionally the model definition. |
| | 180 | | /// Status codes: |
| | 181 | | /// 200 (OK): Success. |
| | 182 | | /// 404 (Not Found): There is no model with the provided id. |
| | 183 | | /// </summary> |
| | 184 | | /// <param name="id"> The id for the model. The id is globally unique and case sensitive. </param> |
| | 185 | | /// <param name="includeModelDefinition"> When true the model definition will be returned as part of the result. |
| | 186 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 187 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 188 | | public Response<ModelData> GetById(string id, bool? includeModelDefinition = null, CancellationToken cancellatio |
| | 189 | | { |
| 24 | 190 | | if (id == null) |
| | 191 | | { |
| 0 | 192 | | throw new ArgumentNullException(nameof(id)); |
| | 193 | | } |
| | 194 | |
|
| 24 | 195 | | using var message = CreateGetByIdRequest(id, includeModelDefinition); |
| 24 | 196 | | _pipeline.Send(message, cancellationToken); |
| 24 | 197 | | switch (message.Response.Status) |
| | 198 | | { |
| | 199 | | case 200: |
| | 200 | | { |
| | 201 | | ModelData value = default; |
| 6 | 202 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 6 | 203 | | value = ModelData.DeserializeModelData(document.RootElement); |
| 6 | 204 | | return Response.FromValue(value, message.Response); |
| | 205 | | } |
| | 206 | | default: |
| 18 | 207 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 208 | | } |
| 6 | 209 | | } |
| | 210 | |
|
| | 211 | | internal HttpMessage CreateUpdateRequest(string id, IEnumerable<object> updateModel) |
| | 212 | | { |
| 0 | 213 | | var message = _pipeline.CreateMessage(); |
| 0 | 214 | | var request = message.Request; |
| 0 | 215 | | request.Method = RequestMethod.Patch; |
| 0 | 216 | | var uri = new RawRequestUriBuilder(); |
| 0 | 217 | | uri.Reset(endpoint); |
| 0 | 218 | | uri.AppendPath("/models/", false); |
| 0 | 219 | | uri.AppendPath(id, true); |
| 0 | 220 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 221 | | request.Uri = uri; |
| 0 | 222 | | request.Headers.Add("Content-Type", "application/json-patch+json"); |
| 0 | 223 | | var content = new Utf8JsonRequestContent(); |
| 0 | 224 | | content.JsonWriter.WriteStartArray(); |
| 0 | 225 | | foreach (var item in updateModel) |
| | 226 | | { |
| 0 | 227 | | content.JsonWriter.WriteObjectValue(item); |
| | 228 | | } |
| 0 | 229 | | content.JsonWriter.WriteEndArray(); |
| 0 | 230 | | request.Content = content; |
| 0 | 231 | | return message; |
| | 232 | | } |
| | 233 | |
|
| | 234 | | internal HttpMessage CreateDeleteRequest(string id) |
| | 235 | | { |
| 24 | 236 | | var message = _pipeline.CreateMessage(); |
| 24 | 237 | | var request = message.Request; |
| 24 | 238 | | request.Method = RequestMethod.Delete; |
| 24 | 239 | | var uri = new RawRequestUriBuilder(); |
| 24 | 240 | | uri.Reset(endpoint); |
| 24 | 241 | | uri.AppendPath("/models/", false); |
| 24 | 242 | | uri.AppendPath(id, true); |
| 24 | 243 | | uri.AppendQuery("api-version", apiVersion, true); |
| 24 | 244 | | request.Uri = uri; |
| 24 | 245 | | return message; |
| | 246 | | } |
| | 247 | |
|
| | 248 | | /// <summary> |
| | 249 | | /// Deletes a model. A model can only be deleted if no other models reference it. |
| | 250 | | /// Status codes: |
| | 251 | | /// 204 (No Content): Success. |
| | 252 | | /// 400 (Bad Request): The request is invalid. |
| | 253 | | /// 404 (Not Found): There is no model with the provided id. |
| | 254 | | /// 409 (Conflict): There are dependencies on the model that prevent it from being deleted. |
| | 255 | | /// </summary> |
| | 256 | | /// <param name="id"> The id for the model. The id is globally unique and case sensitive. </param> |
| | 257 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 258 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 259 | | public async Task<Response> DeleteAsync(string id, CancellationToken cancellationToken = default) |
| | 260 | | { |
| 12 | 261 | | if (id == null) |
| | 262 | | { |
| 0 | 263 | | throw new ArgumentNullException(nameof(id)); |
| | 264 | | } |
| | 265 | |
|
| 12 | 266 | | using var message = CreateDeleteRequest(id); |
| 12 | 267 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 12 | 268 | | switch (message.Response.Status) |
| | 269 | | { |
| | 270 | | case 204: |
| 12 | 271 | | return message.Response; |
| | 272 | | default: |
| 0 | 273 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 274 | | } |
| 12 | 275 | | } |
| | 276 | |
|
| | 277 | | /// <summary> |
| | 278 | | /// Deletes a model. A model can only be deleted if no other models reference it. |
| | 279 | | /// Status codes: |
| | 280 | | /// 204 (No Content): Success. |
| | 281 | | /// 400 (Bad Request): The request is invalid. |
| | 282 | | /// 404 (Not Found): There is no model with the provided id. |
| | 283 | | /// 409 (Conflict): There are dependencies on the model that prevent it from being deleted. |
| | 284 | | /// </summary> |
| | 285 | | /// <param name="id"> The id for the model. The id is globally unique and case sensitive. </param> |
| | 286 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 287 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 288 | | public Response Delete(string id, CancellationToken cancellationToken = default) |
| | 289 | | { |
| 12 | 290 | | if (id == null) |
| | 291 | | { |
| 0 | 292 | | throw new ArgumentNullException(nameof(id)); |
| | 293 | | } |
| | 294 | |
|
| 12 | 295 | | using var message = CreateDeleteRequest(id); |
| 12 | 296 | | _pipeline.Send(message, cancellationToken); |
| 12 | 297 | | switch (message.Response.Status) |
| | 298 | | { |
| | 299 | | case 204: |
| 12 | 300 | | return message.Response; |
| | 301 | | default: |
| 0 | 302 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 303 | | } |
| 12 | 304 | | } |
| | 305 | |
|
| | 306 | | internal HttpMessage CreateListNextPageRequest(string nextLink, IEnumerable<string> dependenciesFor, bool? inclu |
| | 307 | | { |
| 0 | 308 | | var message = _pipeline.CreateMessage(); |
| 0 | 309 | | var request = message.Request; |
| 0 | 310 | | request.Method = RequestMethod.Get; |
| 0 | 311 | | var uri = new RawRequestUriBuilder(); |
| 0 | 312 | | uri.Reset(endpoint); |
| 0 | 313 | | uri.AppendRawNextLink(nextLink, false); |
| 0 | 314 | | request.Uri = uri; |
| 0 | 315 | | if (digitalTwinModelsListOptions?.MaxItemCount != null) |
| | 316 | | { |
| 0 | 317 | | request.Headers.Add("x-ms-max-item-count", digitalTwinModelsListOptions.MaxItemCount.Value); |
| | 318 | | } |
| 0 | 319 | | return message; |
| | 320 | | } |
| | 321 | |
|
| | 322 | | /// <summary> |
| | 323 | | /// Retrieves model metadata and, optionally, model definitions. |
| | 324 | | /// Status codes: |
| | 325 | | /// 200 (OK): Success. |
| | 326 | | /// 400 (Bad Request): The request is invalid. |
| | 327 | | /// </summary> |
| | 328 | | /// <param name="nextLink"> The URL to the next page of results. </param> |
| | 329 | | /// <param name="dependenciesFor"> The set of the models which will have their dependencies retrieved. If omitte |
| | 330 | | /// <param name="includeModelDefinition"> When true the model definition will be returned as part of the result. |
| | 331 | | /// <param name="digitalTwinModelsListOptions"> Parameter group. </param> |
| | 332 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 333 | | /// <exception cref="ArgumentNullException"> <paramref name="nextLink"/> is null. </exception> |
| | 334 | | public async Task<Response<PagedModelDataCollection>> ListNextPageAsync(string nextLink, IEnumerable<string> dep |
| | 335 | | { |
| 0 | 336 | | if (nextLink == null) |
| | 337 | | { |
| 0 | 338 | | throw new ArgumentNullException(nameof(nextLink)); |
| | 339 | | } |
| | 340 | |
|
| 0 | 341 | | using var message = CreateListNextPageRequest(nextLink, dependenciesFor, includeModelDefinition, digitalTwin |
| 0 | 342 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 343 | | switch (message.Response.Status) |
| | 344 | | { |
| | 345 | | case 200: |
| | 346 | | { |
| | 347 | | PagedModelDataCollection value = default; |
| 0 | 348 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 349 | | value = PagedModelDataCollection.DeserializePagedModelDataCollection(document.RootElement); |
| 0 | 350 | | return Response.FromValue(value, message.Response); |
| | 351 | | } |
| | 352 | | default: |
| 0 | 353 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 354 | | } |
| 0 | 355 | | } |
| | 356 | |
|
| | 357 | | /// <summary> |
| | 358 | | /// Retrieves model metadata and, optionally, model definitions. |
| | 359 | | /// Status codes: |
| | 360 | | /// 200 (OK): Success. |
| | 361 | | /// 400 (Bad Request): The request is invalid. |
| | 362 | | /// </summary> |
| | 363 | | /// <param name="nextLink"> The URL to the next page of results. </param> |
| | 364 | | /// <param name="dependenciesFor"> The set of the models which will have their dependencies retrieved. If omitte |
| | 365 | | /// <param name="includeModelDefinition"> When true the model definition will be returned as part of the result. |
| | 366 | | /// <param name="digitalTwinModelsListOptions"> Parameter group. </param> |
| | 367 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 368 | | /// <exception cref="ArgumentNullException"> <paramref name="nextLink"/> is null. </exception> |
| | 369 | | public Response<PagedModelDataCollection> ListNextPage(string nextLink, IEnumerable<string> dependenciesFor = nu |
| | 370 | | { |
| 0 | 371 | | if (nextLink == null) |
| | 372 | | { |
| 0 | 373 | | throw new ArgumentNullException(nameof(nextLink)); |
| | 374 | | } |
| | 375 | |
|
| 0 | 376 | | using var message = CreateListNextPageRequest(nextLink, dependenciesFor, includeModelDefinition, digitalTwin |
| 0 | 377 | | _pipeline.Send(message, cancellationToken); |
| 0 | 378 | | switch (message.Response.Status) |
| | 379 | | { |
| | 380 | | case 200: |
| | 381 | | { |
| | 382 | | PagedModelDataCollection value = default; |
| 0 | 383 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 384 | | value = PagedModelDataCollection.DeserializePagedModelDataCollection(document.RootElement); |
| 0 | 385 | | return Response.FromValue(value, message.Response); |
| | 386 | | } |
| | 387 | | default: |
| 0 | 388 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 389 | | } |
| 0 | 390 | | } |
| | 391 | | } |
| | 392 | | } |