2025-06-06 02:17:54 +09:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
|
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
2025-06-05 20:09:28 +09:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UVC.Network;
|
|
|
|
|
|
|
|
|
|
|
|
namespace UVC.Data
|
|
|
|
|
|
{
|
|
|
|
|
|
public class HttpPipeLine
|
|
|
|
|
|
{
|
|
|
|
|
|
private Dictionary<string, HttpPipeLineInfo> infoList = new Dictionary<string, HttpPipeLineInfo>();
|
|
|
|
|
|
public void Add(string key, HttpPipeLineInfo info)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!infoList.ContainsKey(key))
|
|
|
|
|
|
{
|
|
|
|
|
|
infoList.Add(key, info);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
infoList[key] = info; // Update existing entry
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Remove(string key)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (infoList.ContainsKey(key))
|
|
|
|
|
|
{
|
|
|
|
|
|
infoList.Remove(key);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async void Excute(string key)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (infoList.ContainsKey(key))
|
|
|
|
|
|
{
|
|
|
|
|
|
HttpPipeLineInfo info = infoList[key];
|
|
|
|
|
|
|
|
|
|
|
|
string result = await HttpRequester.Request<string>(info.url, info.method, info.body, info.headers);
|
|
|
|
|
|
|
2025-06-06 02:17:54 +09:00
|
|
|
|
IDataObject? dataObject = null;
|
|
|
|
|
|
if (!string.IsNullOrEmpty(result))
|
2025-06-05 20:09:28 +09:00
|
|
|
|
{
|
2025-06-06 02:17:54 +09:00
|
|
|
|
result = result.Trim();
|
|
|
|
|
|
if (result.StartsWith("{"))
|
|
|
|
|
|
{
|
|
|
|
|
|
JObject source = JObject.Parse(result);
|
|
|
|
|
|
if (info.dataMapper != null) dataObject = info.dataMapper.Mapping(source);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(result.StartsWith("["))
|
|
|
|
|
|
{
|
|
|
|
|
|
JArray source = JArray.Parse(result);
|
|
|
|
|
|
if (info.dataMapper != null) dataObject = info.dataMapper.Mapping(source);
|
|
|
|
|
|
}
|
2025-06-05 20:09:28 +09:00
|
|
|
|
}
|
2025-06-06 02:17:54 +09:00
|
|
|
|
if(dataObject != null) dataObject = DataRepository.Instance.AddData(key, dataObject);
|
|
|
|
|
|
info.handler?.Invoke(dataObject);
|
2025-06-05 20:09:28 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|