< Summary

Class:Microsoft.Azure.OperationalInsights.OperationalInsightsDataClient
Assembly:Microsoft.Azure.OperationalInsights
File(s):C:\Git\azure-sdk-for-net\sdk\operationalinsights\Microsoft.Azure.OperationalInsights\src\Customized\OperationalInsightsDataClient.cs
C:\Git\azure-sdk-for-net\sdk\operationalinsights\Microsoft.Azure.OperationalInsights\src\Generated\OperationalInsightsDataClient.cs
Covered lines:112
Uncovered lines:70
Coverable lines:182
Total lines:517
Line coverage:61.5% (112 of 182)
Covered branches:29
Total branches:68
Branch coverage:42.6% (29 of 68)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
Initialize()-100%100%
.ctor(...)-100%100%
QueryWithHttpMessagesAsync()-100%100%
.ctor(...)-0%100%
CustomInitialize()-90%50%
get_BaseUri()-100%100%
get_SerializationSettings()-100%100%
get_DeserializationSettings()-100%100%
get_AdditionalWorkspaces()-0%100%
get_WorkspaceId()-100%100%
get_Preferences()-0%100%
get_Credentials()-100%100%
get_NameHeader()-0%100%
get_RequestId()-0%100%
.ctor(...)-100%100%
get_BaseUri()-100%100%
get_SerializationSettings()-100%100%
get_DeserializationSettings()-100%100%
get_WorkspaceId()-100%100%
get_Credentials()-100%100%
.ctor(...)-100%100%
.ctor(...)-0%100%
.ctor(...)-0%0%
.ctor(...)-0%0%
.ctor(...)-85.71%75%
.ctor(...)-0%0%
.ctor(...)-0%0%
.ctor(...)-0%0%
Initialize()-100%100%
QueryWithHttpMessagesAsync()-72.15%59.52%

File(s)

C:\Git\azure-sdk-for-net\sdk\operationalinsights\Microsoft.Azure.OperationalInsights\src\Customized\OperationalInsightsDataClient.cs

#LineLine coverage
 1using Microsoft.Azure.OperationalInsights.Models;
 2using Microsoft.Rest;
 3using System.Collections.Generic;
 4using System.Net.Http;
 5
 6namespace Microsoft.Azure.OperationalInsights
 7{
 8    public partial class OperationalInsightsDataClient : ServiceClient<OperationalInsightsDataClient>, IOperationalInsig
 9    {
 10        /// <summary>
 11        /// Initializes a new instance of the OperationalInsightsDataClient class.
 12        /// </summary>
 13        /// <param name='credentials'>
 14        /// Required. Subscription credentials which uniquely identify client subscription.
 15        /// </param>
 16        /// <exception cref="System.ArgumentNullException">
 17        /// Thrown when a required parameter is null
 18        /// </exception>
 19        public OperationalInsightsDataClient(ServiceClientCredentials credentials)
 020            : this(credentials, (DelegatingHandler[])null)
 21        {
 022        }
 23
 24        partial void CustomInitialize()
 25        {
 826            var firstHandler = this.FirstMessageHandler as DelegatingHandler;
 027            if (firstHandler == null) return;
 828
 829            var customHandler = new CustomDelegatingHandler
 830            {
 831                InnerHandler = firstHandler.InnerHandler,
 832                Client = this,
 1633            };
 34
 835            firstHandler.InnerHandler = customHandler;
 836        }
 37
 838        /// <summary>
 39        /// Additional workspaces referenced in cross-resource queries.
 40        /// </summary>
 041        public IList<string> AdditionalWorkspaces { get; set; } = new List<string>();
 42
 43        /// <summary>
 1444        /// Query preferences.
 45        /// </summary>
 046        public ApiPreferences Preferences { get; set; } = new ApiPreferences();
 47
 48        /// <summary>
 2049        /// Unique name for the calling application. This is only used for telemetry and debugging.
 50        /// </summary>
 051        public string NameHeader { get; set; }
 52
 53        /// <summary>
 54        /// A unique ID per request. This will be generated per request if not specified.
 55        /// </summary>
 056        public string RequestId { get; set; }
 457    }
 58}

C:\Git\azure-sdk-for-net\sdk\operationalinsights\Microsoft.Azure.OperationalInsights\src\Generated\OperationalInsightsDataClient.cs

