Exemplo n.º 1
0
 /// <summary>
 /// 固定接收一条数据
 /// </summary>
 /// <param name="securityURL"></param>
 /// <param name="targetUrl"></param>
 /// <param name="userCode"></param>
 /// <param name="userPwd"></param>
 /// <returns></returns>
 public static UReceiveResponse Receive_Test(string securityURL, string targetUrl, string userCode, string userPwd, ref UUserToken _token)
 {
     try
     {
         UserSecurityImpl imp = new UserSecurityImpl(securityURL);
         _token = imp.authenticate(userCode, userPwd);
         UExchangeTransportImpl ueti           = new UExchangeTransportImpl(targetUrl);
         UReceiveRequest        receiveRequest = new UReceiveRequest(userCode, 1);
         try
         {
             UReceiveResponse response = ueti.receive(_token, receiveRequest);
             return(response);
         }
         catch (UCommonFaultType ex)
         {
             throw new Exception(string.Format("接收失败[失败代码:{0} 失败内容:{1}]", ex.getCodeField().Trim(), ex.getErrorMessageField().Trim()));
         }
         catch (Exception ex)
         {
             throw new Exception("接收出现错误或者没有数据接收:" + ex.GetBaseException());
         }
     }
     catch (Exception ex)
     {
         throw new Exception("接收出错[" + ex.Message + "]");
     }
 }
Exemplo n.º 2
0
 public static bool Confirm_Test(UReceiveResponse response, string targetUrl, UUserToken _token)
 {
     try
     {
         UExchangeTransportImpl  ueti            = new UExchangeTransportImpl(targetUrl);
         UConfirmReceiveResponse ConfirmResponse = ueti.confirm(_token, response.getConfirmReceiveRequest());
         if (ConfirmResponse != null)
         {
             if (ConfirmResponse.getConfirmResultField() == "true")
             {
                 return(true);
             }
         }
     }
     catch (UCommonFaultType ex)
     {
         throw new Exception(string.Format("接收确认失败[失败代码:{0} 失败内容:{1}]", ex.getCodeField().Trim(), ex.getErrorMessageField().Trim()));
     }
     catch (Exception ex)
     {
         throw new Exception("调用接收确认异常:" + ex.GetBaseException());
     }
     return(false);
 }
Exemplo n.º 3
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", ""));
            }
        }