public override void OnReceived(CT2SubscribeInterface lpSub, int subscribeIndex, void *lpData, int nLength, tagSubscribeRecvData lpRecvData) { //Debug.Print("/*********************************收到主推数据 begin***************************/"); //string strInfo = string.Format("附加数据长度: {0}", lpRecvData.iAppDataLen); //Debug.Print(strInfo); //if (lpRecvData.iAppDataLen > 0) //{ // unsafe // { // strInfo = string.Format("附加数据: {0}", Marshal.PtrToStringAuto(new IntPtr(lpRecvData.lpAppData))); // Debug.Print(strInfo); // } //} //Debug.Print("过滤字段部分:\n"); //if (lpRecvData.iFilterDataLen > 0) //{ // CT2UnPacker lpUnpack = new CT2UnPacker(lpRecvData.lpFilterData, (uint)lpRecvData.iFilterDataLen); // //ufxengine.ShowUnPacker(lpUnpack); // lpUnpack.Dispose(); //} //CT2UnPacker lpUnPack1 = new CT2UnPacker((void*)lpData, (uint)nLength); //if (lpUnPack1 != null) //{ // //ufxengine.ShowUnPacker(lpUnPack1); // lpUnPack1.Dispose(); //} //Debug.Print("/*********************************收到主推数据 end ***************************/"); }
public override void OnReceived(CT2SubscribeInterface lpSub, int subscribeIndex, void* lpData, int nLength, tagSubscribeRecvData lpRecvData) { //收到主推数据 - 开始 if (lpRecvData.iAppDataLen > 0) { unsafe { //附加数据 string strInfo = string.Format("{0}", Marshal.PtrToStringAuto(new IntPtr(lpRecvData.lpAppData))); } } //过滤字段部分 if (lpRecvData.iFilterDataLen > 0) { CT2UnPacker lpUnpacker = new CT2UnPacker(lpRecvData.lpFilterData, (uint)lpRecvData.iFilterDataLen); //解包 //..... lpUnpacker.Dispose(); } CT2UnPacker lpUnpacker1 = new CT2UnPacker((void*)lpData, (uint)nLength); if(lpUnpacker1 != null) { //解包 //.... lpUnpacker1.Dispose(); } //收到主推数据 - 结束 }
//回报 public override void OnReceived(CT2SubscribeInterface lpSub, int subscribeIndex, void *lpData, int nLength, tagSubscribeRecvData lpRecvData) { try { Debug.Print("/*********************************收到主推数据 begin***************************/"); string strInfo = string.Format("附加数据长度: {0}", lpRecvData.iAppDataLen); Debug.Print(strInfo); if (lpRecvData.iAppDataLen > 0) { unsafe { strInfo = string.Format("附加数据: {0}", Marshal.PtrToStringAuto(new IntPtr(lpRecvData.lpAppData))); Debug.Print(strInfo); } } Debug.Print("过滤字段部分:\n"); if (lpRecvData.iFilterDataLen > 0) { CT2UnPacker lpUnpack = new CT2UnPacker(lpRecvData.lpFilterData, (uint)lpRecvData.iFilterDataLen); //ufxengine.ShowUnPacker(lpUnpack); lpUnpack.Dispose(); } CT2UnPacker lpUnPack1 = new CT2UnPacker((void *)lpData, (uint)nLength); if (lpUnPack1 != null) { //ufxengine.ShowUnPacker(lpUnPack1); lpUnPack1.Dispose(); } Debug.Print("/*********************************收到主推数据 end ***************************/"); } catch (System.Exception ex) { throw ex; } }
public override void OnReceived(CT2SubscribeInterface lpSub, int subscribeIndex, void *lpData, int nLength, tagSubscribeRecvData lpRecvData) { //收到主推数据 - 开始 if (lpRecvData.iAppDataLen > 0) { unsafe { //附加数据 string strInfo = string.Format("{0}", Marshal.PtrToStringAuto(new IntPtr(lpRecvData.lpAppData))); } } UFXPushMessageType messageType = UFXPushMessageType.None; //过滤字段部分 if (lpRecvData.iFilterDataLen > 0) { CT2UnPacker lpUnpacker = new CT2UnPacker(lpRecvData.lpFilterData, (uint)lpRecvData.iFilterDataLen); //解包 //..... DataParser parser = new DataParser(); parser.Parse(lpUnpacker); Log("====推送=====过滤字段部分=====开始"); //parser.Output(); Log(parser); Log("====推送=====过滤字段部分=====结束"); lpUnpacker.Dispose(); messageType = _filterBLL.GetMessageType(parser); } if (nLength > 0) { CT2UnPacker lpUnpacker1 = new CT2UnPacker((void *)lpData, (uint)nLength); if (lpUnpacker1 != null) { //解包 //.... DataParser parser = new DataParser(); parser.Parse(lpUnpacker1); Log("====推送*****数据部分=====开始"); //parser.Output(); Log(parser); Log("====推送*****数据部分=====结束"); lpUnpacker1.Dispose(); IUFXMessageHandlerBase subscriberHandler = _handlerFactory.Create(messageType); if (subscriberHandler != null) { TaskFactory taskFactory = new TaskFactory(_taskScheduler); taskFactory.StartNew(() => subscriberHandler.Handle(parser)); } } } //收到主推数据 - 结束 }
public ConnectionCode Subscribe(LoginUser user, IUFXMessageHandlerFactory handlerFactory) { callback = new T2SubCallback(handlerFactory); subcribe = _conn.NewSubscriber(callback, SubscribeName, (int)_timeOut, 2000, 100); if (subcribe == null) { string msg = string.Format("主推业务订阅创建失败: {0}", _conn.GetMCLastError()); logger.Error(msg); return(ConnectionCode.ErrorFailSubscribe); } CT2SubscribeParamInterface args = new CT2SubscribeParamInterface(); args.SetTopicName("ufx_topic"); args.SetReplace(false); args.SetFilter("operator_no", user.Operator); CT2Packer req = new CT2Packer(2); req.BeginPack(); req.AddField("login_operator_no", Convert.ToSByte('S'), 16, 4); req.AddField("password", Convert.ToSByte('S'), 16, 4); req.AddStr(user.Operator); req.AddStr(user.Password); req.EndPack(); CT2UnPacker unpacker = null; int ret = subcribe.SubscribeTopicEx(args, 50000, out unpacker, req); req.Dispose(); //根据文档说明,返回值大于0表示有效的订阅标识,否则其他表示错误。 if (ret > 0) { string msg = string.Format("主推业务订阅创建成功, 返回码: {0}, 消息: {1}", ret, _conn.GetErrorMsg(ret)); logger.Info(msg); return(ConnectionCode.SuccessSubscribe); } else { string outMsg = string.Empty; if (unpacker != null) { //Show(back); DataParser parser = new DataParser(); parser.Parse(unpacker); unpacker.Dispose(); var errResponse = T2ErrorHandler.Handle(parser); outMsg = errResponse.MessageDetail; } string msg = string.Format("主推业务订阅创建失败,返回码: {0}, 消息: {1}, 返回数据包消息: {2}", ret, _conn.GetErrorMsg(ret), outMsg); logger.Error(msg); return(ConnectionCode.ErrorFailSubscribe); } }
public override void OnRecvTickMsg(CT2SubscribeInterface lpSub, int subscribeIndex, string TickMsgInfo) { Debug.Print(MethodBase.GetCurrentMethod().Name); }
public override void OnRecvTickMsg(CT2SubscribeInterface lpSub, int subscribeIndex, string TickMsgInfo) { throw new NotImplementedException(); }
public override void OnRecvTickMsg(CT2SubscribeInterface lpSub, int subscribeIndex, string TickMsgInfo) { }
public override void OnRecvTickMsg(CT2SubscribeInterface lpSub, int subscribeIndex, string TickMsgInfo) { Console.WriteLine("T2SubCallback.OnRecvTickMsg"); }