schangxiang@126.com
2025-11-04 ca398287db3f5ea01f03aac4a85edb13b28100a6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using DataEntity.Share;
using DriverLib.Engine;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Xml;
using XCommon;
using XCommon.Log;
using XCore;
using XHandler.Controls.Run.Com;
using XHandler.View;
using XHandler.View.MethodProperty;
using XImaging.Automation.Service.Interface;
using XImagingXhandler.XDAL;
using static HxEnum.OperationTypeEnum;
using DataRWDAL;
using NPOI.SS.Formula.Functions;
using XHandler.Class;
using DataRWDAL.Rack;
using System.Configuration;
using XHandler.Properties;
using XHandler.View.Liquids;
using DataEntity;
using DriverLibrary;
using HxEnum;
using XHandler.Class.DataEx;
using XCoreBLL;
 
namespace XHandler.Controls
{
    public class WaitForControl
    {
        string strCurrentCulture = "";
        public RunWnd launchView = null;
        WaitForBll waitForBll = new WaitForBll();
        TimerBll timerBll = new TimerBll();
        public WaitForControl(string strCurrentCulture)
        {
            this.strCurrentCulture = strCurrentCulture;
        }
 
        #region 执行等待,返回结果字符串
        /// <summary>
        /// 执行等待,返回结果字符串
        /// </summary>
        /// <param name="xmlEnv">板位节点信息</param>
        /// <param name="methodNode">装载方法属性节点对象</param>
        /// <param name="xmlDocument">完整xml对象</param>
        /// <param name="isSimulator">false:连接谁;true:仿真</param>
        /// <returns></returns>
        public bool ExecuteWaitFor(XmlNode xmlEnv, XmlNode methodNode,XmlDocument xmlDocument,bool isSimulator)
        {
            bool result = true;
            if (launchView._cancelSource.IsCancellationRequested)
            {
                result = false;
                return result;
            }
 
            string methodName = methodNode.SelectSingleNode("name").InnerText;
            try
            {
                
                string duringTimeText = methodNode.SelectSingleNode("duringTimeText").InnerText;
                string duringTimeTextStrIndex = methodNode.SelectSingleNode("duringTimeTextStrIndex").InnerText;
                bool enableEndWaitfor = (methodNode.SelectSingleNode("enableEndWaitfor").InnerText.ToLower() == "true") ? true : false;
                MethodWaitFor methodWaitFor = waitForBll.GenerateMethodTimer(methodNode);
 
                #region Start Log
                if (strCurrentCulture.Equals("zh-CN"))
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodName + "】" + Properties.MachineRunResource.strStart.ToString());
                }
                else
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodName + "】start:");
                }
                #endregion
 
                //数据准备
                //查找关联的Timer节点
                XmlNodeList methodListXML = xmlDocument.SelectNodes("root/method");
                foreach(XmlNode xn in methodListXML)
                {
                    if (xn.SelectSingleNode("strIndex").InnerText == duringTimeTextStrIndex)
                    {
                        XmlNode timerNodeXML = xn;
                        if (timerNodeXML != null)
                        {
                            MethodTimer methodTimer = timerBll.GenerateMethodTimer(timerNodeXML);
                            if (launchView != null)
                            {
                                HxResult ret = waitForBll.ExecutePause(1, isSimulator);
                                if (ret.Result != ResultType.Success)
                                {
                                    if (strCurrentCulture.Equals("zh-CN"))
                                    {
                                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodName + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.PauseResource.strPauseError.ToString() + ret.AlarmInfo);
                                    }
                                    else
                                    {
                                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodName + "】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: 【" + methodName + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.PauseResource.strPauseOk.ToString());
                                    }
                                    else
                                    {
                                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodName + "】progress:pause is successful!");
                                    }
                                    var currentMethodTimer = launchView.methodTimers.SingleOrDefault(x => x.strIndex.Equals(methodTimer.strIndex));
                                    if (currentMethodTimer != null&&Convert.ToDouble(currentMethodTimer.duringTime)>0)
                                    {
                                        methodTimer.duringTime = currentMethodTimer.duringTime;
                                        bool b = launchView.ShowDialogForWaitFor(methodTimer, methodWaitFor);
 
                                        HxResult ret1 = waitForBll.ExecutePause(2, isSimulator);
                                        if (ret1.Result != ResultType.Success)
                                        {
                                            if (strCurrentCulture.Equals("zh-CN"))
                                            {
                                                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodName + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.PauseResource.strContinueError.ToString() + ret.AlarmInfo);
                                            }
                                            else
                                            {
                                                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodName + "】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: 【" + methodName + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.PauseResource.strContinueOk.ToString());
                                            }
                                            else
                                            {
                                                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodName + "】progress:continue is successful!");
                                            }
                                        }
                                    }
                                    else
                                    {
 
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
 
                if (strCurrentCulture.Equals("zh-CN"))
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodName + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.MachineRunResource.strEnd.ToString());
                }
                else
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodName + "】progress: complete;");
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
 
                if (strCurrentCulture.Equals("zh-CN"))
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodName + "】" + Properties.MachineRunResource.strError.ToString() + " 源 " + ex.Source + " 错误信息 " + ex.Message + ";");
                }
                else
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodName + "】error:source:" + ex.Source + ";error:" + ex.Message + ";");
                }
 
                result = false;
            }
            return result;
        }
        #endregion
    }
}