-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
TimeSeriesInsightsClient.cs
149 lines (132 loc) · 8.6 KB
/
TimeSeriesInsightsClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using Azure.Core;
using Azure.Core.Pipeline;
namespace Azure.IoT.TimeSeriesInsights
{
/// <summary>
/// The Time Series Insights client.
/// </summary>
public class TimeSeriesInsightsClient
{
private readonly ClientDiagnostics _clientDiagnostics;
private readonly HttpPipeline _httpPipeline;
private const string TsiDefaultAppId = "https://api.timeseries.azure.com/";
private const string DefaultPermissionConsent = "/.default";
private static readonly string[] s_tsiDefaultScopes = new[] { TsiDefaultAppId + DefaultPermissionConsent };
private readonly ModelSettingsRestClient _modelSettingsRestClient;
private readonly TimeSeriesInstancesRestClient _timeSeriesInstancesRestClient;
private readonly TimeSeriesTypesRestClient _timeSeriesTypesRestClient;
private readonly TimeSeriesHierarchiesRestClient _timeSeriesHierarchiesRestClient;
private readonly QueryRestClient _queryRestClient;
/// <summary>
/// Create a new <see cref="TimeSeriesInsightsModelSettings"/> client to get and update model settings.
/// </summary>
/// <returns>A new <see cref="TimeSeriesInsightsModelSettings"/> instance.</returns>
public virtual TimeSeriesInsightsModelSettings GetModelSettingsClient()
{
return new TimeSeriesInsightsModelSettings(_modelSettingsRestClient, _clientDiagnostics);
}
/// <summary>
/// Create a new <see cref="TimeSeriesInsightsInstances"/> client to perform various Time Series Insights instances operations.
/// </summary>
/// <returns>A new <see cref="TimeSeriesInsightsInstances"/> instance.</returns>
public virtual TimeSeriesInsightsInstances GetInstancesClient()
{
return new TimeSeriesInsightsInstances(_timeSeriesInstancesRestClient, _clientDiagnostics);
}
/// <summary>
/// Create a new <see cref="TimeSeriesInsightsTypes"/> client to perform various Time Series Insights types operations.
/// </summary>
/// <returns>A new <see cref="TimeSeriesInsightsTypes"/> instance.</returns>
public virtual TimeSeriesInsightsTypes GetTypesClient()
{
return new TimeSeriesInsightsTypes(_timeSeriesTypesRestClient, _clientDiagnostics);
}
/// <summary>
/// Create a new <see cref="TimeSeriesInsightsHierarchies"/> client to perform various Time Series Insights hierarchies operations.
/// </summary>
/// <returns>A new <see cref="TimeSeriesInsightsHierarchies"/> instance.</returns>
public virtual TimeSeriesInsightsHierarchies GetHierarchiesClient()
{
return new TimeSeriesInsightsHierarchies(_timeSeriesHierarchiesRestClient, _clientDiagnostics);
}
/// <summary>
/// Create a new <see cref="TimeSeriesInsightsQueries"/> client that can be used can be used to perform query operations on Time Series Insights.
/// </summary>
/// <returns>A new <see cref="TimeSeriesInsightsQueries"/> instance.</returns>
public virtual TimeSeriesInsightsQueries GetQueriesClient()
{
return new TimeSeriesInsightsQueries(_queryRestClient, _clientDiagnostics);
}
/// <summary>
/// Creates a new instance of the <see cref="TimeSeriesInsightsClient"/> class.
/// </summary>
/// <param name='environmentFqdn'>Per environment FQDN, for example 10000000-0000-0000-0000-100000000109.env.timeseries.azure.com.
/// You can obtain this domain name from the response of the Get Environments API, Azure portal, or Azure Resource Manager.</param>
/// <param name="credential">The <see cref="TokenCredential"/> implementation which will be used to request for the authentication token.</param>
/// <seealso cref="TimeSeriesInsightsClient(string, TokenCredential, TimeSeriesInsightsClientOptions)">
/// This other constructor provides an opportunity to override default behavior, including specifying API version,
/// overriding <see href="https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Pipeline.md">transport</see>,
/// enabling <see href="https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Diagnostics.md">diagnostics</see>,
/// and controlling <see href="https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Configuration.md">retry strategy</see>.
/// </seealso>
/// <example>
/// <code snippet="Snippet:TimeSeriesInsightsSampleCreateServiceClientWithClientSecret">
/// // DefaultAzureCredential supports different authentication mechanisms and determines the appropriate credential type based on the environment it is executing in.
/// // It attempts to use multiple credential types in an order until it finds a working credential.
/// var tokenCredential = new DefaultAzureCredential();
///
/// var client = new TimeSeriesInsightsClient(
/// tsiEndpoint,
/// tokenCredential);
/// </code>
/// </example>
public TimeSeriesInsightsClient(string environmentFqdn, TokenCredential credential)
: this(environmentFqdn, credential, new TimeSeriesInsightsClientOptions())
{
}
/// <summary>
/// Creates a new instance of the <see cref="TimeSeriesInsightsClient"/> class, with options.
/// </summary>
/// <param name='environmentFqdn'>Per environment FQDN, for example 10000000-0000-0000-0000-100000000109.env.timeseries.azure.com.
/// You can obtain this domain name from the response of the Get Environments API, Azure portal, or Azure Resource Manager.</param>
/// <param name="credential">The <see cref="TokenCredential"/> implementation which will be used to request for the authentication token.</param>
/// <param name="options">Options that allow configuration of requests sent to the time series insights service.</param>
/// <remarks>
/// <para>
/// The options parameter provides an opportunity to override default behavior, including specifying API version,
/// overriding <see href="https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Pipeline.md">transport</see>,
/// enabling <see href="https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Diagnostics.md">diagnostics</see>,
/// and controlling <see href="https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Configuration.md">retry strategy</see>.
/// </para>
/// </remarks>
public TimeSeriesInsightsClient(string environmentFqdn, TokenCredential credential, TimeSeriesInsightsClientOptions options)
{
Argument.AssertNotNullOrEmpty(environmentFqdn, nameof(environmentFqdn));
Argument.AssertNotNull(credential, nameof(credential));
Argument.AssertNotNull(options, nameof(options));
_clientDiagnostics = new ClientDiagnostics(options);
options.AddPolicy(new BearerTokenAuthenticationPolicy(credential, GetAuthorizationScopes()), HttpPipelinePosition.PerCall);
_httpPipeline = HttpPipelineBuilder.Build(options);
string versionString = options.GetVersionString();
_modelSettingsRestClient = new ModelSettingsRestClient(_clientDiagnostics, _httpPipeline, environmentFqdn, versionString);
_timeSeriesInstancesRestClient = new TimeSeriesInstancesRestClient(_clientDiagnostics, _httpPipeline, environmentFqdn, versionString);
_timeSeriesTypesRestClient = new TimeSeriesTypesRestClient(_clientDiagnostics, _httpPipeline, environmentFqdn, versionString);
_timeSeriesHierarchiesRestClient = new TimeSeriesHierarchiesRestClient(_clientDiagnostics, _httpPipeline, environmentFqdn, versionString);
_queryRestClient = new QueryRestClient(_clientDiagnostics, _httpPipeline, environmentFqdn, versionString);
}
/// <summary>
/// Creates a new instance of the <see cref="TimeSeriesInsightsClient"/> class, provided for unit testing purposes only.
/// </summary>
protected TimeSeriesInsightsClient()
{
}
/// <summary>
/// Gets the scope for authentication/authorization policy.
/// </summary>
/// <returns>List of scopes for the specified endpoint.</returns>
internal static string[] GetAuthorizationScopes() => s_tsiDefaultScopes;
}
}