/// <summary> /// Gets a single PDU based on the response bytes. /// </summary> /// <param name="response">The SMSC response.</param> /// <returns>The PDU corresponding to the bytes.</returns> private Pdu GetPDU(byte[] response) { var commandID = Pdu.DecodeCommandId(response); Pdu packet; switch(commandID) { case CommandId.alert_notification: packet = new SmppAlertNotification(response); break; case CommandId.bind_receiver_resp: case CommandId.bind_transceiver_resp: case CommandId.bind_transmitter_resp: packet = new SmppBindResp(response); break; case CommandId.cancel_sm_resp: packet = new SmppCancelSmResp(response); break; case CommandId.data_sm_resp: packet = new SmppDataSmResp(response); break; case CommandId.deliver_sm: packet = new SmppDeliverSm(response); break; case CommandId.enquire_link_resp: packet = new SmppEnquireLinkResp(response); break; case CommandId.outbind: packet = new SmppOutbind(response); break; case CommandId.query_sm_resp: packet = new SmppQuerySmResp(response); break; case CommandId.replace_sm_resp: packet = new SmppReplaceSmResp(response); break; case CommandId.submit_multi_resp: packet = new SmppSubmitMultiResp(response); break; case CommandId.submit_sm_resp: packet = new SmppSubmitSmResp(response); break; case CommandId.unbind_resp: packet = new SmppUnbindResp(response); break; case CommandId.generic_nack: packet = new SmppGenericNack(response); break; default: packet = null; break; } return packet; }
/// <summary> /// Fires an event off based on what Pdu is received in. /// </summary> /// <param name="response">The response to fire an event for.</param> private void FireEvents(Pdu response) { //here we go... if(response is SmppBindResp) { if(OnBindResp != null) { OnBindResp(this, new BindRespEventArgs((SmppBindResp)response)); } } else if(response is SmppUnbindResp) { //disconnect asClient.Disconnect(); if(OnUnboundResp != null) { OnUnboundResp(this, new UnbindRespEventArgs((SmppUnbindResp)response)); } } else if(response is SmppAlertNotification) { if(OnAlert != null) { OnAlert(this, new AlertEventArgs((SmppAlertNotification)response)); } } else if(response is SmppSubmitSmResp) { if(OnSubmitSmResp != null) { OnSubmitSmResp(this, new SubmitSmRespEventArgs((SmppSubmitSmResp)response)); } } else if(response is SmppEnquireLinkResp) { if(OnEnquireLinkResp != null) { OnEnquireLinkResp(this, new EnquireLinkRespEventArgs((SmppEnquireLinkResp)response)); } } else if(response is SmppSubmitSm) { if(OnSubmitSm != null) { OnSubmitSm(this, new SubmitSmEventArgs((SmppSubmitSm)response)); } else { //default a response SmppSubmitSmResp pdu = new SmppSubmitSmResp(); pdu.SequenceNumber = response.SequenceNumber; pdu.MessageId = System.Guid.NewGuid().ToString().Substring(0, 10); pdu.CommandStatus = 0; SendPdu(pdu); } } else if(response is SmppQuerySm) { if(OnQuerySm != null) { OnQuerySm(this, new QuerySmEventArgs((SmppQuerySm)response)); } else { //default a response SmppQuerySmResp pdu = new SmppQuerySmResp(); pdu.SequenceNumber = response.SequenceNumber; pdu.CommandStatus = 0; SendPdu(pdu); } } else if(response is SmppGenericNack) { if(OnGenericNack != null) { OnGenericNack(this, new GenericNackEventArgs((SmppGenericNack)response)); } } else if(response is SmppEnquireLink) { if(OnEnquireLink != null) { OnEnquireLink(this, new EnquireLinkEventArgs((SmppEnquireLink)response)); } //send a response back SmppEnquireLinkResp pdu = new SmppEnquireLinkResp(); pdu.SequenceNumber = response.SequenceNumber; pdu.CommandStatus = 0; SendPdu(pdu); } else if(response is SmppUnbind) { if(OnUnbind != null) { OnUnbind(this, new UnbindEventArgs((SmppUnbind)response)); } else { //default a response SmppUnbindResp pdu = new SmppUnbindResp(); pdu.SequenceNumber = response.SequenceNumber; pdu.CommandStatus = 0; SendPdu(pdu); } } else if(response is SmppBind) { if(OnBind != null) { OnBind(this, new BindEventArgs((SmppBind)response)); } else { //default a response SmppBindResp pdu = new SmppBindResp(); pdu.SequenceNumber = response.SequenceNumber; pdu.CommandStatus = 0; pdu.SystemId = "Generic"; SendPdu(pdu); } } else if(response is SmppCancelSm) { if(OnCancelSm != null) { OnCancelSm(this, new CancelSmEventArgs((SmppCancelSm)response)); } else { //default a response SmppCancelSmResp pdu = new SmppCancelSmResp(); pdu.SequenceNumber = response.SequenceNumber; pdu.CommandStatus = 0; SendPdu(pdu); } } else if(response is SmppCancelSmResp) { if(OnCancelSmResp != null) { OnCancelSmResp(this, new CancelSmRespEventArgs((SmppCancelSmResp)response)); } } else if(response is SmppCancelSmResp) { if(OnCancelSmResp != null) { OnCancelSmResp(this, new CancelSmRespEventArgs((SmppCancelSmResp)response)); } } else if(response is SmppQuerySmResp) { if(OnQuerySmResp != null) { OnQuerySmResp(this, new QuerySmRespEventArgs((SmppQuerySmResp)response)); } } else if(response is SmppDataSm) { if(OnDataSm != null) { OnDataSm(this, new DataSmEventArgs((SmppDataSm)response)); } else { //default a response SmppDataSmResp pdu = new SmppDataSmResp(); pdu.SequenceNumber = response.SequenceNumber; pdu.CommandStatus = 0; pdu.MessageId = "Generic"; SendPdu(pdu); } } else if(response is SmppDataSmResp) { if(OnDataSmResp != null) { OnDataSmResp(this, new DataSmRespEventArgs((SmppDataSmResp)response)); } } else if(response is SmppDeliverSm) { if(OnDeliverSm != null) { OnDeliverSm(this, new DeliverSmEventArgs((SmppDeliverSm)response)); } else { //default a response SmppDeliverSmResp pdu = new SmppDeliverSmResp(); pdu.SequenceNumber = response.SequenceNumber; pdu.CommandStatus = 0; SendPdu(pdu); } } else if(response is SmppDeliverSmResp) { if(OnDeliverSmResp != null) { OnDeliverSmResp(this, new DeliverSmRespEventArgs((SmppDeliverSmResp)response)); } } else if(response is SmppReplaceSm) { if(OnReplaceSm != null) { OnReplaceSm(this, new ReplaceSmEventArgs((SmppReplaceSm)response)); } else { //default a response SmppReplaceSmResp pdu = new SmppReplaceSmResp(); pdu.SequenceNumber = response.SequenceNumber; pdu.CommandStatus = 0; SendPdu(pdu); } } else if(response is SmppReplaceSmResp) { if(OnReplaceSmResp != null) { OnReplaceSmResp(this, new ReplaceSmRespEventArgs((SmppReplaceSmResp)response)); } } else if(response is SmppSubmitMulti) { if(OnSubmitMulti != null) { OnSubmitMulti(this, new SubmitMultiEventArgs((SmppSubmitMulti)response)); } else { //default a response SmppSubmitMultiResp pdu = new SmppSubmitMultiResp(); pdu.SequenceNumber = response.SequenceNumber; pdu.CommandStatus = 0; SendPdu(pdu); } } else if(response is SmppSubmitMultiResp) { if(OnSubmitMultiResp != null) { OnSubmitMultiResp(this, new SubmitMultiRespEventArgs((SmppSubmitMultiResp)response)); } } }
/// <summary> /// Creates a DataSmRespEventArgs. /// </summary> /// <param name="packet">The PDU that was received.</param> internal DataSmRespEventArgs(SmppDataSmResp packet) : base(packet) { _response = packet; }