コード例 #1
0
ファイル: NDQ.cs プロジェクト: wuyunhai/EasyCareAuto
        private bool CheckNdqParam(MesSession _session, TransData _transData, string equipmentNumber, List <string> lstProcessData)
        {
            LogInfo log;

            #region 参数校验[螺丝/气密性/预热/固话/点胶]及包含参数是否正确

            string ndqType    = string.Empty;
            bool   paramCheck = true;
            int    paramCount = GetNDQParamCount(lstProcessData, out ndqType); //确认采集类别及参数数量
            if (lstProcessData.Count != paramCount)
            {
                paramCheck = false;
            }

            string mEmployeeName = $"{EmployeeName}-{ndqType}";
            if (!paramCheck)
            {
                log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{mEmployeeName}】接口失败>> 协议错误,请检查协议中是否至少包含采集类别码,业务数据({paramCount}项),执行参数:{_transData.ProcessData}。");
                _transData.ProcessData = $"Protocol error, procedure data should be {paramCount} items, current is {lstProcessData.Count} items, procedure data: {_transData.ProcessData}";
                EmployeeComm.SendMsg(_session, _transData, CheckResult.NG);
                return(false);
            }

            #endregion

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// 料箱与栈位关联关系校验
        /// </summary>
        /// <param name="_session"></param>
        /// <param name="_transData"></param>
        private void ExecuteSTM(MesSession _session, TransData _transData)
        {
            //1、参数校验---equipmentID---------------------------------
            string equipmentID = string.Empty;

            if (!EmployeeComm.CheckEquipmentID(_session, _transData, out equipmentID, EmployeeName))
            {
                return;
            }

            //2、参数校验---ProcessData = 2项------------------------------
            List <string> lstProcessData = new List <string>();

            if (!EmployeeComm.CheckProcessData(_session, _transData, out lstProcessData, EmployeeName, Comparator.Equal, 2))
            {
                return;
            }

            if (!GlobalData.IsDebug)
            {
                //5、执行过站 ---------------------------------
                if (!ExecuteCheckLink(_session, _transData, equipmentID, lstProcessData))
                {
                    return;
                }
            }

            //6、API执行成功  ---------------------------------
            EmployeeComm.SendMsg(_session, _transData, CheckResult.OK);
        }
コード例 #3
0
ファイル: PTC.cs プロジェクト: wuyunhai/EasyCareAuto
        /// <summary>
        /// 产品条码校验
        /// </summary>
        /// <param name="_session"></param>
        /// <param name="_transData"></param>
        private void ExecutePTC(MesSession _session, TransData _transData)
        {
            //1、参数校验---缓存产品条码---------------------------------
            string cacheSN = string.Empty;

            if (!EmployeeComm.CheckNormalParam(_session, _transData, "OP010_SN_CHECK", out cacheSN, "缓存产品条码", EmployeeName))
            {
                return;
            }

            //2、判断条码是否匹配 ---------------------------------
            LogInfo log = null;

            if (cacheSN != _transData.SN)
            {
                log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{EmployeeName}】接口失败>> 请求校验条码:{_transData.SN},缓存条码:{cacheSN}。");
                _transData.ProcessData = $"Bar Code validation failed, request validation BarCode: {_transData.SN}, Cache BarCode: {cacheSN}";
                EmployeeComm.SendMsg(_session, _transData, CheckResult.NG);
                return;
            }

            //3、API执行成功  ---------------------------------
            log = new SocketService.LogInfo(_session, LogLevel.Info, $"[{_transData.SN}]执行【{EmployeeName}】接口成功>> 请求校验条码:{_transData.SN},缓存条码:{cacheSN}。");
            EmployeeComm.SendMsg(_session, _transData, CheckResult.OK);
        }
コード例 #4
0
        /// <summary>
        /// 前工序校验
        /// </summary>
        /// <param name="_session"></param>
        /// <param name="_transData"></param>
        private void ExecutePRC(MesSession _session, TransData _transData)
        {
            //1、参数校验---equipmentID---------------------------------
            string equipmentID = string.Empty;

            if (!EmployeeComm.CheckEquipmentID(_session, _transData, out equipmentID, EmployeeName))
            {
                return;
            }

            if (!GlobalData.IsDebug)
            {
                //3、执行前工序校验
                if (!CheckRouteOnlyCheck(_session, _transData, equipmentID))
                {
                    return;
                }

                //4、执行报工
                EmployeeComm.WorkingEfficiency(_session, _transData, equipmentID, EmployeeName, "103IN");
            }

            //5、API执行成功  ---------------------------------
            EmployeeComm.SendMsg(_session, _transData, CheckResult.OK);
        }
コード例 #5
0
ファイル: PTR.cs プロジェクト: wuyunhai/EasyCareAuto
        /// <summary>
        /// 条码打印请求
        /// </summary>
        /// <param name="_session"></param>
        /// <param name="_transData"></param>
        private void ExecutePTR(MesSession _session, TransData _transData)
        {
            EmployeeName = "条码打印请求";

            //1、参数校验---WorkOrder---------------------------------
            string workOrder = string.Empty;

            if (!EmployeeComm.CheckWorkOrder(_session, _transData, out workOrder, EmployeeName, DataFrom.SQLite))
            {
                return;
            }

            if (_transData.DeviceCode == "OP010")
            {
                EmployeeName = "产品" + EmployeeName;
                //2、获取条码 ---------------------------------
                if (!GetSN(_session, _transData, workOrder))
                {
                    return;
                }

                //4、开始打印打印 ---------------------------------
                if (!Print(_session, _transData))
                {
                    return;
                }

                //5、参数校验---equipmentID---------------------------------
                string equipmentID = string.Empty;
                if (!EmployeeComm.CheckEquipmentID(_session, _transData, out equipmentID, $"EmployeeName <103IN 报工获取设备ID>"))
                {
                    return;
                }

                if (!GlobalData.IsDebug)
                {
                    //5、首站选择在这里获取条码回来后进行执行报工
                    EmployeeComm.WorkingEfficiency(_session, _transData, equipmentID, EmployeeName, "103IN");
                }
            }
            else
            {
                EmployeeName = "成品" + EmployeeName;
                //3、获取条码 ---------------------------------
                if (!GetFinishSN(_session, _transData, workOrder))
                {
                    return;
                }

                //4、开始打印打印 ---------------------------------
                if (!Print(_session, _transData))
                {
                    return;
                }
            }

            //5、API执行成功  ---------------------------------
            EmployeeComm.SendMsg(_session, _transData, CheckResult.OK);
        }
コード例 #6
0
ファイル: NDQ.cs プロジェクト: wuyunhai/EasyCareAuto
        /// <summary>
        /// 通用数据采集
        /// </summary>
        /// <param name="_session"></param>
        /// <param name="_transData"></param>
        private void ExecuteNDQ(MesSession _session, TransData _transData)
        {
            //1、参数校验---equipmentID---------------------------------
            string equipmentID = string.Empty;

            if (!EmployeeComm.CheckEquipmentID(_session, _transData, out equipmentID, EmployeeName))
            {
                return;
            }

            //2、参数校验---ProcessData > 2项------------------------------
            List <string> lstProcessData = new List <string>();

            if (!EmployeeComm.CheckProcessData(_session, _transData, out lstProcessData, EmployeeName, Comparator.MoreThan, 2))
            {
                return;
            }

            if (!GlobalData.IsDebug)
            {
                if ((lstProcessData[0]) == "02")
                {
                    string nEmployeeName = $"气密性测试数据采集-通用过站";

                    //2.1、参数校验---apiStatus
                    string apiStatus = string.Empty;
                    if (!EmployeeComm.CheckApiStatus(_session, _transData, out apiStatus, nEmployeeName))
                    {
                        return;
                    }

                    //2.2、【气密性测试数据采集】需要提前执行【通过过站】操作 //不需要传制令单号
                    if (!EmployeeComm.CheckRoute(_session, _transData, "", equipmentID, apiStatus, nEmployeeName))
                    {
                        return;
                    }

                    //2.3、队列方式进行报工(如果记录了不良则无需进行第二次报工,因为记录不良时已经进行第一次报工了)
                    if (apiStatus != "FAIL")
                    {
                        GlobalData.queueServerNDQ.EnqueueItem(new TestItemFlex(_session, _transData, equipmentID, nEmployeeName, "103OUT"));
                    }
                }

                //3、采集数据参数校验
                if (!CheckNdqParam(_session, _transData, equipmentID, lstProcessData))
                {
                    return;
                }
            }

            //4、API执行成功  ---------------------------------
            EmployeeComm.SendMsg(_session, _transData, CheckResult.OK);

            //5、队列方式保存采集数据
            GlobalData.queueServerNDQ.EnqueueItem(new TestItemFlex(_transData.SN, _transData.DeviceCode, equipmentID, lstProcessData, _session));
        }
コード例 #7
0
        public static T RunTaskWithTimeout <T>(Func <T> TaskAction, int TimeoutMillisecond, MesSession _session, TransData _transData, string actionParam, string caller, bool toPlc = true)
        {
            LogInfo  log;
            Task <T> backgroundTask;

            try
            {
                backgroundTask = Task.Factory.StartNew(TaskAction);
                backgroundTask.Wait(new TimeSpan(0, 0, 0, 0, TimeoutMillisecond));
            }
            catch (AggregateException ex)
            {
                // task failed
                var failMessage = ex.Flatten().InnerException.Message;
                log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】接口超时(>{GlobalData.ApiTimeout}ms),原因:{failMessage},执行参数:{actionParam}.");
                _transData.ProcessData = $"Mission Timeout({TimeoutMillisecond}ms) , Please check the database connection";
                if (toPlc)
                {
                    EmployeeComm.SendMsg(_session, _transData, CheckResult.NG);
                }

                return(default(T));
            }
            catch (Exception ex)
            {
                // task failed
                var failMessage = ex.Message;
                log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】接口超时(>{GlobalData.ApiTimeout}ms),原因:{failMessage},执行参数:{actionParam}.");
                _transData.ProcessData = $"Mission Timeout({TimeoutMillisecond}ms) , Please check the database connection";
                if (toPlc)
                {
                    EmployeeComm.SendMsg(_session, _transData, CheckResult.NG);
                }
                return(default(T));
            }

            if (!backgroundTask.IsCompleted)
            {
                // task timed out
                log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】接口超时(>{GlobalData.ApiTimeout}ms),请检查网络状况或数据库连接配置文件是否正确,执行参数:{actionParam}.");
                _transData.ProcessData = $"Mission Timeout({TimeoutMillisecond}ms) , Please check the database connection,Check SQLServer Connection. ";
                if (toPlc)
                {
                    EmployeeComm.SendMsg(_session, _transData, CheckResult.NG);
                }
                return(default(T));
            }

            // task succeeded
            log = new LogInfo(_session, LogLevel.Info, $"[{_transData.SN}]执行【{caller}】接口成功>> 执行参数:{actionParam}。");
            return(backgroundTask.Result);
        }
コード例 #8
0
        /// <summary>
        /// 检验工序过站(值类型)
        /// </summary>
        /// <param name="_session"></param>
        /// <param name="_transData"></param>
        private void ExecuteTVC(MesSession _session, TransData _transData)
        {
            LogInfo log = null;

            //1、参数校验---EquipmentNumber---------------------------------
            string equipmentID = string.Empty;

            if (!EmployeeComm.CheckEquipmentID(_session, _transData, out equipmentID, EmployeeName))
            {
                return;
            }

            //2、参数校验---WorkOrder---------------------------------
            string workOrder = string.Empty;

            if (!EmployeeComm.CheckWorkOrder(_session, _transData, out workOrder, EmployeeName, DataFrom.SQLite))
            {
                return;
            }

            //3、参数校验---获取待检验数据并校验有效性 ---------------------------------
            decimal weight = ConvertHelper.ToDecimal(_transData.ProcessData, 0);

            if (weight <= 0)
            {
                log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{EmployeeName}】之称重检验接口失败>> 协议错误,请检查协议中过程数据是否为有效值(数值需大于0),当前过程数据:{_transData.ProcessData}。");
                EmployeeComm.SendMsg(_session, _transData, CheckResult.NG);
                return;
            }

            if (!GlobalData.IsDebug)
            {
                //4、执行称重校验 ---------------------------------
                string apiStatus = string.Empty;
                CheckWeight(_session, _transData, weight, out apiStatus);

                //5、执行过站
                if (!EmployeeComm.CheckRoute(_session, _transData, workOrder, equipmentID, apiStatus, EmployeeName))
                {
                    return;
                }

                //5.1、队列方式进行报工(如果记录了不良则无需进行第二次报工,因为记录不良时已经进行第一次报工了)
                if (apiStatus != "FAIL")
                {
                    GlobalData.queueServerNDQ.EnqueueItem(new TestItemFlex(_session, _transData, equipmentID, EmployeeName, "103OUT"));
                }
            }
            //6、API执行成功  ---------------------------------
            EmployeeComm.SendMsg(_session, _transData, CheckResult.OK);
        }
コード例 #9
0
        /// <summary>
        /// 校验EquipmentID并返回
        /// </summary>
        /// <param name="_session"></param>
        /// <param name="_transData"></param>
        /// <param name="equipmentID"></param>
        /// <returns></returns>
        public static bool CheckEquipmentID(MesSession _session, TransData _transData, out string equipmentID, string caller)
        {
            caller     += "-获取设备编码";
            equipmentID = string.Empty;
            META_DevLinkInfo info = BLLFactory <META_DevLink> .Instance.FindSingle($"DevCode='{_transData.DeviceCode}'");

            if (info == null)
            {
                LogInfo log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】接口失败>> 参数错误,根据机台编码[{_transData.DeviceCode}] 获取设备编码失败,请检查SQLLite中是否配置机台映射关系。");
                _transData.ProcessData = $"Failed to get the equipmentID by {_transData.DeviceCode},Check SQLite DB.";
                EmployeeComm.SendMsg(_session, _transData, CheckResult.NG);
                return(false);
            }

            //前工序校验是获取产品工艺类型
            if (!GlobalData.IsDebug && _transData.FuncCode == "PRC")
            {
                DataTable dtR;
                DM_API.DM_SFCInterface Dm_Interface = new DM_API.DM_SFCInterface();
                caller += "-获取工艺类型<用于识别设备编码>";
                string[] arrSN = _transData.SN.Trim().Split('-');
                bool     bRet  = GlobalData.RunTaskWithTimeoutDT <DataTable>(delegate { return(Dm_Interface.SFC_DM_SelectProductionProcess(arrSN[0])); }, out dtR, GlobalData.ApiTimeout, _session, _transData, arrSN[0], caller);
                if (!bRet)
                {
                    return(false);
                }

                string type = DataTableHelper.GetCellValueinDT(dtR, 0, 1);
                info.ProcessType = type;
                BLLFactory <META_DevLink> .Instance.Update(info, info.ID);

                LogInfo log = new SocketService.LogInfo(_session, LogLevel.Info, $"[{_transData.SN}]获取当前机台工艺类型成功,工艺类型[{info.ProcessType}]【已缓存】 ");
            }

            switch (info.ProcessType)
            {
            case "PHEV-3.3KW":
                equipmentID = info.EquipmentID2;
                break;

            case "PHEV-6.6KW":
                equipmentID = info.EquipmentID3;
                break;

            default:
                equipmentID = info.EquipmentID1;
                break;
            }
            return(true);
        }
コード例 #10
0
        /// <summary>
        /// 校验Status并返回
        /// </summary>
        /// <param name="_session"></param>
        /// <param name="_transData"></param>
        /// <param name="status"></param>
        /// <param name="caller"></param>
        /// <returns></returns>
        public static bool CheckApiStatus(MesSession _session, TransData _transData, out string apiStatus, string caller)
        {
            META_ParameterInfo info = BLLFactory <META_Parameter> .Instance.FindSingle($"Key='{_transData.Status}'");

            apiStatus = "ERROR";
            if (info == null || string.IsNullOrEmpty(info.Value))
            {
                LogInfo log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】接口失败>> 参数错误,请检查SQLLite中是否配置WorkOrder参数,执行参数:{_transData.Status}。");
                EmployeeComm.SendMsg(_session, _transData, CheckResult.NG);
                return(false);
            }
            apiStatus = info.Value;
            return(true);
        }
コード例 #11
0
        /// <summary>
        /// 校验WorkOrder并返回
        /// </summary>
        /// <param name="_session"></param>
        /// <param name="_transData"></param>
        /// <param name="workOrder"></param>
        /// <param name="caller"></param>
        /// <returns></returns>
        public static bool CheckNormalParam(MesSession _session, TransData _transData, string paramKey, out string paramValue, string paramDisplay, string caller)
        {
            META_ParameterInfo info = BLLFactory <META_Parameter> .Instance.FindSingle($"Key='{paramKey}'");

            if (info == null && string.IsNullOrEmpty(info.Value))
            {
                paramValue = "ERROR";
                LogInfo log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】接口失败>> 参数错误,获取{paramDisplay}失败,请检查SQLLite中是否缓存{paramDisplay},(请求参数:{paramKey})。");
                _transData.ProcessData = $"Failed to get the cache barcode by [{paramKey}],Check SQLite DB.";
                EmployeeComm.SendMsg(_session, _transData, CheckResult.NG);
                return(false);
            }

            paramValue = info.Value;
            return(true);
        }
コード例 #12
0
        /// <summary>
        /// 通用过站
        /// </summary>
        /// <param name="_session"></param>
        /// <param name="_transData"></param>
        private void ExecuteNRC(MesSession _session, TransData _transData)
        {
            //1、参数校验---equipmentID
            string equipmentID = string.Empty;

            if (!EmployeeComm.CheckEquipmentID(_session, _transData, out equipmentID, EmployeeName))
            {
                return;
            }

            //2、参数校验---WorkOrder
            string workOrder = string.Empty;

            if (_transData.DeviceCode == "OP010") //首站需要校验制令单号
            {
                if (!EmployeeComm.CheckWorkOrder(_session, _transData, out workOrder, $"{EmployeeName}-工单获取", DataFrom.SQLite))
                {
                    return;
                }
            }

            //3、参数校验---apiStatus
            string apiStatus = string.Empty;

            if (!EmployeeComm.CheckApiStatus(_session, _transData, out apiStatus, EmployeeName))
            {
                return;
            }

            if (!GlobalData.IsDebug)
            {
                //4、执行过站
                if (!EmployeeComm.CheckRoute(_session, _transData, workOrder, equipmentID, apiStatus, EmployeeName))
                {
                    return;
                }

                //4.1 队列方式进行报工(如果记录了不良则无需进行第二次报工,因为记录不良时已经进行第一次报工了)
                if (apiStatus != "FAIL")
                {
                    GlobalData.queueServerNDQ.EnqueueItem(new TestItemFlex(_session, _transData, equipmentID, EmployeeName, "103OUT"));
                }
            }

            //5、API执行成功 ---------------------------------
            EmployeeComm.SendMsg(_session, _transData, CheckResult.OK);
        }
コード例 #13
0
        /// <summary>
        /// 校验ProcessData并返回
        /// </summary>
        /// <param name="_session"></param>
        /// <param name="_transData"></param>
        /// <param name="status"></param>
        /// <param name="caller"></param>
        /// <returns></returns>
        public static bool CheckProcessData(MesSession _session, TransData _transData, out List <string> lstProcessData, string caller, Comparator comparator, int count)
        {
            lstProcessData = StringHelper.GetStrArray(_transData.ProcessData, ',', false);
            bool bCp = false;

            switch (comparator)
            {
            case Comparator.MoreThan:
                if (lstProcessData.Count > count)
                {
                    bCp = true;
                }
                break;

            case Comparator.LessThan:
                if (lstProcessData.Count < count)
                {
                    bCp = true;
                }
                break;

            case Comparator.Equal:
                if (lstProcessData.Count == count)
                {
                    bCp = true;
                }
                break;

            case Comparator.NotEqual:
                if (lstProcessData.Count != count)
                {
                    bCp = true;
                }
                break;
            }

            if (!bCp)
            {
                LogInfo log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】协议错误,当前协议中过程数据项应该是{EnumHelper.GetDescription(typeof(Comparator), comparator)}{count}项,当前过程数据({lstProcessData.Count} 项):{_transData.ProcessData}。");
                _transData.ProcessData = $"Protocol error, procedure data should be {comparator} {count} items, current is {lstProcessData.Count} items, procedure data: {_transData.ProcessData}";
                EmployeeComm.SendMsg(_session, _transData, CheckResult.NG);
            }

            return(bCp);
        }
コード例 #14
0
 private static void QueueServer_ProcessItem(TestItemFlex item)
 {
     try
     {
         if (string.IsNullOrEmpty(item.Type))
         {
             InsertNdqData(item);
         }
         else
         {
             EmployeeComm.WorkingEfficiency(item.MesSession, item.TransData, item.EquipmentID, item.EmployeeName, item.Type);
         }
     }
     catch (Exception e)
     {
         throw;
     }
 }
コード例 #15
0
        /// <summary>
        /// 装配工序校验
        /// </summary>
        /// <param name="_session"></param>
        /// <param name="_transData"></param>
        private void ExecuteBRC(MesSession _session, TransData _transData)
        {
            //1、参数校验---equipmentID---------------------------------
            string equipmentID = string.Empty;

            if (!EmployeeComm.CheckEquipmentID(_session, _transData, out equipmentID, EmployeeName))
            {
                return;
            }

            //3、参数校验-获取料箱条码与PCBA条码 并校验---------------------------------
            List <string> lstProcessData = StringHelper.GetStrArray(_transData.ProcessData, ',', false);

            if (!EmployeeComm.CheckProcessData(_session, _transData, out lstProcessData, EmployeeName, Comparator.Equal, 2))
            {
                return;
            }

            if (!GlobalData.IsDebug)
            {
                string boxCode  = lstProcessData[0];
                string pcbaCode = lstProcessData[1];
                //4、PCBA条码验证(是否使用过)
                if (!PCBACheck(_session, _transData, pcbaCode, equipmentID))
                {
                    return;
                }

                //5、PCBA与料箱关联
                if (!PCBALinkBox(_session, _transData, pcbaCode, boxCode))
                {
                    return;
                }

                //6、PCBA与产品关联
                if (!PCBALinkSN(_session, _transData, pcbaCode, equipmentID))
                {
                    return;
                }
            }
            //7、API执行成功  ---------------------------------
            EmployeeComm.SendMsg(_session, _transData, CheckResult.OK);
        }
コード例 #16
0
ファイル: WOR.cs プロジェクト: wuyunhai/EasyCareAuto
        /// <summary>
        /// 工单余量请求
        /// </summary>
        /// <param name="_session"></param>
        /// <param name="_transData"></param>
        private void ExecuteWOR(MesSession _session, TransData _transData)
        {
            //1、参数校验---EquipmentNumber---------------------------------
            //string equipmentID = string.Empty;
            //if (!EmployeeComm.CheckEquipmentID(_session, _transData, out equipmentID, EmployeeName))
            //    return;

            //2、参数校验---WorkOrder---------------------------------
            //string workOrder = string.Empty;
            //if (!EmployeeComm.CheckWorkOrder(_session, _transData, out workOrder, EmployeeName, DataFrom.DB))
            //    return;

            //5、执行获取工单余量
            if (!ExecuteResidueByWO(_session, _transData))
            {
                return;
            }

            //6、API执行成功  ---------------------------------
            EmployeeComm.SendMsg(_session, _transData, CheckResult.OK);
        }
コード例 #17
0
        /// <summary>
        /// 校验WorkOrder并返回(配置文件获取)
        /// </summary>
        /// <param name="_session"></param>
        /// <param name="_transData"></param>
        /// <param name="workOrder"></param>
        /// <param name="caller"></param>
        /// <returns></returns>
        public static bool CheckWorkOrder(MesSession _session, TransData _transData, out string workOrder, string caller, DataFrom getFrom)
        {
            workOrder = string.Empty;
            caller   += "-获取工单编码";

            META_ParameterInfo info = BLLFactory <META_Parameter> .Instance.FindSingle($"Key='WorkOrder'");

            if (info == null && string.IsNullOrEmpty(info.Value))
            {
                LogInfo log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】接口失败>> 参数错误,请检查SQLLite中是否配置WorkOrder参数。");
                EmployeeComm.SendMsg(_session, _transData, CheckResult.NG);
                return(false);
            }

            switch (getFrom)
            {
            case DataFrom.SQLite:
                workOrder = info.Value;
                break;

            case DataFrom.SQLServer:
                DataTable dtR;
                DM_API.DM_SFCInterface Dm_Interface = new DM_API.DM_SFCInterface();
                bool bRet = GlobalData.RunTaskWithTimeoutDT <DataTable>(delegate { return(DBHelper.GetWorkOrderRemain()); }, out dtR, GlobalData.ApiTimeout, _session, _transData, "空", caller);
                if (!bRet)
                {
                    return(false);
                }

                workOrder  = DataTableHelper.GetCellValueinDT(dtR, 0, "ReturnMsg");
                info.Value = workOrder;
                BLLFactory <META_Parameter> .Instance.Update(info, info.ID);

                LogInfo log = new SocketService.LogInfo(_session, LogLevel.Info, $"[{_transData.SN}]执行【{caller}】接口成功,数据缓存本地成功,当前工单号:{workOrder}。");

                break;
            }
            return(true);
        }
コード例 #18
0
        public static bool RunTaskWithTimeoutDT <DataTableT>(Func <DataTable> TaskAction, out DataTable dtR, int TimeoutMillisecond, MesSession _session, TransData _transData, string actionParam, string caller, bool toPlc = true)
        {
            LogInfo          log;
            Task <DataTable> backgroundTask;

            dtR = null;
            try
            {
                backgroundTask = Task.Factory.StartNew(TaskAction);
                backgroundTask.Wait(new TimeSpan(0, 0, 0, 0, TimeoutMillisecond));
            }
            catch (AggregateException ex)
            {
                var failMessage = ex.Flatten().InnerException.Message;
                log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】接口超时(>{TimeoutMillisecond}ms),原因:{failMessage},执行参数:{actionParam}.");
                _transData.ProcessData = $"Mission Timeout({TimeoutMillisecond}ms) , Please check the database connection";
                if (toPlc)
                {
                    EmployeeComm.SendMsg(_session, _transData, CheckResult.NG);
                }
                return(false);
            }
            catch (Exception ex)
            {
                var failMessage = ex.Message;
                log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】接口超时(>{TimeoutMillisecond}ms),原因:{failMessage},执行参数:{actionParam}.");
                _transData.ProcessData = $"Mission Timeout({TimeoutMillisecond}ms) , Please check the database connection";
                if (toPlc)
                {
                    EmployeeComm.SendMsg(_session, _transData, CheckResult.NG);
                }
                return(false);
            }

            if (!backgroundTask.IsCompleted)
            {
                log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】接口超时(>{TimeoutMillisecond}ms),请检查网络状况或数据库连接配置文件是否正确,执行参数:{actionParam}.");
                _transData.ProcessData = $"Mission Timeout({TimeoutMillisecond}ms) , Please check the database connection";
                if (toPlc)
                {
                    EmployeeComm.SendMsg(_session, _transData, CheckResult.NG);
                }
                return(false);
            }

            // task succeeded
            dtR = backgroundTask.Result;
            // 判断API是否执行成功 ---------------------------------
            //string checkStatusR = DataTableHelper.GetCellValueinDT(dtR, 0, "CheckStatus");
            //string checkMsgR = DataTableHelper.GetCellValueinDT(dtR, 0, "ReturnMsg");
            string checkStatusR = DataTableHelper.GetCellValueinDT(dtR, 0, 0);
            string checkMsgR    = DataTableHelper.GetCellValueinDT(dtR, 0, 1);

            if (checkStatusR == "-1")
            {
                log = new LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】接口失败>> 接口返回({checkStatusR}---{checkMsgR}),执行参数:{actionParam}。");
                _transData.ProcessData = $"Error:{checkMsgR}";
                if (toPlc)
                {
                    EmployeeComm.SendMsg(_session, _transData, CheckResult.NG);
                }
                return(false);
            }

            log = new LogInfo(_session, LogLevel.Info, $"[{_transData.SN}]执行【{caller}】接口成功>> 执行参数:{actionParam}。");
            return(true);
        }