private void _OnCmppMessageReceive(CmppMessageReceiveEvent evt) { if (OnCmppMessageReceive != null) { OnCmppMessageReceive(this, evt); } }
void transport_OnCmppMessageReceive(object sender, CmppMessageReceiveEvent e) { Console.WriteLine("Recieved {0}", e.Message.GetType().Name); if (e.Message is CmppConnectResp) { Assert.AreEqual(0, ((CmppConnectResp)e.Message).Status); _connectEvent.Set(); } if (e.Message is CmppActiveTestResp) { _activeResponse.Set(); } }
private void OnCmppMessageReceive(object sender, CmppMessageReceiveEvent e) { _lastTransferTime = DateTime.Now; if (Status == Cmpp30ClientStatus.Authenticating) { if (e.Header.CommandId != CmppConstants.CommandCode.ConnectResp || !(e.Message is CmppConnectResp)) { Status = Cmpp30ClientStatus.Disconnected; StatusText = "Unexpected response"; return; } var response = (CmppConnectResp)e.Message; if (response.Status != 0) { Status = Cmpp30ClientStatus.AuthenticationFailed; switch (response.Status) { case 1: StatusText = "消息结构错误"; return; case 2: StatusText = "非法源地址"; return; case 3: StatusText = "认证失败"; return; case 4: StatusText = "版本错误"; return; default: StatusText = string.Format("其它错误({0})", response.Status); return; } } Status = Cmpp30ClientStatus.Connected; StatusText = ""; _transport.Send(NextSequenceId, new CmppActiveTest()); return; } try { switch (e.Header.CommandId) { case CmppConstants.CommandCode.Deliver: var deliver = (CmppDeliver)e.Message; _transport.Send(e.Header.SequenceId, new CmppDeliverResp { MsgId = deliver.MsgId, Result = 0 }); switch (deliver.RegisteredDelivery) { case 0: // mo message if (OnMessageReceive != null) { OnMessageReceive(this, new ReceiveEventArgs { Content = deliver.MsgContent, Source = deliver.SrcTerminalId, MessageId = BitConverter.ToInt64(BitConverter.GetBytes(deliver.MsgId), 0), Destination = deliver.DestId }); } break; case 1: // message report var report = deliver.GetReport(); if (OnMessageReport != null) { OnMessageReport(this, new ReportEventArgs { MessageId = (long)report.MsgId, StatusText = report.Stat, Destination = report.DestTerminalId, }); } break; } break; case CmppConstants.CommandCode.ActiveTest: _transport.Send(e.Header.SequenceId, new CmppActiveTestResp()); break; case CmppConstants.CommandCode.Error: case CmppConstants.CommandCode.Terminate: Status = Cmpp30ClientStatus.Disconnected; StatusText = "Server respond with error"; _Disconnect(); break; case CmppConstants.CommandCode.SubmitResp: lock (_cmppWindows) { if (_cmppWindows.ContainsKey(e.Header.SequenceId)) { _cmppWindows[e.Header.SequenceId].Result = e.Message; _cmppWindows[e.Header.SequenceId].WaitHandle.Set(); _cmppWindows.Remove(e.Header.SequenceId); } } break; } } catch (Exception ex) { log.ErrorFormat( "[{0}] Unable to handle CMPP receive package. Error: {1}.", _config.SpCode, ex ); } }
private void OnCmppMessageReceive(object sender, CmppMessageReceiveEvent e) { _lastTransferTime = DateTime.Now; if (Status == Cmpp30ClientStatus.Authenticating) { if (e.Header.CommandId != CmppConstants.CommandCode.ConnectResp || !(e.Message is CmppConnectResp)) { Status = Cmpp30ClientStatus.Disconnected; StatusText = "Unexpected response"; return; } var response = (CmppConnectResp)e.Message; if (response.Status != 0) { Status = Cmpp30ClientStatus.AuthenticationFailed; switch (response.Status) { case 1: StatusText = "消息结构错误"; return; case 2: StatusText = "非法源地址"; return; case 3: StatusText = "认证失败"; return; case 4: StatusText = "版本错误"; return; default: StatusText = string.Format("其它错误({0})", response.Status); return; } } Status = Cmpp30ClientStatus.Connected; StatusText = ""; _transport.Send(NextSequenceId, new CmppActiveTest()); return; } try { switch (e.Header.CommandId) { case CmppConstants.CommandCode.Deliver: var deliver = (CmppDeliver)e.Message; _transport.Send(e.Header.SequenceId, new CmppDeliverResp { MsgId = deliver.MsgId, Result = 0 }); switch (deliver.RegisteredDelivery) { case 0: // mo message if (OnMessageReceive != null) OnMessageReceive(this, new ReceiveEventArgs { Content = deliver.MsgContent, Source = deliver.SrcTerminalId, MessageId = BitConverter.ToInt64(BitConverter.GetBytes(deliver.MsgId), 0), Destination = deliver.DestId }); break; case 1: // message report var report = deliver.GetReport(); if (OnMessageReport != null) OnMessageReport(this, new ReportEventArgs { MessageId = (long)report.MsgId, StatusText = report.Stat, Destination = report.DestTerminalId, }); break; } break; case CmppConstants.CommandCode.ActiveTest: _transport.Send(e.Header.SequenceId, new CmppActiveTestResp()); break; case CmppConstants.CommandCode.Error: case CmppConstants.CommandCode.Terminate: Status = Cmpp30ClientStatus.Disconnected; StatusText = "Server respond with error"; _Disconnect(); break; case CmppConstants.CommandCode.SubmitResp: lock (_cmppWindows) { if (_cmppWindows.ContainsKey(e.Header.SequenceId)) { _cmppWindows[e.Header.SequenceId].Result = e.Message; _cmppWindows[e.Header.SequenceId].WaitHandle.Set(); _cmppWindows.Remove(e.Header.SequenceId); } } break; } } catch (Exception ex) { Console.WriteLine("[{0}] Unable to handle CMPP receive package. Error: {1}.", _config.SpCode, ex); } }
private void _OnCmppMessageReceive(CmppMessageReceiveEvent evt) { if (OnCmppMessageReceive != null) OnCmppMessageReceive(this, evt); }