Пример #1
0
        public async Task TimeSeriesInsightsClient_ModelSettingsTest()
        {
            TimeSeriesInsightsClient        client = GetClient();
            TimeSeriesInsightsModelSettings modelSettingsClient = client.GetModelSettingsClient();
            TimeSeriesInsightsTypes         typesClient         = client.GetTypesClient();

            // GET model settings
            Response <TimeSeriesModelSettings> currentSettings = await modelSettingsClient.GetAsync().ConfigureAwait(false);

            currentSettings.GetRawResponse().Status.Should().Be((int)HttpStatusCode.OK);
            string testName = "testModel";
            // UPDATE model settings
            string typeId = await createTimeSeriesTypeAsync(client).ConfigureAwait(false);

            string defaultTypeId = await getDefaultTypeIdAsync(modelSettingsClient).ConfigureAwait(false);

            try
            {
                Response <TimeSeriesModelSettings> updatedSettingsName = await modelSettingsClient.UpdateNameAsync(testName).ConfigureAwait(false);

                updatedSettingsName.GetRawResponse().Status.Should().Be((int)HttpStatusCode.OK);
                updatedSettingsName.Value.Name.Should().Be(testName);

                await TestRetryHelper.RetryAsync <Response <TimeSeriesModelSettings> >(async() =>
                {
                    Response <TimeSeriesModelSettings> updatedSettingsId = await modelSettingsClient.UpdateDefaultTypeIdAsync(typeId).ConfigureAwait(false);
                    updatedSettingsId.Value.DefaultTypeId.Should().Be(typeId);

                    // update it back to the default Type Id
                    updatedSettingsId = await modelSettingsClient.UpdateDefaultTypeIdAsync(defaultTypeId).ConfigureAwait(false);
                    updatedSettingsId.Value.DefaultTypeId.Should().Be(defaultTypeId);

                    return(null);
                }, MaxNumberOfRetries, s_retryDelay);
            }
            finally
            {
                // clean up
                try
                {
                    Response <TimeSeriesOperationError[]> deleteTypesResponse = await typesClient
                                                                                .DeleteByIdAsync(new string[] { typeId })
                                                                                .ConfigureAwait(false);

                    // Assert that the response array does not have any error object set
                    deleteTypesResponse.Value.Should().OnlyContain((errorResult) => errorResult == null);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Test clean up failed: {ex.Message}");
                    throw;
                }
            }
        }
Пример #2
0
        public void UpdateModelSettingsWithInvalidType_ThrowsBadRequestException()
        {
            // arrange
            TimeSeriesInsightsClient        client = GetClient();
            TimeSeriesInsightsModelSettings modelSettingsClient = client.GetModelSettingsClient();

            // act
            Func <Task> act = async() => await modelSettingsClient.UpdateDefaultTypeIdAsync("testId").ConfigureAwait(false);

            // assert
            act.Should().Throw <RequestFailedException>()
            .And.Status.Should().Be((int)HttpStatusCode.BadRequest);
        }
        /// <summary>
        /// This sample demonstrates getting Time Series model settings, updating model settings and changing the default type Id for a model.
        /// </summary>
        public async Task RunSamplesAsync(TimeSeriesInsightsClient client)
        {
            PrintHeader("TIME SERIES INSIGHTS MODEL SETTINGS SAMPLE");

            #region Snippet:TimeSeriesInsightsSampleGetModelSettings
            TimeSeriesInsightsModelSettings    modelSettingsClient      = client.GetModelSettingsClient();
            TimeSeriesInsightsTypes            typesClient              = client.GetTypesClient();
            Response <TimeSeriesModelSettings> getModelSettingsResponse = await modelSettingsClient.GetAsync();

            Console.WriteLine($"Retrieved Time Series Insights model settings \nname : '{getModelSettingsResponse.Value.Name}', " +
                              $"default type Id: {getModelSettingsResponse.Value.DefaultTypeId}'");
            IReadOnlyList <TimeSeriesIdProperty> timeSeriesIdProperties = getModelSettingsResponse.Value.TimeSeriesIdProperties;
            foreach (TimeSeriesIdProperty property in timeSeriesIdProperties)
            {
                Console.WriteLine($"Time Series Id property name : '{property.Name}', type : '{property.PropertyType}'.");
            }
            #endregion Snippet:TimeSeriesInsightsSampleGetModelSettings

            // Store the default type Id so it can be used during clean up
            string defaultTypeId = getModelSettingsResponse.Value.DefaultTypeId;

            #region Snippet:TimeSeriesInsightsSampleUpdateModelSettingsName
            Response <TimeSeriesModelSettings> updateModelSettingsNameResponse = await modelSettingsClient.UpdateNameAsync("NewModelSettingsName");

            Console.WriteLine($"Updated Time Series Insights model settings name: " +
                              $"{updateModelSettingsNameResponse.Value.Name}");
            #endregion Snippet:TimeSeriesInsightsSampleUpdateModelSettingsName

            // For every Time Series Insights environment, there is a default type that any newly created Time Series instance will be associated with.
            // You can change the default type for a TSI environment by creating a new type and calling the API to update the default type Id.

            // Create a Time Series type.
            var aggregateVariable = new AggregateVariable(new TimeSeriesExpression("count()"));
            var variables         = new Dictionary <string, TimeSeriesVariable>
            {
                { "aggregateVariableName", aggregateVariable },
            };
            var type            = new TimeSeriesType("tsiTypeName", variables);
            var timeSeriesTypes = new List <TimeSeriesType> {
                type
            };
            string tsiTypeId = null;
            Response <TimeSeriesTypeOperationResult[]> createTsiTypeResponse = await typesClient
                                                                               .CreateOrReplaceAsync(timeSeriesTypes);

            // Ensure no error was reported as part of the response
            if (createTsiTypeResponse.Value[0].Error == null)
            {
                // Store the Time Series type id to use it for updating default type in model settings
                tsiTypeId = createTsiTypeResponse.Value[0].TimeSeriesType.Id;

                #region Snippet:TimeSeriesInsightsSampleUpdateModelSettingsDefaultType
                Response <TimeSeriesModelSettings> updateDefaultTypeIdResponse = await modelSettingsClient
                                                                                 .UpdateDefaultTypeIdAsync(tsiTypeId);

                Console.WriteLine($"Updated Time Series Insights model settings default type Id: " +
                                  $"{updateDefaultTypeIdResponse.Value.Name}");
                #endregion Snippet:TimeSeriesInsightsSampleUpdateModelSettingsDefaultType
            }
            // Clean up
            try
            {
                // Revert back to the original default type Id
                await modelSettingsClient
                .UpdateDefaultTypeIdAsync(defaultTypeId);

                // Delete the type created
                if (tsiTypeId != null)
                {
                    await typesClient
                    .DeleteByIdAsync(new List <string> {
                        tsiTypeId
                    });
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Failed at one of the clean up steps: {ex.Message}");
            }
        }