PhaseG0: 网关核心 — 7接口+10模型+3基础设施 编译通过
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using System.Net.Http.Json;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace IntegrationGateway.Core.Infrastructure;
|
||||
|
||||
public class GatewayClientFactory
|
||||
{
|
||||
private readonly IHttpClientFactory _httpFactory;
|
||||
private readonly string _volProBaseUrl;
|
||||
|
||||
public GatewayClientFactory(IHttpClientFactory httpFactory, string volProBaseUrl)
|
||||
{
|
||||
_httpFactory = httpFactory;
|
||||
_volProBaseUrl = volProBaseUrl.TrimEnd('/');
|
||||
}
|
||||
|
||||
public HttpClient CreateClient() => _httpFactory.CreateClient("VolPro");
|
||||
|
||||
public async Task<JsonDocument?> RegisterAsync(GatewayRegisterRequest req)
|
||||
{
|
||||
var http = CreateClient();
|
||||
var resp = await http.PostAsJsonAsync($"{_volProBaseUrl}/api/gateway/register", req);
|
||||
if (!resp.IsSuccessStatusCode) return null;
|
||||
return await resp.Content.ReadFromJsonAsync<JsonDocument>();
|
||||
}
|
||||
|
||||
public async Task<bool> HeartbeatAsync(GatewayHeartbeatRequest req)
|
||||
{
|
||||
var http = CreateClient();
|
||||
var resp = await http.PostAsJsonAsync($"{_volProBaseUrl}/api/gateway/heartbeat", req);
|
||||
return resp.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<JsonDocument?> SyncDevicesAsync(string nodeCode, string token, List<object> devices)
|
||||
{
|
||||
var http = CreateClient();
|
||||
var resp = await http.PostAsJsonAsync($"{_volProBaseUrl}/api/gateway/sync/devices",
|
||||
new { nodeCode, token, devices });
|
||||
if (!resp.IsSuccessStatusCode) return null;
|
||||
return await resp.Content.ReadFromJsonAsync<JsonDocument>();
|
||||
}
|
||||
|
||||
public async Task<JsonDocument?> SyncAlarmsAsync(string nodeCode, string token, List<object> alarms)
|
||||
{
|
||||
var http = CreateClient();
|
||||
var resp = await http.PostAsJsonAsync($"{_volProBaseUrl}/api/gateway/sync/alarms",
|
||||
new { nodeCode, token, alarms });
|
||||
if (!resp.IsSuccessStatusCode) return null;
|
||||
return await resp.Content.ReadFromJsonAsync<JsonDocument>();
|
||||
}
|
||||
}
|
||||
|
||||
public class GatewayRegisterRequest
|
||||
{
|
||||
public string NodeCode { get; set; } = "";
|
||||
public string Token { get; set; } = "";
|
||||
public string AdapterTypes { get; set; } = "";
|
||||
public string BaseUrl { get; set; } = "";
|
||||
}
|
||||
|
||||
public class GatewayHeartbeatRequest
|
||||
{
|
||||
public string NodeCode { get; set; } = "";
|
||||
public string Token { get; set; } = "";
|
||||
}
|
||||
Reference in New Issue
Block a user