示例#1
0
        private void _bw_DoWork(object sender, DoWorkEventArgs e)
        {
            DateTime dtNow     = DateTime.Now;
            string   msg       = dtNow.ToString() + ":【同步TMS运单】 ";
            bool     addResult = false;
            string   xmlResult = string.Empty;

            try
            {
                StringBuilder param = new StringBuilder();
                param.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://service.webservice.vtradex.com\" > ");
                param.Append("<soapenv:Header/>");
                param.Append("<soapenv:Body>");
                param.Append("<ser:shipmentXml>" + Utility._SecretKey + "</ser:shipmentXml>");
                param.Append("</soapenv:Body>");
                param.Append("</soapenv:Envelope>");
                xmlResult = HTTPHelper.SendHTTPRequest(param.ToString(), "shipmentXml", "shipmentXml");

                XML result = Utility.ParseXMLToObjec <XML>(xmlResult);
                if (result.MSGCODE != null)
                {
                    msg      += result.MSGCONTENT;
                    addResult = true;
                }
                else
                {
                    msg += result.MESSAGEHEAD.FILENAME + " " + result.MESSAGEHEAD.FILEFUNCTION + " ";
                    if (result.MESSAGEHEAD.FILEFUNCTION == "ADD")
                    {
                        Utility.AddLogText("-------------------------------------------------");
                        Utility.AddLogText("同步TMS运单");
                        addResult = TMSOrderServer.AddTMSOrders(result._MESSAGEDETAIL);
                        msg      += addResult ? "同步成功" : "同步失败";
                        Utility.AddLogText(addResult ? "同步成功" : "同步失败");
                        Utility.AddLogText("-------------------------------------------------");
                        Utility.SaveXMLRequestAndRespond(param.ToString(), xmlResult, "Order", "n");
                    }
                    else
                    {
                        msg += "不处理";
                    }
                }
            }
            catch (Exception ex)
            {
                msg += ex.Message + " ";
                Utility.SaveErrLog(ex.Message, "Order");
                Utility.AddLogText(string.Format("_bw_DoWork-SyncTMSOrder:{0}", ex.Message));
            }
            finally
            {
                if (!addResult && !string.IsNullOrEmpty(xmlResult))
                {
                    string filePath = Utility.SaveXMLFile(xmlResult, dtNow);
                    if (filePath != string.Empty)
                    {
                        msg += "订单内容已保存到[" + filePath + "]";
                    }
                    SendEmail(new Exception(msg), filePath);
                }
                Console.WriteLine(msg.Replace("\n", ""));
            }
        }
示例#2
0
        private void _bw_DoWork(object sender, DoWorkEventArgs e)
        {
            DateTime dtNow     = DateTime.Now;
            string   msg       = dtNow.ToString() + ":【重试运单同步】 ";
            bool     addResult = false;
            string   xmlResult = string.Empty;
            string   filePath  = AppDomain.CurrentDomain.BaseDirectory + "SyncTMSOrderFaild";
            string   fileName  = string.Empty;

            try
            {
                if (Directory.Exists(filePath))
                {
                    string[] files = Directory.GetFiles(filePath);
                    if (files.Count() > 0)
                    {
                        int rIndex = new Random().Next(files.Count());
                        fileName = files[rIndex];
                    }
                }
                if (fileName == string.Empty)
                {
                    addResult = true;
                    msg      += "没有同步失败的TMS运单";
                    return;
                }
                msg += "文件名:" + Path.GetFileName(fileName) + " ";
                try
                {
                    XmlDocument xdoc = new XmlDocument();
                    xdoc.Load(fileName);
                    xmlResult = xdoc.InnerXml;
                }
                catch (Exception ex)
                {
                    throw new Exception("加载xml文件失败:" + ex.Message);
                }
                XML result = Utility.ParseXMLToObjec <XML>(xmlResult);
                if (result.MSGCODE != null)
                {
                    msg      += result.MSGCONTENT;
                    addResult = true;
                }
                else
                {
                    msg += result.MESSAGEHEAD.FILENAME + " " + result.MESSAGEHEAD.FILEFUNCTION + " ";
                    if (result.MESSAGEHEAD.FILEFUNCTION == "ADD")
                    {
                        Utility.AddLogText("-------------------------------------------------");
                        Utility.AddLogText("开始运单同步");
                        addResult = TMSOrderServer.AddTMSOrders(result._MESSAGEDETAIL);
                        msg      += addResult ? "同步成功" : "同步失败";
                        Utility.AddLogText(addResult ? "同步成功" : "同步失败");
                        Utility.AddLogText("-------------------------------------------------");
                    }
                    else
                    {
                        addResult = true;
                        msg      += "不处理";
                    }
                }
            }
            catch (Exception ex)
            {
                msg += ex.Message + " ";
                Utility.AddLogText(string.Format("_bw_DoWork-SyncRetryFaildTMSOrder:{0}", ex.Message));
            }
            finally
            {
                if (addResult && !string.IsNullOrEmpty(fileName))
                {
                    try
                    {
                        File.Delete(fileName);
                    }
                    catch
                    {
                    }
                    Thread.Sleep(1000);
                }
                Console.WriteLine(msg.Replace("\n", ""));
            }
        }