803 lines
25 KiB
C#
803 lines
25 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using static DeviceQuery;
|
|
using static PortQuery;
|
|
using UnityEngine.Timeline;
|
|
using AutoMapper;
|
|
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
static GameManager _inst;
|
|
public static GameManager Inst => _inst;
|
|
/// <summary>
|
|
/// 接口地址
|
|
/// </summary>
|
|
public webURL Jk_URL;
|
|
/// <summary>
|
|
/// 登录后返回
|
|
/// </summary>
|
|
public string token;
|
|
|
|
//[Header("机柜点位集合")]
|
|
//public List<Transform> Cabinets_POS;
|
|
[Header("机柜区域集合")]
|
|
public List<Transform> Cabinet_quYu;
|
|
|
|
[Header("设备-查询接口")] public DeviceQuery.Root root_AllDevice;
|
|
|
|
///// <summary>
|
|
///// 场景所有机柜
|
|
///// </summary>
|
|
// public List<GameObject> Cabinets_go;
|
|
/// <summary>
|
|
/// 场景所有机柜
|
|
/// </summary>
|
|
[Header("场景所有机柜")] public List<GameObject> Cabinets_go;
|
|
/// <summary>
|
|
/// 场景所有机柜信息
|
|
/// </summary>
|
|
public List<DeviceList> Cabinets;
|
|
|
|
|
|
/// <summary>
|
|
/// 场景所有机框
|
|
/// </summary>
|
|
[Header("场景所有机框信息")] public List<GameObject> Racks_go;
|
|
/// <summary>
|
|
/// 场景所有机框信息
|
|
/// </summary>
|
|
public List<DeviceList> Racks;
|
|
|
|
/// <summary>
|
|
/// 场景所有机槽
|
|
/// </summary>
|
|
[Header("场景所有机槽信息")] public List<GameObject> MachineSlots_go;
|
|
/// <summary>
|
|
/// 场景所有机槽信息
|
|
/// </summary>
|
|
public List<DeviceList> MachineSlots;
|
|
|
|
/// <summary>
|
|
/// 场景所有板卡
|
|
/// </summary>
|
|
[Header("场景所有板卡信息")] public List<GameObject> TmsCards_go;
|
|
/// <summary>
|
|
/// 场景所有板卡信息
|
|
/// </summary>
|
|
public List<DeviceList> TmsCards;
|
|
|
|
[Header(""), Header("端口-查询接口")] public PortQuery.Root root_AllPort;
|
|
|
|
/// <summary>
|
|
/// 场景所有端口
|
|
/// </summary>
|
|
[Header("场景所有端口信息")] public List<GameObject> TmsPorts_go;
|
|
/// <summary>
|
|
/// 场景所有端口信息
|
|
/// </summary>
|
|
public List<PortList> TmsPorts;
|
|
|
|
[HideInInspector]public int nowLayerMask = 6;
|
|
|
|
[Header("当前设备ID")] public string nowDeviceID;
|
|
|
|
private void Awake()
|
|
{
|
|
if (_inst != null && _inst != this)
|
|
{
|
|
Destroy(this.gameObject);
|
|
}
|
|
else
|
|
{
|
|
_inst = this;
|
|
DontDestroyOnLoad(this.gameObject);
|
|
}
|
|
Jk_URL = new webURL();
|
|
}
|
|
|
|
public IEnumerator dsaklj()
|
|
{
|
|
yield return StartCoroutine(LoadJSON(Application.streamingAssetsPath + "/设备查询.json"));
|
|
|
|
}
|
|
|
|
private async void OnEnable()
|
|
{
|
|
//StartCoroutine(dsaklj());//测试
|
|
//return;//测试
|
|
#region 正式
|
|
await deleteInit();
|
|
TransparentGlowManage.Inst.addScript();
|
|
await initAsync();//正式
|
|
if (root_AllDevice.data == null) return;
|
|
|
|
#region 加载场景所有设备
|
|
//设备信息分类-保存
|
|
foreach (var item in root_AllDevice.data)
|
|
{
|
|
//(机柜)
|
|
if (item.type == "1")
|
|
{
|
|
Cabinets.Add(item);
|
|
}
|
|
//(机框)
|
|
if (item.type == "2" && item.deviceType == "1")
|
|
{
|
|
Racks.Add(item);
|
|
}
|
|
//(机槽)
|
|
else if (item.type == "2" && item.deviceType == "2")
|
|
{
|
|
MachineSlots.Add(item);
|
|
}
|
|
//(板卡)
|
|
else if (item.type == "2" && item.deviceType == "3")
|
|
{
|
|
TmsCards.Add(item);
|
|
}
|
|
}
|
|
|
|
//读取机柜配置
|
|
#region 单独机柜
|
|
//if (Cabinets_POS != null)
|
|
//{
|
|
// for (int i = 0; i < Cabinets_POS.Count; i++)
|
|
// {
|
|
// for (int j = 0; j < Cabinets.Count; j++)
|
|
// {
|
|
// if (Cabinets_POS[i].name == Cabinets[j].devicePosition && Cabinets[j].type == "1")
|
|
// {
|
|
// GameObject go;
|
|
// try
|
|
// {
|
|
// go = Instantiate(Resources.Load<GameObject>("古泉站换流站机房/" + ""));//??
|
|
// }
|
|
// catch (Exception e)
|
|
// {
|
|
// Debug.Log("模型生成错误:" + e.Message);
|
|
// break;
|
|
// }
|
|
// var n = Cabinets_POS[i].name.Split('-');//拆分区域-编号
|
|
// go.name = Cabinets_POS[i].name;
|
|
// go.transform.SetParent(Cabinet_quYu[CengJi(n[0])]);
|
|
// go.transform.position = Cabinets_POS[i].position;
|
|
// go.transform.rotation = Cabinets_POS[i].rotation;
|
|
// go.GetComponent<DeviceQuery>().deviceList = root_AllDevice.data[j];
|
|
// Cabinets_go.Add(go);
|
|
// break;
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
#endregion
|
|
|
|
//读取机柜配置
|
|
if (Cabinets_go != null)
|
|
{
|
|
for (int i = 0; i < Cabinets_go.Count; i++)
|
|
{
|
|
var n = Cabinets_go[i].GetComponent<DeviceQuery>().deviceList;
|
|
for (int j = 0; j < Cabinets.Count; j++)
|
|
{
|
|
if (n.devicePosition == Cabinets[j].devicePosition)
|
|
{
|
|
n = Cabinets[j];
|
|
Cabinets_go[i].GetComponent<DeviceQuery>().deviceList = n;
|
|
//AssignFields(n, Cabinets[j]);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//动态加载设备(机框)
|
|
for (int i = 0; i < Racks.Count; i++)
|
|
{
|
|
foreach (var item in Cabinets_go)
|
|
{
|
|
/*if (item.deviceType == "1")
|
|
{
|
|
}*/
|
|
if (item.GetComponent<DeviceQuery>().deviceList.id == Racks[i].rackId)
|
|
{
|
|
//获取模型编号
|
|
string modelNum = Racks[i].modelNum;
|
|
//获取U位
|
|
var U = Racks[i].devicePosition;
|
|
GameObject go;
|
|
try
|
|
{
|
|
go = Instantiate(Resources.Load<GameObject>("古泉站机房模型90个型号/" + modelNum));
|
|
//写入机框配置
|
|
go.GetComponent<DeviceQuery>().deviceList = Racks[i];
|
|
Racks_go.Add(go);
|
|
|
|
Renderer renderer = go.GetComponentInChildren<Renderer>();
|
|
if (renderer)
|
|
{
|
|
var initrot = go.transform.rotation;
|
|
go.transform.rotation = Quaternion.identity;
|
|
|
|
var bounds = renderer.bounds;
|
|
var a = go.AddComponent<BoxCollider>();
|
|
a.isTrigger = false;
|
|
a.center = bounds.center - go.transform.position;
|
|
a.size = bounds.size;
|
|
//a.transform.rotation = Quaternion.identity; //重置其旋转为默认值
|
|
|
|
go.transform.rotation = initrot;
|
|
}
|
|
Vector3 center = renderer.bounds.center;
|
|
go.transform.position = item.transform.Find("U位/" + U).position;
|
|
//go.transform.rotation = item.transform.Find("U位/" + U).rotation;
|
|
go.name = Racks[i].deviceName;
|
|
go.transform.SetParent(item.transform.Find("U位/" + U));
|
|
break;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.Log("模型生成错误:" + item.name + "\n" + e.Message);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//动态加载设备(机槽)
|
|
for (int i = 0; i < Racks_go.Count; i++)//遍历机框
|
|
{
|
|
//机框下所有设备
|
|
var jc = Racks_go[i].transform.GetComponentsInChildren<DeviceQuery>().ToList();
|
|
for (int j = 0; j < jc.Count; j++)
|
|
{
|
|
//如果是机槽
|
|
if (jc[j].deviceList.deviceType == "2")
|
|
{
|
|
MachineSlots_go.Add(jc[j].gameObject);
|
|
}
|
|
}
|
|
}
|
|
//读取机槽配置
|
|
for (int i = 0; i < MachineSlots_go.Count; i++)
|
|
{
|
|
DeviceQuery DP;
|
|
DP = MachineSlots_go[i].transform.parent.GetComponent<DeviceQuery>();//机槽父物体
|
|
if (!DP) continue;
|
|
foreach (var item in MachineSlots)
|
|
{
|
|
//机槽在机框里
|
|
/*if (item.deviceType == "2")
|
|
{
|
|
|
|
}*/
|
|
if (DP.deviceList.deviceType == "1" && item.shelfId == DP.deviceList.id)
|
|
{
|
|
MachineSlots_go[i].GetComponent<DeviceQuery>().deviceList = item;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//动态加载设备(板卡)
|
|
for (int i = 0; i < MachineSlots_go.Count; i++)//遍历机槽
|
|
{
|
|
//机槽下所有设备
|
|
var bk = MachineSlots_go[i].transform.GetComponentsInChildren<DeviceQuery>().ToList();
|
|
for (int j = 0; j < bk.Count; j++)
|
|
{
|
|
//如果是板卡
|
|
if (bk[j].deviceList.deviceType == "3")
|
|
{
|
|
TmsCards_go.Add(bk[j].gameObject);
|
|
}
|
|
}
|
|
}
|
|
for (int i = 0; i < Racks_go.Count; i++)//遍历机框
|
|
{
|
|
//机框下所有设备
|
|
var bk = Racks_go[i].transform.GetComponentsInChildren<DeviceQuery>().ToList();
|
|
for (int j = 0; j < bk.Count; j++)
|
|
{
|
|
//如果是板卡
|
|
if (bk[j].deviceList.deviceType == "3")
|
|
{
|
|
TmsCards_go.Add(bk[j].gameObject);
|
|
}
|
|
}
|
|
}
|
|
//读取板卡配置
|
|
for (int i = 0; i < TmsCards_go.Count; i++)
|
|
{
|
|
DeviceQuery DP;
|
|
DeviceQuery D;
|
|
DP = TmsCards_go[i].transform.parent.GetComponent<DeviceQuery>();//板卡父物体
|
|
//D = TmsCards_go[i].transform.GetComponent<DeviceQuery>();//板卡
|
|
if (!DP) continue;
|
|
foreach (var item in TmsCards)
|
|
{
|
|
/*if (item.deviceType == "3")
|
|
{
|
|
|
|
}*/
|
|
//板卡在机槽里
|
|
if (DP.deviceList.deviceType == "2" && item.slotId == DP.deviceList.id)
|
|
{
|
|
TmsCards_go[i].GetComponent<DeviceQuery>().deviceList = item;
|
|
break;
|
|
}
|
|
//板卡在机框里
|
|
else if (DP.deviceList.deviceType == "1" && item.shelfId == DP.deviceList.id)
|
|
{
|
|
TmsCards_go[i].GetComponent<DeviceQuery>().deviceList = item;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
/***********************************************************/
|
|
|
|
//端口信息-保存
|
|
foreach (var item in root_AllPort.data)
|
|
{
|
|
TmsPorts.Add(item);
|
|
}
|
|
//动态加载设备(端口)
|
|
for (int i = 0; i < TmsCards_go.Count; i++)//遍历板卡
|
|
{
|
|
//板卡下所有设备
|
|
var dk = TmsCards_go[i].transform.GetComponentsInChildren<PortQuery>().ToList();
|
|
for (int j = 0; j < dk.Count; j++)
|
|
{
|
|
TmsPorts_go.Add(dk[j].gameObject);
|
|
}
|
|
}
|
|
for (int i = 0; i < Racks_go.Count; i++)//遍历机框
|
|
{
|
|
//机框下所有设备
|
|
var dk = Racks_go[i].transform.GetComponentsInChildren<PortQuery>().ToList();
|
|
for (int j = 0; j < dk.Count; j++)
|
|
{
|
|
TmsPorts_go.Add(dk[j].gameObject);
|
|
}
|
|
}
|
|
for (int i = 0; i < MachineSlots.Count; i++)//遍历机槽
|
|
{
|
|
//机槽下所有设备
|
|
var dk = MachineSlots_go[i].transform.GetComponentsInChildren<PortQuery>().ToList();
|
|
for (int j = 0; j < dk.Count; j++)
|
|
{
|
|
TmsPorts_go.Add(dk[j].gameObject);
|
|
}
|
|
}
|
|
|
|
//读取端口配置
|
|
for (int i = 0; i < TmsPorts_go.Count; i++)
|
|
{
|
|
DeviceQuery DP;
|
|
DP = TmsPorts_go[i].transform.parent.GetComponent<DeviceQuery>();
|
|
if (!DP) continue;
|
|
foreach (var item in TmsPorts)
|
|
{
|
|
if (item.deviceId == DP.deviceList.id)
|
|
{
|
|
TmsPorts_go[i].GetComponent<PortQuery>().portList = item;
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
////Debug.Log(transform.Find("22 (2)").childCount);
|
|
//GameObject go = GameObject.Instantiate(Resources.Load<GameObject>("23 (1)"));
|
|
////go.name = go.name.Replace("(Clone)", "");
|
|
////var deviceQuery = go.AddComponent<DeviceQuery>();
|
|
////deviceQuery.deviceList = root.data[0];
|
|
//go.transform.SetParent(Cabinets[0].transform);
|
|
//Renderer renderer = go.GetComponentInChildren<Renderer>();
|
|
//Vector3 center = renderer.bounds.center;
|
|
//go.transform.position = Cabinets[0].transform.position;
|
|
//go.transform.rotation = Cabinets[0].transform.rotation;
|
|
////go.transform.position = new Vector3(go.transform.position.x, go.transform.position.y- center.y, go.transform.position.z);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 场景模型数据初始化
|
|
/// </summary>
|
|
public async Task deleteInit()
|
|
{
|
|
for (int i = 0; i < Racks_go.Count; i++)
|
|
{
|
|
DestroyImmediate(Racks_go[i]);
|
|
}
|
|
for (int i = 0; i < MachineSlots_go.Count; i++)
|
|
{
|
|
DestroyImmediate(MachineSlots_go[i]);
|
|
}
|
|
for (int i = 0; i < TmsCards_go.Count; i++)
|
|
{
|
|
DestroyImmediate(TmsCards_go[i]);
|
|
}
|
|
for (int i = 0; i < TmsPorts_go.Count; i++)
|
|
{
|
|
DestroyImmediate(TmsPorts_go[i]);
|
|
}
|
|
|
|
Cabinets.Clear();
|
|
|
|
Racks_go.Clear();
|
|
Racks.Clear();
|
|
|
|
MachineSlots_go.Clear();
|
|
MachineSlots.Clear();
|
|
|
|
TmsCards_go.Clear();
|
|
TmsCards.Clear();
|
|
|
|
TmsPorts_go.Clear();
|
|
TmsPorts.Clear();
|
|
}
|
|
|
|
IEnumerator LoadJSON(string url)
|
|
{
|
|
UnityWebRequest www = UnityWebRequest.Get(url);
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.result != UnityWebRequest.Result.Success)
|
|
{
|
|
Debug.Log(www.error);
|
|
}
|
|
else
|
|
{
|
|
string jsonData = www.downloadHandler.text;
|
|
// 解析JSON数据
|
|
ParseJSON(jsonData);
|
|
}
|
|
}
|
|
|
|
void ParseJSON(string jsonString)
|
|
{
|
|
// 使用JsonUtility类解析JSON数据到自定义的类对象
|
|
root_AllDevice = JsonConvert.DeserializeObject<DeviceQuery.Root>(jsonString);
|
|
|
|
// 现在你可以访问dataObject中的数据了
|
|
//Debug.Log("Name: " + dataObject.name);
|
|
//Debug.Log("Age: " + dataObject.age);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取层级
|
|
/// </summary>
|
|
/// <param name="s"></param>
|
|
/// <returns></returns>
|
|
public int CengJi(string s)
|
|
{
|
|
int cj = 0;
|
|
switch (s)
|
|
{
|
|
case "A":
|
|
cj = 0;
|
|
break;
|
|
case "B":
|
|
cj = 1;
|
|
break;
|
|
case "C":
|
|
cj = 2;
|
|
break;
|
|
case "D":
|
|
cj = 3;
|
|
break;
|
|
case "E":
|
|
cj = 4;
|
|
break;
|
|
case "F":
|
|
cj = 5;
|
|
break;
|
|
case "G":
|
|
cj = 6;
|
|
break;
|
|
case "H":
|
|
cj = 7;
|
|
break;
|
|
case "I":
|
|
cj = 8;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return cj;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据配置生成线缆
|
|
/// </summary>
|
|
[ContextMenu("根据配置生成线缆")]
|
|
public void FindPortPos()
|
|
{
|
|
var pqs = Array.FindAll(GameObject.FindObjectsOfType<PortQuery>(), itme =>
|
|
{
|
|
PortQuery pq = itme.GetComponent<PortQuery>();
|
|
if (!string.IsNullOrEmpty(pq.portList.id))
|
|
return true;
|
|
else
|
|
return false;
|
|
//return true;
|
|
})/*.Select(item => item.gameObject).ToArray()*/;
|
|
var P_list = FindObjectGroups(pqs.ToList());
|
|
|
|
CreateLine createLine = PatternChoose.Inst.transform.Find("画线").GetComponent<CreateLine>();
|
|
createLine.list7.Clear();
|
|
foreach (var item in P_list)
|
|
{
|
|
createLine.list7.Add(item[0].transform);
|
|
createLine.list7.Add(item[1].transform);
|
|
}
|
|
|
|
createLine.F7();
|
|
}
|
|
|
|
public List<List<PortQuery>> FindObjectGroups(List<PortQuery> objects)
|
|
{
|
|
List<List<PortQuery>> objectGroups = new List<List<PortQuery>>();
|
|
|
|
for (int i = 0; i < objects.Count; i++)
|
|
{
|
|
PortQuery objectA = objects[i];
|
|
|
|
for (int j = i + 1; j < objects.Count; j++)
|
|
{
|
|
PortQuery objectB = objects[j];
|
|
|
|
if (objectA.portList.conDevice == objectB.portList.deviceId && objectA.portList.port == objectB.portList.conPort &&
|
|
objectB.portList.conDevice == objectA.portList.deviceId && objectB.portList.port == objectA.portList.conPort)
|
|
{
|
|
bool isDuplicate = false;
|
|
|
|
foreach (List<PortQuery> group in objectGroups)
|
|
{
|
|
if (group.Contains(objectA) || group.Contains(objectB))
|
|
{
|
|
isDuplicate = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!isDuplicate)
|
|
{
|
|
List<PortQuery> newGroup = new List<PortQuery>();
|
|
newGroup.Add(objectA);
|
|
newGroup.Add(objectB);
|
|
objectGroups.Add(newGroup);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return objectGroups;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 查询所有设备
|
|
/// </summary>
|
|
/// <param name="token"></param>
|
|
/// <returns></returns>
|
|
public async Task initAsync()
|
|
{
|
|
var jsonResult = await CombineJSON.GetJson_POST(Jk_URL.sb_cx, token);
|
|
|
|
root_AllDevice = JsonConvert.DeserializeObject<DeviceQuery.Root>(jsonResult);
|
|
|
|
var jsonResult1 = await CombineJSON.GetJson_POST(Jk_URL.dk_cx, token);
|
|
|
|
root_AllPort = JsonConvert.DeserializeObject<PortQuery.Root>(jsonResult1);
|
|
//return root;
|
|
}
|
|
|
|
public void AssignFields<T, U>(T target, U source)
|
|
{
|
|
Type typeTarget = typeof(T);
|
|
Type typeSource = typeof(U);
|
|
|
|
PropertyInfo[] propertiesTarget = typeTarget.GetProperties();
|
|
PropertyInfo[] propertiesSource = typeSource.GetProperties();
|
|
|
|
foreach (PropertyInfo propertyTarget in propertiesTarget)
|
|
{
|
|
PropertyInfo propertySource = Array.Find(propertiesSource, p => p.Name == propertyTarget.Name);
|
|
|
|
if (propertySource != null)
|
|
{
|
|
object propertyValue = propertySource.GetValue(source);
|
|
propertyTarget.SetValue(target, propertyValue);
|
|
}
|
|
}
|
|
}
|
|
#region MyRegion
|
|
[ContextMenu("改位置")]
|
|
public async void dsa()
|
|
{
|
|
foreach (var item in Cabinets)
|
|
{
|
|
RedactDevice redactDevice = new RedactDevice();
|
|
int a = int.Parse(item.deviceCode.Split('R')[1]);
|
|
string b = "";
|
|
string nub = "";
|
|
if (a <= 8) { b = "I-"; nub = (a % 8).ToString().PadLeft(2, '0'); }
|
|
else if (a <= 16) { b = "H-"; nub = ((a - 8) % 8).ToString().PadLeft(2, '0'); }
|
|
else if (a <= 24) { b = "G-"; nub = ((a - 16) % 8).ToString().PadLeft(2, '0'); }
|
|
else if (a <= 32) { b = "F-"; nub = ((a - 24) % 8).ToString().PadLeft(2, '0'); }
|
|
else if (a <= 40) { b = "E-"; nub = ((a - 32) % 8).ToString().PadLeft(2, '0'); }
|
|
else if (a <= 48) { b = "D-"; nub = ((a - 40) % 8).ToString().PadLeft(2, '0'); }
|
|
else if (a <= 56) { b = "C-"; nub = ((a - 48) % 8).ToString().PadLeft(2, '0'); }
|
|
else if (a <= 64) { b = "B-"; nub = ((a - 56) % 8).ToString().PadLeft(2, '0'); }
|
|
else if (a <= 72) { b = "A-"; nub = ((a - 64) % 8).ToString().PadLeft(2, '0'); }
|
|
if (nub == "00") nub = "08";
|
|
item.devicePosition = b + nub;
|
|
|
|
MapperConfiguration config = new MapperConfiguration(cfg =>
|
|
{
|
|
cfg.CreateMap<DeviceList, RedactDevice.Body>();
|
|
cfg.CreateMap<RedactDevice.Body, DeviceList>();
|
|
});
|
|
|
|
IMapper mapper = config.CreateMapper();
|
|
var objB = mapper.Map<RedactDevice.Body>(item);
|
|
//redactDevice.mybody = ObjectConverter.Convert<DeviceList, RedactDevice.Body>(item);
|
|
redactDevice.mybody = objB;
|
|
await redactDevice.saveJson();
|
|
await Task.Delay(500); // 等待5秒钟
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public static class ObjectConverter
|
|
{
|
|
public static TTarget Convert<TSource, TTarget>(TSource source)
|
|
{
|
|
Type targetType = typeof(TTarget);
|
|
Type sourceType = typeof(TSource);
|
|
|
|
PropertyInfo[] targetProperties = targetType.GetProperties();
|
|
PropertyInfo[] sourceProperties = sourceType.GetProperties();
|
|
|
|
var targetInstance = Activator.CreateInstance(targetType);
|
|
|
|
foreach (var targetProperty in targetProperties)
|
|
{
|
|
var sourceProperty = Array.Find(sourceProperties, p => p.Name == targetProperty.Name);
|
|
|
|
if (sourceProperty != null && sourceProperty.PropertyType == targetProperty.PropertyType)
|
|
{
|
|
var value = sourceProperty.GetValue(source);
|
|
var targetSetMethod = targetProperty.GetSetMethod();
|
|
|
|
if (targetSetMethod != null)
|
|
{
|
|
targetSetMethod.Invoke(targetInstance, new object[] { value });
|
|
}
|
|
}
|
|
}
|
|
|
|
return (TTarget)targetInstance;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 接口地址
|
|
/// </summary>
|
|
[System.Serializable]
|
|
public class webURL
|
|
{
|
|
/// <summary>
|
|
/// 设备-查询URL
|
|
/// </summary>
|
|
[Header("设备-查询URL")] public string sb_cx;
|
|
/// <summary>
|
|
/// 设备-新增URL
|
|
/// </summary>
|
|
[Header("设备-新增URL")] public string sb_xz;
|
|
/// <summary>
|
|
/// 设备-删除URL
|
|
/// </summary>
|
|
[Header("设备-删除URL")] public string sb_sc;
|
|
/// <summary>
|
|
/// 设备-编辑URL
|
|
/// </summary>
|
|
[Header("设备-编辑URL")] public string sb_bj;
|
|
/// <summary>
|
|
/// 端口-查询URL
|
|
/// </summary>
|
|
[Header("端口-查询URL")] public string dk_cx;
|
|
/// <summary>
|
|
/// 端口-新增URL
|
|
/// </summary>
|
|
[Header("端口-新增URL")] public string dk_xz;
|
|
/// <summary>
|
|
/// 端口-删除URL
|
|
/// </summary>
|
|
[Header("端口-删除URL")] public string dk_sc;
|
|
/// <summary>
|
|
/// 端口-编辑URL
|
|
/// </summary>
|
|
[Header("端口-编辑URL")] public string dk_bj;
|
|
|
|
/// <summary>
|
|
/// 环境-查询URL
|
|
/// </summary>
|
|
[Header("环境-查询URL")] public string hj_cx;
|
|
/// <summary>
|
|
/// 告警-查询URL
|
|
/// </summary>
|
|
[Header("告警-查询URL")] public string gj_cx;
|
|
/// <summary>
|
|
/// 工作票-查询URL
|
|
/// </summary>
|
|
[Header("工作票-查询URL")] public string gzp_cx;
|
|
/// <summary>
|
|
/// 检修票-查询URL
|
|
/// </summary>
|
|
[Header("检修票-查询URL")] public string jxp_cx;
|
|
|
|
public webURL()
|
|
{
|
|
string ct = "http://192.168.0.57:8081/";
|
|
sb_cx = ct + "machineRoom/device/queryList";
|
|
sb_xz = ct + "machineRoom/device/save";
|
|
sb_sc = ct + "machineRoom/device/delete";
|
|
sb_bj = ct + "machineRoom/device/updateById";
|
|
|
|
dk_cx = ct + "machineRoom/port/queryList";
|
|
dk_xz = ct + "machineRoom/port/save";
|
|
dk_sc = ct + "machineRoom/port/delete";
|
|
dk_bj = ct + "machineRoom/port/updateById";
|
|
|
|
hj_cx = ct + "machineRoom/tmsPoint/queryList";
|
|
gj_cx = ct + "machineRoom/tmsAlarm/queryList";
|
|
gzp_cx = ct + "machineRoom/tmsWorkTicket/queryList";
|
|
jxp_cx = ct + "machineRoom/tmsOverhaulTicket/queryList";
|
|
}
|
|
|
|
}
|
|
}
|