|
|
|
@ -0,0 +1,50 @@
|
|
|
|
|
using Infrastructure.Extensions;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace IoTCenter.Api
|
|
|
|
|
{
|
|
|
|
|
[ApiVersion("1.0")]
|
|
|
|
|
[Route("api/v{version:apiVersion}/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class InfluxController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IConfiguration _cfg;
|
|
|
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
|
|
|
|
|
|
|
|
|
public InfluxController(IConfiguration cfg, IHttpClientFactory httpClientFactory)
|
|
|
|
|
{
|
|
|
|
|
this._cfg = cfg;
|
|
|
|
|
this._httpClientFactory = httpClientFactory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Produces("application/json")]
|
|
|
|
|
public async Task<string> Query()
|
|
|
|
|
{
|
|
|
|
|
var server = this._cfg["influxdb:url"];
|
|
|
|
|
var url = $"{server}/query";
|
|
|
|
|
var data = new Dictionary<string, string>();
|
|
|
|
|
foreach (var item in this.Request.Form)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
data.Add(item.Key, Encoding.UTF8.GetString(Convert.FromBase64String(item.Value.ToString())));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ex.PrintStack();
|
|
|
|
|
data.Add(item.Key, item.Value.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
using var content = new FormUrlEncodedContent(data);
|
|
|
|
|
var client = _httpClientFactory.CreateClient();
|
|
|
|
|
return await client.PostAsync(url, content).Result.Content.ReadAsStringAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|