Esempio n. 1
0
        private int HandlData(UFXFunctionCode functionCode, int hSend, DataParser parser)
        {
            //FunctionCode functionCode = (FunctionCode)parser.FunctionCode;
            if (_dataHandlerMap.ContainsKey(functionCode))
            {
                var callbacker = GetDataHandler(functionCode, hSend);
                if (callbacker != null)
                {
                    var token    = callbacker.Token;
                    var callback = callbacker.DataHandler;
                    if (callback != null)
                    {
                        callback(token, parser);
                    }

                    return(1);
                }
                else
                {
                    string msg = string.Format("提交UFX请求时,功能号[{0}]的回调方法,未注册的句柄ID[{0}]!", functionCode, hSend);
                    logger.Error(msg);

                    return(-1);
                }
            }
            else
            {
                string msg = string.Format("提交UFX请求时,未注册功能号[{0}]的回调方法!", functionCode);
                logger.Error(msg);

                return(-1);
            }
        }
Esempio n. 2
0
 public void UnRegister(UFXFunctionCode functionCode)
 {
     if (!_dataHandlerMap.ContainsKey(functionCode))
     {
         _dataHandlerMap.Remove(functionCode);
     }
 }
Esempio n. 3
0
        public static void Info(ILog logger, UFXFunctionCode functionCode, string info)
        {
#if DEBUG
            string msg = string.Format("功能号: [{0}], {1}", (int)functionCode, info);
            logger.Info(msg);
#endif
        }
Esempio n. 4
0
 /// <summary>
 /// 注册功能号和委托,如果针对该功能号的调用成功,就会触发该功能号委托的回调。这里所说的调用成功,指的是针对UFX接口
 /// 的调用顺利,这个过程之后有可能会触发参数错误等各种问题,而不表示调用结果正确,获得正确的返回值。
 /// 因此,获取返回数据后,还需要通过分析数据中的返回码来确定本次调用是否无误。
 /// 注意:每个注册码只会保留最后一次注册的委托,多次注册时,先注册的委托会被后面的覆盖掉。
 /// </summary>
 /// <param name="functionCode">功能号</param>
 /// <param name="receiver">本功能号的委托</param>
 public void Register(UFXFunctionCode functionCode, DataHandlerCallback receiver)
 {
     if (!_dataHandlerMap.ContainsKey(functionCode))
     {
         _dataHandlerMap[functionCode] = receiver;
     }
     else
     {
         _dataHandlerMap[functionCode] = receiver;
     }
 }
Esempio n. 5
0
        public FunctionItem GetFunctionItem(UFXFunctionCode code)
        {
            int key = (int)code;

            if (!functionItemDict.ContainsKey(key))
            {
                string msg = string.Format("The function code [{0}] is not supported in configuration file /config/function.json.", key);
                throw new KeyNotFoundException("");
            }

            return(functionItemDict[key]);
        }
Esempio n. 6
0
        //protected void RemoveDataHandler(FunctionCode funtionCode, Callbacker callbacker)
        //{
        //    if (_dataHandlerMap.ContainsKey(funtionCode))
        //    {
        //        _dataHandlerMap[funtionCode].Dequeue(callbacker);
        //    }
        //}

        protected Callbacker GetDataHandler(UFXFunctionCode functionCode, int hSend)
        {
            Callbacker callbacker = null;

            if (_dataHandlerMap.ContainsKey(functionCode))
            {
                var sendCbMap = _dataHandlerMap[functionCode];
                if (sendCbMap.ContainsKey(hSend))
                {
                    callbacker = sendCbMap[hSend];
                    sendCbMap.Remove(hSend);
                }
            }

            return(callbacker);
        }
Esempio n. 7
0
 protected void AddDataHandler(UFXFunctionCode functionCode, int hSend, Callbacker callbacker)
 {
     if (_dataHandlerMap.ContainsKey(functionCode))
     {
         if (_dataHandlerMap[functionCode].ContainsKey(hSend))
         {
             _dataHandlerMap[functionCode][hSend] = callbacker;
         }
         else
         {
             _dataHandlerMap[functionCode].Add(hSend, callbacker);
         }
     }
     else
     {
         _dataHandlerMap[functionCode] = new Dictionary <int, Callbacker>();
         _dataHandlerMap[functionCode].Add(hSend, callbacker);
     }
 }
