/// <summary> /// This method gets the buffer and returns an instance of class /// corresponding to the type of the PDU which was in the buffer; the /// fields of the returned PDU are set to the data from the buffer. /// </summary> public static SmppPdu Create(Stream buffer) { // Read the length and id from the buffer SmppReader reader = new SmppReader(buffer); int length = reader.ReadInt32(); int id = reader.ReadInt32(); // If we don't have the entire message yet, then throw an exception. if (buffer.Length < length) { throw new IncompletePduException(); } // Create a new PDU SmppPdu pdu = PduFactory.CreatePdu(id); if (pdu != null) { // Reset back to the length buffer.Seek(-8, SeekOrigin.Current); // Stream the whole thing in pdu.Deserialize(reader); return(pdu); } // Not found in our list of supported PDUs throw new UnknownPduException(id); }
/// <summary> /// Compares two PDU. Two PDUs are equal if their sequence number is equal. /// </summary> public override bool Equals(object obj) { if (obj != null && (obj is SmppPdu)) { SmppPdu pdu = (SmppPdu)obj; return(CommandId == pdu.CommandId && sequenceNumber_ == pdu.SequenceNumber); } return(false); }
/// <summary> /// This is the entrypoint which is called by the session object to dispatch /// a given PDU to the handler. /// </summary> /// <param name="state"></param> /// <param name="pdu"></param> /// <returns></returns> public static bool Dispatch(SmppSessionState state, SmppPdu pdu) { // Quick validation of the received PDU; make sure the command id matches up // to the type of PDU received and that we have a handler. if (typeMap_.ContainsKey(pdu.CommandId)) { PduHandler handler = typeMap_[pdu.CommandId]; try { handler.InternalDispatch(state, pdu); return(true); } catch (InvalidCastException) { } } return(false); }
/// <summary> /// This method walks the Pdu list and creates new Pdu object instances /// using the existing one already created. /// </summary> /// <param name="commandId">Command Id to create</param> /// <returns>New Pdu object</returns> public static SmppPdu CreatePdu(int commandId) { int size = pduFactory_.Count; for (int i = 0; i < size; i++) { SmppPdu pdu = (SmppPdu)pduFactory_[i]; if (pdu != null && pdu.CommandId == commandId) { try { return((SmppPdu)Activator.CreateInstance(pdu.GetType())); } catch (Exception) { } } } return(null); }
/// <summary> /// This method must be overridden in implementations to cast the PDU /// to a concrete type and call the appropriate session state method. /// </summary> /// <param name="state">Session state</param> /// <param name="pdu">PDU</param> /// <returns></returns> public virtual void InternalDispatch(SmppSessionState state, SmppPdu pdu) { throw new NotImplementedException(); }
public override void InternalDispatch(SmppSessionState state, SmppPdu pdu) { state.Process((list_dls)pdu); }
public override void InternalDispatch(SmppSessionState state, SmppPdu pdu) { state.Process((enquire_sub)pdu); }
public override void InternalDispatch(SmppSessionState state, SmppPdu pdu) { state.Process((cancel_broadcast_sm)pdu); }
public override void InternalDispatch(SmppSessionState state, SmppPdu pdu) { state.Process((submit_multi)pdu); }
public override void InternalDispatch(SmppSessionState state, SmppPdu pdu) { state.Process((bind_transceiver_resp)pdu); }
public override void InternalDispatch(SmppSessionState state, SmppPdu pdu) { state.Process((replace_sm)pdu); }
public override void InternalDispatch(SmppSessionState state, SmppPdu pdu) { state.Process((deliver_sm_resp)pdu); }
public override void InternalDispatch(SmppSessionState state, SmppPdu pdu) { state.Process((generic_nack)pdu); }
public override void InternalDispatch(SmppSessionState state, SmppPdu pdu) { state.Process((alert_notification)pdu); }