using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using XCore;
using XHandler.View;
using XImagingXhandler.XDAL;
using System.Data;
using System.Reflection;
using DriverLib.Engine;
using System.Threading;
using XHandler.View.MethodProperty;
using XCommon.Log;
namespace XHandler.Controls
{
public class PauseControl
{
PauseMoveBll pauseMoveBll = new PauseMoveBll();
public RunWnd launchView = null;
private string strCurrentCulture = string.Empty;
///
/// 构造函数
///
public PauseControl(string strCurrentCulture)
{
this.strCurrentCulture = strCurrentCulture;
}
#region 执行暂停,返回结果字符串
///
/// 执行暂停,返回结果字符串
///
/// 装载方法属性节点对象
/// false:连接谁;true:仿真
///
public bool ExecutePause(XmlNode methodNode,bool isSimulator)
{
bool result = true;
if (launchView._cancelSource.IsCancellationRequested)
{
result = false;
return result;
}
#region 数据准备
string name = methodNode.SelectSingleNode("name").InnerText;
string label = methodNode.SelectSingleNode("label").InnerText;
int pauseModel = Convert.ToInt32(methodNode.SelectSingleNode("pauseMode").InnerText);
int pauseTime = 0;
string pauseTipInfo = "";
if (pauseModel == 0)
{
pauseTime = Convert.ToInt32(methodNode.SelectSingleNode("pauseTime").InnerText);
}
else
{
pauseTipInfo = methodNode.SelectSingleNode("pauseTipInfo").InnerText;
}
MethodPauseMove methodPauseMove = new MethodPauseMove();
methodPauseMove.pauseTipInfo = pauseTipInfo;
methodPauseMove.pauseMode= pauseModel;
methodPauseMove.pauseTime = pauseTime.ToString();
#endregion
if (strCurrentCulture.Equals("zh-CN"))
{
launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + name + "】" + Properties.MachineRunResource.strStart.ToString());
}
else
{
launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + name + "】start:");
}
try
{
int iPauseTime = pauseTime;
HxResult ret = pauseMoveBll.ExecutePause(1, isSimulator);
if (ret.Result != ResultType.Success)
{
if (strCurrentCulture.Equals("zh-CN"))
{
launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + name + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.PauseResource.strPauseError.ToString() + ret.AlarmInfo);
}
else
{
launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + name + "】progress:pause is failed! error information:" + ret.AlarmInfo);
}
result = false;
}
else
{
if (strCurrentCulture.Equals("zh-CN"))
{
launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + name + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.PauseResource.strPauseOk.ToString());
}
else
{
launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + name + "】progress:pause is successful!");
}
bool b = launchView.ShowDialogForPause(methodPauseMove);
HxResult ret1 = pauseMoveBll.ExecutePause(2, isSimulator);
if (ret1.Result != ResultType.Success)
{
if (strCurrentCulture.Equals("zh-CN"))
{
launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + name + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.PauseResource.strContinueError.ToString() + ret.AlarmInfo);
}
else
{
launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + name + "】progress:continue is failed! error information:" + ret1.AlarmInfo);
}
result = false;
}
else
{
if (strCurrentCulture.Equals("zh-CN"))
{
launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + name + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.PauseResource.strContinueOk.ToString());
}
else
{
launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + name + "】progress:continue is successful!");
}
}
}
if (strCurrentCulture.Equals("zh-CN"))
{
launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + name + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.MachineRunResource.strEnd.ToString());
}
else
{
launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + name + "】progress: complete;");
}
}
catch (Exception ex)
{
LoggerHelper.ErrorLog("ERROR:", ex);
if (strCurrentCulture.Equals("zh-CN"))
{
launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + name + "】" + Properties.MachineRunResource.strError.ToString() + " 源 " + ex.Source + " 错误信息 " + ex.Message + ";");
}
else
{
launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + name + "】error:source:" + ex.Source + ";error:" + ex.Message + ";");
}
result = false;
}
return result;
}
#endregion
}
}