Esempio n. 8
0
        public override void OnReceivedBizMsg(CT2Connection lpConnection, int hSend, CT2BizMessage lpMsg)
        {
            UFXLogger.Info(logger, "OnReceivedBizMsg: 成功触发回调接收数据!");
            //获取返回码
            int iRetCode = lpMsg.GetReturnCode();

            //获取错误码
            int iErrorCode = lpMsg.GetErrorNo();

            int iFunction = lpMsg.GetFunction();

            if (iRetCode != 0)
            {
                logger.Error("异步接收数据出错:" + lpMsg.GetErrorNo().ToString() + lpMsg.GetErrorInfo());
            }
            else
            {
                //Console.WriteLine("主推业务订阅 - 返回码:{0}, 错误码: {1}, 功能号: {2}", iRetCode, iErrorCode, iFunction);
                if (Enum.IsDefined(typeof(UFXFunctionCode), iFunction))
                {
                    UFXFunctionCode functionCode = (UFXFunctionCode)Enum.ToObject(typeof(UFXFunctionCode), iFunction);
                    switch (functionCode)
                    {
                    case UFXFunctionCode.MCHeartBeat:
                        break;

                    case UFXFunctionCode.MCRecvSubscribe:
                        break;

                    case UFXFunctionCode.MCRecvUnsubscribe:
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    string msg = string.Format("为支持的功能号:{0}", iFunction);
                    logger.Error(msg);
                }
            }
        }
Esempio n. 9
0
        public ConnectionCode QueryHolder()
        {
            UFXFunctionCode functionCode = UFXFunctionCode.QueryHolder;
            FunctionItem    functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(functionCode);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                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);
            }

            foreach (FieldItem item in functionItem.RequestFields)
            {
                switch (item.Name)
                {
                case "user_token":
                    packer.AddStr(LoginManager.Instance.LoginUser.Token);
                    break;

                case "account_code":
                    packer.AddStr("");
                    break;

                case "asset_no":
                    packer.AddStr("");
                    break;

                case "combi_no":
                    packer.AddStr("");
                    break;

                case "market_no":
                    packer.AddStr("");
                    break;

                default:
                    break;
                }
            }

            packer.EndPack();

            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            var parser = _t2SDKWrap.SendSync2(bizMessage);

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

            if (parser.ErrorCode != ConnectionCode.Success)
            {
                UFXLogger.Error(logger, functionCode, "交易股东查询失败");
                return(parser.ErrorCode);
            }

            var response = T2ErrorHandler.Handle(parser);

            if (T2ErrorHandler.Success(response.ErrorCode))
            {
                if (parser.DataSets.Count > 1)
                {
                    var dataSet = parser.DataSets[1];
                    foreach (var dataRow in dataSet.Rows)
                    {
                        HolderItem p = new HolderItem();
                        p.AccountCode   = dataRow.Columns["account_code"].GetStr();
                        p.AssetNo       = dataRow.Columns["asset_no"].GetStr();
                        p.CombiNo       = dataRow.Columns["combi_no"].GetStr();
                        p.StockHolderId = dataRow.Columns["stockholder_id"].GetStr();
                        p.MarketNo      = dataRow.Columns["market_no"].GetStr();

                        LoginManager.Instance.AddHolder(p);
                    }
                }

                return(ConnectionCode.Success);
            }
            else
            {
                UFXLogger.Error(logger, functionCode, response);
                return(ConnectionCode.ErrorFailContent);
            }
        }
