diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/DigitalTwinModelsRestClient.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/DigitalTwinModelsRestClient.cs index 69af707455d29..313135c44490d 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/DigitalTwinModelsRestClient.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/DigitalTwinModelsRestClient.cs @@ -16,7 +16,10 @@ internal partial class DigitalTwinModelsRestClient { // The modelUpdates parameter needs to be changed from IEnumerable to IEnumerable // and not parsed like a json object. - internal async Task>> AddAsync(IEnumerable models = null, CreateModelsOptions digitalTwinModelsAddOptions = null, CancellationToken cancellationToken = default) + internal async Task>> AddAsync( + IEnumerable models = null, + CreateModelsOptions digitalTwinModelsAddOptions = null, + CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope("DigitalTwinModelsClient.Add"); scope.Start(); @@ -30,7 +33,9 @@ internal async Task>> AddAsync(IEn case 201: { IReadOnlyList value = default; - using JsonDocument document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + using JsonDocument document = await JsonDocument + .ParseAsync(message.Response.ContentStream, default, cancellationToken) + .ConfigureAwait(false); List array = new List(document.RootElement.GetArrayLength()); foreach (JsonElement item in document.RootElement.EnumerateArray()) { @@ -52,7 +57,10 @@ internal async Task>> AddAsync(IEn // The modelUpdates parameter needs to be changed from IEnumerable to IEnumerable // and not parsed like a json object. - internal Response> Add(IEnumerable models = null, CreateModelsOptions digitalTwinModelsAddOptions = null, CancellationToken cancellationToken = default) + internal Response> Add( + IEnumerable models = null, + CreateModelsOptions digitalTwinModelsAddOptions = null, + CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope("DigitalTwinModelsClient.Add"); scope.Start(); @@ -88,7 +96,11 @@ internal Response> Add(IEnumerable // The modelUpdates parameter needs to be changed from IEnumerable to IEnumerable // and not parsed like a json object. - internal async Task UpdateAsync(string id, IEnumerable modelUpdates, DecomissionModelOptions digitalTwinModelsUpdateOptions = null, CancellationToken cancellationToken = default) + internal async Task UpdateAsync( + string id, + IEnumerable modelUpdates, + DecommissionModelOptions digitalTwinModelsUpdateOptions = null, + CancellationToken cancellationToken = default) { if (id == null) { @@ -120,7 +132,11 @@ internal async Task UpdateAsync(string id, IEnumerable modelUp // The modelUpdates parameter needs to be changed from IEnumerable to IEnumerable // and not parsed like a json object. - internal Response Update(string id, IEnumerable modelUpdates, DecomissionModelOptions digitalTwinModelsUpdateOptions = null, CancellationToken cancellationToken = default) + internal Response Update( + string id, + IEnumerable modelUpdates, + DecommissionModelOptions digitalTwinModelsUpdateOptions = null, + CancellationToken cancellationToken = default) { if (id == null) { @@ -182,7 +198,7 @@ private HttpMessage CreateAddRequest(IEnumerable models, CreateModelsOpt // The strings are already json, so we do not want them to be serialized. // Instead, the payloads need to be concatenated into a json array. - private HttpMessage CreateUpdateRequest(string id, IEnumerable modelUpdates, DecomissionModelOptions digitalTwinModelsUpdateOptions) + private HttpMessage CreateUpdateRequest(string id, IEnumerable modelUpdates, DecommissionModelOptions digitalTwinModelsUpdateOptions) { var message = _pipeline.CreateMessage(); var request = message.Request; diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/DigitalTwinsRestClient.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/DigitalTwinsRestClient.cs index 1722cf40477de..775f33f8943a4 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/DigitalTwinsRestClient.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/DigitalTwinsRestClient.cs @@ -79,6 +79,7 @@ internal async Task> AddAsync( } case 202: return Response.FromValue(null, message.Response); + default: throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); } @@ -90,7 +91,11 @@ internal async Task> AddAsync( } } - internal Response Add(string id, Stream twin, CreateOrReplaceDigitalTwinOptions digitalTwinsAddOptions = null, CancellationToken cancellationToken = default) + internal Response Add( + string id, + Stream twin, + CreateOrReplaceDigitalTwinOptions digitalTwinsAddOptions = null, + CancellationToken cancellationToken = default) { if (id == null) { @@ -112,6 +117,7 @@ internal Response Add(string id, Stream twin, CreateOrReplaceDigitalTwin } case 202: return Response.FromValue(null, message.Response); + default: throw _clientDiagnostics.CreateRequestFailedException(message.Response); } @@ -760,10 +766,10 @@ private HttpMessage CreateUpdateRequest( } private HttpMessage CreateAddRelationshipRequest( - string id, - string relationshipId, - Stream relationship, - CreateOrReplaceRelationshipOptions digitalTwinsAddRelationshipOptions) + string id, + string relationshipId, + Stream relationship, + CreateOrReplaceRelationshipOptions digitalTwinsAddRelationshipOptions) { HttpMessage message = _pipeline.CreateMessage(); Request request = message.Request; diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/Models/DecomissionModelOptions.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/Models/DecommissionModelOptions.cs similarity index 94% rename from sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/Models/DecomissionModelOptions.cs rename to sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/Models/DecommissionModelOptions.cs index 0fe1f3b700aa5..f1db0a33f6b6a 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/Models/DecomissionModelOptions.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Customized/Models/DecommissionModelOptions.cs @@ -7,7 +7,7 @@ namespace Azure.DigitalTwins.Core { /// [CodeGenModel("DigitalTwinModelsUpdateOptions")] - internal partial class DecomissionModelOptions + internal partial class DecommissionModelOptions { // This class declaration changes the namespace, class name and property visibility; do not remove. diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/DigitalTwinsClient.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/DigitalTwinsClient.cs index af67a049af5b9..a3086a6ac4f35 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/DigitalTwinsClient.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/DigitalTwinsClient.cs @@ -159,16 +159,20 @@ public virtual async Task> GetDigitalTwinAsync(string digitalTwin try { // Get the digital twin as a stream object - Response digitalTwinStream = await _dtRestClient.GetByIdAsync(digitalTwinId, null, cancellationToken).ConfigureAwait(false); + Response digitalTwinStream = await _dtRestClient + .GetByIdAsync(digitalTwinId, null, cancellationToken) + .ConfigureAwait(false); // Deserialize the stream into the specified type - T deserializedDigitalTwin = (T)await _objectSerializer.DeserializeAsync(digitalTwinStream, typeof(T), cancellationToken).ConfigureAwait(false); + T deserializedDigitalTwin = (T)await _objectSerializer + .DeserializeAsync(digitalTwinStream, typeof(T), cancellationToken) + .ConfigureAwait(false); return Response.FromValue(deserializedDigitalTwin, digitalTwinStream.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -213,9 +217,9 @@ public virtual Response GetDigitalTwin(string digitalTwinId, CancellationT return Response.FromValue(deserializedDigitalTwin, digitalTwinStream.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -281,22 +285,27 @@ public virtual async Task> CreateOrReplaceDigitalTwinAsync( try { // Serialize the digital twin object and write it to a stream - using MemoryStream memoryStream = await WriteToStreamAsync(digitalTwin, _objectSerializer, cancellationToken).ConfigureAwait(false); + using MemoryStream memoryStream = await WriteToStreamAsync(digitalTwin, _objectSerializer, cancellationToken) + .ConfigureAwait(false); // Get the response of the digital twin as a stream object - CreateOrReplaceDigitalTwinOptions options = ifNoneMatch != null ? - new CreateOrReplaceDigitalTwinOptions { IfNoneMatch = ifNoneMatch.Value.ToString() } : - null; - Response digitalTwinStream = await _dtRestClient.AddAsync(digitalTwinId, memoryStream, options, cancellationToken).ConfigureAwait(false); + CreateOrReplaceDigitalTwinOptions options = ifNoneMatch == null + ? null + : new CreateOrReplaceDigitalTwinOptions { IfNoneMatch = ifNoneMatch.Value.ToString() }; + Response digitalTwinStream = await _dtRestClient + .AddAsync(digitalTwinId, memoryStream, options, cancellationToken) + .ConfigureAwait(false); // Deserialize the stream into the specified type - T deserializedDigitalTwin = (T)await _objectSerializer.DeserializeAsync(digitalTwinStream, typeof(T), cancellationToken).ConfigureAwait(false); + T deserializedDigitalTwin = (T)await _objectSerializer + .DeserializeAsync(digitalTwinStream, typeof(T), cancellationToken) + .ConfigureAwait(false); return Response.FromValue(deserializedDigitalTwin, digitalTwinStream.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -347,9 +356,9 @@ public virtual Response CreateOrReplaceDigitalTwin( using MemoryStream memoryStream = WriteToStream(digitalTwin, _objectSerializer, cancellationToken); // Get the response of the digital twin as a stream object - CreateOrReplaceDigitalTwinOptions options = ifNoneMatch != null ? - new CreateOrReplaceDigitalTwinOptions { IfNoneMatch = ifNoneMatch.Value.ToString() } : - null; + CreateOrReplaceDigitalTwinOptions options = ifNoneMatch == null + ? null + : new CreateOrReplaceDigitalTwinOptions { IfNoneMatch = ifNoneMatch.Value.ToString() }; Response digitalTwinStream = _dtRestClient.Add(digitalTwinId, memoryStream, options, cancellationToken); // Deserialize the stream into the specified type @@ -357,9 +366,9 @@ public virtual Response CreateOrReplaceDigitalTwin( return Response.FromValue(deserializedDigitalTwin, digitalTwinStream.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -397,14 +406,14 @@ public virtual async Task DeleteDigitalTwinAsync(string digitalTwinId, try { - DeleteDigitalTwinOptions options = ifMatch != null ? - new DeleteDigitalTwinOptions { IfMatch = ifMatch.Value.ToString() } : - null; + DeleteDigitalTwinOptions options = ifMatch == null + ? null + : new DeleteDigitalTwinOptions { IfMatch = ifMatch.Value.ToString() }; return await _dtRestClient.DeleteAsync(digitalTwinId, options, cancellationToken).ConfigureAwait(false); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -438,14 +447,14 @@ public virtual Response DeleteDigitalTwin(string digitalTwinId, ETag? ifMatch = try { - DeleteDigitalTwinOptions options = ifMatch != null ? - new DeleteDigitalTwinOptions { IfMatch = ifMatch.Value.ToString() } : - null; + DeleteDigitalTwinOptions options = ifMatch == null + ? null + : new DeleteDigitalTwinOptions { IfMatch = ifMatch.Value.ToString() }; return _dtRestClient.Delete(digitalTwinId, options, cancellationToken); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -476,14 +485,16 @@ public virtual async Task UpdateDigitalTwinAsync(string digitalTwinId, try { Argument.AssertNotNull(jsonPatchDocument, nameof(jsonPatchDocument)); - UpdateDigitalTwinOptions options = ifMatch != null ? - new UpdateDigitalTwinOptions { IfMatch = ifMatch.Value.ToString() } : - null; - return await _dtRestClient.UpdateAsync(digitalTwinId, jsonPatchDocument.ToString(), options, cancellationToken).ConfigureAwait(false); + UpdateDigitalTwinOptions options = ifMatch == null + ? null + : new UpdateDigitalTwinOptions { IfMatch = ifMatch.Value.ToString() }; + return await _dtRestClient + .UpdateAsync(digitalTwinId, jsonPatchDocument.ToString(), options, cancellationToken) + .ConfigureAwait(false); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -517,14 +528,14 @@ public virtual Response UpdateDigitalTwin(string digitalTwinId, JsonPatchDocumen try { Argument.AssertNotNull(jsonPatchDocument, nameof(jsonPatchDocument)); - UpdateDigitalTwinOptions options = ifMatch != null ? - new UpdateDigitalTwinOptions { IfMatch = ifMatch.Value.ToString() } : - null; + UpdateDigitalTwinOptions options = ifMatch == null + ? null + : new UpdateDigitalTwinOptions { IfMatch = ifMatch.Value.ToString() }; return _dtRestClient.Update(digitalTwinId, jsonPatchDocument.ToString(), options, cancellationToken); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -561,16 +572,20 @@ public virtual async Task> GetComponentAsync(string digitalTwinId try { // Get the component as a stream object - Response componentStream = await _dtRestClient.GetComponentAsync(digitalTwinId, componentName, null, cancellationToken).ConfigureAwait(false); + Response componentStream = await _dtRestClient + .GetComponentAsync(digitalTwinId, componentName, null, cancellationToken) + .ConfigureAwait(false); // Deserialize the stream into the specified type - T deserializedComponent = (T)await _objectSerializer.DeserializeAsync(componentStream, typeof(T), cancellationToken).ConfigureAwait(false); + T deserializedComponent = (T)await _objectSerializer + .DeserializeAsync(componentStream, typeof(T), cancellationToken) + .ConfigureAwait(false); return Response.FromValue(deserializedComponent, componentStream.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -612,9 +627,9 @@ public virtual Response GetComponent(string digitalTwinId, string componen return Response.FromValue(deserializedComponent, componentStream.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -647,7 +662,12 @@ public virtual Response GetComponent(string digitalTwinId, string componen /// Console.WriteLine($"Updated component for digital twin '{basicDtId}'."); /// /// - public virtual async Task UpdateComponentAsync(string digitalTwinId, string componentName, JsonPatchDocument jsonPatchDocument, ETag? ifMatch = null, CancellationToken cancellationToken = default) + public virtual async Task UpdateComponentAsync( + string digitalTwinId, + string componentName, + JsonPatchDocument jsonPatchDocument, + ETag? ifMatch = null, + CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DigitalTwinsClient)}.{nameof(UpdateComponent)}"); scope.AddAttribute(nameof(digitalTwinId), digitalTwinId); @@ -657,20 +677,22 @@ public virtual async Task UpdateComponentAsync(string digitalTwinId, s try { Argument.AssertNotNull(jsonPatchDocument, nameof(jsonPatchDocument)); - UpdateComponentOptions options = ifMatch != null ? - new UpdateComponentOptions { IfMatch = ifMatch.Value.ToString() } : - null; + UpdateComponentOptions options = ifMatch == null + ? null + : new UpdateComponentOptions { IfMatch = ifMatch.Value.ToString() }; - return await _dtRestClient.UpdateComponentAsync( - digitalTwinId, - componentName, - jsonPatchDocument.ToString(), - options, - cancellationToken).ConfigureAwait(false); + return await _dtRestClient + .UpdateComponentAsync( + digitalTwinId, + componentName, + jsonPatchDocument.ToString(), + options, + cancellationToken) + .ConfigureAwait(false); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -696,7 +718,12 @@ public virtual async Task UpdateComponentAsync(string digitalTwinId, s /// /// See the asynchronous version of this method for examples. /// - public virtual Response UpdateComponent(string digitalTwinId, string componentName, JsonPatchDocument jsonPatchDocument, ETag? ifMatch = null, CancellationToken cancellationToken = default) + public virtual Response UpdateComponent( + string digitalTwinId, + string componentName, + JsonPatchDocument jsonPatchDocument, + ETag? ifMatch = null, + CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DigitalTwinsClient)}.{nameof(UpdateComponent)}"); scope.AddAttribute(nameof(digitalTwinId), digitalTwinId); @@ -706,14 +733,14 @@ public virtual Response UpdateComponent(string digitalTwinId, string componentNa try { Argument.AssertNotNull(jsonPatchDocument, nameof(jsonPatchDocument)); - UpdateComponentOptions options = ifMatch != null ? - new UpdateComponentOptions { IfMatch = ifMatch.Value.ToString() } : - null; + UpdateComponentOptions options = ifMatch == null + ? null + : new UpdateComponentOptions { IfMatch = ifMatch.Value.ToString() }; return _dtRestClient.UpdateComponent(digitalTwinId, componentName, jsonPatchDocument.ToString(), options, cancellationToken); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -754,7 +781,10 @@ public virtual Response UpdateComponent(string digitalTwinId, string componentNa /// } /// /// - public virtual AsyncPageable GetRelationshipsAsync(string digitalTwinId, string relationshipName = null, CancellationToken cancellationToken = default) + public virtual AsyncPageable GetRelationshipsAsync( + string digitalTwinId, + string relationshipName = null, + CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DigitalTwinsClient)}.{nameof(GetRelationships)}"); scope.AddAttribute(nameof(digitalTwinId), digitalTwinId); @@ -806,9 +836,9 @@ async Task> NextPageFunc(string nextLink, int? pageSizeHint) return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -883,9 +913,9 @@ Page NextPageFunc(string nextLink, int? pageSizeHint) return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -929,7 +959,9 @@ async Task> FirstPageFunc(int? pageSizeHint) scope.Start(); try { - Response response = await _dtRestClient.ListIncomingRelationshipsAsync(digitalTwinId, null, cancellationToken).ConfigureAwait(false); + Response response = await _dtRestClient + .ListIncomingRelationshipsAsync(digitalTwinId, null, cancellationToken) + .ConfigureAwait(false); return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); } catch (Exception ex) @@ -945,7 +977,9 @@ async Task> NextPageFunc(string nextLink, int? pageSi scope.Start(); try { - Response response = await _dtRestClient.ListIncomingRelationshipsNextPageAsync(nextLink, digitalTwinId, null, cancellationToken).ConfigureAwait(false); + Response response = await _dtRestClient + .ListIncomingRelationshipsNextPageAsync(nextLink, digitalTwinId, null, cancellationToken) + .ConfigureAwait(false); return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); } catch (Exception ex) @@ -957,9 +991,9 @@ async Task> NextPageFunc(string nextLink, int? pageSi return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -999,9 +1033,9 @@ Page FirstPageFunc(int? pageSizeHint) Response response = _dtRestClient.ListIncomingRelationships(digitalTwinId, null, cancellationToken); return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -1015,18 +1049,18 @@ Page NextPageFunc(string nextLink, int? pageSizeHint) Response response = _dtRestClient.ListIncomingRelationshipsNextPage(nextLink, digitalTwinId, null, cancellationToken); return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -1082,9 +1116,9 @@ public virtual async Task> GetRelationshipAsync( return Response.FromValue(deserializedRelationship, relationshipStream.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -1129,9 +1163,9 @@ public virtual Response GetRelationship( return Response.FromValue(deserializedRelationship, relationshipStream.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -1167,9 +1201,9 @@ public virtual async Task DeleteRelationshipAsync(string digitalTwinId null; return await _dtRestClient.DeleteRelationshipAsync(digitalTwinId, relationshipId, options, cancellationToken).ConfigureAwait(false); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -1203,14 +1237,14 @@ public virtual Response DeleteRelationship(string digitalTwinId, string relation try { - DeleteRelationshipOptions options = ifMatch != null ? - new DeleteRelationshipOptions { IfMatch = ifMatch.Value.ToString() } : - null; + DeleteRelationshipOptions options = ifMatch == null + ? null + : new DeleteRelationshipOptions { IfMatch = ifMatch.Value.ToString() }; return _dtRestClient.DeleteRelationship(digitalTwinId, relationshipId, options, cancellationToken); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -1283,22 +1317,27 @@ public virtual async Task> CreateOrReplaceRelationshipAsync( try { // Serialize the relationship and write it to a stream - using MemoryStream memoryStream = await WriteToStreamAsync(relationship, _objectSerializer, cancellationToken).ConfigureAwait(false); + using MemoryStream memoryStream = await WriteToStreamAsync(relationship, _objectSerializer, cancellationToken) + .ConfigureAwait(false); // Get the response component as a stream object - CreateOrReplaceRelationshipOptions options = ifNoneMatch != null ? - new CreateOrReplaceRelationshipOptions { IfNoneMatch = ifNoneMatch.Value.ToString() } : - null; - Response relationshipStream = await _dtRestClient.AddRelationshipAsync(digitalTwinId, relationshipId, memoryStream, options, cancellationToken).ConfigureAwait(false); + CreateOrReplaceRelationshipOptions options = ifNoneMatch == null + ? null + : new CreateOrReplaceRelationshipOptions { IfNoneMatch = ifNoneMatch.Value.ToString() }; + Response relationshipStream = await _dtRestClient + .AddRelationshipAsync(digitalTwinId, relationshipId, memoryStream, options, cancellationToken) + .ConfigureAwait(false); // Deserialize the stream into the specified type - T deserializedRelationship = (T)await _objectSerializer.DeserializeAsync(relationshipStream, typeof(T), cancellationToken).ConfigureAwait(false); + T deserializedRelationship = (T)await _objectSerializer + .DeserializeAsync(relationshipStream, typeof(T), cancellationToken) + .ConfigureAwait(false); return Response.FromValue(deserializedRelationship, relationshipStream.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -1360,9 +1399,9 @@ public virtual Response CreateOrReplaceRelationship( using MemoryStream memoryStream = WriteToStream(relationship, _objectSerializer, cancellationToken); // Get the response relationship as a stream object - CreateOrReplaceRelationshipOptions options = ifNoneMatch != null ? - new CreateOrReplaceRelationshipOptions { IfNoneMatch = ifNoneMatch.Value.ToString() } : - null; + CreateOrReplaceRelationshipOptions options = ifNoneMatch == null + ? null + : new CreateOrReplaceRelationshipOptions { IfNoneMatch = ifNoneMatch.Value.ToString() }; Response relationshipStream = _dtRestClient.AddRelationship(digitalTwinId, relationshipId, memoryStream, options, cancellationToken); // Deserialize the stream into the specified type @@ -1370,9 +1409,9 @@ public virtual Response CreateOrReplaceRelationship( return Response.FromValue(deserializedRelationship, relationshipStream.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -1395,7 +1434,12 @@ public virtual Response CreateOrReplaceRelationship( /// /// The exception is thrown when or is null. /// - public virtual async Task UpdateRelationshipAsync(string digitalTwinId, string relationshipId, JsonPatchDocument jsonPatchDocument, ETag? ifMatch = null, CancellationToken cancellationToken = default) + public virtual async Task UpdateRelationshipAsync( + string digitalTwinId, + string relationshipId, + JsonPatchDocument jsonPatchDocument, + ETag? ifMatch = null, + CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DigitalTwinsClient)}.{nameof(UpdateRelationship)}"); scope.AddAttribute(nameof(digitalTwinId), digitalTwinId); @@ -1405,19 +1449,21 @@ public virtual async Task UpdateRelationshipAsync(string digitalTwinId try { Argument.AssertNotNull(jsonPatchDocument, nameof(jsonPatchDocument)); - UpdateRelationshipOptions options = ifMatch != null ? - new UpdateRelationshipOptions { IfMatch = ifMatch.Value.ToString() } : - null; - return await _dtRestClient.UpdateRelationshipAsync( - digitalTwinId, - relationshipId, - jsonPatchDocument.ToString(), - options, - cancellationToken).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); + UpdateRelationshipOptions options = ifMatch == null + ? null + : new UpdateRelationshipOptions { IfMatch = ifMatch.Value.ToString() }; + return await _dtRestClient + .UpdateRelationshipAsync( + digitalTwinId, + relationshipId, + jsonPatchDocument.ToString(), + options, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); throw; } } @@ -1443,7 +1489,12 @@ public virtual async Task UpdateRelationshipAsync(string digitalTwinId /// /// See the asynchronous version of this method for examples. /// - public virtual Response UpdateRelationship(string digitalTwinId, string relationshipId, JsonPatchDocument jsonPatchDocument, ETag? ifMatch = null, CancellationToken cancellationToken = default) + public virtual Response UpdateRelationship( + string digitalTwinId, + string relationshipId, + JsonPatchDocument jsonPatchDocument, + ETag? ifMatch = null, + CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DigitalTwinsClient)}.{nameof(UpdateRelationship)}"); scope.AddAttribute(nameof(digitalTwinId), digitalTwinId); @@ -1453,14 +1504,14 @@ public virtual Response UpdateRelationship(string digitalTwinId, string relation try { Argument.AssertNotNull(jsonPatchDocument, nameof(jsonPatchDocument)); - UpdateRelationshipOptions options = ifMatch != null ? - new UpdateRelationshipOptions { IfMatch = ifMatch.Value.ToString() } : - null; + UpdateRelationshipOptions options = ifMatch == null + ? null + : new UpdateRelationshipOptions { IfMatch = ifMatch.Value.ToString() }; return _dtRestClient.UpdateRelationship(digitalTwinId, relationshipId, jsonPatchDocument.ToString(), options, cancellationToken); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -1510,12 +1561,14 @@ async Task> FirstPageFunc(int? pageSizeHint) // Page size hint is only specified by AsPages() methods, so we add it here manually since the user can't set it on the options object directly options.MaxItemsPerPage = pageSizeHint; - Response response = await _dtModelsRestClient.ListAsync(options?.DependenciesFor, options?.IncludeModelDefinition, options, cancellationToken).ConfigureAwait(false); + Response response = await _dtModelsRestClient + .ListAsync(options?.DependenciesFor, options?.IncludeModelDefinition, options, cancellationToken) + .ConfigureAwait(false); return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -1534,21 +1587,23 @@ async Task> NextPageFunc(string nextLink, int? pageS // Page size hint is only specified by AsPages() methods, so we add it here manually since the user can't set it on the options object directly options.MaxItemsPerPage = pageSizeHint; - Response response = await _dtModelsRestClient.ListNextPageAsync(nextLink, options?.DependenciesFor, options?.IncludeModelDefinition, options, cancellationToken).ConfigureAwait(false); + Response response = await _dtModelsRestClient + .ListNextPageAsync(nextLink, options?.DependenciesFor, options?.IncludeModelDefinition, options, cancellationToken) + .ConfigureAwait(false); return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -1581,12 +1636,13 @@ Page FirstPageFunc(int? pageSizeHint) scope.Start(); try { - Response response = _dtModelsRestClient.List(options?.DependenciesFor, options?.IncludeModelDefinition, options, cancellationToken); + Response response = _dtModelsRestClient + .List(options?.DependenciesFor, options?.IncludeModelDefinition, options, cancellationToken); return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -1597,21 +1653,22 @@ Page NextPageFunc(string nextLink, int? pageSizeHint) scope.Start(); try { - Response response = _dtModelsRestClient.ListNextPage(nextLink, options?.DependenciesFor, options?.IncludeModelDefinition, options, cancellationToken); + Response response = _dtModelsRestClient + .ListNextPage(nextLink, options?.DependenciesFor, options?.IncludeModelDefinition, options, cancellationToken); return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -1648,9 +1705,9 @@ public virtual async Task> GetModelAsync(string // The GetModel API will include the model definition in its response by default. return await _dtModelsRestClient.GetByIdAsync(modelId, IncludeModelDefinition, null, cancellationToken).ConfigureAwait(false); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -1684,9 +1741,9 @@ public virtual Response GetModel(string modelId, Cancella // The GetModel API will include the model definition in its response by default. return _dtModelsRestClient.GetById(modelId, IncludeModelDefinition, null, cancellationToken); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -1734,11 +1791,13 @@ public virtual async Task DecommissionModelAsync(string modelId, Cance try { - return await _dtModelsRestClient.UpdateAsync(modelId, ModelsConstants.DecommissionModelOperationList, null, cancellationToken).ConfigureAwait(false); + return await _dtModelsRestClient + .UpdateAsync(modelId, ModelsConstants.DecommissionModelOperationList, null, cancellationToken) + .ConfigureAwait(false); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -1778,9 +1837,9 @@ public virtual Response DecommissionModel(string modelId, CancellationToken canc { return _dtModelsRestClient.Update(modelId, ModelsConstants.DecommissionModelOperationList, null, cancellationToken); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -1818,19 +1877,20 @@ public virtual async Task> CreateModelsAsync(I int index = 1; foreach (var id in dtdlModels) { - scope.AddAttribute("model" + index, id); - index++; + scope.AddAttribute($"model{index++}", id); } scope.Start(); try { - Response> response = await _dtModelsRestClient.AddAsync(dtdlModels, null, cancellationToken).ConfigureAwait(false); + Response> response = await _dtModelsRestClient + .AddAsync(dtdlModels, null, cancellationToken) + .ConfigureAwait(false); return Response.FromValue(response.Value.ToArray(), response.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -1865,8 +1925,7 @@ public virtual Response CreateModels(IEnumerable CreateModels(IEnumerable> response = _dtModelsRestClient.Add(dtdlModels, null, cancellationToken); return Response.FromValue(response.Value.ToArray(), response.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -1930,9 +1989,9 @@ public virtual async Task DeleteModelAsync(string modelId, Cancellatio { return await _dtModelsRestClient.DeleteAsync(modelId, null, cancellationToken).ConfigureAwait(false); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -1975,9 +2034,9 @@ public virtual Response DeleteModel(string modelId, CancellationToken cancellati { return _dtModelsRestClient.Delete(modelId, null, cancellationToken); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -2093,9 +2152,9 @@ async Task> NextPageFunc(string nextLink, int? pageSizeHint) return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -2182,12 +2241,11 @@ Page NextPageFunc(string nextLink, int? pageSizeHint) MaxItemsPerPage = pageSizeHint }; - Response> response = _queryClient - .QueryTwins( - querySpecification, - options, - _objectSerializer, - cancellationToken); + Response> response = _queryClient.QueryTwins( + querySpecification, + options, + _objectSerializer, + cancellationToken); return Page.FromValues(response.Value.Value, response.Value.ContinuationToken, response.GetRawResponse()); } @@ -2200,9 +2258,9 @@ Page NextPageFunc(string nextLink, int? pageSizeHint) return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -2246,12 +2304,14 @@ async Task> FirstPageFunc(int? pageSizeHint) MaxItemsPerPage = pageSizeHint }; - Response response = await _eventRoutesRestClient.ListAsync(options, cancellationToken).ConfigureAwait(false); + Response response = await _eventRoutesRestClient + .ListAsync(options, cancellationToken) + .ConfigureAwait(false); return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -2268,21 +2328,23 @@ async Task> NextPageFunc(string nextLink, int? page MaxItemsPerPage = pageSizeHint }; - Response response = await _eventRoutesRestClient.ListNextPageAsync(nextLink, options, cancellationToken).ConfigureAwait(false); + Response response = await _eventRoutesRestClient + .ListNextPageAsync(nextLink, options, cancellationToken) + .ConfigureAwait(false); return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -2323,9 +2385,9 @@ Page FirstPageFunc(int? pageSizeHint) Response response = _eventRoutesRestClient.List(options, cancellationToken); return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -2346,18 +2408,18 @@ Page NextPageFunc(string nextLink, int? pageSizeHint) Response response = _eventRoutesRestClient.ListNextPage(nextLink, options, cancellationToken); return Page.FromValues(response.Value.Value, response.Value.NextLink, response.GetRawResponse()); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -2387,9 +2449,9 @@ public virtual async Task> GetEventRouteAsync(s { return await _eventRoutesRestClient.GetByIdAsync(eventRouteId, null, cancellationToken).ConfigureAwait(false); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -2422,9 +2484,9 @@ public virtual Response GetEventRoute(string eventRouteI { return _eventRoutesRestClient.GetById(eventRouteId, null, cancellationToken); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -2465,9 +2527,9 @@ public virtual async Task CreateOrReplaceEventRouteAsync(string eventR { return await _eventRoutesRestClient.AddAsync(eventRouteId, eventRoute, null, cancellationToken).ConfigureAwait(false); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -2502,9 +2564,9 @@ public virtual Response CreateOrReplaceEventRoute(string eventRouteId, DigitalTw { return _eventRoutesRestClient.Add(eventRouteId, eventRoute, null, cancellationToken); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -2540,9 +2602,9 @@ public virtual async Task DeleteEventRouteAsync(string eventRouteId, C { return await _eventRoutesRestClient.DeleteAsync(eventRouteId, null, cancellationToken).ConfigureAwait(false); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -2575,9 +2637,9 @@ public virtual Response DeleteEventRoute(string eventRouteId, CancellationToken { return _eventRoutesRestClient.Delete(eventRouteId, null, cancellationToken); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -2635,11 +2697,13 @@ public virtual async Task PublishTelemetryAsync( options.TimeStamp = timestamp.Value; } - return await _dtRestClient.SendTelemetryAsync(digitalTwinId, messageId, payload, options, cancellationToken).ConfigureAwait(false); + return await _dtRestClient + .SendTelemetryAsync(digitalTwinId, messageId, payload, options, cancellationToken) + .ConfigureAwait(false); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -2667,7 +2731,12 @@ public virtual async Task PublishTelemetryAsync( /// /// See the asynchronous version of this method for examples. /// - public virtual Response PublishTelemetry(string digitalTwinId, string messageId, string payload, DateTimeOffset? timestamp = null, CancellationToken cancellationToken = default) + public virtual Response PublishTelemetry( + string digitalTwinId, + string messageId, + string payload, + DateTimeOffset? timestamp = null, + CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(DigitalTwinsClient)}.{nameof(PublishTelemetry)}"); scope.AddAttribute(nameof(digitalTwinId), digitalTwinId); @@ -2690,9 +2759,9 @@ public virtual Response PublishTelemetry(string digitalTwinId, string messageId, return _dtRestClient.SendTelemetry(digitalTwinId, messageId, payload, options, cancellationToken); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -2762,11 +2831,12 @@ public virtual async Task PublishComponentTelemetryAsync( } return await _dtRestClient - .SendComponentTelemetryAsync(digitalTwinId, componentName, messageId, payload, options, cancellationToken).ConfigureAwait(false); + .SendComponentTelemetryAsync(digitalTwinId, componentName, messageId, payload, options, cancellationToken) + .ConfigureAwait(false); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } @@ -2825,9 +2895,9 @@ public virtual Response PublishComponentTelemetry( return _dtRestClient.SendComponentTelemetry(digitalTwinId, componentName, messageId, payload, options, cancellationToken); } - catch (Exception e) + catch (Exception ex) { - scope.Failed(e); + scope.Failed(ex); throw; } } diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Generated/DigitalTwinModelsRestClient.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Generated/DigitalTwinModelsRestClient.cs index 0564801051cf5..0f497e8a0afd4 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Generated/DigitalTwinModelsRestClient.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Generated/DigitalTwinModelsRestClient.cs @@ -330,7 +330,7 @@ public Response GetById(string id, bool? includeModelDefi } } - internal HttpMessage CreateUpdateRequest(string id, IEnumerable updateModel, DecomissionModelOptions digitalTwinModelsUpdateOptions) + internal HttpMessage CreateUpdateRequest(string id, IEnumerable updateModel, DecommissionModelOptions digitalTwinModelsUpdateOptions) { var message = _pipeline.CreateMessage(); var request = message.Request; @@ -372,7 +372,7 @@ internal HttpMessage CreateUpdateRequest(string id, IEnumerable updateMo /// Parameter group. /// The cancellation token to use. /// or is null. - public async Task UpdateAsync(string id, IEnumerable updateModel, DecomissionModelOptions digitalTwinModelsUpdateOptions = null, CancellationToken cancellationToken = default) + public async Task UpdateAsync(string id, IEnumerable updateModel, DecommissionModelOptions digitalTwinModelsUpdateOptions = null, CancellationToken cancellationToken = default) { if (id == null) { @@ -412,7 +412,7 @@ public async Task UpdateAsync(string id, IEnumerable updateMod /// Parameter group. /// The cancellation token to use. /// or is null. - public Response Update(string id, IEnumerable updateModel, DecomissionModelOptions digitalTwinModelsUpdateOptions = null, CancellationToken cancellationToken = default) + public Response Update(string id, IEnumerable updateModel, DecommissionModelOptions digitalTwinModelsUpdateOptions = null, CancellationToken cancellationToken = default) { if (id == null) { diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Generated/Models/DecomissionModelOptions.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Generated/Models/DecommissionModelOptions.cs similarity index 58% rename from sdk/digitaltwins/Azure.DigitalTwins.Core/src/Generated/Models/DecomissionModelOptions.cs rename to sdk/digitaltwins/Azure.DigitalTwins.Core/src/Generated/Models/DecommissionModelOptions.cs index 9ac2852cc59bf..c6796db481328 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Generated/Models/DecomissionModelOptions.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Generated/Models/DecommissionModelOptions.cs @@ -8,10 +8,10 @@ namespace Azure.DigitalTwins.Core { /// Parameter group. - internal partial class DecomissionModelOptions + internal partial class DecommissionModelOptions { - /// Initializes a new instance of DecomissionModelOptions. - public DecomissionModelOptions() + /// Initializes a new instance of DecommissionModelOptions. + public DecommissionModelOptions() { } } diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Models/DigitalTwinsModelFactory.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Models/DigitalTwinsModelFactory.cs index 8e10ec4c517e0..531d37106faa5 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Models/DigitalTwinsModelFactory.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Models/DigitalTwinsModelFactory.cs @@ -36,7 +36,8 @@ public static DigitalTwinsModelData DigitalTwinsModelData( /// /// Initializes a new instance of for mocking purposes. /// - /// A user-provided string representing the id of this relationship, unique in the context of the source digital twin, i.e. sourceId + relationshipId is unique in the context of the service. + /// A user-provided string representing the id of this relationship, unique in the context of the source digital twin, + /// i.e. sourceId + relationshipId is unique in the context of the service. /// The id of the source digital twin. /// The name of the relationship. /// Link to the relationship, to be used for deletion.