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;
|
|
var fileName = @"Config\MESUrl.cfg";
|
|
if (!File.Exists(fileName))
|
|
throw new Exception("缺少配置文件MESUrl.cfg");
|
|
var url = File.ReadAllText(fileName);
|
|
if (string.IsNullOrEmpty(url))
|
|
throw new Exception("MESUrl.cfg 配置文件错误");
|
|
clientRpc = new ClientRpc(url);
|
|
}
|
|
}
|
|
}
|