Пример #1
0
        /// <summary> Called to create a SubmitSmResp object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="buf"></param>
        /// <param name="offset"></param>
        /// <returns> SubmitSmResp </returns>
        public static SubmitSmResp Create(DataCodings defaultEncoding, SmppBuffer buf, ref int offset)
        {
            SubmitSmResp submitSmResp = new SubmitSmResp(defaultEncoding);

            try
            {
                int start_offset = offset;

                buf.ExtractHeader(submitSmResp, ref offset);

                if (submitSmResp.Length > Header.HEADER_LENGTH)
                {
                    submitSmResp.MessageId = buf.ExtractCString(ref offset);

                    while (offset - start_offset < submitSmResp.Length)
                    {
                        submitSmResp.Optional.Add(buf.ExtractTLV(ref offset));
                    }
                }
            }

            catch
            {
                submitSmResp = null;
            }

            return(submitSmResp);
        }
Пример #2
0
        /// <summary> Called when the SMPP Server receives a sent message </summary>
        /// <param name="sender"></param>
        /// <param name="data"></param>
        private void ClientEventSubmitSmResp(object sender, SubmitSmResp data)
        {
            try
            {
                WriteLog("ESMEConnection : ClientEventSubmitSmResp : Info : Sequence[{0}] Status[{1}]", data.Sequence, data.Status);

                if (SubmitMessageHandler != null)
                {
                    SubmitMessageHandler(LogKey, (int)data.Sequence, data.MessageId);
                }
            }

            catch (Exception exception)
            {
                WriteLog(LogEventNotificationTypes.Email, "ESMEConnection : ClientEventSubmitSmResp : ERROR : {0}", exception.ToString());
            }
        }
Пример #3
0
        /// <summary> Called to create a SubmitSmResp object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="buf"></param>
        /// <param name="offset"></param>
        /// <returns> SubmitSmResp </returns>
        public static SubmitSmResp Create(DataCodings defaultEncoding, SmppBuffer buf, ref int offset)
        {
            SubmitSmResp submitSmResp = new SubmitSmResp(defaultEncoding);

            try
            {
                int start_offset = offset;

                buf.ExtractHeader(submitSmResp, ref offset);

                if (submitSmResp.Length > Header.HEADER_LENGTH)
                {
                    submitSmResp.MessageId = buf.ExtractCString(ref offset);

                    while (offset - start_offset < submitSmResp.Length)
                    {
                        submitSmResp.Optional.Add(buf.ExtractTLV(ref offset));
                    }
                }
            }

            catch
            {
                submitSmResp = null;
            }

            return submitSmResp;
        }
Пример #4
0
        /// <summary> Called to send the message </summary>
        /// <param name="phoneNumber"></param>
        /// <param name="serviceType"></param>
        /// <param name="sourceTon"></param>
        /// <param name="sourceNpi"></param>
        /// <param name="submitDataCoding"></param>
        /// <param name="encodeDataCoding"></param>
        /// <param name="message"></param>
        /// <param name="submitSm"></param>
        /// <param name="submitSmResp"></param>
        /// <returns> 1 - Successful / 0 - Failed </returns>
        public int SendMessage(string phoneNumber, string serviceType, Ton sourceTon, Npi sourceNpi, DataCodings submitDataCoding, DataCodings encodeDataCoding, string message, out SubmitSm submitSm, out SubmitSmResp submitSmResp)
        {
            int retVal = 0;

            submitSm     = null;
            submitSmResp = null;

            try
            {
                // Capture the next transmitter connection
                ESMEConnection smppConnection = NextTransmitterConnection();

                if (smppConnection == null)
                {
                    WriteLog("ESMEManager : SendMessage : Warning : Not Bound To The SMPP Server");

                    return(2);
                }

                // Send the message
                retVal = smppConnection.SendMessage(phoneNumber, serviceType, sourceTon, sourceNpi, submitDataCoding, encodeDataCoding, message, out submitSm, out submitSmResp);
            }

            catch (Exception exception)
            {
                WriteLog(LogEventNotificationTypes.Email, "ESMEManager : SendMessage : ERROR : {0}", exception.ToString());
            }

            return(retVal);
        }