Esempio n. 10
0
        public ConnectionCode QueryAccount()
        {
            UFXFunctionCode functionCode = UFXFunctionCode.QueryAccount;
            FunctionItem    functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(functionCode);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                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);
            }

            foreach (FieldItem item in functionItem.RequestFields)
            {
                switch (item.Name)
                {
                case "user_token":
                    packer.AddStr(LoginManager.Instance.LoginUser.Token);
                    break;

                case "account_code":
                    packer.AddStr("");
                    break;

                default:
                    break;
                }
            }

            packer.EndPack();

            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            var parser = _t2SDKWrap.SendSync2(bizMessage);

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

            if (parser.ErrorCode != ConnectionCode.Success)
            {
                UFXLogger.Error(logger, functionCode, "账户查询失败");
                return(ConnectionCode.ErrorConn);
            }

            var response = T2ErrorHandler.Handle(parser);

            if (T2ErrorHandler.Success(response.ErrorCode))
            {
                if (parser.DataSets.Count > 1)
                {
                    var dataSet = parser.DataSets[1];
                    foreach (var dataRow in dataSet.Rows)
                    {
                        AccountItem acc = new AccountItem();
                        acc.AccountCode = dataRow.Columns["account_code"].GetStr();
                        acc.AccountName = dataRow.Columns["account_name"].GetStr();

                        string accType = dataRow.Columns["account_type"].GetStr();
                        int    temp;
                        if (int.TryParse(accType, out temp))
                        {
                            acc.AccountType = (FundAccountType)temp;
                        }

                        LoginManager.Instance.AddAccount(acc);
                    }
                }

                return(ConnectionCode.Success);
            }
            else
            {
                UFXLogger.Error(logger, functionCode, response);
                return(ConnectionCode.ErrorFailContent);
            }
        }
