Example #1
0
        public static bool SendMail(MailMessage message, MailPriority priority, int auditLogId = 0)
        {
            try
            {
                SmtpClient client   = new SmtpClient();
                string     smtpHost = ConfigurationManager.AppSettings["SmtpHost"];

                if (!String.IsNullOrEmpty(smtpHost))
                {
                    client.Host = smtpHost;
                }
                else
                {
                    client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
                }

                message.Priority = priority;

                if (message.From == null)
                {
                    message.From = new MailAddress(ConfigurationManager.AppSettings["FromEmailAddress"]);
                }

                if (message.From == null)
                {
                    throw new InvalidOperationException("Mail can't be without sender");
                }

                client.Send(message);
            }
            catch (Exception ex)
            {
                try
                {
                    EventLog myLog       = new EventLog();
                    string   traceSource = "logging-event-source-name";
                    if (String.IsNullOrEmpty(traceSource))
                    {
                        traceSource = "NOC";
                    }

                    myLog.Source = traceSource;
                    myLog.WriteEntry(ex.ToString(), EventLogEntryType.Error);
                }
                catch
                {
                }

                if (auditLogId <= 0)
                {
                    auditLogId = AuditLog.AddLog("SendMail exception").Id;
                }

                IObjectManager manager    = (ManagerCache.GetManager(typeof(AuditLog)));
                AuditLog       log        = (AuditLog)manager.GetObject(auditLogId);
                string         messageLog = "";
                messageLog += "Expection: " + ex.ToString();
                if (ex.InnerException != null)
                {
                    messageLog += "\r\n<br/>Inner Exception: " + ex.InnerException.ToString();
                }
                messageLog += "\r\n<br/>Mail To: " + message.To.ToString();
                messageLog += "\r\n<br/>Mail Body: " + message.Body;
                log.AddLogDetails(AuditLogType.Error, messageLog);
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// 外部调用api接口信息
        /// </summary>
        /// <returns></returns>
        public ActionResult Query()
        {
            LogisticPara LogisticPara = null;
            ExpressData  ExpressData  = new ExpressData();

            ExpressData.Success = false;
            ExpressData.Message = "获取失败";
            //获取Post参数
            Stream       postData    = Request.InputStream;
            StreamReader sRead       = new StreamReader(postData);
            string       postContent = sRead.ReadToEnd();

            sRead.Close();

            if (IsDebug)
            {
                Normal.WritLog("接受到的参数_postContent:" + postContent);
            }
            if (string.IsNullOrWhiteSpace(postContent))
            {
                ExpressData.Success = false; ExpressData.Message = "缺少参数";
                return(View());
            }
            try
            {
                LogisticPara = JsonConvert.DeserializeObject <LogisticPara>(postContent);
            }
            catch (Exception ex)
            {
                ExpressData.Success = false; ExpressData.Message = "缺少参数";
                return(View());
            }
            if (LogisticPara == null)
            {
                ExpressData.Success = false;
                ExpressData.Message = "缺少参数";
                return(View());
            }
            //验证物流单号
            if (string.IsNullOrWhiteSpace(LogisticPara.logisticsCode))
            {
                ExpressData.Success = false; ExpressData.Message = "缺少物流单号参数"; return(View());
            }
            if (string.IsNullOrWhiteSpace(LogisticPara.shipperCode))
            {
                ExpressData.Success = false; ExpressData.Message = "缺少物流公司代码"; return(View());
            }
            ManagerCache theManagerCache = new ManagerCache(true);

            //如果缓存没有信息
            if (!theManagerCache.CacheService.IsSet(LogisticPara.logisticsCode))
            {
                ExpressData = DataQuery.Query_WuliuMess(LogisticPara.logisticsCode);//从数据库取出
                bool isNewItem = false;
                if (ExpressData == null? isNewItem = true : isNewItem = false || ExpressData.Status == 1 || ExpressData.Status == 2)
                {
                    #region ###涪擎物流接口
                    Logistics.Entity.AliFuQing.Config_Fuqing.GetPara Para_fuqing = new Logistics.Entity.AliFuQing.Config_Fuqing.GetPara();
                    Para_fuqing.type    = LogisticPara.shipperCode;
                    Para_fuqing.no      = LogisticPara.logisticsCode;
                    Para_fuqing.AppCode = LogisticPara.KuaidiApp_Code;
                    ExpressData         = new FuQingService().ConvertToExpressData(new FuQingService().Service(Para_fuqing));
                    #endregion
                    //如果查询失败转向下一接口
                    if (ExpressData.Success == false)
                    {
                        #region ###易源物流接口
                        Logistics.Entity.AliYiYuan.Config.GetPara Para = new Logistics.Entity.AliYiYuan.Config.GetPara();
                        Para.com     = LogisticPara.shipperCode;
                        Para.nu      = LogisticPara.logisticsCode;
                        Para.AppCode = LogisticPara.KuaidiApp_Code;
                        ExpressData  = new AliYiYuanService().ConvertToExpressData(new AliYiYuanService().Service(Para));
                        #endregion
                    }
                    string jsoncontent = JsonConvert.SerializeObject(ExpressData.ExpressDataItems);
                    //写库 根据isNewItem值判断是新增还是修改
                    DataCMD.AddorUp_WuliuMess(ExpressData.number, ExpressData.type, ExpressData.Status, ExpressData.date, jsoncontent, ExpressData.ApiName, isNewItem);
                }
                //HttpRuntime缓存
                //List<CacheCode> list = HttpRuntime.Cache.Get("CacheCode") as List<CacheCode>;
                //HttpRuntime.Cache.Insert();
                //MemoryCache缓存
                theManagerCache.CacheService.Set(LogisticPara.logisticsCode, ExpressData, 60 * 20, 2);
            }
            ViewBag.ExpressData = theManagerCache.CacheService.Get <object>(LogisticPara.logisticsCode);
            if (IsDebug)
            {
                Normal.WritLog("接受到的参数:" + JsonConvert.SerializeObject(ExpressData));
            }
            return(View());
        }