using BestHTTP;
using Newtonsoft.Json;
using System.Collections.Generic;
using UnityEngine;
///
/// 对网络组件的扩展
///
public static class HttpExtensions
{
private static readonly string _LoopIpAddress = string.Format("{0}://{1}:{2}/{3}/",GlobalConfig.agreement, GlobalConfig.serverIp, GlobalConfig.serverPort, GlobalConfig.LoopApiPostfix);
private static readonly string _EmulatorIpAddress = string.Format("{0}://{1}:{2}/{3}/", GlobalConfig.agreement, GlobalConfig.serverIp, GlobalConfig.serverPort, GlobalConfig.EmulatorApiPostfix);
///
/// 根据KEY 保存数据到远程服务
/// 如果远程服务该key已存在会覆盖已有数据
///
///
///
///
///
public static void RemoteSaveData(this NetWorkComponent netWorkComponent, string lable,object value)
{
KeyValueObject data = new(lable, value);
netWorkComponent.PostJson(GetEmulatorUrl(GlobalConfig.remoteSaveDataApi), data);
}
public static void RemoteSaveData(this NetWorkComponent netWorkComponent, string lable, object value, OnRequestFinishedDelegate callBack)
{
KeyValueObject data = new(lable, value);
netWorkComponent.PostJson(GetEmulatorUrl(GlobalConfig.remoteSaveDataApi), data, callBack);
}
///
/// 获取远程服务器的数据
///
///
///
///
///
public static HTTPRequest RemoteGetDataByLable(this NetWorkComponent netWorkComponent, string lable, OnRequestFinishedDelegate callBack)
{
string urlApi = string.Format("{0}?label={1}", GlobalConfig.remoteGetDataApi,lable);
return netWorkComponent.Get(GetEmulatorUrl(urlApi), callBack);
}
///
/// 远程安排获取库存信息
///
///
///
///
///
public static void RemoteGetStorageDataByRows(this NetWorkComponent netWorkComponent, List rows, OnRequestFinishedDelegate callBack)
{
StorageRequestEntity requestEntity = new();
requestEntity.rows = rows;
Debug.LogWarning("序列化 =" +JsonConvert.SerializeObject(requestEntity));
netWorkComponent.PostJson(GetLoopUrl(GlobalConfig.getStorageDataAip), requestEntity, callBack);
}
///
/// 获取远程agv任务列表
///
///
///
///
public static void RemoteGetAgvTaskListData(this NetWorkComponent netWorkComponent, OnRequestFinishedDelegate callBack)
{
netWorkComponent.Get(GetLoopUrl(GlobalConfig.agvTaskListApi), callBack);
}
///
/// 反馈远程agv任务状态
///
///
///
///
///
public static void RemoteFeedBackAgvTaskStatus(this NetWorkComponent netWorkComponent,object data, OnRequestFinishedDelegate callBack)
{
netWorkComponent.PostJson(GetLoopUrl(GlobalConfig.agvTaskStatusFeedBackApi), data, callBack);
}
private static string GetLoopUrl(string api)
{
return _LoopIpAddress + api;
}
private static string GetEmulatorUrl(string api)
{
return _EmulatorIpAddress + api;
}
}