Пример #5
0
        /// <summary> Called when the SMPP Server receives a sent message </summary>
        /// <param name="sender"></param>
        /// <param name="data"></param>
        private void ClientEventSubmitSmResp(object sender, SubmitSmResp data)
        {
            try
            {
                WriteLog("ESMEConnection : ClientEventSubmitSmResp : Info : Sequence[{0}] Status[{1}]", data.Sequence, data.Status);

                if (SubmitMessageHandler != null)
                {
                    SubmitMessageHandler(LogKey, (int) data.Sequence, data.MessageId);
                }
            }

            catch (Exception exception)
            {
                WriteLog(LogEventNotificationTypes.Email, "ESMEConnection : ClientEventSubmitSmResp : ERROR : {0}", exception.ToString());
            }
        }
Пример #6
0
        /// <summary> Called to send the message </summary>
        /// <param name="phoneNumber"></param>
        /// <param name="serviceType"></param>
        /// <param name="destinationTon"></param>
        /// <param name="destinationNpi"></param>
        /// <param name="submitDataCoding"></param>
        /// <param name="encodeDataCoding"></param>
        /// <param name="message"></param>
        /// <param name="submitSm"></param>
        /// <param name="submitSmResp"></param>
        /// <returns> 0 - Successful / 1 - Failed / 2 - Not Connected </returns>
        public int SendMessage(string phoneNumber, string serviceType, Ton destinationTon, Npi destinationNpi, DataCodings submitDataCoding, DataCodings encodeDataCoding, string message, out SubmitSm submitSm, out SubmitSmResp submitSmResp)
        {
            int retVal = 1;

            submitSm = null;
            submitSmResp = null;

            try
            {
                if (Client.Status != ConnectionStatus.Bound)
                {
                    WriteLog("ESMEConnection : SendMessage : Warning : Not Connected To The SMPP Server");

                    return 2;
                }

                // The message to send
                string sendMessage = null;

                // Do we need to cut the message down
                if (encodeDataCoding == DataCodings.UCS2)
                {
                    // UCS2 only supports 140 bytes
                    if (message.Length > 70)
                    {
                        WriteLog(LogEventNotificationTypes.Email, "ESMEConnection : SendMessage : WARNING : Truncating UCS2 message to 70 characters.");

                        // The default is Unicode so truncate the message
                        sendMessage = message.Substring(0, 70);
                    }
                }
                else
                {
                    if (message.Length > 160)
                    {
                        WriteLog(LogEventNotificationTypes.Email, "ESMEConnection : SendMessage : WARNING : Truncating Default message to 160 characters.");

                        sendMessage = message.Substring(0, 160);
                    }
                }

                // Prepare the message, I have made sure there is only ever one message
                // with the trunacting above
                submitSm = Client.PrepareSubmit(
                    SubmitMode.ShortMessage,
                    serviceType,
                    (byte) Ton.NetworkSpecific,
                    (byte) Npi.Unknown,
                    ShortLongCode,
                    (byte) destinationTon,
                    (byte) destinationNpi,
                    phoneNumber,
                    submitDataCoding,
                    encodeDataCoding,
                    (sendMessage == null) ? message : sendMessage);

                // Send the message
                submitSmResp = Client.Submit(submitSm);

                // Log the send call
                WriteLog("ESMEConnection : SendMessage : Send : Sequence[{0}] Phone[{1}] Status[{2}]", submitSmResp.Sequence, phoneNumber, submitSmResp.Status);

                // Was it successful
                if (submitSmResp.Status != CommandStatus.ESME_ROK)
                {
                    WriteLog("ESMEConnection : SendMessage : ERROR : Failed For Unknown Reason");

                    retVal = 1;
                }

                // Success
                retVal = 0;
            }

            catch (Exception exception)
            {
                WriteLog(LogEventNotificationTypes.Email, "ESMEConnection : SendMessage : ERROR : {0}", exception.ToString());

                retVal = 1;
            }

            return retVal;
        }
