예제 #1
0
        private void PostMail(MailBaseData _MailBaseData, string recipientsAddressRange,
                              string MailSubject, string Describe, string File_Path)
        {
            MailSubject = MailSubject + " (" + WIPCommon.ForamtCurDateTime() + ")";//任务名称
            Describe   += "<br/><br/>";
            Describe   += "消息来自主机:" + WIPCommon.GetHostName() + "<br/>";
            Describe   += "主机发生时间:" + WIPCommon.ForamtCurDateTime() + "<br/>";
            IDictionary <string, object> logDict = new Dictionary <string, object>();

            logDict.Add("recipientsAddressRange", recipientsAddressRange);
            logDict.Add("MailSubject", MailSubject);
            logDict.Add("Describe", Describe);
            logDict.Add("File_Path", File_Path);
            ExceptionInfoEntity exception = WipLogHelper.GetExceptionInfo <IDictionary <string, object> >(namespaceName, "MailSending", logDict, "", "");

            try
            {
                if (File_Path == null)
                {
                    File_Path = "";
                }

                SMTPHelper.MailSending(_MailBaseData, _recipientsAddressRange, MailSubject, Describe.ToString(), "");
            }
            catch (Exception ex)
            {
                WipLogHelper.GetExceptionInfoForError(ex, ref exception);
                WipLogHelper.WriteExceptionInfo(exception);
            }
        }
