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
using XHandler.View.Liquids;
using DataEntity;
using DriverLibrary;
using HxEnum;
using XHandler.Class.DataEx;
using XCoreBLL;
using XHandler.View;
using DriverLib.Engine;
using System.Xml;
using System;
using XCommon.Log;
using XImagingXhandler.XDAL;
 
namespace XHandler.Controls.Run
{
    public class TimerControl
    {
        string strCurrentCulture = "";
        public RunWnd launchView = null;
        WaitForBll waitForBll = new WaitForBll();
        TimerBll timerBll = new TimerBll();
        public TimerControl(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 ExecuteTimer(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 strIndex = methodNode.SelectSingleNode("strIndex").InnerText;//定时器节点Id
                double duringTime = Convert.ToDouble(methodNode.SelectSingleNode("duringTime").InnerText);
                MethodTimer methodTimer = timerBll.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
                
                if (launchView != null)
                {
                    launchView.methodTimers.Add(methodTimer);
                    if (strCurrentCulture.Equals("zh-CN"))
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodName + "】" + methodTimer.duringTime+" s" );
                    }
                    else
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodName + "】" + methodTimer.duringTime + " s");
                    }
                }
            }
            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
    }
}