data pipeline 개발
This commit is contained in:
54
Assets/Scripts/UVC/Data/HttpPipeLine.cs
Normal file
54
Assets/Scripts/UVC/Data/HttpPipeLine.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
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);
|
||||
JObject jsonResult = JObject.Parse(result);
|
||||
DataObject dataObject = new DataObject(jsonResult);
|
||||
|
||||
if (info.dataMapper != null)
|
||||
{
|
||||
dataObject = info.dataMapper.Map(jsonResult);
|
||||
}
|
||||
DataRepository.Instance.AddData(key, dataObject);
|
||||
if (info.handler != null)
|
||||
{
|
||||
info.handler(dataObject);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user