diff --git a/Source/SmppClient/ESMEConnection.cs b/Source/SmppClient/ESMEConnection.cs index c89c6a0..d241e13 100644 --- a/Source/SmppClient/ESMEConnection.cs +++ b/Source/SmppClient/ESMEConnection.cs @@ -12,11 +12,11 @@ namespace BSN.SmppClient { /// Manages a single ESME (Extended Short Message Entity) connection internal class ESMEConnection : IDisposable - { + { #region Delegates - + /// Called when a message is received - /// + /// /// /// /// @@ -754,6 +754,106 @@ public int SendMessage(string phoneNumber, string serviceType, Ton destinationTo return retVal; } + /// Called to send the message + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// 0 - Successful / 1 - Failed For Exception / 2 - Not Binded / 3 - Failed For Unknown Reason + public int SendMessage(string phoneNumber, string serviceType, Ton sourceTon, Npi sourceNpi, 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)sourceTon, + (byte)sourceNpi, + 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); + + // Success + if (submitSmResp.Status == CommandStatus.ESME_ROK) + { + retVal = 0; + } + // Bind Failed + else if (submitSmResp.Status == CommandStatus.ESME_RBINDFAIL) + { + WriteLog("ESMEConnection : SendMessage : ERROR : Bind Failed"); + + retVal = 2; + } + // Isn't successful + else + { + WriteLog("ESMEConnection : SendMessage : ERROR : Failed For Unknown Reason"); + + retVal = 3; + } + + } + catch (Exception ex) + { + WriteLog(LogEventNotificationTypes.Email, "ESMEConnection : SendMessage : ERROR : {0}", ex.ToString()); + retVal = 1; + } + + return retVal; + } + /// Called to send the message /// /// diff --git a/Source/SmppClient/ESMEManager.cs b/Source/SmppClient/ESMEManager.cs index 418a660..596bc15 100644 --- a/Source/SmppClient/ESMEManager.cs +++ b/Source/SmppClient/ESMEManager.cs @@ -12,11 +12,11 @@ namespace BSN.SmppClient { /// Provides ESME (Extended Short Message Entity) Management public class ESMEManager : IDisposable - { + { #region Delegates - + /// Called when a message is received - /// + /// /// /// /// @@ -248,10 +248,10 @@ public void ConnectionEventConnectionHandler(string logKey, ConnectionEventTypes { ConnectionEventHandler(logKey, connectionEventType, message); } - } - + } + /// Called when a message is received on a connection - /// + /// /// /// /// @@ -503,7 +503,7 @@ public void AddConnections(int howMany, ConnectionModes connectionMode, string h /// /// /// - /// 1 - Successful / 0 - Failed + /// 0 - Successful / 1 - Failed 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; @@ -535,6 +535,48 @@ public int SendMessage(string phoneNumber, string serviceType, Ton sourceTon, Np return retVal; } + /// Called to send the message + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// 0 - Successful / 1 - Failed + public int SendMessage(string phoneNumber, string serviceType, Ton sourceTon, Npi sourceNpi, Ton destTon, Npi destNpi, 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 eSMEConnection = NextTransmitterConnection(); + + if (eSMEConnection == null) + { + WriteLog("ESMEManager : SendMessage : Warning : Not Bound To The SMPP Server"); + + return 2; + } + + // Send the message + retVal = eSMEConnection.SendMessage(phoneNumber, serviceType, sourceTon, sourceNpi, destTon, destNpi, submitDataCoding, encodeDataCoding, message, out submitSm, out submitSmResp); + } + catch (Exception ex) + { + WriteLog(LogEventNotificationTypes.Email, "ESMEManager : SendMessage : ERROR : {0}", ex.ToString()); + } + + return retVal; + } + /// Called to send the message /// ///