Esempio n. 11
0
        private int HandleReceivedBizMsg(SendType sendType, UFXFunctionCode functionCode, int hSend, CT2BizMessage bizMessage)
        {
            int iRetCode   = bizMessage.GetReturnCode();
            int iErrorCode = bizMessage.GetErrorNo();
            int iFunction  = bizMessage.GetFunction();

            //FunctionCode functionCode = (FunctionCode)iFunction;
            if (iRetCode != 0)
            {
                string msg = string.Format("同步接收数据出错: {0}, {1}", iErrorCode, bizMessage.GetErrorInfo());
                logger.Error(msg);
                return(iRetCode);
            }

            CT2UnPacker unpacker = null;

            unsafe
            {
                int   iLen   = 0;
                void *lpdata = bizMessage.GetContent(&iLen);
                unpacker = new CT2UnPacker(lpdata, (uint)iLen);
            }

            int ret = (int)ConnectionCode.ErrorConn;

            if (unpacker == null)
            {
                ret = (int)ConnectionCode.ErrorFailContent;
                string msg = string.Format("提交UFX请求回调中,功能号[{0}]数据获取失败!", iFunction);
                logger.Error(msg);

                return(ret);
            }

            DataParser parser = new DataParser();

            parser.FunctionCode = functionCode;
            parser.Parse(unpacker);
            unpacker.Dispose();

            //parser.Output();
            if (!_dataHandlerMap.ContainsKey(functionCode))
            {
                ret = (int)ConnectionCode.ErrorNoCallback;
                string msg = string.Format("提交UFX请求时,未注册功能号[{0}]的回调方法!", iFunction);
                logger.Error(msg);

                return(ret);
            }

            var dataHandler = _dataHandlerMap[functionCode];

            if (dataHandler == null)
            {
                ret = (int)ConnectionCode.ErrorNoCallback;
                string msg = string.Format("提交UFX请求时,未注册功能号[{0}]的回调方法!", iFunction);
                logger.Error(msg);

                return(ret);
            }

            if (sendType == SendType.Sync)
            {
                return(dataHandler(functionCode, hSend, parser));
            }
            else
            {
                //TODO: control the maximum number of the thread?
                //Task task = new Task(() => dataHandler(parser));
                //task.Start();

                //use the TaskScheduler to limit the maximum thread number
                TaskFactory taskFactory = new TaskFactory(_taskScheduler);
                taskFactory.StartNew(() => dataHandler(functionCode, hSend, parser));

                return((int)ConnectionCode.Success);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// 通过调用UFX接口同步发送请求,并将结果封装在DataParser对象中返回。
        /// </summary>
        /// <param name="message">CT2BizMessage对象的实例,包含用户信息,功能号,请求参数等信息</param>
        /// <returns>DataParser对象实例,包含错误代码和最终数据。</returns>
        public DataParser SendSync2(CT2BizMessage message)
        {
            DataParser dataParser = new DataParser();

            int iRet = _conn.SendBizMsg(message, (int)SendType.Sync);

            if (iRet < 0)
            {
                string msg = string.Format("一般交易业务同步发送数据失败! 错误码:{0}, 错误消息:{1}", iRet, _conn.GetErrorMsg(iRet));
                logger.Error(msg);
                dataParser.ErrorCode = ConnectionCode.ErrorSendMsg;

                return(dataParser);
            }

            CT2BizMessage bizMessage = null;
            int           retCode    = _conn.RecvBizMsg(iRet, out bizMessage, (int)_timeOut, 1);

            if (retCode < 0)
            {
                string msg = "一般交易业务同步接收出错: " + _conn.GetErrorMsg(retCode);
                logger.Error(msg);
                dataParser.ErrorCode = ConnectionCode.ErrorRecvMsg;

                return(dataParser);
            }

            int iFunction = bizMessage.GetFunction();

            if (!Enum.IsDefined(typeof(UFXFunctionCode), iFunction))
            {
                dataParser.ErrorCode = ConnectionCode.ErrorNoFunctionCode;

                return(dataParser);
            }

            dataParser.FunctionCode = (UFXFunctionCode)iFunction;

            int             iRetCode     = bizMessage.GetReturnCode();
            int             iErrorCode   = bizMessage.GetErrorNo();
            UFXFunctionCode functionCode = (UFXFunctionCode)iFunction;

            if (iRetCode != 0)
            {
                string msg = string.Format("同步接收数据出错: {0}, {1}", iErrorCode, bizMessage.GetErrorInfo());
                //Console.WriteLine(msg);
                logger.Error(msg);

                dataParser.ErrorCode = ConnectionCode.ErrorRecvMsg;
                return(dataParser);
            }

            CT2UnPacker unpacker = null;

            unsafe
            {
                int   iLen   = 0;
                void *lpdata = bizMessage.GetContent(&iLen);
                unpacker = new CT2UnPacker(lpdata, (uint)iLen);
            }

            if (unpacker == null)
            {
                string msg = string.Format("提交UFX请求回调中,功能号[{0}]数据获取失败!", iFunction);
                logger.Error(msg);

                dataParser.ErrorCode = ConnectionCode.ErrorFailContent;
            }
            else
            {
                dataParser.Parse(unpacker);
                unpacker.Dispose();

                dataParser.ErrorCode = ConnectionCode.Success;
            }

            return(dataParser);
        }
Esempio n. 13
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. 14
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. 15
0
 /// <summary>
 /// 向UFX封装的接口T2SDKWrap注册回调,对所有的功能号注册相同的回调,回调函数触发之后,再在其中处理找到本次调用实际需要处理的
 /// 后续方法。
 /// 这里的回调顺序是:
 /// 1.T2SDKWrap中回调用_dataHandler
 /// 2._dataHandler中找到本次实际调用者注册的回调函数,调用者信息在_dataHandlerMap保存
 /// 3.如果存在调用者注册的回调函数,则调用。
 /// </summary>
 /// <param name="functionCode"></param>
 protected void RegisterUFX(UFXFunctionCode functionCode)
 {
     _t2SDKWrap.Register(functionCode, _dataHandler);
 }
Esempio n. 16
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);
        }
