93 lines
3.6 KiB
C#
93 lines
3.6 KiB
C#
using BestHTTP;
|
|
using Newtonsoft.Json;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 对网络组件的扩展
|
|
/// </summary>
|
|
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);
|
|
/// <summary>
|
|
/// 根据KEY 保存数据到远程服务
|
|
/// 如果远程服务该key已存在会覆盖已有数据
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="netWorkComponent"></param>
|
|
/// <param name="lable"></param>
|
|
/// <param name="value"></param>
|
|
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);
|
|
}
|
|
/// <summary>
|
|
/// 获取远程服务器的数据
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="netWorkComponent"></param>
|
|
/// <param name="lable"></param>
|
|
/// <param name="callBack"></param>
|
|
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);
|
|
}
|
|
/// <summary>
|
|
/// 远程安排获取库存信息
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="netWorkComponent"></param>
|
|
/// <param name="rows"></param>
|
|
/// <param name="callBack"></param>
|
|
public static void RemoteGetStorageDataByRows(this NetWorkComponent netWorkComponent, List<string> rows, OnRequestFinishedDelegate callBack)
|
|
{
|
|
StorageRequestEntity requestEntity = new();
|
|
requestEntity.rows = rows;
|
|
Debug.LogWarning("序列化 =" +JsonConvert.SerializeObject(requestEntity));
|
|
netWorkComponent.PostJson(GetLoopUrl(GlobalConfig.getStorageDataAip), requestEntity, callBack);
|
|
}
|
|
/// <summary>
|
|
/// 获取远程agv任务列表
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="netWorkComponent"></param>
|
|
/// <param name="callBack"></param>
|
|
public static void RemoteGetAgvTaskListData(this NetWorkComponent netWorkComponent, OnRequestFinishedDelegate callBack)
|
|
{
|
|
netWorkComponent.Get(GetLoopUrl(GlobalConfig.agvTaskListApi), callBack);
|
|
}
|
|
/// <summary>
|
|
/// 反馈远程agv任务状态
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="netWorkComponent"></param>
|
|
/// <param name="data"></param>
|
|
/// <param name="callBack"></param>
|
|
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;
|
|
}
|
|
|
|
}
|