|
|
using MaterialTraceability.Entity.DAO;
|
|
|
using Nancy;
|
|
|
using Newtonsoft.Json;
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using TouchSocket.Core;
|
|
|
using TouchSocket.Rpc;
|
|
|
using TouchSocket.Sockets;
|
|
|
using TouchSocket.WebApi;
|
|
|
|
|
|
namespace MaterialTraceabilityUI.ViewModel
|
|
|
{
|
|
|
public class MesHttpClient
|
|
|
{
|
|
|
public static WebApiClient _MeshttpClient;
|
|
|
public async void init()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
_MeshttpClient = new WebApiClient();
|
|
|
await _MeshttpClient.SetupAsync(new TouchSocketConfig()
|
|
|
//.SetRemoteIPHost("10.150.144.83:5001")
|
|
|
.SetRemoteIPHost("127.0.0.1:9880")
|
|
|
.ConfigurePlugins(a =>
|
|
|
{
|
|
|
//a.Add<Myweb>
|
|
|
//a.UseWebApi();
|
|
|
//.ConfigureConverter(converter =>
|
|
|
//{
|
|
|
// //配置转换器
|
|
|
|
|
|
// //converter.Clear();//可以选择性的清空现有所有格式化器
|
|
|
|
|
|
// //添加Json格式化器,可以自定义Json的一些设置
|
|
|
// converter.AddJsonSerializerFormatter(new Newtonsoft.Json.JsonSerializerSettings() { Formatting = Newtonsoft.Json.Formatting.None });
|
|
|
|
|
|
// //添加Xml格式化器
|
|
|
// converter.AddXmlSerializerFormatter();
|
|
|
//});
|
|
|
|
|
|
}));
|
|
|
await _MeshttpClient.ConnectAsync();
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
//FrmDisplayView.LogInfo.Fatal("MES接口连接异常: " + ex.Message);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public ApiResponse<SysUserInfo> LoadMESdata(string Resource)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
IInvokeOption invokeOption = new InvokeOption();
|
|
|
var requestForPost = new WebApiRequest();
|
|
|
requestForPost.Method = HttpMethodType.Get;
|
|
|
requestForPost.Querys = new KeyValuePair<string, string>[] { new KeyValuePair<string, string>("Resource", Resource) };
|
|
|
JToken responseValue = _MeshttpClient.InvokeT<JToken>("/GetUserList", invokeOption, requestForPost);
|
|
|
|
|
|
return JTokenToEntity<ApiResponse<SysUserInfo>>(responseValue);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
//FrmDisplayView.LogInfo.Fatal("MES接口调用异常: " + ex.Message);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
public static T JTokenToEntity<T>(JToken value) where T : class
|
|
|
{
|
|
|
if (value == null)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
string json = value.ToString();
|
|
|
if (string.IsNullOrEmpty(json))
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
T ResponseEntity;
|
|
|
ResponseEntity = JsonConvert.DeserializeObject<T>(json);
|
|
|
return ResponseEntity;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|