|
1 | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
| 4 | +using System; |
4 | 5 | using System.Threading; |
5 | 6 | using System.Threading.Tasks; |
6 | 7 | using Azure.Core; |
@@ -94,40 +95,103 @@ protected TimeSeriesInsightsClient() |
94 | 95 | } |
95 | 96 |
|
96 | 97 | /// <summary> |
97 | | - /// Returns the model settings which includes model display name, Time Series ID properties and default type ID. Every Gen2 environment has a model that is automatically created. |
| 98 | + /// Gets the scope for authentication/authorization policy. |
98 | 99 | /// </summary> |
99 | | - /// <param name="clientSessionId"> Optional client session ID. Service records this value. Allows the service to trace a group of related operations across services, and allows the customer to contact support regarding a particular group of requests. </param> |
100 | | - /// <param name="cancellationToken"> The cancellation token to use. </param> |
101 | | - /// <returns>The deserialized application/json model settings digital twin and the http response <see cref="Response{ModelSettingsResponse}"/>.</returns> |
102 | | - /// <example> |
103 | | - /// This sample demonstrates getting and deserializing a model settings. |
104 | | - /// |
105 | | - /// <code snippet="Snippet:TimeSeriesInsightsGetModelSettings"> |
106 | | - /// // Get the model settings for the time series insights environment |
107 | | - /// Response<Models.ModelSettingsResponse> response = await client.GetAsync().ConfigureAwait(false); |
108 | | - /// Console.WriteLine($"Retrieved model {response.Value.ModelSettings.Name}."); |
109 | | - /// </code> |
110 | | - /// </example> |
111 | | - public virtual Task<Response<ModelSettingsResponse>> GetAsync(string clientSessionId = null, CancellationToken cancellationToken = default) |
| 100 | + /// <returns>List of scopes for the specified endpoint.</returns> |
| 101 | + internal static string[] GetAuthorizationScopes() => s_tsiDefaultScopes; |
| 102 | + |
| 103 | + /// <summary> |
| 104 | + /// Gets Time Series model settings asynchronously. |
| 105 | + /// </summary> |
| 106 | + /// <param name="cancellationToken">The cancellation token.</param> |
| 107 | + /// <returns>The model settings which includes model display name, Time Series Id properties and default type Id with the http response <see cref="Response{TimeSeriesModelSettings}"/>.</returns> |
| 108 | + public virtual async Task<Response<TimeSeriesModelSettings>> GetModelSettingsAsync(CancellationToken cancellationToken = default) |
112 | 109 | { |
113 | | - return _modelSettingsRestClient.GetAsync(clientSessionId, cancellationToken); |
| 110 | + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TimeSeriesInsightsClient)}.{nameof(GetModelSettings)}"); |
| 111 | + scope.Start(); |
| 112 | + try |
| 113 | + { |
| 114 | + // To do: Generate client session Id |
| 115 | + Response<ModelSettingsResponse> modelSettings = await _modelSettingsRestClient.GetAsync(null, cancellationToken).ConfigureAwait(false); |
| 116 | + return Response.FromValue(modelSettings.Value.ModelSettings, modelSettings.GetRawResponse()); |
| 117 | + } |
| 118 | + catch (Exception ex) |
| 119 | + { |
| 120 | + scope.Failed(ex); |
| 121 | + throw; |
| 122 | + } |
114 | 123 | } |
115 | 124 |
|
116 | 125 | /// <summary> |
117 | | - /// Returns the model settings which includes model display name, Time Series ID properties and default type ID. Every Gen2 environment has a model that is automatically created. |
| 126 | + /// Gets Time Series model settings synchronously. |
118 | 127 | /// </summary> |
119 | | - /// <param name="clientSessionId"> Optional client session ID. Service records this value. Allows the service to trace a group of related operations across services, and allows the customer to contact support regarding a particular group of requests. </param> |
120 | | - /// <param name="cancellationToken"> The cancellation token to use. </param> |
121 | | - /// <returns>The deserialized application/json model settings digital twin and the http response <see cref="Response{ModelSettingsResponse}"/>.</returns> |
122 | | - public virtual Response<ModelSettingsResponse> Get(string clientSessionId = null, CancellationToken cancellationToken = default) |
| 128 | + /// <param name="cancellationToken">The cancellation token.</param> |
| 129 | + /// <returns>The model settings which includes model display name, Time Series Id properties and default type Id with the http response <see cref="Response{TimeSeriesModelSettings}"/>.</returns> |
| 130 | + public virtual Response<TimeSeriesModelSettings> GetModelSettings(CancellationToken cancellationToken = default) |
123 | 131 | { |
124 | | - return _modelSettingsRestClient.Get(clientSessionId, cancellationToken); |
| 132 | + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TimeSeriesInsightsClient)}.{nameof(GetModelSettings)}"); |
| 133 | + scope.Start(); |
| 134 | + try |
| 135 | + { |
| 136 | + // To do: Generate client session Id |
| 137 | + Response<ModelSettingsResponse> modelSettings = _modelSettingsRestClient.Get(null, cancellationToken); |
| 138 | + return Response.FromValue(modelSettings.Value.ModelSettings, modelSettings.GetRawResponse()); |
| 139 | + } |
| 140 | + catch (Exception ex) |
| 141 | + { |
| 142 | + scope.Failed(ex); |
| 143 | + throw; |
| 144 | + } |
125 | 145 | } |
126 | 146 |
|
127 | 147 | /// <summary> |
128 | | - /// Gets the scope for authentication/authorization policy. |
| 148 | + /// Updates model name or default type Id on Time Series model settings asynchronously. |
129 | 149 | /// </summary> |
130 | | - /// <returns>List of scopes for the specified endpoint.</returns> |
131 | | - internal static string[] GetAuthorizationScopes() => s_tsiDefaultScopes; |
| 150 | + /// <param name="options">Model settings update request body.</param> |
| 151 | + /// <param name="cancellationToken">The cancellation token.</param> |
| 152 | + /// <returns>The updated model settings with the http response <see cref="Response{TimeSeriesModelSettings}"/>.</returns> |
| 153 | + /// <exception cref="ArgumentNullException"> <paramref name="options"/> is null. </exception> |
| 154 | + public virtual async Task<Response<TimeSeriesModelSettings>> UpdateModelSettingsAsync(UpdateModelSettingsOptions options, CancellationToken cancellationToken = default) |
| 155 | + { |
| 156 | + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TimeSeriesInsightsClient)}.{nameof(UpdateModelSettings)}"); |
| 157 | + scope.Start(); |
| 158 | + try |
| 159 | + { |
| 160 | + // To do: Generate client session Id |
| 161 | + Argument.AssertNotNull(options, nameof(options)); |
| 162 | + Response<ModelSettingsResponse> modelSettings = await _modelSettingsRestClient.UpdateAsync(options, null, cancellationToken).ConfigureAwait(false); |
| 163 | + return Response.FromValue(modelSettings.Value.ModelSettings, modelSettings.GetRawResponse()); |
| 164 | + } |
| 165 | + catch (Exception ex) |
| 166 | + { |
| 167 | + scope.Failed(ex); |
| 168 | + throw; |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + /// <summary> |
| 173 | + /// Updates model name or default type Id on Time Series model settings synchronously. |
| 174 | + /// </summary> |
| 175 | + /// <param name="options">Model settings update request body.</param> |
| 176 | + /// <param name="cancellationToken">The cancellation token.</param> |
| 177 | + /// <returns>The updated model settings with the http response <see cref="Response{TimeSeriesModelSettings}"/>.</returns> |
| 178 | + /// <exception cref="ArgumentNullException"> <paramref name="options"/> is null. </exception> |
| 179 | + public virtual Response<TimeSeriesModelSettings> UpdateModelSettings(UpdateModelSettingsOptions options, CancellationToken cancellationToken = default) |
| 180 | + { |
| 181 | + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TimeSeriesInsightsClient)}.{nameof(UpdateModelSettings)}"); |
| 182 | + scope.Start(); |
| 183 | + try |
| 184 | + { |
| 185 | + // To do: Generate client session Id |
| 186 | + Argument.AssertNotNull(options, nameof(options)); |
| 187 | + Response<ModelSettingsResponse> modelSettings = _modelSettingsRestClient.Update(options, null, cancellationToken); |
| 188 | + return Response.FromValue(modelSettings.Value.ModelSettings, modelSettings.GetRawResponse()); |
| 189 | + } |
| 190 | + catch (Exception ex) |
| 191 | + { |
| 192 | + scope.Failed(ex); |
| 193 | + throw; |
| 194 | + } |
| 195 | + } |
132 | 196 | } |
133 | 197 | } |
0 commit comments