Ejemplo n.º 1
0
 static void DoHandleScanLaterOrder(object state)
 {
     if (DateTime.Now.Hour == Utility._HandleScanLaterOrderTime)
     {
         if (_checkTime == null)
         {
             _checkTime = DateTime.Now;
             TMSOrderServer.HandleScanLaterOrder(true);
         }
         else
         {
             Console.WriteLine("[派单修复]今天已执行过自动修复:" + ((DateTime)_checkTime).ToString("yyyy-MM-dd HH:mm:ss"));
         }
     }
     if (_checkTime != null)
     {
         if (((TimeSpan)(DateTime.Now - _checkTime)).TotalDays >= 1)
         {
             _checkTime = null;
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 暂时忽略掉的关系
        /// </summary>
        //private List<int> _ignoreTempRelationList = new List<int>();

        #region Logink正式环境
        private void _bw_DoWork(object sender, DoWorkEventArgs e)
        {
            DateTime      dtNow     = DateTime.Now;
            string        msg       = dtNow.ToString() + ":【节点上报】 ";
            string        xmlResult = string.Empty;
            RelationModel relation  = new RelationModel();

            try
            {
                List <string> senderCodeList = null;
                M_TMSNode     loginkNode     = null;
                if (Utility._LinkType == "2")
                {
                    senderCodeList = TMSOrderServer.GetAllLoginkSenderCode();
                    if (senderCodeList.Count == 0)
                    {
                        msg += "没有配置通过运管平台交换数据的上游发货单位";
                        return;
                    }
                }
                Model.NodeUpload.MESSAGEDETAIL.XML details = NodeUploadServer.GetFirstWaitUploadNode(senderCodeList, ref loginkNode, out relation);

                if (relation != null && relation.Id != 0)
                {
                    msg += string.Format("Relation【{0}】 Number【{1}】 CustomerId【{3}】 当前上报节点Id【{2}】 ", relation.RelationId, relation.Number, relation.CurrentUploadNodeId, relation.CustomerId);
                }
                if (details == null)
                {
                    if (relation != null && relation.Id != 0)                  // && !_ignoreTempRelationList.Contains(relation.Id))
                    {
                        NodeUploadServer.UpdateHandleTime(relation.Id, false); //_ignoreTempRelationList.Add(relation.Id);
                    }
                    msg += "暂无需要上报的节点";
                    return;
                }
                //运管平台上报
                if (senderCodeList != null)
                {
                    string nodeXml      = Utility.ParseXMLToString(loginkNode);
                    string receiverCode = TMSOrderServer.GetAllLoginkSenderCode(relation.CustomerId.ToString())[0];
                    LoginkHelp.Send(Utility._SecurityURL, Utility._TransportURL, Utility._MyCode, Utility._MyPwd, receiverCode, nodeXml, ActionType.LOGINK_CN_TRANSPORT_PREBOOKING);
                    msg += "上报成功 Receiver[" + receiverCode + "]";
                    bool isArrived = false;
                    if (details.CONTENTLIST[0].DETAILLIST[0].TRACKTYPE == "18")//正常签收
                    {
                        isArrived = true;
                        msg      += " 当前为签收节点 ";
                    }
                    bool isUpdate = NodeUploadServer.UpdateCurrentUploadNodeId(relation, isArrived, senderCodeList);
                    Utility.SaveXMLRequestAndRespond(nodeXml, string.Empty, "Node", relation.RelationId);
                    msg += isUpdate ? "更新当前上报节点成功" : "更新当前上报节点失败";
                    return;
                }
                #region 大华东供应链节点上报处理
                _UploadXML.MESSAGEHEAD.SENDTIME = dtNow.ToString("yyyy-MM-dd HH:mm:ss");
                _UploadXML.MESSAGEHEAD.FILENAME = dtNow.ToString("yyyyMMddHHmmss");
                _UploadXML.MESSAGEDETAIL        = "<![CDATA[" + Utility.ParseXMLToString <Model.NodeUpload.MESSAGEDETAIL.XML>(details) + "]]>";
                string xmlRequest = Utility.ParseXMLToString <Model.NodeUpload.XML>(_UploadXML).Replace("<", "&lt;").Replace(">", "&gt;");
                Utility.AddLogText("上传前:" + xmlRequest);
                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:tmsShipmentInTransitXml>" + xmlRequest + "</ser:tmsShipmentInTransitXml>");
                param.Append("</soapenv:Body>");
                param.Append("</soapenv:Envelope>");
                xmlResult = HTTPHelper.SendHTTPRequest(param.ToString(), "tmsShipmentInTransitXml", "tmsShipmentInTransitXml");
                Model.NodeUpload.XML uploadResult = Utility.ParseXMLToObjec <Model.NodeUpload.XML>(xmlResult);
                if (uploadResult.MSGCODE == "0" || string.IsNullOrEmpty(uploadResult.MSGCODE))
                {
                    msg += "上报失败" + " " + uploadResult.MSGCONTENT;
                }
                else if (uploadResult.MSGCODE == "1")
                {
                    msg += "上报成功 ";
                    try
                    {
                        bool isArrived = false;
                        if (details.CONTENTLIST[0].DETAILLIST[0].TRACKTYPE == "18")//正常签收
                        {
                            isArrived = true;
                            msg      += " 当前为签收节点 ";
                        }
                        bool isUpdate = NodeUploadServer.UpdateCurrentUploadNodeId(relation, isArrived, senderCodeList);
                        msg += isUpdate ? "更新当前上报节点成功" : "更新当前上报节点失败";
                        if (isArrived && isUpdate)
                        {
                            UploadCarrierArrived(details.CONTENTLIST[0].DETAILLIST[0], relation.CurrentUploadDataTime);
                        }
                    }
                    catch (Exception ex1)
                    {
                        msg += ex1.Message;
                    }
                }
                Utility.SaveXMLRequestAndRespond(param.ToString(), xmlResult, "Node", relation.RelationId);
                #endregion
            }
            catch (Exception ex)
            {
                msg += ex.Message;
                Utility.SaveErrLog(ex.Message, "Node");
                if (!ex.Message.Contains("重新开始") && !ex.Message.Contains("成功"))
                {
                    if (relation != null)
                    {
                        NodeUploadServer.UpdateHandleTime(relation.Id, false);
                    }
                    SendEmail(new Exception(msg));
                }
            }
            finally
            {
                Console.WriteLine(msg.Replace("\n", ""));
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine(string.Format("-------------------------------欢迎使用上海思博源 TMS运单信息同步系统V{0}-------------------------------\n", Utility._ThisVersion));
            int isEnable = 0;

            //运单同步
            if (int.TryParse(Utility._SyncTMSOrderInterval, out isEnable) && isEnable > 0)
            {
                SyncTMSOrder.Instance.Start();
                Console.WriteLine(string.Format("[运单同步]已开启,同步频率[{0}]秒", Utility._SyncTMSOrderInterval));
                Thread.Sleep(1000);
            }
            else
            {
                Console.WriteLine("[运单同步]未开启,配置文件中[SyncTMSOrderInterval=" + Utility._SyncTMSOrderInterval + "]");
            }
            //新节点上报机制
            if (int.TryParse(Utility._SyncNodeUploadInterval_New, out isEnable) && isEnable > 0)
            {
                SyncNodeUpload_New.Instance.Start();
                Console.WriteLine(string.Format("[节点上报(新)]已开启,上报频率[{0}]秒", Utility._SyncNodeUploadInterval_New));
                Thread.Sleep(1000);
            }
            else
            {
                Console.WriteLine("[节点上报(新)]未开启,配置文件中[SyncNodeUploadInterval_New=" + Utility._SyncNodeUploadInterval_New + "]");
            }
            //节点上报
            if (int.TryParse(Utility._SyncNodeUploadInterval, out isEnable) && isEnable > 0)
            {
                SyncNodeUpload.Instance.Start();
                Console.WriteLine(string.Format("[节点上报]已开启,上报频率[{0}]秒", Utility._SyncNodeUploadInterval));
                Thread.Sleep(1000);
            }
            else
            {
                Console.WriteLine("[节点上报]未开启,配置文件中[SyncNodeUploadInterval=" + Utility._SyncNodeUploadInterval + "]");
            }
            //新机制 节点冷链数据上报
            if (int.TryParse(Utility._SyncNodeDataUploadInterval_New, out isEnable) && isEnable > 0)
            {
                if (int.TryParse(Utility._NodeDataUploadCount, out isEnable) == false)
                {
                    Utility._NodeDataUploadCount = "200";//默认每次上报200条
                }
                if (int.TryParse(Utility._StorageDataTimeOut, out isEnable) == false)
                {
                    Utility._StorageDataTimeOut = "2";
                }
                SyncNodeDataUpload_New.Instance.Start();
                Console.WriteLine(string.Format("[冷链数据上报(新)]已开启,上报频率[{0}]秒 每次上报{1}条", Utility._SyncNodeDataUploadInterval_New, Utility._NodeDataUploadCount));
                Thread.Sleep(1000);
            }
            else
            {
                Console.WriteLine("[冷链数据上报(新)]未开启,配置文件中[SyncNodeDataUploadInterval=" + Utility._SyncNodeDataUploadInterval + "]");
            }
            //节点冷链数据上报
            if (int.TryParse(Utility._SyncNodeDataUploadInterval, out isEnable) && isEnable > 0)
            {
                if (int.TryParse(Utility._NodeDataUploadCount, out isEnable) == false)
                {
                    Utility._NodeDataUploadCount = "200";//默认每次上报200条
                }
                if (int.TryParse(Utility._StorageDataTimeOut, out isEnable) == false)
                {
                    Utility._StorageDataTimeOut = "30";//默认每次上报200条
                }
                SyncNodeDataUpload.Instance.Start();
                Console.WriteLine(string.Format("[冷链数据上报]已开启,上报频率[{0}]秒 每次上报{1}条", Utility._SyncNodeDataUploadInterval, Utility._NodeDataUploadCount));
                Thread.Sleep(1000);
            }
            else
            {
                Console.WriteLine("[冷链数据上报]未开启,配置文件中[SyncNodeDataUploadInterval=" + Utility._SyncNodeDataUploadInterval + "]");
            }
            //重试运单上报
            if (int.TryParse(Utility._RetryFaildTMSOrderUploadInterval, out isEnable) && isEnable > 0)
            {
                SyncRetryFaildTMSOrder.Instance.Start();
                Console.WriteLine(string.Format("[重试运单同步]已开启,重试频率[{0}]秒", Utility._RetryFaildTMSOrderUploadInterval));
                Thread.Sleep(1000);
            }
            else
            {
                Console.WriteLine("[重试运单同步]未开启,配置文件[RetryFaildTMSOrderUploadInterval=" + Utility._RetryFaildTMSOrderUploadInterval + "]");
            }

            if (Utility._HandleScanLaterOrderTime < 0 || Utility._HandleScanLaterOrderTime > 23)
            {
                Console.WriteLine(string.Format("[自动检查先扫描后派单的运单并进行处理]配置为[{0}]无效参数,有效参数为[0-23] 仅启动程序时执行一次", Utility._HandleScanLaterOrderTime));
                TMSOrderServer.HandleScanLaterOrder(true);
            }
            else
            {
                Console.WriteLine(string.Format("[自动检查先扫描后派单的运单并进行处理]配置为[{0}] 每天[{0}]点钟自动执行一次", Utility._HandleScanLaterOrderTime));
                Timer _t = new Timer(DoHandleScanLaterOrder, 600000, 0, 600000);//每过10分钟检查一次今天是否运行过自动检查
            }
            Console.WriteLine();
            ReadCommand();
        }
        /// <summary>
        /// 暂时忽略掉的关系
        /// </summary>
        //private List<long> _ignoreTempRelationList = new List<long>();


        #region Logink正式环境
        private void _bw_DoWork(object sender, DoWorkEventArgs e)
        {
            DateTime      dtNow     = DateTime.Now;
            string        msg       = dtNow.ToString() + ":【订单温湿度上报】 ";
            string        xmlResult = string.Empty;
            RelationModel relation  = new RelationModel();

            try
            {
                List <string>    senderCodeList = null;
                List <M_TMSData> loginkData     = null;
                if (Utility._LinkType == "2")
                {
                    senderCodeList = TMSOrderServer.GetAllLoginkSenderCode();
                    if (senderCodeList.Count == 0)
                    {
                        msg += "没有配置通过运管平台交换数据的上游发货单位";
                        return;
                    }
                }
                XML details = DataUploadServer.GetNextWaitUploadDatas(senderCodeList, ref loginkData, out relation);
                if (relation != null && relation.Id != 0)
                {
                    msg += string.Format("R【{0}】 O【{1}】 N【{2}】 T【{3}】", relation.RelationId, relation.Number, relation.CurrentUploadDataNodeId, relation.CurrentUploadDataTime);
                }
                if (details == null)
                {
                    if (relation != null && relation.Id != 0)                    // && !_ignoreTempRelationList.Contains(relation.Id))
                    {
                        DataUploadServer.UpdateHandleTHTime(relation.Id, false); //_ignoreTempRelationList.Add(relation.Id);
                    }
                    msg += "没有新的节点数据[relationId:" + relation.Id + "]";
                    return;
                }
                //运管平台上报
                if (senderCodeList != null)
                {
                    string dataXml      = Utility.ParseXMLToString(loginkData);
                    string receiverCode = TMSOrderServer.GetAllLoginkSenderCode()[0];
                    LoginkHelp.Send(Utility._SecurityURL, Utility._TransportURL, Utility._MyCode, Utility._MyPwd, receiverCode, dataXml, ActionType.LOGINK_CN_TRANSPORT_PREBOOKING);
                    msg += "上报成功 Receiver[" + receiverCode + "]";
                    bool isUpdate = DataUploadServer.UpdataUploadDataNode(relation);//, ref _ignoreTempRelationList);
                    Utility.SaveXMLRequestAndRespond(dataXml, string.Empty, "Temperature", relation.RelationId);
                    msg += isUpdate ? "更新进度成功" : "更新进度失败";
                    return;
                }
                _UploadXML.MESSAGEHEAD.SENDTIME = dtNow.ToString("yyyy-MM-dd HH:mm:ss");
                _UploadXML.MESSAGEHEAD.FILENAME = dtNow.ToString("yyyyMMddHHmmss");
                _UploadXML.MESSAGEDETAIL        = "<![CDATA[" + Utility.ParseXMLToString <Model.NodeDataUpload.XML>(details) + "]]>";
                string        xmlRequest = Utility.ParseXMLToString <Model.NodeUpload.XML>(_UploadXML).Replace("<", "&lt;").Replace(">", "&gt;");
                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:temperatureXml1>" + xmlRequest + "</ser:temperatureXml1>");
                param.Append("</soapenv:Body>");
                param.Append("</soapenv:Envelope>");
                xmlResult = HTTPHelper.SendHTTPRequest(param.ToString(), "getTmsShipmentTemperature", "temperatureXml1");
                Model.NodeUpload.XML uploadResult = Utility.ParseXMLToObjec <Model.NodeUpload.XML>(xmlResult, param.ToString());
                if (uploadResult.MSGCODE == "0" || string.IsNullOrEmpty(uploadResult.MSGCODE))
                {
                    msg += "上报失败 " + uploadResult.MSGCONTENT;
                }
                else if (uploadResult.MSGCODE == "1")
                {
                    msg += "上报成功 ";
                    try
                    {
                        msg += DataUploadServer.UpdataUploadDataNode(relation) ? "更新进度成功." : "更新进度失败.";
                    }
                    catch (Exception ex1)
                    {
                        msg += ex1.Message;
                    }
                }
                Utility.SaveXMLRequestAndRespond(param.ToString(), xmlResult, "Temperature", relation.RelationId);
            }
            catch (Exception ex)
            {
                msg += ex.Message;
                Utility.SaveErrLog(ex.Message, "Temperature");
                //if (relation.Id != 0 )//&& _ignoreTempRelationList.Contains(relation.Id) == false)
                //    DataUploadServer.UpdateHandleTHTime(relation.Id, false); //_ignoreTempRelationList.Add(relation.Id);
                if (relation != null && relation.CurrentUploadDataNodeId != -1)
                {
                    if (!ex.Message.Contains("重新开始") && !ex.Message.Contains("成功") && !ex.Message.Contains("没有新的载体温湿度"))
                    {
                        DataUploadServer.UpdateHandleTHTime(relation.Id, false);
                        SendEmail(new Exception(msg));
                    }
                }
            }
            finally
            {
                Console.WriteLine(msg.Replace("\n", ""));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 运管平台订单同步 正式环境
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _bw_DoWork_Logink(object sender, DoWorkEventArgs e)
        {
            DateTime          dtNow             = DateTime.Now;
            string            msg               = dtNow.ToString() + ":【同步TMS运单】 ";
            MyEventReceiver   evevnt            = null;
            ExchangeTransport exchangeTransport = null;
            int handelCount = 0;

            try
            {
                List <string> senderCodeList = TMSOrderServer.GetAllLoginkSenderCode();
                if (senderCodeList.Count == 0)
                {
                    msg += "没有配置通过运管平台交换数据的上游发货单位";
                    return;
                }
                MyReceiveResponses response = LoginkHelp.Receive(Utility._SecurityURL, Utility._TransportURL, Utility._MyCode, Utility._MyPwd, ref exchangeTransport);
                if (response == null || response.getEventReceiverList() == null ||
                    (response != null && response.getEventReceiverList() != null && response.getEventReceiverList().Count == 0))
                {
                    msg += "没有数据接收";
                    return;
                }
                evevnt = response.getEventReceiverList()[0];
                string sendCode = evevnt.getEventsender();
                if (evevnt.getXmlcontent() != null)
                {
                    if (!senderCodeList.Contains(sendCode))
                    {
                        handelCount = 1;
                        msg        += "[Code:" + sendCode + "]没有加入系统,不保存此订单数据";
                        string filePath = Utility.SaveXMLFile(evevnt.getXmlcontent(), dtNow, sendCode);
                        msg += " 已保存XML数据到[" + filePath + "]";
                        Utility.SaveErrLog(msg, "Order");
                        return;
                    }
                    try
                    {
                        List <M_TMSOrder> orders = Utility.ParseXMLToObjec <List <M_TMSOrder> >(evevnt.getXmlcontent());
                        TMSOrderServer.AddTMSOrders_Logink(orders, sendCode);
                        handelCount = 1;
                        Utility.SaveXMLRequestAndRespond(evevnt.getXmlcontent(), string.Empty, "Order", orders.Count.ToString());
                        msg += "成功同步" + orders.Count + "条数据 Sender[" + sendCode + "]";
                    }
                    catch (Exception ex)
                    {
                        string filePath = Utility.SaveXMLFile(evevnt.getXmlcontent(), dtNow, sendCode);
                        msg += ex.Message + " ,已保存XML数据到[" + filePath + "]";
                        SendEmail(new Exception(msg), filePath);
                    }
                }
            }
            catch (Exception ex)
            {
                msg += ex.Message + " ";
                if (ex.Message.Contains("订单解析失败"))
                {
                    handelCount = 1;
                }
                SendEmail(new Exception(msg));
                Utility.SaveErrLog(ex.Message, "Order");
            }
            finally
            {
                if (evevnt != null && handelCount > 0)
                {
                    try
                    {
                        if (LoginkHelp.Confirm(exchangeTransport, evevnt.getEventid()))
                        {
                            msg += " 接收确认成功";
                        }
                        else
                        {
                            msg += " 接收确认失败";
                        }
                    }
                    catch (Exception ex)
                    {
                        msg += " " + ex.Message;
                    }
                }
                Console.WriteLine(msg.Replace("\n", ""));
            }
        }
Ejemplo n.º 6
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", ""));
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 运管平台订单同步 测试环境
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _bw_DoWork_Logink_Test(object sender, DoWorkEventArgs e)
        {
            DateTime         dtNow    = DateTime.Now;
            string           msg      = dtNow.ToString() + ":【同步TMS运单】 ";
            UReceiveResponse response = null;
            UUserToken       _token   = null;
            int handelCount           = 0;

            try
            {
                List <string> senderCodeList = TMSOrderServer.GetAllLoginkSenderCode();
                if (senderCodeList.Count == 0)
                {
                    msg += "没有配置通过运管平台交换数据的上游发货单位";
                    return;
                }
                response = LoginkHelp.Receive_Test(Utility._SecurityURL, Utility._TransportURL, Utility._MyCode, Utility._MyPwd, ref _token);
                if (response == null || response.getEventReceiverList() == null ||
                    (response != null && response.getEventReceiverList() != null && response.getEventReceiverList().Count == 0))
                {
                    msg += "没有数据接收";
                    return;
                }
                UEventReceiver evevnt   = response.getEventReceiverList()[0];
                string         sendCode = evevnt.getEventsender();
                //如果返回内容中有键值对,则保存到错误日志中
                if (evevnt.getSimpledata() != null)
                {
                    StringBuilder dicStr = new StringBuilder();
                    foreach (KeyValuePair <string, string> item in evevnt.getSimpledata())
                    {
                        dicStr.AppendLine(string.Format("key={0},value={1}", item.Key, item.Value));
                    }
                    handelCount = 1;
                    Utility.SaveErrLog(dicStr.ToString(), "Order");
                    msg += "接收到的数据存在字典,已保存到ErrLog目录中";
                }
                //接收到的是附件
                if (evevnt.getAttachmentData() != null)
                {
                    handelCount = 1;
                    //保存附件到c盘
                    FileUtil.writeFile(evevnt.getAttachmentData(), "ErrLog/" + dtNow.ToString("yyyyMMdd_HH:mm:ss") + "_" + sendCode + evevnt.getFilename());
                    msg += "接收到的数据存在附件,已保存到ErrLog目录中";
                }
                if (evevnt.getXmlcontent() != null)
                {
                    if (!senderCodeList.Contains(sendCode))
                    {
                        handelCount = 1;
                        msg        += "[Code:" + sendCode + "]没有加入系统,不保存此订单数据";
                        string filePath = Utility.SaveXMLFile(evevnt.getXmlcontent(), dtNow, sendCode);
                        msg += " 已保存XML数据到[" + filePath + "]";
                        Utility.SaveErrLog(msg, "Order");
                        return;
                    }
                    try
                    {
                        List <M_TMSOrder> orders = Utility.ParseXMLToObjec <List <M_TMSOrder> >(evevnt.getXmlcontent());
                        TMSOrderServer.AddTMSOrders_Logink(orders, sendCode);
                        handelCount = 1;
                        Utility.SaveXMLRequestAndRespond(evevnt.getXmlcontent(), string.Empty, "Order", orders.Count.ToString());
                        msg += "成功同步" + orders.Count + "条数据 Sender[" + sendCode + "]";
                    }
                    catch (Exception ex)
                    {
                        string filePath = Utility.SaveXMLFile(evevnt.getXmlcontent(), dtNow, sendCode);
                        msg += ex.Message + " ,已保存XML数据到[" + filePath + "]";
                        SendEmail(new Exception(msg), filePath);
                    }
                }
            }
            catch (Exception ex)
            {
                msg += ex.Message + " ";
                Utility.SaveErrLog(ex.Message, "Order");
            }
            finally
            {
                if (response != null && response.getEventReceiverList() != null && response.getEventReceiverList().Count > 0 && handelCount > 0)
                {
                    try
                    {
                        if (LoginkHelp.Confirm_Test(response, Utility._TransportURL, _token))
                        {
                            msg += " 接收确认成功";
                        }
                        else
                        {
                            msg += " 接收确认失败";
                        }
                    }
                    catch (Exception ex)
                    {
                        msg += " " + ex.Message;
                    }
                }
                Console.WriteLine(msg.Replace("\n", ""));
            }
        }
Ejemplo n.º 8
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", ""));
            }
        }