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 IUFXMessageHandlerBase Create(UFXPushMessageType msgType) { IUFXMessageHandlerBase handler = null; switch (msgType) { case UFXPushMessageType.EntrustCommit: { handler = new UFXEntrustCommitHandler(); } break; case UFXPushMessageType.EntrustConfirm: { handler = new UFXEntrustConfirmHandler(); } break; case UFXPushMessageType.EntrustFailed: { handler = new UFXEntrustFailedHandler(); } break; case UFXPushMessageType.EntrustWithdraw: { handler = new UFXWithdrawHandler(); } break; case UFXPushMessageType.EntrustWithdrawDone: { handler = new UFXWithdrawCompletedHandler(); } break; case UFXPushMessageType.EntrustWithdrawFailed: { handler = new UFXWithdrawFailedHandler(); } break; case UFXPushMessageType.EntrustDeal: { handler = new UFXEntrustDealHandler(); } break; default: { string msg = string.Format("Not supported the message type: {0}", msgType); logger.Error(msg); throw new NotSupportedException(msg); } } return(handler); }