Example #1
0
 public ISellerCommandProcessor(
     IIocResolver iocResolver, ExpoServer expoServer, LegancyISellerConfiguration legancyISellerConfiguration)
 {
     this.iocResolver = iocResolver;
     this.expoServer  = expoServer;
     this.legancyISellerConfiguration = legancyISellerConfiguration;
 }
        public RpcTransportMessageRequest BuidRpcTransportMessage(LegancyISellerConfiguration configuration)
        {
            string messageId = MessageIdGenerator.CreateMessageId();

            return(new RpcTransportMessageRequest(messageId)
            {
                MessageHeader = new RpcTransportMessageHeader() /*TODO: 请求上下文*/ }
                {
        /// <summary>
        /// 向老版本iSeller发出EXPO请求,获取EXPO响应
        /// </summary>
        /// <param name="request">EXPO请求</param>
        /// <param name="configuration">EXPO响应</param>
        /// <returns></returns>
        public ISellerExpoResponse SendMessageToLegencyISeller(ISellerExpoRequest request, LegancyISellerConfiguration configuration)
        {
            //构建消息体
            var requestMsg = new Message();

            requestMsg.SetCommand((ushort)configuration.AppClassId, (uint)configuration.CommandId);

            byte[] jsonByte = Encoding.Default.GetBytes(request.ConvertToJson());
            requestMsg.FillBody(new object[] { jsonByte }, true);

            var expoSyncMessage = new WindMessageBus.SyncUserMessage(requestMsg);
            int resultVal       = this.appServer.sendMessage(expoSyncMessage, configuration.CommandTimeout);

            //处理(抛出)异常
            if (expoSyncMessage.ErrInfo != null)
            {
                throw new WindServiceBusException(expoSyncMessage.ErrInfo);
            }

            var responseMsg = expoSyncMessage.Response;

            if (responseMsg.Header.CommandClass != configuration.AppClassId ||
                responseMsg.Header.CommandValue != configuration.CommandId)
            {
                throw new WindServiceBusException("expo response not match request!");
            }

            if (responseMsg.isErrMsg())
            {
                string errorInfo = "unknow expo response exception";
                responseMsg.GetErrInfo(out errorInfo);
                throw new WindServiceBusException(errorInfo);
            }

            // 构建消息返回
            var    expoResponse = responseMsg.ToAnswerObj();
            string jsonResult   = Encoding.Default.GetString((expoResponse[0] as byte[]));

            return(ISellerExpoResponse.ConvertFromJson(jsonResult));
        }