#LineLine coverage
 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
 7namespace 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>
 828        public System.Uri BaseUri { get; set; }
 29
 30        /// <summary>
 31        /// Gets or sets json serialization settings.
 32        /// </summary>
 833        public JsonSerializerSettings SerializationSettings { get; private set; }
 34
 35        /// <summary>
 36        /// Gets or sets json deserialization settings.
 37        /// </summary>
 838        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>
 1444        public string WorkspaceId { get; set; }
 45
 46        /// <summary>
 47        /// Subscription credentials which uniquely identify client subscription.
 48        /// </summary>
 2049        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>
 457        protected OperationalInsightsDataClient(params DelegatingHandler[] handlers) : base(handlers)
 58        {
 459            Initialize();
 460        }
 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>
 071        protected OperationalInsightsDataClient(HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : ba
 72        {
 073            Initialize();
 074        }
 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>
 088        protected OperationalInsightsDataClient(System.Uri baseUri, params DelegatingHandler[] handlers) : this(handlers
 89        {
 090            if (baseUri == null)
 91            {
 092                throw new System.ArgumentNullException("baseUri");
 93            }
 094            BaseUri = baseUri;
 095        }
 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>
 0112        protected OperationalInsightsDataClient(System.Uri baseUri, HttpClientHandler rootHandler, params DelegatingHand
 113        {
 0114            if (baseUri == null)
 115            {
 0116                throw new System.ArgumentNullException("baseUri");
 117            }
 0118            BaseUri = baseUri;
 0119        }
 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>
 4133        public OperationalInsightsDataClient(ServiceClientCredentials credentials, params DelegatingHandler[] handlers) 
 134        {
 4135            if (credentials == null)
 136            {
 0137                throw new System.ArgumentNullException("credentials");
 138            }
 4139            Credentials = credentials;
 4140            if (Credentials != null)
 141            {
 4142                Credentials.InitializeServiceClient(this);
 143            }
 4144        }
 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>
 0161        public OperationalInsightsDataClient(ServiceClientCredentials credentials, HttpClientHandler rootHandler, params
 162        {
 0163            if (credentials == null)
 164            {
 0165                throw new System.ArgumentNullException("credentials");
 166            }
 0167            Credentials = credentials;
 0168            if (Credentials != null)
 169            {
 0170                Credentials.InitializeServiceClient(this);
 171            }
 0172        }
 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>
 0189        public OperationalInsightsDataClient(System.Uri baseUri, ServiceClientCredentials credentials, params Delegating
 190        {
 0191            if (baseUri == null)
 192            {
 0193                throw new System.ArgumentNullException("baseUri");
 194            }
 0195            if (credentials == null)
 196            {
 0197                throw new System.ArgumentNullException("credentials");
 198            }
 0199            BaseUri = baseUri;
 0200            Credentials = credentials;
 0201            if (Credentials != null)
 202            {
 0203                Credentials.InitializeServiceClient(this);
 204            }
 0205        }
 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>
 0225        public OperationalInsightsDataClient(System.Uri baseUri, ServiceClientCredentials credentials, HttpClientHandler
 226        {
 0227            if (baseUri == null)
 228            {
 0229                throw new System.ArgumentNullException("baseUri");
 230            }
 0231            if (credentials == null)
 232            {
 0233                throw new System.ArgumentNullException("credentials");
 234            }
 0235            BaseUri = baseUri;
 0236            Credentials = credentials;
 0237            if (Credentials != null)
 238            {
 0239                Credentials.InitializeServiceClient(this);
 240            }
 0241        }
 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        {
 4252            BaseUri = new System.Uri("https://api.loganalytics.io/v1");
 4253            SerializationSettings = new JsonSerializerSettings
 4254            {
 4255                Formatting = Newtonsoft.Json.Formatting.Indented,
 4256                DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
 4257                DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc,
 4258                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
 4259                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
 4260                ContractResolver = new ReadOnlyJsonContractResolver(),
 4261                Converters = new  List<JsonConverter>
 4262                    {
 4263                        new Iso8601TimeSpanConverter()
 4264                    }
 4265            };
 4266            DeserializationSettings = new JsonSerializerSettings
 4267            {
 4268                DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
 4269                DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc,
 4270                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
 4271                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
 4272                ContractResolver = new ReadOnlyJsonContractResolver(),
 4273                Converters = new List<JsonConverter>
 4274                    {
 4275                        new Iso8601TimeSpanConverter()
 4276                    }
 4277            };
 4278            CustomInitialize();
 4279        }
 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        {
 4322            if (WorkspaceId == null)
 323            {
 0324                throw new ValidationException(ValidationRules.CannotBeNull, "this.WorkspaceId");
 325            }
 4326            if (query == null)
 327            {
 0328                throw new ValidationException(ValidationRules.CannotBeNull, "query");
 329            }
 4330            QueryBody body = new QueryBody();
 4331            if (query != null || timespan != null || workspaces != null)
 332            {
 4333                body.Query = query;
 4334                body.Timespan = timespan;
 4335                body.Workspaces = workspaces;
 336            }
 337            // Tracing
 4338            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 4339            string _invocationId = null;
 4340            if (_shouldTrace)
 341            {
 0342                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0343                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0344                tracingParameters.Add("body", body);
 0345                tracingParameters.Add("cancellationToken", cancellationToken);
 0346                ServiceClientTracing.Enter(_invocationId, this, "Query", tracingParameters);
 347            }
 348            // Construct URL
 4349            var _baseUrl = BaseUri.AbsoluteUri;
 4350            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "workspaces/{works
 4351            _url = _url.Replace("{workspaceId}", System.Uri.EscapeDataString(WorkspaceId));
 352            // Create HTTP transport objects
 4353            var _httpRequest = new HttpRequestMessage();
 4354            HttpResponseMessage _httpResponse = null;
 4355            _httpRequest.Method = new HttpMethod("POST");
 4356            _httpRequest.RequestUri = new System.Uri(_url);
 357            // Set Headers
 358
 359
 4360            if (customHeaders != null)
 361            {
 0362                foreach(var _header in customHeaders)
 363                {
 0364                    if (_httpRequest.Headers.Contains(_header.Key))
 365                    {
 0366                        _httpRequest.Headers.Remove(_header.Key);
 367                    }
 0368                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 369                }
 370            }
 371
 372            // Serialize Request
 4373            string _requestContent = null;
 4374            if(body != null)
 375            {
 4376                _requestContent = SafeJsonConvert.SerializeObject(body, SerializationSettings);
 4377                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 4378                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 379            }
 380            // Set Credentials
 4381            if (Credentials != null)
 382            {
 4383                cancellationToken.ThrowIfCancellationRequested();
 4384                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 385            }
 386            // Send Request
 4387            if (_shouldTrace)
 388            {
 0389                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 390            }
 4391            cancellationToken.ThrowIfCancellationRequested();
 4392            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 4393            if (_shouldTrace)
 394            {
 0395                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 396            }
 4397            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 4398            cancellationToken.ThrowIfCancellationRequested();
 4399            string _responseContent = null;
 4400            if ((int)_statusCode != 200)
 401            {
 2402                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 403                try
 404                {
 2405                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2406                    ErrorResponse _errorBody =  SafeJsonConvert.DeserializeObject<ErrorResponse>(_responseContent, Deser
 2407                    if (_errorBody != null)
 408                    {
 2409                        ex.Body = _errorBody;
 410                    }
 2411                }
 0412                catch (JsonException)
 413                {
 414                    // Ignore the exception
 0415                }
 2416                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 2417                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 2418                if (_shouldTrace)
 419                {
 0420                    ServiceClientTracing.Error(_invocationId, ex);
 421                }
 2422                _httpRequest.Dispose();
 2423                if (_httpResponse != null)
 424                {
 2425                    _httpResponse.Dispose();
 426                }
 2427                throw ex;
 428            }
 429            // Create Result
 2430            var _result = new HttpOperationResponse<QueryResults>();
 2431            _result.Request = _httpRequest;
 2432            _result.Response = _httpResponse;
 433            // Deserialize Response
 2434            if ((int)_statusCode == 200)
 435            {
 2436                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 437                try
 438                {
 2439                    _result.Body = SafeJsonConvert.DeserializeObject<QueryResults>(_responseContent, DeserializationSett
 2440                }
 0441                catch (JsonException ex)
 442                {
 0443                    _httpRequest.Dispose();
 0444                    if (_httpResponse != null)
 445                    {
 0446                        _httpResponse.Dispose();
 447                    }
 0448                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 449                }
 450            }
 2451            if (_shouldTrace)
 452            {
 0453                ServiceClientTracing.Exit(_invocationId, _result);
 454            }
 2455            return _result;
 2456        }
 457
 458    }
 459}