Esempio n. 17
0
        public ConnectionCode Login(LoginUser user)
        {
            UFXFunctionCode functionCode = UFXFunctionCode.Login;
            FunctionItem    functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(functionCode);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                return(ConnectionCode.ErrorLogin);
            }

            LoginManager.Instance.LoginUser = user;
            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);
            }

            foreach (FieldItem item in functionItem.RequestFields)
            {
                switch (item.Name)
                {
                case "operator_no":
                    packer.AddStr(user.Operator);
                    break;

                case "password":
                    packer.AddStr(user.Password);
                    break;

                case "mac_address":
                {
                    packer.AddStr(ConfigManager.Instance.GetTerminalConfig().MacAddress);
                }
                break;

                case "op_station":
                {
                    packer.AddStr("www.htsec.com");
                }
                break;

                case "ip_address":
                {
                    packer.AddStr(ConfigManager.Instance.GetTerminalConfig().IPAddress);
                }
                break;

                case "hd_volserial":
                {
                    packer.AddStr("");
                }
                break;

                case "authorization_id":
                {
                    //TODO:
                    packer.AddStr("authorization_id");
                }
                break;

                default:
                    if (item.Type == UFXPackFieldType.IntType)
                    {
                        packer.AddInt(-1);
                    }
                    else if (item.Type == UFXPackFieldType.StringType || item.Type == UFXPackFieldType.CharType)
                    {
                        packer.AddStr(item.Name);
                    }
                    else
                    {
                        packer.AddStr(item.Name);
                    }
                    break;
                }
            }
            packer.EndPack();

            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            var parser = _t2SDKWrap.SendSync2(bizMessage);

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

            var ret = parser.ErrorCode;

            if (ret == ConnectionCode.Success)
            {
                string token    = string.Empty;
                string version  = string.Empty;
                var    response = T2ErrorHandler.Handle(parser);
                if (T2ErrorHandler.Success(response.ErrorCode))
                {
                    if (parser.DataSets[1].Rows[0].Columns.ContainsKey("user_token"))
                    {
                        token = parser.DataSets[1].Rows[0].Columns["user_token"].GetStr();
                    }

                    if (parser.DataSets[1].Rows[0].Columns.ContainsKey("version_no"))
                    {
                        version = parser.DataSets[1].Rows[0].Columns["version_no"].GetStr();
                    }

                    string msg = string.Format("Login success - token: [{0}], version: [{1}]", token, version);
                    UFXLogger.Info(logger, functionCode, msg);
                }
                else
                {
                    UFXLogger.Error(logger, functionCode, response);
                }

                if (!string.IsNullOrEmpty(token))
                {
                    LoginManager.Instance.LoginUser.Token = token;
                    ret = ConnectionCode.Success;
                }
                else
                {
                    ret = ConnectionCode.ErrorLogin;
                }
            }

            return(ret);
        }
Esempio n. 18
0
        public static void Error(ILog logger, UFXFunctionCode functionCode, UFXErrorResponse err)
        {
            string msg = string.Format("功能号: [{0}], 错误码: {1}, 消息: {2}", (int)functionCode, err.ErrorCode, err.ErrorMessage);

            logger.Error(msg);
        }
Esempio n. 19
0
 /// <summary>
 /// 该函数不可被调用,目前不可以删除
 /// </summary>
 /// <param name="functionCode"></param>
 protected void UnRegisterUFX(UFXFunctionCode functionCode)
 {
     _t2SDKWrap.UnRegister(functionCode);
 }
Esempio n. 20
0
        public ConnectionCode HeartBeat()
        {
            UFXFunctionCode functionCode = UFXFunctionCode.HeartBeat;
            FunctionItem    functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(functionCode);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                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);
            }

            foreach (FieldItem item in functionItem.RequestFields)
            {
                switch (item.Name)
                {
                case "user_token":
                    packer.AddStr(LoginManager.Instance.LoginUser.Token);
                    break;

                default:
                    break;
                }
            }

            packer.EndPack();

            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            var parser = _t2SDKWrap.SendSync2(bizMessage);

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

            if (parser.ErrorCode == ConnectionCode.Success)
            {
                var response = T2ErrorHandler.Handle(parser);
                if (!T2ErrorHandler.Success(response.ErrorCode))
                {
                    UFXLogger.Error(logger, functionCode, response);
                    return(ConnectionCode.ErrorFailContent);
                }
            }
            else
            {
                UFXLogger.Error(logger, functionCode, "心跳检测失败");
                return(ConnectionCode.ErrorConn);
            }

            return(ConnectionCode.Success);
        }
Esempio n. 21
0
        public static void Error(ILog logger, UFXFunctionCode functionCode, string info)
        {
            string msg = string.Format("功能号: [{0}], {1}", (int)functionCode, info);

            logger.Error(msg);
        }