| | 1 | | // <auto-generated> |
| | 2 | | // Code generated by Microsoft (R) AutoRest Code Generator. |
| | 3 | | // Changes may cause incorrect behavior and will be lost if the code is |
| | 4 | | // regenerated. |
| | 5 | | // </auto-generated> |
| | 6 | |
|
| | 7 | | namespace Microsoft.Azure.OperationalInsights |
| | 8 | | { |
| | 9 | | using Microsoft.Rest; |
| | 10 | | using Microsoft.Rest.Serialization; |
| | 11 | | using Models; |
| | 12 | | using Newtonsoft.Json; |
| | 13 | | using System.Collections; |
| | 14 | | using System.Collections.Generic; |
| | 15 | | using System.Net; |
| | 16 | | using System.Net.Http; |
| | 17 | | using System.Threading; |
| | 18 | | using System.Threading.Tasks; |
| | 19 | |
|
| | 20 | | /// <summary> |
| | 21 | | /// Operational Insights Data Client |
| | 22 | | /// </summary> |
| | 23 | | public partial class OperationalInsightsDataClient : ServiceClient<OperationalInsightsDataClient>, IOperationalInsig |
| | 24 | | { |
| | 25 | | /// <summary> |
| | 26 | | /// The base URI of the service. |
| | 27 | | /// </summary> |
| 8 | 28 | | public System.Uri BaseUri { get; set; } |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// Gets or sets json serialization settings. |
| | 32 | | /// </summary> |
| 8 | 33 | | public JsonSerializerSettings SerializationSettings { get; private set; } |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// Gets or sets json deserialization settings. |
| | 37 | | /// </summary> |
| 8 | 38 | | public JsonSerializerSettings DeserializationSettings { get; private set; } |
| | 39 | |
|
| | 40 | | /// <summary> |
| | 41 | | /// ID of the workspace. This is Workspace ID from the Properties blade in the |
| | 42 | | /// Azure portal. |
| | 43 | | /// </summary> |
| 14 | 44 | | public string WorkspaceId { get; set; } |
| | 45 | |
|
| | 46 | | /// <summary> |
| | 47 | | /// Subscription credentials which uniquely identify client subscription. |
| | 48 | | /// </summary> |
| 20 | 49 | | public ServiceClientCredentials Credentials { get; private set; } |
| | 50 | |
|
| | 51 | | /// <summary> |
| | 52 | | /// Initializes a new instance of the OperationalInsightsDataClient class. |
| | 53 | | /// </summary> |
| | 54 | | /// <param name='handlers'> |
| | 55 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 56 | | /// </param> |
| 4 | 57 | | protected OperationalInsightsDataClient(params DelegatingHandler[] handlers) : base(handlers) |
| | 58 | | { |
| 4 | 59 | | Initialize(); |
| 4 | 60 | | } |
| | 61 | |
|
| | 62 | | /// <summary> |
| | 63 | | /// Initializes a new instance of the OperationalInsightsDataClient class. |
| | 64 | | /// </summary> |
| | 65 | | /// <param name='rootHandler'> |
| | 66 | | /// Optional. The http client handler used to handle http transport. |
| | 67 | | /// </param> |
| | 68 | | /// <param name='handlers'> |
| | 69 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 70 | | /// </param> |
| 0 | 71 | | protected OperationalInsightsDataClient(HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : ba |
| | 72 | | { |
| 0 | 73 | | Initialize(); |
| 0 | 74 | | } |
| | 75 | |
|
| | 76 | | /// <summary> |
| | 77 | | /// Initializes a new instance of the OperationalInsightsDataClient class. |
| | 78 | | /// </summary> |
| | 79 | | /// <param name='baseUri'> |
| | 80 | | /// Optional. The base URI of the service. |
| | 81 | | /// </param> |
| | 82 | | /// <param name='handlers'> |
| | 83 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 84 | | /// </param> |
| | 85 | | /// <exception cref="System.ArgumentNullException"> |
| | 86 | | /// Thrown when a required parameter is null |
| | 87 | | /// </exception> |
| 0 | 88 | | protected OperationalInsightsDataClient(System.Uri baseUri, params DelegatingHandler[] handlers) : this(handlers |
| | 89 | | { |
| 0 | 90 | | if (baseUri == null) |
| | 91 | | { |
| 0 | 92 | | throw new System.ArgumentNullException("baseUri"); |
| | 93 | | } |
| 0 | 94 | | BaseUri = baseUri; |
| 0 | 95 | | } |
| | 96 | |
|
| | 97 | | /// <summary> |
| | 98 | | /// Initializes a new instance of the OperationalInsightsDataClient class. |
| | 99 | | /// </summary> |
| | 100 | | /// <param name='baseUri'> |
| | 101 | | /// Optional. The base URI of the service. |
| | 102 | | /// </param> |
| | 103 | | /// <param name='rootHandler'> |
| | 104 | | /// Optional. The http client handler used to handle http transport. |
| | 105 | | /// </param> |
| | 106 | | /// <param name='handlers'> |
| | 107 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 108 | | /// </param> |
| | 109 | | /// <exception cref="System.ArgumentNullException"> |
| | 110 | | /// Thrown when a required parameter is null |
| | 111 | | /// </exception> |
| 0 | 112 | | protected OperationalInsightsDataClient(System.Uri baseUri, HttpClientHandler rootHandler, params DelegatingHand |
| | 113 | | { |
| 0 | 114 | | if (baseUri == null) |
| | 115 | | { |
| 0 | 116 | | throw new System.ArgumentNullException("baseUri"); |
| | 117 | | } |
| 0 | 118 | | BaseUri = baseUri; |
| 0 | 119 | | } |
| | 120 | |
|
| | 121 | | /// <summary> |
| | 122 | | /// Initializes a new instance of the OperationalInsightsDataClient class. |
| | 123 | | /// </summary> |
| | 124 | | /// <param name='credentials'> |
| | 125 | | /// Required. Subscription credentials which uniquely identify client subscription. |
| | 126 | | /// </param> |
| | 127 | | /// <param name='handlers'> |
| | 128 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 129 | | /// </param> |
| | 130 | | /// <exception cref="System.ArgumentNullException"> |
| | 131 | | /// Thrown when a required parameter is null |
| | 132 | | /// </exception> |
| 4 | 133 | | public OperationalInsightsDataClient(ServiceClientCredentials credentials, params DelegatingHandler[] handlers) |
| | 134 | | { |
| 4 | 135 | | if (credentials == null) |
| | 136 | | { |
| 0 | 137 | | throw new System.ArgumentNullException("credentials"); |
| | 138 | | } |
| 4 | 139 | | Credentials = credentials; |
| 4 | 140 | | if (Credentials != null) |
| | 141 | | { |
| 4 | 142 | | Credentials.InitializeServiceClient(this); |
| | 143 | | } |
| 4 | 144 | | } |
| | 145 | |
|
| | 146 | | /// <summary> |
| | 147 | | /// Initializes a new instance of the OperationalInsightsDataClient class. |
| | 148 | | /// </summary> |
| | 149 | | /// <param name='credentials'> |
| | 150 | | /// Required. Subscription credentials which uniquely identify client subscription. |
| | 151 | | /// </param> |
| | 152 | | /// <param name='rootHandler'> |
| | 153 | | /// Optional. The http client handler used to handle http transport. |
| | 154 | | /// </param> |
| | 155 | | /// <param name='handlers'> |
| | 156 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 157 | | /// </param> |
| | 158 | | /// <exception cref="System.ArgumentNullException"> |
| | 159 | | /// Thrown when a required parameter is null |
| | 160 | | /// </exception> |
| 0 | 161 | | public OperationalInsightsDataClient(ServiceClientCredentials credentials, HttpClientHandler rootHandler, params |
| | 162 | | { |
| 0 | 163 | | if (credentials == null) |
| | 164 | | { |
| 0 | 165 | | throw new System.ArgumentNullException("credentials"); |
| | 166 | | } |
| 0 | 167 | | Credentials = credentials; |
| 0 | 168 | | if (Credentials != null) |
| | 169 | | { |
| 0 | 170 | | Credentials.InitializeServiceClient(this); |
| | 171 | | } |
| 0 | 172 | | } |
| | 173 | |
|
| | 174 | | /// <summary> |
| | 175 | | /// Initializes a new instance of the OperationalInsightsDataClient class. |
| | 176 | | /// </summary> |
| | 177 | | /// <param name='baseUri'> |
| | 178 | | /// Optional. The base URI of the service. |
| | 179 | | /// </param> |
| | 180 | | /// <param name='credentials'> |
| | 181 | | /// Required. Subscription credentials which uniquely identify client subscription. |
| | 182 | | /// </param> |
| | 183 | | /// <param name='handlers'> |
| | 184 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 185 | | /// </param> |
| | 186 | | /// <exception cref="System.ArgumentNullException"> |
| | 187 | | /// Thrown when a required parameter is null |
| | 188 | | /// </exception> |
| 0 | 189 | | public OperationalInsightsDataClient(System.Uri baseUri, ServiceClientCredentials credentials, params Delegating |
| | 190 | | { |
| 0 | 191 | | if (baseUri == null) |
| | 192 | | { |
| 0 | 193 | | throw new System.ArgumentNullException("baseUri"); |
| | 194 | | } |
| 0 | 195 | | if (credentials == null) |
| | 196 | | { |
| 0 | 197 | | throw new System.ArgumentNullException("credentials"); |
| | 198 | | } |
| 0 | 199 | | BaseUri = baseUri; |
| 0 | 200 | | Credentials = credentials; |
| 0 | 201 | | if (Credentials != null) |
| | 202 | | { |
| 0 | 203 | | Credentials.InitializeServiceClient(this); |
| | 204 | | } |
| 0 | 205 | | } |
| | 206 | |
|
| | 207 | | /// <summary> |
| | 208 | | /// Initializes a new instance of the OperationalInsightsDataClient class. |
| | 209 | | /// </summary> |
| | 210 | | /// <param name='baseUri'> |
| | 211 | | /// Optional. The base URI of the service. |
| | 212 | | /// </param> |
| | 213 | | /// <param name='credentials'> |
| | 214 | | /// Required. Subscription credentials which uniquely identify client subscription. |
| | 215 | | /// </param> |
| | 216 | | /// <param name='rootHandler'> |
| | 217 | | /// Optional. The http client handler used to handle http transport. |
| | 218 | | /// </param> |
| | 219 | | /// <param name='handlers'> |
| | 220 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 221 | | /// </param> |
| | 222 | | /// <exception cref="System.ArgumentNullException"> |
| | 223 | | /// Thrown when a required parameter is null |
| | 224 | | /// </exception> |
| 0 | 225 | | public OperationalInsightsDataClient(System.Uri baseUri, ServiceClientCredentials credentials, HttpClientHandler |
| | 226 | | { |
| 0 | 227 | | if (baseUri == null) |
| | 228 | | { |
| 0 | 229 | | throw new System.ArgumentNullException("baseUri"); |
| | 230 | | } |
| 0 | 231 | | if (credentials == null) |
| | 232 | | { |
| 0 | 233 | | throw new System.ArgumentNullException("credentials"); |
| | 234 | | } |
| 0 | 235 | | BaseUri = baseUri; |
| 0 | 236 | | Credentials = credentials; |
| 0 | 237 | | if (Credentials != null) |
| | 238 | | { |
| 0 | 239 | | Credentials.InitializeServiceClient(this); |
| | 240 | | } |
| 0 | 241 | | } |
| | 242 | |
|
| | 243 | | /// <summary> |
| | 244 | | /// An optional partial-method to perform custom initialization. |
| | 245 | | ///</summary> |
| | 246 | | partial void CustomInitialize(); |
| | 247 | | /// <summary> |
| | 248 | | /// Initializes client properties. |
| | 249 | | /// </summary> |
| | 250 | | private void Initialize() |
| | 251 | | { |
| 4 | 252 | | BaseUri = new System.Uri("https://api.loganalytics.io/v1"); |
| 4 | 253 | | SerializationSettings = new JsonSerializerSettings |
| 4 | 254 | | { |
| 4 | 255 | | Formatting = Newtonsoft.Json.Formatting.Indented, |
| 4 | 256 | | DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, |
| 4 | 257 | | DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, |
| 4 | 258 | | NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, |
| 4 | 259 | | ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, |
| 4 | 260 | | ContractResolver = new ReadOnlyJsonContractResolver(), |
| 4 | 261 | | Converters = new List<JsonConverter> |
| 4 | 262 | | { |
| 4 | 263 | | new Iso8601TimeSpanConverter() |
| 4 | 264 | | } |
| 4 | 265 | | }; |
| 4 | 266 | | DeserializationSettings = new JsonSerializerSettings |
| 4 | 267 | | { |
| 4 | 268 | | DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, |
| 4 | 269 | | DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, |
| 4 | 270 | | NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, |
| 4 | 271 | | ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, |
| 4 | 272 | | ContractResolver = new ReadOnlyJsonContractResolver(), |
| 4 | 273 | | Converters = new List<JsonConverter> |
| 4 | 274 | | { |
| 4 | 275 | | new Iso8601TimeSpanConverter() |
| 4 | 276 | | } |
| 4 | 277 | | }; |
| 4 | 278 | | CustomInitialize(); |
| 4 | 279 | | } |
| | 280 | | /// <summary> |
| | 281 | | /// Execute an Analytics query |
| | 282 | | /// </summary> |
| | 283 | | /// <remarks> |
| | 284 | | /// Executes an Analytics query for data. |
| | 285 | | /// [Here](/documentation/2-Using-the-API/Query) is an example for using POST |
| | 286 | | /// with an Analytics query. |
| | 287 | | /// </remarks> |
| | 288 | | /// <param name='query'> |
| | 289 | | /// The query to execute. |
| | 290 | | /// </param> |
| | 291 | | /// <param name='timespan'> |
| | 292 | | /// Optional. The timespan over which to query data. This is an ISO8601 time |
| | 293 | | /// period value. This timespan is applied in addition to any that are |
| | 294 | | /// specified in the query expression. |
| | 295 | | /// </param> |
| | 296 | | /// <param name='workspaces'> |
| | 297 | | /// A list of workspaces that are included in the query. |
| | 298 | | /// </param> |
| | 299 | | /// <param name='customHeaders'> |
| | 300 | | /// Headers that will be added to request. |
| | 301 | | /// </param> |
| | 302 | | /// <param name='cancellationToken'> |
| | 303 | | /// The cancellation token. |
| | 304 | | /// </param> |
| | 305 | | /// <exception cref="ErrorResponseException"> |
| | 306 | | /// Thrown when the operation returned an invalid status code |
| | 307 | | /// </exception> |
| | 308 | | /// <exception cref="SerializationException"> |
| | 309 | | /// Thrown when unable to deserialize the response |
| | 310 | | /// </exception> |
| | 311 | | /// <exception cref="ValidationException"> |
| | 312 | | /// Thrown when a required parameter is null |
| | 313 | | /// </exception> |
| | 314 | | /// <exception cref="System.ArgumentNullException"> |
| | 315 | | /// Thrown when a required parameter is null |
| | 316 | | /// </exception> |
| | 317 | | /// <return> |
| | 318 | | /// A response object containing the response body and response headers. |
| | 319 | | /// </return> |
| | 320 | | public async Task<HttpOperationResponse<QueryResults>> QueryWithHttpMessagesAsync(string query, System.TimeSpan? |
| | 321 | | { |
| 4 | 322 | | if (WorkspaceId == null) |
| | 323 | | { |
| 0 | 324 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.WorkspaceId"); |
| | 325 | | } |
| 4 | 326 | | if (query == null) |
| | 327 | | { |
| 0 | 328 | | throw new ValidationException(ValidationRules.CannotBeNull, "query"); |
| | 329 | | } |
| 4 | 330 | | QueryBody body = new QueryBody(); |
| 4 | 331 | | if (query != null || timespan != null || workspaces != null) |
| | 332 | | { |
| 4 | 333 | | body.Query = query; |
| 4 | 334 | | body.Timespan = timespan; |
| 4 | 335 | | body.Workspaces = workspaces; |
| | 336 | | } |
| | 337 | | // Tracing |
| 4 | 338 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 339 | | string _invocationId = null; |
| 4 | 340 | | if (_shouldTrace) |
| | 341 | | { |
| 0 | 342 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 343 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 344 | | tracingParameters.Add("body", body); |
| 0 | 345 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 346 | | ServiceClientTracing.Enter(_invocationId, this, "Query", tracingParameters); |
| | 347 | | } |
| | 348 | | // Construct URL |
| 4 | 349 | | var _baseUrl = BaseUri.AbsoluteUri; |
| 4 | 350 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "workspaces/{works |
| 4 | 351 | | _url = _url.Replace("{workspaceId}", System.Uri.EscapeDataString(WorkspaceId)); |
| | 352 | | // Create HTTP transport objects |
| 4 | 353 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 354 | | HttpResponseMessage _httpResponse = null; |
| 4 | 355 | | _httpRequest.Method = new HttpMethod("POST"); |
| 4 | 356 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 357 | | // Set Headers |
| | 358 | |
|
| | 359 | |
|
| 4 | 360 | | if (customHeaders != null) |
| | 361 | | { |
| 0 | 362 | | foreach(var _header in customHeaders) |
| | 363 | | { |
| 0 | 364 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 365 | | { |
| 0 | 366 | | _httpRequest.Headers.Remove(_header.Key); |
| | 367 | | } |
| 0 | 368 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 369 | | } |
| | 370 | | } |
| | 371 | |
|
| | 372 | | // Serialize Request |
| 4 | 373 | | string _requestContent = null; |
| 4 | 374 | | if(body != null) |
| | 375 | | { |
| 4 | 376 | | _requestContent = SafeJsonConvert.SerializeObject(body, SerializationSettings); |
| 4 | 377 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 4 | 378 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 379 | | } |
| | 380 | | // Set Credentials |
| 4 | 381 | | if (Credentials != null) |
| | 382 | | { |
| 4 | 383 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 384 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 385 | | } |
| | 386 | | // Send Request |
| 4 | 387 | | if (_shouldTrace) |
| | 388 | | { |
| 0 | 389 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 390 | | } |
| 4 | 391 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 392 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 393 | | if (_shouldTrace) |
| | 394 | | { |
| 0 | 395 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 396 | | } |
| 4 | 397 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 398 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 399 | | string _responseContent = null; |
| 4 | 400 | | if ((int)_statusCode != 200) |
| | 401 | | { |
| 2 | 402 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 403 | | try |
| | 404 | | { |
| 2 | 405 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 2 | 406 | | ErrorResponse _errorBody = SafeJsonConvert.DeserializeObject<ErrorResponse>(_responseContent, Deser |
| 2 | 407 | | if (_errorBody != null) |
| | 408 | | { |
| 2 | 409 | | ex.Body = _errorBody; |
| | 410 | | } |
| 2 | 411 | | } |
| 0 | 412 | | catch (JsonException) |
| | 413 | | { |
| | 414 | | // Ignore the exception |
| 0 | 415 | | } |
| 2 | 416 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 2 | 417 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 2 | 418 | | if (_shouldTrace) |
| | 419 | | { |
| 0 | 420 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 421 | | } |
| 2 | 422 | | _httpRequest.Dispose(); |
| 2 | 423 | | if (_httpResponse != null) |
| | 424 | | { |
| 2 | 425 | | _httpResponse.Dispose(); |
| | 426 | | } |
| 2 | 427 | | throw ex; |
| | 428 | | } |
| | 429 | | // Create Result |
| 2 | 430 | | var _result = new HttpOperationResponse<QueryResults>(); |
| 2 | 431 | | _result.Request = _httpRequest; |
| 2 | 432 | | _result.Response = _httpResponse; |
| | 433 | | // Deserialize Response |
| 2 | 434 | | if ((int)_statusCode == 200) |
| | 435 | | { |
| 2 | 436 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 437 | | try |
| | 438 | | { |
| 2 | 439 | | _result.Body = SafeJsonConvert.DeserializeObject<QueryResults>(_responseContent, DeserializationSett |
| 2 | 440 | | } |
| 0 | 441 | | catch (JsonException ex) |
| | 442 | | { |
| 0 | 443 | | _httpRequest.Dispose(); |
| 0 | 444 | | if (_httpResponse != null) |
| | 445 | | { |
| 0 | 446 | | _httpResponse.Dispose(); |
| | 447 | | } |
| 0 | 448 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 449 | | } |
| | 450 | | } |
| 2 | 451 | | if (_shouldTrace) |
| | 452 | | { |
| 0 | 453 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 454 | | } |
| 2 | 455 | | return _result; |
| 2 | 456 | | } |
| | 457 | |
|
| | 458 | | } |
| | 459 | | } |