Пример #7
0
        /// <summary> Called to send the message </summary>
        /// <param name="phoneNumber"></param>
        /// <param name="serviceType"></param>
        /// <param name="sourceTon"></param>
        /// <param name="sourceNpi"></param>
        /// <param name="submitDataCoding"></param>
        /// <param name="encodeDataCoding"></param>
        /// <param name="message"></param>
        /// <param name="submitSm"></param>
        /// <param name="submitSmResp"></param>
        /// <returns> 1 - Successful / 0 - Failed </returns>
        public int SendMessage(string phoneNumber, string serviceType, Ton sourceTon, Npi sourceNpi, DataCodings submitDataCoding, DataCodings encodeDataCoding, string message,  out SubmitSm submitSm, out SubmitSmResp submitSmResp)
        {
            int retVal = 0;

            submitSm = null;
            submitSmResp = null;

            try
            {
                // Capture the next transmitter connection
                ESMEConnection smppConnection = NextTransmitterConnection();

                if (smppConnection == null)
                {
                    WriteLog("ESMEManager : SendMessage : Warning : Not Bound To The SMPP Server");

                    return 2;
                }

                // Send the message
                retVal = smppConnection.SendMessage(phoneNumber, serviceType, sourceTon, sourceNpi, submitDataCoding, encodeDataCoding, message, out submitSm, out submitSmResp);
            }

            catch (Exception exception)
            {
                WriteLog(LogEventNotificationTypes.Email, "ESMEManager : SendMessage : ERROR : {0}", exception.ToString());
            }

            return retVal;
        }
Пример #8
0
        /// <summary> Called to send the message </summary>
        /// <param name="phoneNumber"></param>
        /// <param name="serviceType"></param>
        /// <param name="destinationTon"></param>
        /// <param name="destinationNpi"></param>
        /// <param name="submitDataCoding"></param>
        /// <param name="encodeDataCoding"></param>
        /// <param name="message"></param>
        /// <param name="submitSm"></param>
        /// <param name="submitSmResp"></param>
        /// <returns> 0 - Successful / 1 - Failed / 2 - Not Connected </returns>
        public int SendMessage(string phoneNumber, string serviceType, Ton destinationTon, Npi destinationNpi, DataCodings submitDataCoding, DataCodings encodeDataCoding, string message, out SubmitSm submitSm, out SubmitSmResp submitSmResp)
        {
            int retVal = 1;

            submitSm     = null;
            submitSmResp = null;

            try
            {
                if (Client.Status != ConnectionStatus.Bound)
                {
                    WriteLog("ESMEConnection : SendMessage : Warning : Not Connected To The SMPP Server");

                    return(2);
                }

                // The message to send
                string sendMessage = null;

                // Do we need to cut the message down
                if (encodeDataCoding == DataCodings.UCS2)
                {
                    // UCS2 only supports 140 bytes
                    if (message.Length > 70)
                    {
                        WriteLog(LogEventNotificationTypes.Email, "ESMEConnection : SendMessage : WARNING : Truncating UCS2 message to 70 characters.");

                        // The default is Unicode so truncate the message
                        sendMessage = message.Substring(0, 70);
                    }
                }
                else
                {
                    if (message.Length > 160)
                    {
                        WriteLog(LogEventNotificationTypes.Email, "ESMEConnection : SendMessage : WARNING : Truncating Default message to 160 characters.");

                        sendMessage = message.Substring(0, 160);
                    }
                }

                // Prepare the message, I have made sure there is only ever one message
                // with the trunacting above
                submitSm = Client.PrepareSubmit(
                    SubmitMode.ShortMessage,
                    serviceType,
                    (byte)Ton.NetworkSpecific,
                    (byte)Npi.Unknown,
                    ShortLongCode,
                    (byte)destinationTon,
                    (byte)destinationNpi,
                    phoneNumber,
                    submitDataCoding,
                    encodeDataCoding,
                    (sendMessage == null) ? message : sendMessage);

                // Send the message
                submitSmResp = Client.Submit(submitSm);

                // Log the send call
                WriteLog("ESMEConnection : SendMessage : Send : Sequence[{0}] Phone[{1}] Status[{2}]", submitSmResp.Sequence, phoneNumber, submitSmResp.Status);

                // Was it successful
                if (submitSmResp.Status != CommandStatus.ESME_ROK)
                {
                    WriteLog("ESMEConnection : SendMessage : ERROR : Failed For Unknown Reason");

                    retVal = 1;
                }

                // Success
                retVal = 0;
            }

            catch (Exception exception)
            {
                WriteLog(LogEventNotificationTypes.Email, "ESMEConnection : SendMessage : ERROR : {0}", exception.ToString());

                retVal = 1;
            }

            return(retVal);
        }
Пример #9
0
        /// <summary> Called to fire the submit pdu event </summary>
        /// <param name="data"></param>
        internal void OnSubmitSmResp(SubmitSmResp data)
        {
            try
            {
                if (SubmitSmRespEvent != null)
                {
                    SubmitSmRespEvent(this, data);
                }
            }

            catch
            {
            }
        }