public void DeleteDetectionConfigurationValidatesArguments()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            Assert.That(() => adminClient.DeleteDetectionConfigurationAsync(null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.DeleteDetectionConfigurationAsync(""), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => adminClient.DeleteDetectionConfigurationAsync("configId"), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException)));

            Assert.That(() => adminClient.DeleteDetectionConfiguration(null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.DeleteDetectionConfiguration(""), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => adminClient.DeleteDetectionConfiguration("configId"), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException)));
        }
        public void DeleteDetectionConfigurationRespectsTheCancellationToken()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            using var cancellationSource = new CancellationTokenSource();
            cancellationSource.Cancel();

            Assert.That(() => adminClient.DeleteDetectionConfigurationAsync(FakeGuid, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
            Assert.That(() => adminClient.DeleteDetectionConfiguration(FakeGuid, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
        }
        public async Task CreateAndDeleteDetectionConfigurationAsync()
        {
            string endpoint        = MetricsAdvisorUri;
            string subscriptionKey = MetricsAdvisorSubscriptionKey;
            string apiKey          = MetricsAdvisorApiKey;
            var    credential      = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);

            var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential);

            #region Snippet:CreateDetectionConfigurationAsync
#if SNIPPET
            string metricId          = "<metricId>";
            string configurationName = "<configurationName>";
#else
            string metricId          = MetricId;
            string configurationName = GetUniqueName();
#endif

            var detectionConfiguration = new AnomalyDetectionConfiguration()
            {
                MetricId = metricId,
                Name     = configurationName,
                WholeSeriesDetectionConditions = new MetricWholeSeriesDetectionCondition()
            };

            var detectCondition = detectionConfiguration.WholeSeriesDetectionConditions;

            var hardSuppress = new SuppressCondition(1, 100);
            detectCondition.HardThresholdCondition = new HardThresholdCondition(AnomalyDetectorDirection.Down, hardSuppress)
            {
                LowerBound = 5.0
            };

            var smartSuppress = new SuppressCondition(4, 50);
            detectCondition.SmartDetectionCondition = new SmartDetectionCondition(10.0, AnomalyDetectorDirection.Up, smartSuppress);

            detectCondition.CrossConditionsOperator = DetectionConditionsOperator.Or;

            Response <AnomalyDetectionConfiguration> response = await adminClient.CreateDetectionConfigurationAsync(detectionConfiguration);

            AnomalyDetectionConfiguration createdDetectionConfiguration = response.Value;

            Console.WriteLine($"Anomaly detection configuration ID: {createdDetectionConfiguration.Id}");
            #endregion

            // Delete the created anomaly detection configuration to clean up the Metrics Advisor resource.
            // Do not perform this step if you intend to keep using the configuration.

            await adminClient.DeleteDetectionConfigurationAsync(createdDetectionConfiguration.Id);
        }
        public async Task CreateAndDeleteDetectionConfigurationAsync()
        {
            string endpoint        = MetricsAdvisorUri;
            string subscriptionKey = MetricsAdvisorSubscriptionKey;
            string apiKey          = MetricsAdvisorApiKey;
            var    credential      = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);

            var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential);

            string metricId = MetricId;

            #region Snippet:CreateDetectionConfigurationAsync
            //@@ string metricId = "<metricId>";
            string configurationName = "Sample anomaly detection configuration";

            var hardThresholdSuppressCondition = new SuppressCondition(1, 100);
            var hardThresholdCondition         = new HardThresholdCondition(AnomalyDetectorDirection.Down, hardThresholdSuppressCondition)
            {
                LowerBound = 5.0
            };

            var smartDetectionSuppressCondition = new SuppressCondition(4, 50);
            var smartDetectionCondition         = new SmartDetectionCondition(10.0, AnomalyDetectorDirection.Up, smartDetectionSuppressCondition);

            var detectionCondition = new MetricWholeSeriesDetectionCondition()
            {
                HardThresholdCondition  = hardThresholdCondition,
                SmartDetectionCondition = smartDetectionCondition,
                CrossConditionsOperator = DetectionConditionsOperator.Or
            };

            var detectionConfiguration = new AnomalyDetectionConfiguration(metricId, configurationName, detectionCondition);

            Response <string> response = await adminClient.CreateDetectionConfigurationAsync(detectionConfiguration);

            string detectionConfigurationId = response.Value;

            Console.WriteLine($"Anomaly detection configuration ID: {detectionConfigurationId}");
            #endregion

            // Delete the created anomaly detection configuration to clean up the Metrics Advisor resource.
            // Do not perform this step if you intend to keep using the configuration.

            await adminClient.DeleteDetectionConfigurationAsync(detectionConfigurationId);
        }
 /// <summary>
 /// Deletes the configuration this instance is associated with.
 /// </summary>
 public async ValueTask DisposeAsync() => await _adminClient.DeleteDetectionConfigurationAsync(Id);