< Summary

Class:Microsoft.Azure.CognitiveServices.AnomalyDetector.AnomalyDetectorClient
Assembly:Microsoft.Azure.CognitiveServices.AnomalyDetector
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\AnomalyDetector\src\Generated\AnomalyDetectorClient.cs
Covered lines:0
Uncovered lines:214
Coverable lines:214
Total lines:554
Line coverage:0% (0 of 214)
Covered branches:0
Total branches:88
Branch coverage:0% (0 of 88)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_BaseUri()-0%100%
get_SerializationSettings()-0%100%
get_DeserializationSettings()-0%100%
get_Endpoint()-0%100%
get_Credentials()-0%100%
.ctor(...)-0%100%
.ctor(...)-0%100%
.ctor(...)-0%100%
.ctor(...)-0%0%
.ctor(...)-0%0%
.ctor(...)-0%0%
Initialize()-0%100%
EntireDetectWithHttpMessagesAsync()-0%0%
LastDetectWithHttpMessagesAsync()-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\AnomalyDetector\src\Generated\AnomalyDetectorClient.cs

#LineLine coverage
 1// <auto-generated>
 2// Copyright (c) Microsoft Corporation. All rights reserved.
 3// Licensed under the MIT License. See License.txt in the project root for
 4// license information.
 5//
 6// Code generated by Microsoft (R) AutoRest Code Generator.
 7// Changes may cause incorrect behavior and will be lost if the code is
 8// regenerated.
 9// </auto-generated>
 10
 11namespace Microsoft.Azure.CognitiveServices.AnomalyDetector
 12{
 13    using Microsoft.Rest;
 14    using Microsoft.Rest.Serialization;
 15    using Models;
 16    using Newtonsoft.Json;
 17    using System.Collections;
 18    using System.Collections.Generic;
 19    using System.Net;
 20    using System.Net.Http;
 21    using System.Threading;
 22    using System.Threading.Tasks;
 23
 24    /// <summary>
 25    /// The Anomaly Detector API detects anomalies automatically in time series
 26    /// data. It supports two functionalities, one is for detecting the whole
 27    /// series with model trained by the timeseries, another is detecting last
 28    /// point with model trained by points before. By using this service,
 29    /// business customers can discover incidents and establish a logic flow
 30    /// for root cause analysis.
 31    /// </summary>
 32    public partial class AnomalyDetectorClient : ServiceClient<AnomalyDetectorClient>, IAnomalyDetectorClient
 33    {
 34        /// <summary>
 35        /// The base URI of the service.
 36        /// </summary>
 037        internal string BaseUri {get; set;}
 38
 39        /// <summary>
 40        /// Gets or sets json serialization settings.
 41        /// </summary>
 042        public JsonSerializerSettings SerializationSettings { get; private set; }
 43
 44        /// <summary>
 45        /// Gets or sets json deserialization settings.
 46        /// </summary>
 047        public JsonSerializerSettings DeserializationSettings { get; private set; }
 48
 49        /// <summary>
 50        /// Supported Cognitive Services endpoints (protocol and hostname, for example:
 51        /// https://westus2.api.cognitive.microsoft.com).
 52        /// </summary>
 053        public string Endpoint { get; set; }
 54
 55        /// <summary>
 56        /// Subscription credentials which uniquely identify client subscription.
 57        /// </summary>
 058        public ServiceClientCredentials Credentials { get; private set; }
 59
 60        /// <summary>
 61        /// Initializes a new instance of the AnomalyDetectorClient class.
 62        /// </summary>
 63        /// <param name='httpClient'>
 64        /// HttpClient to be used
 65        /// </param>
 66        /// <param name='disposeHttpClient'>
 67        /// True: will dispose the provided httpClient on calling AnomalyDetectorClient.Dispose(). False: will not dispo
 068        protected AnomalyDetectorClient(HttpClient httpClient, bool disposeHttpClient) : base(httpClient, disposeHttpCli
 69        {
 070            Initialize();
 071        }
 72
 73        /// <summary>
 74        /// Initializes a new instance of the AnomalyDetectorClient class.
 75        /// </summary>
 76        /// <param name='handlers'>
 77        /// Optional. The delegating handlers to add to the http client pipeline.
 78        /// </param>
 079        protected AnomalyDetectorClient(params DelegatingHandler[] handlers) : base(handlers)
 80        {
 081            Initialize();
 082        }
 83
 84        /// <summary>
 85        /// Initializes a new instance of the AnomalyDetectorClient class.
 86        /// </summary>
 87        /// <param name='rootHandler'>
 88        /// Optional. The http client handler used to handle http transport.
 89        /// </param>
 90        /// <param name='handlers'>
 91        /// Optional. The delegating handlers to add to the http client pipeline.
 92        /// </param>
 093        protected AnomalyDetectorClient(HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : base(rootH
 94        {
 095            Initialize();
 096        }
 97
 98        /// <summary>
 99        /// Initializes a new instance of the AnomalyDetectorClient class.
 100        /// </summary>
 101        /// <param name='credentials'>
 102        /// Required. Subscription credentials which uniquely identify client subscription.
 103        /// </param>
 104        /// <param name='handlers'>
 105        /// Optional. The delegating handlers to add to the http client pipeline.
 106        /// </param>
 107        /// <exception cref="System.ArgumentNullException">
 108        /// Thrown when a required parameter is null
 109        /// </exception>
 0110        public AnomalyDetectorClient(ServiceClientCredentials credentials, params DelegatingHandler[] handlers) : this(h
 111        {
 0112            if (credentials == null)
 113            {
 0114                throw new System.ArgumentNullException("credentials");
 115            }
 0116            Credentials = credentials;
 0117            if (Credentials != null)
 118            {
 0119                Credentials.InitializeServiceClient(this);
 120            }
 0121        }
 122
 123        /// <summary>
 124        /// Initializes a new instance of the AnomalyDetectorClient class.
 125        /// </summary>
 126        /// <param name='credentials'>
 127        /// Required. Subscription credentials which uniquely identify client subscription.
 128        /// </param>
 129        /// <param name='httpClient'>
 130        /// HttpClient to be used
 131        /// </param>
 132        /// <param name='disposeHttpClient'>
 133        /// True: will dispose the provided httpClient on calling AnomalyDetectorClient.Dispose(). False: will not dispo
 134        /// <exception cref="System.ArgumentNullException">
 135        /// Thrown when a required parameter is null
 136        /// </exception>
 0137        public AnomalyDetectorClient(ServiceClientCredentials credentials, HttpClient httpClient, bool disposeHttpClient
 138        {
 0139            if (credentials == null)
 140            {
 0141                throw new System.ArgumentNullException("credentials");
 142            }
 0143            Credentials = credentials;
 0144            if (Credentials != null)
 145            {
 0146                Credentials.InitializeServiceClient(this);
 147            }
 0148        }
 149
 150        /// <summary>
 151        /// Initializes a new instance of the AnomalyDetectorClient class.
 152        /// </summary>
 153        /// <param name='credentials'>
 154        /// Required. Subscription credentials which uniquely identify client subscription.
 155        /// </param>
 156        /// <param name='rootHandler'>
 157        /// Optional. The http client handler used to handle http transport.
 158        /// </param>
 159        /// <param name='handlers'>
 160        /// Optional. The delegating handlers to add to the http client pipeline.
 161        /// </param>
 162        /// <exception cref="System.ArgumentNullException">
 163        /// Thrown when a required parameter is null
 164        /// </exception>
 0165        public AnomalyDetectorClient(ServiceClientCredentials credentials, HttpClientHandler rootHandler, params Delegat
 166        {
 0167            if (credentials == null)
 168            {
 0169                throw new System.ArgumentNullException("credentials");
 170            }
 0171            Credentials = credentials;
 0172            if (Credentials != null)
 173            {
 0174                Credentials.InitializeServiceClient(this);
 175            }
 0176        }
 177
 178        /// <summary>
 179        /// An optional partial-method to perform custom initialization.
 180        ///</summary>
 181        partial void CustomInitialize();
 182        /// <summary>
 183        /// Initializes client properties.
 184        /// </summary>
 185        private void Initialize()
 186        {
 0187            BaseUri = "{Endpoint}/anomalydetector/v1.0";
 0188            SerializationSettings = new JsonSerializerSettings
 0189            {
 0190                Formatting = Newtonsoft.Json.Formatting.Indented,
 0191                DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
 0192                DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc,
 0193                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
 0194                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
 0195                ContractResolver = new ReadOnlyJsonContractResolver(),
 0196                Converters = new  List<JsonConverter>
 0197                    {
 0198                        new Iso8601TimeSpanConverter()
 0199                    }
 0200            };
 0201            DeserializationSettings = new JsonSerializerSettings
 0202            {
 0203                DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
 0204                DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc,
 0205                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
 0206                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
 0207                ContractResolver = new ReadOnlyJsonContractResolver(),
 0208                Converters = new List<JsonConverter>
 0209                    {
 0210                        new Iso8601TimeSpanConverter()
 0211                    }
 0212            };
 213            CustomInitialize();
 0214        }
 215        /// <summary>
 216        /// Detect anomalies for the entire series in batch.
 217        /// </summary>
 218        /// <remarks>
 219        /// This operation generates a model using an entire series, each point is
 220        /// detected with the same model. With this method, points before and after a
 221        /// certain point are used to determine whether it is an anomaly. The entire
 222        /// detection can give user an overall status of the time series.
 223        /// </remarks>
 224        /// <param name='body'>
 225        /// Time series points and period if needed. Advanced model parameters can also
 226        /// be set in the request.
 227        /// </param>
 228        /// <param name='customHeaders'>
 229        /// Headers that will be added to request.
 230        /// </param>
 231        /// <param name='cancellationToken'>
 232        /// The cancellation token.
 233        /// </param>
 234        /// <exception cref="APIErrorException">
 235        /// Thrown when the operation returned an invalid status code
 236        /// </exception>
 237        /// <exception cref="SerializationException">
 238        /// Thrown when unable to deserialize the response
 239        /// </exception>
 240        /// <exception cref="ValidationException">
 241        /// Thrown when a required parameter is null
 242        /// </exception>
 243        /// <exception cref="System.ArgumentNullException">
 244        /// Thrown when a required parameter is null
 245        /// </exception>
 246        /// <return>
 247        /// A response object containing the response body and response headers.
 248        /// </return>
 249        public async Task<HttpOperationResponse<EntireDetectResponse>> EntireDetectWithHttpMessagesAsync(Request body, D
 250        {
 0251            if (Endpoint == null)
 252            {
 0253                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 254            }
 0255            if (body == null)
 256            {
 0257                throw new ValidationException(ValidationRules.CannotBeNull, "body");
 258            }
 0259            if (body != null)
 260            {
 0261                body.Validate();
 262            }
 263            // Tracing
 0264            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0265            string _invocationId = null;
 0266            if (_shouldTrace)
 267            {
 0268                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0269                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0270                tracingParameters.Add("body", body);
 0271                tracingParameters.Add("cancellationToken", cancellationToken);
 0272                ServiceClientTracing.Enter(_invocationId, this, "EntireDetect", tracingParameters);
 273            }
 274            // Construct URL
 0275            var _baseUrl = BaseUri;
 0276            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "timeseries/entire/detect";
 0277            _url = _url.Replace("{Endpoint}", Endpoint);
 278            // Create HTTP transport objects
 0279            var _httpRequest = new HttpRequestMessage();
 0280            HttpResponseMessage _httpResponse = null;
 0281            _httpRequest.Method = new HttpMethod("POST");
 0282            _httpRequest.RequestUri = new System.Uri(_url);
 283            // Set Headers
 284
 285
 0286            if (customHeaders != null)
 287            {
 0288                foreach(var _header in customHeaders)
 289                {
 0290                    if (_httpRequest.Headers.Contains(_header.Key))
 291                    {
 0292                        _httpRequest.Headers.Remove(_header.Key);
 293                    }
 0294                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 295                }
 296            }
 297
 298            // Serialize Request
 0299            string _requestContent = null;
 0300            if(body != null)
 301            {
 0302                _requestContent = SafeJsonConvert.SerializeObject(body, SerializationSettings);
 0303                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0304                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 305            }
 306            // Set Credentials
 0307            if (Credentials != null)
 308            {
 0309                cancellationToken.ThrowIfCancellationRequested();
 0310                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 311            }
 312            // Send Request
 0313            if (_shouldTrace)
 314            {
 0315                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 316            }
 0317            cancellationToken.ThrowIfCancellationRequested();
 0318            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0319            if (_shouldTrace)
 320            {
 0321                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 322            }
 0323            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0324            cancellationToken.ThrowIfCancellationRequested();
 0325            string _responseContent = null;
 0326            if ((int)_statusCode != 200)
 327            {
 0328                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 329                try
 330                {
 0331                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0332                    APIError _errorBody =  SafeJsonConvert.DeserializeObject<APIError>(_responseContent, Deserialization
 0333                    if (_errorBody != null)
 334                    {
 0335                        ex.Body = _errorBody;
 336                    }
 0337                }
 0338                catch (JsonException)
 339                {
 340                    // Ignore the exception
 0341                }
 0342                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0343                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0344                if (_shouldTrace)
 345                {
 0346                    ServiceClientTracing.Error(_invocationId, ex);
 347                }
 0348                _httpRequest.Dispose();
 0349                if (_httpResponse != null)
 350                {
 0351                    _httpResponse.Dispose();
 352                }
 0353                throw ex;
 354            }
 355            // Create Result
 0356            var _result = new HttpOperationResponse<EntireDetectResponse>();
 0357            _result.Request = _httpRequest;
 0358            _result.Response = _httpResponse;
 359            // Deserialize Response
 0360            if ((int)_statusCode == 200)
 361            {
 0362                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 363                try
 364                {
 0365                    _result.Body = SafeJsonConvert.DeserializeObject<EntireDetectResponse>(_responseContent, Deserializa
 0366                }
 0367                catch (JsonException ex)
 368                {
 0369                    _httpRequest.Dispose();
 0370                    if (_httpResponse != null)
 371                    {
 0372                        _httpResponse.Dispose();
 373                    }
 0374                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 375                }
 376            }
 0377            if (_shouldTrace)
 378            {
 0379                ServiceClientTracing.Exit(_invocationId, _result);
 380            }
 0381            return _result;
 0382        }
 383
 384        /// <summary>
 385        /// Detect anomaly status of the latest point in time series.
 386        /// </summary>
 387        /// <remarks>
 388        /// This operation generates a model using points before the latest one. With
 389        /// this method, only historical points are used to determine whether the
 390        /// target point is an anomaly. The latest point detecting operation matches
 391        /// the scenario of real-time monitoring of business metrics.
 392        /// </remarks>
 393        /// <param name='body'>
 394        /// Time series points and period if needed. Advanced model parameters can also
 395        /// be set in the request.
 396        /// </param>
 397        /// <param name='customHeaders'>
 398        /// Headers that will be added to request.
 399        /// </param>
 400        /// <param name='cancellationToken'>
 401        /// The cancellation token.
 402        /// </param>
 403        /// <exception cref="APIErrorException">
 404        /// Thrown when the operation returned an invalid status code
 405        /// </exception>
 406        /// <exception cref="SerializationException">
 407        /// Thrown when unable to deserialize the response
 408        /// </exception>
 409        /// <exception cref="ValidationException">
 410        /// Thrown when a required parameter is null
 411        /// </exception>
 412        /// <exception cref="System.ArgumentNullException">
 413        /// Thrown when a required parameter is null
 414        /// </exception>
 415        /// <return>
 416        /// A response object containing the response body and response headers.
 417        /// </return>
 418        public async Task<HttpOperationResponse<LastDetectResponse>> LastDetectWithHttpMessagesAsync(Request body, Dicti
 419        {
 0420            if (Endpoint == null)
 421            {
 0422                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 423            }
 0424            if (body == null)
 425            {
 0426                throw new ValidationException(ValidationRules.CannotBeNull, "body");
 427            }
 0428            if (body != null)
 429            {
 0430                body.Validate();
 431            }
 432            // Tracing
 0433            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0434            string _invocationId = null;
 0435            if (_shouldTrace)
 436            {
 0437                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0438                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0439                tracingParameters.Add("body", body);
 0440                tracingParameters.Add("cancellationToken", cancellationToken);
 0441                ServiceClientTracing.Enter(_invocationId, this, "LastDetect", tracingParameters);
 442            }
 443            // Construct URL
 0444            var _baseUrl = BaseUri;
 0445            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "timeseries/last/detect";
 0446            _url = _url.Replace("{Endpoint}", Endpoint);
 447            // Create HTTP transport objects
 0448            var _httpRequest = new HttpRequestMessage();
 0449            HttpResponseMessage _httpResponse = null;
 0450            _httpRequest.Method = new HttpMethod("POST");
 0451            _httpRequest.RequestUri = new System.Uri(_url);
 452            // Set Headers
 453
 454
 0455            if (customHeaders != null)
 456            {
 0457                foreach(var _header in customHeaders)
 458                {
 0459                    if (_httpRequest.Headers.Contains(_header.Key))
 460                    {
 0461                        _httpRequest.Headers.Remove(_header.Key);
 462                    }
 0463                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 464                }
 465            }
 466
 467            // Serialize Request
 0468            string _requestContent = null;
 0469            if(body != null)
 470            {
 0471                _requestContent = SafeJsonConvert.SerializeObject(body, SerializationSettings);
 0472                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0473                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 474            }
 475            // Set Credentials
 0476            if (Credentials != null)
 477            {
 0478                cancellationToken.ThrowIfCancellationRequested();
 0479                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 480            }
 481            // Send Request
 0482            if (_shouldTrace)
 483            {
 0484                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 485            }
 0486            cancellationToken.ThrowIfCancellationRequested();
 0487            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0488            if (_shouldTrace)
 489            {
 0490                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 491            }
 0492            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0493            cancellationToken.ThrowIfCancellationRequested();
 0494            string _responseContent = null;
 0495            if ((int)_statusCode != 200)
 496            {
 0497                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 498                try
 499                {
 0500                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0501                    APIError _errorBody =  SafeJsonConvert.DeserializeObject<APIError>(_responseContent, Deserialization
 0502                    if (_errorBody != null)
 503                    {
 0504                        ex.Body = _errorBody;
 505                    }
 0506                }
 0507                catch (JsonException)
 508                {
 509                    // Ignore the exception
 0510                }
 0511                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0512                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0513                if (_shouldTrace)
 514                {
 0515                    ServiceClientTracing.Error(_invocationId, ex);
 516                }
 0517                _httpRequest.Dispose();
 0518                if (_httpResponse != null)
 519                {
 0520                    _httpResponse.Dispose();
 521                }
 0522                throw ex;
 523            }
 524            // Create Result
 0525            var _result = new HttpOperationResponse<LastDetectResponse>();
 0526            _result.Request = _httpRequest;
 0527            _result.Response = _httpResponse;
 528            // Deserialize Response
 0529            if ((int)_statusCode == 200)
 530            {
 0531                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 532                try
 533                {
 0534                    _result.Body = SafeJsonConvert.DeserializeObject<LastDetectResponse>(_responseContent, Deserializati
 0535                }
 0536                catch (JsonException ex)
 537                {
 0538                    _httpRequest.Dispose();
 0539                    if (_httpResponse != null)
 540                    {
 0541                        _httpResponse.Dispose();
 542                    }
 0543                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 544                }
 545            }
 0546            if (_shouldTrace)
 547            {
 0548                ServiceClientTracing.Exit(_invocationId, _result);
 549            }
 0550            return _result;
 0551        }
 552
 553    }
 554}