public async Task <InsightResponseModel> GetIoTHubInsight(string email, string subid, string resourceGroupName, string resourceName, [FromBody] InsightModel insightModel)
 {
     return(await this._ioTHubResourceBus.GetIoTHubInsight(email, subid, resourceGroupName, resourceName, insightModel));
 }
Exemple #2
0
        public async Task <InsightResponseModel> GetIoTHubInsight(string subid, string resourceGroupName, string resourceName, string access_token, InsightModel insightModel)
        {
            string url = string.Format("{0}/resourceGroups/{1}/providers/Microsoft.Devices/IotHubs/" +
                                       "{2}/providers/microsoft.Insights/metrics?" +
                                       "timespan={3}&interval={4}&metricnames={5}&aggregation={6}&metricNamespace=microsoft.devices%2Fiothubs" +
                                       "&autoadjusttimegrain=true&validatedimensions=false&api-version=2019-07-01",
                                       subid, resourceGroupName, resourceName, insightModel.timespan, insightModel.interval, insightModel.metricnames, insightModel.aggregation);
            var request = new HttpRequestMessage(HttpMethod.Get, url);
            var client  = this._clientFactory.CreateClient("chinacloudapi");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", access_token);
            var response = await client.SendAsync(request);

            string data = await response.Content.ReadAsStringAsync();

            InsightResponseModel insight = null;

            if (response.IsSuccessStatusCode)
            {
                insight = JsonConvert.DeserializeObject <InsightResponseModel>(data);
            }
            else
            {
                Console.WriteLine("Error." + response.ReasonPhrase);
            }
            return(insight);
        }
Exemple #3
0
        public async Task <InsightResponseModel> GetIoTHubInsight(string email, string subid, string resourceGroupName, string resourceName, InsightModel insightModel)
        {
            string access_token = _tokenDto.GetTokenString(email, _tokenResource.Value.manage);

            return(await this._ioTHubResourceDto.GetIoTHubInsight(subid, resourceGroupName, resourceName, access_token, insightModel));
        }