You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

53 lines
1.3 KiB

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ButcherFactory.BO.Utils
{
public static class ButcherFactoryUtil
{
public static List<List<T>> SplitList<T>(List<T> list, int size)
where T : new()
{
List<List<T>> result = new List<List<T>>();
for (int i = 0; i < list.Count() / size; i++)
{
T[] clist = new T[size];
list.CopyTo(i * size, clist, 0, size);
result.Add(clist.ToList());
}
int r = list.Count() % size;
if (r != 0)
{
T[] cclist = new T[r];
list.CopyTo(list.Count() - r, cclist, 0, r);
result.Add(cclist.ToList());
}
return result;
}
static ClientRpc clientRpc;
public static T SimpleMESCall<T>(string method, params object[] args)
{
InitClientRpc();
return clientRpc.Call<T>(method, args);
}
static void InitClientRpc()
{
if (clientRpc != null)
return;
if (!File.Exists("MESUrl.cfg"))
throw new Exception("缺少配置文件MESUrl.cfg");
var url = File.ReadAllText("MESUrl.cfg");
if (string.IsNullOrEmpty(url))
throw new Exception("MESUrl.cfg 配置文件错误");
clientRpc = new ClientRpc(url);
}
}
}