dc/Common/MESHeartBit.cs

90 lines
2.8 KiB
C#
Raw Normal View History

2022-04-01 17:03:54 +08:00
#region << >>
/*----------------------------------------------------------------
* 13118
* 2022/3/17 15:08:35
* V1.0.0
*
*
* ----------------------------------------------------------------
*
*
*
*
* V1.0.1
*----------------------------------------------------------------*/
#endregion << >>
using ARI.EAP.HOST.SRD;
using ARI.EAP.HOST.Utilities;
using Glorysoft.SECS.EQP.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
namespace ARI.EAP.HOST.Common
{
/// <summary>
/// MESHeartBit 的摘要说明
/// 提供与MES的连接心跳
/// </summary>
public class MESHeartBit
{
private Timer timer;
private string url = Configuration.conf.httpConfiguration.heartBitUrl;
public MESHeartBit()
{
timer = new Timer(60000);
timer.Elapsed += new ElapsedEventHandler(Method);
timer.AutoReset = true;
timer.Enabled = true;
}
public void Method(object source, ElapsedEventArgs e)
{
string httpContent = SECSUtil.ToJson<MESHeartBitParam>(new MESHeartBitParam());
HttpUtils.sentPOST(url,httpContent);
}
public void Method()
{
string httpContent = SECSUtil.ToJson<MESHeartBitParam>(new MESHeartBitParam());
HttpUtils.sentPOST(url, httpContent);
}
public void MethodClose()
{
MESHeartBitParam mESHeartBitParam = new MESHeartBitParam();
mESHeartBitParam.eapStatus = "stop";
mESHeartBitParam.connectStatus = "disconnected";
mESHeartBitParam.mqStatus = "disconnected";
string httpContent = SECSUtil.ToJson<MESHeartBitParam>(mESHeartBitParam);
HttpUtils.sentPOST(url, httpContent);
}
}
[Serializable]
public class MESHeartBitParam
{
public string connectStatus { get; set; }
public string deviceId { get; set; }
public string eapStatus { get; set; }
public string equipmentName { get; set; }
public string ip { get; set; }
public string mqStatus { get; set; }
public string port { get; set; }
public MESHeartBitParam()
{
this.deviceId = Configuration.conf.connectSetting.deviceId;
this.equipmentName = Configuration.conf.connectSetting.name;
this.ip = Configuration.conf.connectSetting.remoteIp;
this.port = Configuration.conf.connectSetting.remotePort;
this.connectStatus = Global.MF.ConnectStatus.Text;
this.mqStatus = Global.MF.MQStatus.Text;
this.eapStatus = "start";
}
}
}