Files
SystemX.Web/Projects/WebClient/Web.Operation/Services/CPMetaService.cs

83 lines
2.9 KiB
C#

using Newtonsoft.Json;
using System;
using SystemX.Core.Communication;
using SystemX.Core.Services;
using Web.Operation.Packet;
using WebClient.Library.Config;
namespace Web.Operation.Services
{
public class CPMetaService
{
private readonly IServiceScopeFactory _scopeFactory;
private readonly ConfigService<WebClientConfig>? _configService;
public string ApiHost { get; set; } = string.Empty;
public CPMetaService(IServiceProvider serviceProvider, IServiceScopeFactory scopeFactory, ConfigService<WebClientConfig> configService)
{
_scopeFactory = scopeFactory;
_configService = configService;
ApiHost = _configService.GetConfig()?.Api.Find(x => x.Id == 1)?.Host;
}
public async Task<Response_GetWbmsMeta> GetWbmsMeta(DateOnly? startDate, DateOnly? endDate, string host, int shardID = 1)
{
string requestUrl = $"https://{host}/CPMeta/GetWbmsMeta?";
requestUrl += $"startDate={startDate}&";
requestUrl += $"endDate={endDate}&";
requestUrl += $"ShardID={shardID}";
Http http = new Http();
var res = await http.GetJsonAsync<Response_GetWbmsMeta>($"{requestUrl}");
LogXnet.WriteLine($"{res.ToJson()}", LogXLabel.HTTP);
return res;
}
public async Task<Response_GetWbmsMeta> GetWbmsMetaByProductID(string productId, string host, int shardID = 1)
{
string requestUrl = $"https://{host}/CPMeta/GetWbmsMetaByProductID?";
requestUrl += $"ProductID={productId}&";
requestUrl += $"ShardID={shardID}";
Http http = new Http();
var res = await http.GetJsonAsync<Response_GetWbmsMeta>($"{requestUrl}");
LogXnet.WriteLine($"{res.ToJson()}", LogXLabel.HTTP);
return res;
}
public async Task<Response_GetWbmsMeta> GetWbmsMetaByMacAddress(string macAddress, string host, int shardID = 1)
{
string requestUrl = $"https://{host}/CPMeta/GetWbmsMetaByMacAddress?";
requestUrl += $"MacAddress={macAddress}&";
requestUrl += $"ShardID={shardID}";
Http http = new Http();
var res = await http.GetJsonAsync<Response_GetWbmsMeta>($"{requestUrl}");
LogXnet.WriteLine($"{res.ToJson()}", LogXLabel.HTTP);
return res;
}
public async Task<Response_GetWbmsMeta> GetWbmsLatest(string host, int count = 20, int shardID = 1)
{
string requestUrl = $"https://{host}/CPMeta/GetWbmsLatest?";
requestUrl += $"Count={count}&";
requestUrl += $"ShardID={shardID}";
Http http = new Http();
var res = await http.GetJsonAsync<Response_GetWbmsMeta>($"{requestUrl}");
LogXnet.WriteLine($"{res.ToJson()}", LogXLabel.HTTP);
return res;
}
}
}