예제 #2
0
        /// <summary>
        /// 获取需要打印的数据列表
        /// </summary>
        /// <param name="tempName">模板名称</param>
        /// <returns></returns>
        public List <PrintInfoModel> GetNeedPrintList()
        {
            ExceptionInfoEntity exception = WipLogHelper.GetExceptionInfo <string>(namespaceName,
                                                                                   "GetNeedPrintList", "", "", "", ExceptionSource.WIPReceive, ExceptionLevel.BusinessError, WipSource.PrintService);
            List <PrintInfoModel> printList = null;

            try
            {
                string  printTypeStr = string.Join(",", GetPrintTypeList());
                DataSet ds           = dal.GetNeedPrintList(printTypeStr);
                printList = DataTableToListForNeedPrint(ds.Tables[0]);
            }
            catch (Exception ex)
            {
                WipLogHelper.GetExceptionInfoForError(ex, ref exception);
                //判断ex的内容,如果是数据库超时,则过滤,直接光写文本日志
                if (ex.Message.Contains("信号灯超时时间已到") || ex.Message.Contains("未找到或无法访问服务器") ||
                    ex.Message.Contains("超时时间已到"))
                {
                    Log4netHelper.WriteErrorLogByLog4Net(typeof(PrintConfigBLL), ex.Message, ex);
                }
                else
                {
                    WipLogHelper.WriteExceptionInfo(exception);
                }
            }
            return(printList);
        }
        /// <summary>
        /// 公共处理post请求
        /// </summary>
        /// <typeparam name="T">请求参数对象</typeparam>
        /// <typeparam name="T1">返回的data对象</typeparam>
        /// <param name="host">主机名</param>
        /// <param name="url">请求地址</param>
        /// <param name="param">请求参数对象</param>
        ///  <param name="timeout">超时时间,单位:秒,默认为30秒</param>
        /// <returns>返回对象</returns>
        public static ReturnBody <T1> CommonHttpRequestForPost <T, T1>(string host, string url, T param, int timeout = 30)
        {
            try
            {
                Guid guid = Guid.NewGuid();
                WipLogHelper.WriteRequestRecord <T>(host, url, param, guid);

                JavaScriptDateTimeConverter convert = new JavaScriptDateTimeConverter();
                var    strParam = JsonConvert.SerializeObject(param, Formatting.None, convert);//序列化后的字符串
                string content  = new HTTPHelper(host).postContentForString(url,
                                                                            strParam, new Guid(), timeout);
                WipLogHelper.WriteRequestRecord <T>(host, url, param, guid, content);
                if (!string.IsNullOrEmpty(content))
                {
                    ReturnBody <T1> result = JsonConvert.DeserializeObject <ReturnBody <T1> >(content);
                    if (result != null)
                    {
                        return(result);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }
예제 #4
0
 /// <summary>
 /// 公共返回方法
 /// </summary>
 /// <typeparam name="T">返回T</typeparam>
 /// <param name="redCode">返回编号</param>
 /// <param name="exception">异常信息</param>
 /// <param name="resMsg">返回提示</param>
 /// <param name="t">返回t</param>
 /// <returns></returns>
 public static ReturnBody <T> GetReturnBody <T>(string resCode, string resMsg, ExceptionInfoEntity exception, T t = default(T))
 {
     if (resCode != ResCode.SUCCESS)
     {
         WipLogHelper.WriteExceptionInfo(exception);
     }
     return(new ReturnBody <T>()
     {
         resCode = resCode,
         resMsg = resMsg,
         resData = t
     });
 }
예제 #5
0
        /// <summary>
        /// 处理请求(重试功能)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="host"></param>
        /// <param name="url"></param>
        /// <param name="param"></param>
        /// <param name="sysCode"></param>
        /// <param name="requestDesc"></param>
        /// <param name="exception"></param>
        /// <param name="businessExceptionParam"></param>
        /// <param name="requestType"></param>
        /// <param name="execCount"></param>
        private static void CommonDoRequestWithRetry <T>(string host, string url, T param, string sysCode, string requestDesc, ExceptionInfoEntity exception,
                                                         BusinessExceptionMgrParam businessExceptionParam,
                                                         RequestType requestType,
                                                         int execCount = 0)
        {
            execCount = execCount + 1;
            bool            execResult       = false;
            ResponseUpdater _responseUpdater = null;

            try
            {
                switch (requestType)
                {
                case RequestType.PredictiveTask:    // 质量预测发起

                    _responseUpdater = new PredictiveTask_ResUpdater(execResult, exception);

                    break;

                case RequestType.Other:
                case RequestType.QualityTaskToLIMS:

                    _responseUpdater = new ResponseUpdater(execResult, exception);

                    break;

                case RequestType.PushProcessCardInfoToWCS:

                    _responseUpdater = new PushProcessCardInfoToWCS_ResUpdater(execResult, exception);

                    break;
                }

                _responseUpdater.DoResponse <T>(host, url, param, execCount);
                execResult = _responseUpdater._ResponseUpdaterRet.execResult;
                exception  = _responseUpdater._ResponseUpdaterRet.exception;
            }
            catch (Exception ex)
            {
                WipLogHelper.GetExceptionInfoForError(ex, ref exception);
                exception.exceptionMsg += ",执行次数:" + execCount.ToString();
                execResult              = false;
            }
            finally
            {
                if (!execResult)
                {
                    CommonDoRequestWithRetryByFailure <T>(host, url, param, sysCode, requestDesc, exception, businessExceptionParam, requestType, execCount);
                }
            }
        }
예제 #6
0
        public void MailSending(string MailSubject, string Describe, string File_Path)
        {
            #region 数据获取

            try
            {
                _recipientsAddressRange = MailRuleBLL.GetInstance().GetMailPersonListRetStr(_categoryId);

                List <MailBaseData> mailBaseDataList = WIPDataAccess.CreateDAL <ICommonDAL>("CommonDAL").GetMailBaseData();
                if (mailBaseDataList == null || mailBaseDataList.Count == 0)
                {
                    throw new Exception("没有找到邮箱基础数据");
                }
                if (mailBaseDataList.Count > 1)
                {
                    throw new Exception(string.Format("配置的邮箱基础数据大于1条,请检查数据!查到的条数是{0}条", mailBaseDataList.Count.ToString()));
                }
                _MailBaseData = mailBaseDataList[0];
            }
            catch (Exception ex)
            {
                IDictionary <string, object> logDict = new Dictionary <string, object>();
                logDict.Add("MailSubject", MailSubject);
                logDict.Add("Describe", Describe);

                ExceptionInfoEntity exception = WipLogHelper.GetExceptionInfo <IDictionary <string, object> >(namespaceName, "MailSending", logDict, "", "");
                WipLogHelper.GetExceptionInfoForError(ex, ref exception);
                WipLogHelper.WriteExceptionInfo(exception);
            }


            #endregion

            if (string.IsNullOrEmpty(_recipientsAddressRange) || _MailBaseData == null) // 如果基础数据没有获取到,就不发邮件
            {
                return;
            }
            this.PostMail(_MailBaseData, _recipientsAddressRange, MailSubject, Describe.ToString(), "");
        }
예제 #7
0
        /// <summary>
        /// 请求失败的处理
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="host"></param>
        /// <param name="url"></param>
        /// <param name="param"></param>
        /// <param name="sysCode"></param>
        /// <param name="requestDesc"></param>
        /// <param name="exception"></param>
        /// <param name="businessExceptionParam"></param>
        /// <param name="requestType"></param>
        /// <param name="execCount"></param>
        private static void CommonDoRequestWithRetryByFailure <T>(string host, string url, T param, string sysCode, string requestDesc, ExceptionInfoEntity exception,
                                                                  BusinessExceptionMgrParam businessExceptionParam,
                                                                  RequestType requestType,
                                                                  int execCount)
        {
            WipLogHelper.WriteExceptionInfo(exception);
            int retryCount = GetRequestRetryCount();

            if (execCount < retryCount)
            {
                Thread.Sleep(1000);//休眠1秒
                CommonDoRequestWithRetry <T>(host, url, param, sysCode, requestDesc, exception, businessExceptionParam, requestType, execCount);
            }
            else
            {//请求次数用尽
                if (businessExceptionParam != null)
                {
                    //重新赋值异常信息值
                    businessExceptionParam.exceptionMsg = businessExceptionParam.exceptionMsg + "-" + exception.exceptionMsg;
                }

                if (requestType == RequestType.QualityStatusToWCS)
                {//如果是质检结果推送给WCS,则不写业务异常,因为有些料是直接送到后道缓存区,然后线下抽样送检的,库存没有东西的
                }
                else
                {
                    exception.exceptionMsg += "执行次数已超过限制值:" + retryCount.ToString();
                    WipLogHelper.WriteExceptionInfo(exception);

                    //发送报警邮件
                    if (IsSendMail(requestType))
                    {
                        SendMailForCommonDoRequestFailure(param, requestDesc, exception, sysCode, host, url, retryCount, businessExceptionParam);
                    }
                }
            }
        }
        /// <summary>
        /// 公共处理get请求
        /// </summary>
        /// <typeparam name="T">请求参数对象</typeparam>
        /// <typeparam name="T1">返回的data对象</typeparam>
        /// <param name="host">主机名</param>
        /// <param name="url">请求地址</param>
        /// <param name="param">请求参数对象</param>
        /// <param name="timeout">超时时间,单位:秒,默认为30秒</param>
        /// <returns>返回对象</returns>
        public static ReturnBody <T1> CommonHttpRequestForGet <T, T1>(string host, string url, T param, int timeout = 30)
        {
            try
            {
                Guid guid = Guid.NewGuid();
                WipLogHelper.WriteRequestRecord <T>(host, url, param, guid);

                string content = new HTTPHelper(host).getContentForString(url, new Guid(), timeout);
                WipLogHelper.WriteRequestRecord <T>(host, url, param, guid, content);
                if (!string.IsNullOrEmpty(content))
                {
                    ReturnBody <T1> result = JsonConvert.DeserializeObject <ReturnBody <T1> >(content);
                    if (result != null)
                    {
                        return(result);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }