Esempio n. 1
0
        public int Handle(UFX.impl.DataParser dataParser)
        {
            List <UFXWithdrawResponse> responseItems = new List <UFXWithdrawResponse>();
            var dataFieldMap  = UFXDataBindingHelper.GetProperty <UFXWithdrawResponse>();
            var errorResponse = T2ErrorHandler.Handle(dataParser);

            if (T2ErrorHandler.Success(errorResponse.ErrorCode))
            {
                responseItems = UFXDataSetHelper.ParseSubscribeData <UFXWithdrawResponse>(dataParser);
            }

            //update the database
            if (responseItems != null && responseItems.Count > 0)
            {
                foreach (var responseItem in responseItems)
                {
                    int commandId;
                    int submitId;
                    int requestId;

                    if (EntrustRequestHelper.ParseThirdReff(responseItem.ThirdReff, out commandId, out submitId, out requestId))
                    {
                        _entrustSecurityBLL.UpdateEntrustStatus(submitId, commandId, responseItem.StockCode, Model.EnumType.EntrustStatus.CancelToUFX);
                    }
                    else
                    {
                        string msg = string.Format("Fail to parse the third_reff: [{0}], entrust_no: [{1}].", responseItem.ThirdReff, responseItem.EntrustNo);
                        logger.Error(msg);
                    }
                }
            }

            return(responseItems.Count);
        }
Esempio n. 2
0
        private int WithdrawBasketCallback(CallerToken token, DataParser dataParser)
        {
            var errorResponse = T2ErrorHandler.Handle(dataParser);

            List <UFXBasketWithdrawResponse> responseItems = new List <UFXBasketWithdrawResponse>();

            var dataFieldMap = UFXDataBindingHelper.GetProperty <UFXBasketWithdrawResponse>();

            for (int i = 1, count = dataParser.DataSets.Count; i < count; i++)
            {
                var dataSet = dataParser.DataSets[i];
                foreach (var dataRow in dataSet.Rows)
                {
                    UFXBasketWithdrawResponse p = new UFXBasketWithdrawResponse();
                    UFXDataSetHelper.SetValue <UFXBasketWithdrawResponse>(ref p, dataRow.Columns, dataFieldMap);
                    responseItems.Add(p);
                }
            }

            List <EntrustSecurityItem> entrustSecuItems = new List <EntrustSecurityItem>();

            int ret = -1;

            if (token.SubmitId > 0)
            {
                if (T2ErrorHandler.Success(errorResponse.ErrorCode))
                {
                    foreach (var responseItem in responseItems)
                    {
                        var entrustItem = new EntrustSecurityItem
                        {
                            SubmitId  = token.SubmitId,
                            CommandId = token.CommandId,
                            SecuCode  = responseItem.StockCode,
                            EntrustNo = responseItem.EntrustNo,
                        };

                        entrustSecuItems.Add(entrustItem);
                    }

                    ret = _entrustdao.UpdateSecurityEntrustStatus(entrustSecuItems, Model.EnumType.EntrustStatus.CancelSuccess);
                    ret = _entrustcmddao.UpdateEntrustCommandStatus(token.SubmitId, Model.EnumType.EntrustStatus.CancelSuccess);
                    ret = _tradecmddao.UpdateTargetNumBySubmitId(token.SubmitId, token.CommandId);
                }
            }

            if (token.Caller != null)
            {
                token.Caller(token, entrustSecuItems, errorResponse);
            }

            if (token.WaitEvent != null)
            {
                token.WaitEvent.Set();
            }

            return(ret);
        }
Esempio n. 3
0
        public UFXPushMessageType GetMessageType(DataParser dataParser)
        {
            UFXPushMessageType       messageType   = UFXPushMessageType.None;
            List <UFXFilterResponse> responseItems = new List <UFXFilterResponse>();
            var dataFieldMap = UFXDataBindingHelper.GetProperty <UFXFilterResponse>();

            //TODO: check the count of dataset.
            responseItems = UFXDataSetHelper.ParseSubscribeData <UFXFilterResponse>(dataParser);

            if (responseItems != null && responseItems.Count == 1)
            {
                var typeChar = Char.Parse(responseItems[0].MsgType);
                UFXPushMessageType tempType;
                messageType = Enum.TryParse(typeChar.ToString(), true, out tempType) ? tempType : (UFXPushMessageType)typeChar;
            }

            return(messageType);
        }
Esempio n. 4
0
        public static List <T> ParseSubscribeData <T>(DataParser parser) where T : new()
        {
            List <T> responseItems = new List <T>();

            var dataFieldMap = UFXDataBindingHelper.GetProperty <T>();

            for (int i = 0, count = parser.DataSets.Count; i < count; i++)
            {
                var dataSet = parser.DataSets[i];
                foreach (var dataRow in dataSet.Rows)
                {
                    T p = new T();
                    UFXDataSetHelper.SetValue <T>(ref p, dataRow.Columns, dataFieldMap);
                    responseItems.Add(p);
                }
            }

            return(responseItems);
        }
Esempio n. 5
0
        private int EntrustBasketCallback(CallerToken token, DataParser dataParser)
        {
            int ret = -1;
            List <EntrustSecurityItem> entrustSecuItems = new List <EntrustSecurityItem>();

            var errorResponse = T2ErrorHandler.Handle(dataParser);

            token.OutArgs = errorResponse;
            if (T2ErrorHandler.Success(errorResponse.ErrorCode))
            {
                List <UFXBasketEntrustResponse> responseItems = new List <UFXBasketEntrustResponse>();
                var dataFieldMap = UFXDataBindingHelper.GetProperty <UFXBasketEntrustResponse>();
                for (int i = 1, count = dataParser.DataSets.Count; i < count; i++)
                {
                    var dataSet = dataParser.DataSets[i];
                    foreach (var dataRow in dataSet.Rows)
                    {
                        UFXBasketEntrustResponse p = new UFXBasketEntrustResponse();
                        UFXDataSetHelper.SetValue <UFXBasketEntrustResponse>(ref p, dataRow.Columns, dataFieldMap);
                        responseItems.Add(p);
                    }
                }

                foreach (var responseItem in responseItems)
                {
                    var entrustItem = new EntrustSecurityItem
                    {
                        SubmitId         = token.SubmitId,
                        RequestId        = responseItem.ExtSystemId,
                        SecuCode         = responseItem.StockCode,
                        EntrustNo        = responseItem.EntrustNo,
                        BatchNo          = responseItem.BatchNo,
                        EntrustFailCode  = responseItem.EntrustFailCode,
                        EntrustFailCause = responseItem.FailCause,
                    };

                    entrustSecuItems.Add(entrustItem);
                }

                ret = _entrustdao.UpdateSecurityEntrustResponseByRequestId(entrustSecuItems);

                if (token.InArgs != null && token.InArgs is EntrustCommandItem)
                {
                    var cmdItem = token.InArgs as EntrustCommandItem;

                    ret = _tradecmddao.UpdateTargetNum(cmdItem.CommandId, cmdItem.Copies);
                }

                var batchNos = responseItems.Select(p => p.BatchNo).Distinct().ToList();
                if (batchNos.Count == 1)
                {
                    int batchNo = batchNos[0];

                    ret = _entrustcmddao.UpdateEntrustCommandBatchNo(token.SubmitId, batchNo, Model.EnumType.EntrustStatus.Completed, errorResponse.ErrorCode, errorResponse.ErrorMessage);
                }
                else
                {
                    //TODO:
                    string msg = string.Format("The SubmitId [{0}] was split into several batch no", token.SubmitId);
                    logger.Warn(msg);
                }
            }
            else
            {
                ret = -1;
            }

            if (token.Caller != null)
            {
                token.Caller(token, entrustSecuItems, errorResponse);
            }

            if (token.WaitEvent != null)
            {
                token.WaitEvent.Set();
            }

            return(ret);
        }
Esempio n. 6
0
        private void OutputParam <T>(UFXFunctionCode functionCode, List <T> requests)
        {
            FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(functionCode);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("=========================================================");
            sb.AppendLine("FunctionCode: " + (int)functionCode);
            foreach (FieldItem item in functionItem.RequestFields)
            {
                if (item.Name.Equals("entrust_amount"))
                {
                    sb.AppendFormat("{0}|{1}|{2}|{3}\n", item.Name, UFXPackFieldType.FloatType, item.Width, item.Scale);
                }
                else
                {
                    sb.AppendFormat("{0}|{1}|{2}|{3}\n", item.Name, item.Type, item.Width, item.Scale);
                }
            }

            var dataFieldMap = UFXDataBindingHelper.GetProperty <T>();

            foreach (var request in requests)
            {
                foreach (FieldItem item in functionItem.RequestFields)
                {
                    if (dataFieldMap.ContainsKey(item.Name))
                    {
                        var  dataField = dataFieldMap[item.Name];
                        Type type      = request.GetType();

                        object obj = type.GetProperty(dataField.Name).GetValue(request);
                        sb.AppendFormat("{0}:{1}|", item.Name, obj);
                    }
                    else
                    {
                        switch (item.Name)
                        {
                        case "user_token":
                        {
                            sb.AppendFormat("{0}:{1}|", item.Name, LoginManager.Instance.LoginUser.Token);
                        }
                        break;

                        default:
                            if (item.Type == UFXPackFieldType.IntType)
                            {
                                sb.AppendFormat("{0}:{1}|", item.Name, -1);
                            }
                            else if (item.Type == UFXPackFieldType.StringType || item.Type == UFXPackFieldType.CharType)
                            {
                                sb.AppendFormat("{0}:{1}|", item.Name, item.Name);
                            }
                            else
                            {
                                sb.AppendFormat("{0}:{1}|", item.Name, item.Name);
                            }
                            break;
                        }
                    }
                }
                sb.Append("\n");
            }

            sb.AppendLine("=========================================================");
            logger.Info(sb.ToString());
        }
Esempio n. 7
0
        public DataParser SubmitSync <T>(UFXFunctionCode functionCode, List <T> requests)
        {
            DataParser parser = new DataParser();

            FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(functionCode);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                string msg = string.Format("提交UFX请求号[{0}]未定义!", functionCode);
                logger.Error(msg);
                parser.ErrorCode = ConnectionCode.ErrorNoFunctionCode;

                return(parser);
            }

            string userToken = LoginManager.Instance.LoginUser.Token;

            if (string.IsNullOrEmpty(userToken))
            {
                string msg = string.Format("提交UFX请求[{0}]令牌失效!", functionCode);
                logger.Error(msg);
                parser.ErrorCode = ConnectionCode.ErrorLogin;

                return(parser);
            }

            CT2BizMessage bizMessage = new CT2BizMessage();

            //初始化
            bizMessage.SetFunction((int)functionCode);
            bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET);

            //业务包
            CT2Packer packer = new CT2Packer(2);

            packer.BeginPack();

            foreach (FieldItem item in functionItem.RequestFields)
            {
                packer.AddField(item.Name, item.Type, item.Width, item.Scale);
            }

            var dataFieldMap = UFXDataBindingHelper.GetProperty <T>();

            foreach (var request in requests)
            {
                foreach (FieldItem item in functionItem.RequestFields)
                {
                    if (dataFieldMap.ContainsKey(item.Name))
                    {
                        SetRequestField <T>(ref packer, request, item, dataFieldMap);
                    }
                    else
                    {
                        SetRequestDefaultField(ref packer, item, userToken);
                    }
                }
            }
            packer.EndPack();

#if DEBUG
            OutputParam <T>(functionCode, requests);
#endif
            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            parser = _t2SDKWrap.SendSync2(bizMessage);
            return(parser);
        }
Esempio n. 8
0
        /// <summary>
        /// 异步调用UFX接口,完成调用之后,如果不出错,则注册回调信息
        /// </summary>
        /// <typeparam name="T">A generic type defines the UFX request parameters.</typeparam>
        /// <param name="functionCode">An enum type defines the UFX interface number.</param>
        /// <param name="requests">A generic request list. NOTE: the caller MUST control the request count if the
        /// interface does not support many requests at a time.
        /// </param>
        /// <param name="callbacker">It is used to store the callback information.</param>
        /// <returns>It is used to define the call result.</returns>
        public ConnectionCode SubmitAsync <T>(UFXFunctionCode functionCode, List <T> requests, Callbacker callbacker)
        {
            FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(functionCode);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                string msg = string.Format("提交UFX请求号[{0}]未定义!", functionCode);
                logger.Error(msg);
                return(ConnectionCode.ErrorNoFunctionCode);
            }

            string userToken = LoginManager.Instance.LoginUser.Token;

            if (string.IsNullOrEmpty(userToken))
            {
                string msg = string.Format("提交UFX请求[{0}]令牌失效!", functionCode);
                logger.Error(msg);
                return(ConnectionCode.ErrorLogin);
            }

            CT2BizMessage bizMessage = new CT2BizMessage();

            //初始化
            bizMessage.SetFunction((int)functionCode);
            bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET);

            //业务包
            CT2Packer packer = new CT2Packer(2);

            packer.BeginPack();

            foreach (FieldItem item in functionItem.RequestFields)
            {
                packer.AddField(item.Name, item.Type, item.Width, item.Scale);
            }

            var dataFieldMap = UFXDataBindingHelper.GetProperty <T>();

            foreach (var request in requests)
            {
                foreach (FieldItem item in functionItem.RequestFields)
                {
                    if (dataFieldMap.ContainsKey(item.Name))
                    {
                        SetRequestField <T>(ref packer, request, item, dataFieldMap);
                    }
                    else
                    {
                        SetRequestDefaultField(ref packer, item, userToken);
                    }
                }
            }
            packer.EndPack();

#if DEBUG
            OutputParam <T>(functionCode, requests);
#endif
            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            ConnectionCode retCode = ConnectionCode.Success;
            int            hSend   = _t2SDKWrap.SendAsync(bizMessage);
            if (hSend < 0)
            {
                string msg = string.Format("提交UFX请求[{0}]失败, 返回值:[{1}]!", functionCode, hSend);
                logger.Error(msg);
                retCode = ConnectionCode.ErrorConn;
            }
            else
            {
                //注册UFX返回数据后,需要调用的回调
                //此处存在假设,异步提交返回之前,不会触发回调
                AddDataHandler(functionCode, hSend, callbacker);
                retCode = ConnectionCode.Success;
            }

            packer.Dispose();
            bizMessage.Dispose();

            return(retCode);
        }