Example #1
0
        public static string DumpStrigDefault(object obj, SmppEncodingService encodingService = null)
#endif
        {
            var sb = new StringBuilder();

            sb.AppendFormat("{0} -- ", obj.GetType().Name);

            foreach (var property in obj.GetType().GetProperties())
            {
                object value = "--";

                try
                {
                    value = property.GetValue(obj, null);
                }
                catch { }

                if (value is byte[])
                {
                    value = BytesToString(value as byte[], encodingService);
                }
                else if (value is TlvCollection)
                {
                    value = TlvCollectionToString(value as TlvCollection, encodingService);
                }

                sb.AppendFormat("{0}:{1} ", property.Name, value);
            }

            return(sb.ToString());
        }
Example #2
0
 internal static byte[] EncodeString(string str, SmppEncodingService smppEncodingService)
 {
     if (str == null)
     {
         str = "";
     }
     return(smppEncodingService.GetBytesFromString(str));
 }
Example #3
0
 internal QuerySmResp(PDUHeader header, SmppEncodingService smppEncodingService)
     : base(header, smppEncodingService)
 {
     vMessageID    = "";
     vFinalDate    = "";
     vMessageState = MessageState.Unknown;
     vErrorCode    = 0;
 }
Example #4
0
    protected override SubmitSm CreateSubmitSm(SmppEncodingService smppEncodingService)
    {
        var sm = base.CreateSubmitSm(smppEncodingService);

        sm.SourceAddress.Ton = JamaaTech.Smpp.Net.Lib.TypeOfNumber.Aphanumeric;
        sm.SourceAddress.Npi = JamaaTech.Smpp.Net.Lib.NumberingPlanIndicator.Unknown;
        return(sm);
    }
Example #5
0
 internal SendSmPDU(PDUHeader header, SmppEncodingService smppEncodingService)
     : base(header, smppEncodingService)
 {
     vServiceType        = "";
     vEsmClass           = EsmClass.Default;
     vRegisteredDelivery = RegisteredDelivery.None;
     vDataCoding         = DataCoding.ASCII;
 }
Example #6
0
        protected virtual SubmitSm CreateSubmitSm(SmppEncodingService smppEncodingService)
        {
            var sm = new SubmitSm(smppEncodingService);

            //sm.SourceAddress.Ton = TypeOfNumber.Unknown;
            //sm.DestinationAddress.Ton = TypeOfNumber.Unknown;

            return(sm);
        }
Example #7
0
 public ReplaceSm(PDUHeader header, SmppEncodingService smppEncodingService)
     : base(header, smppEncodingService)
 {
     vScheduleDeliveryTime = "";
     vValidityPeriod       = "";
     vRegisteredDelivery   = RegisteredDelivery.None;
     vSmDefaultMessageID   = 0;
     vShortMessage         = "";
     vSmLength             = 0;
 }
Example #8
0
        public byte[] GetBytes(SmppEncodingService smppEncodingService)
        {
            ByteBuffer buffer = new ByteBuffer(64); //Creates buffer with enough capacity

            foreach (Tlv tlv in this)
            {
                buffer.Append(tlv.GetBytes(smppEncodingService));
            }
            return(buffer.ToBytes());
        }
Example #9
0
        public byte[] GetBytes(SmppEncodingService smppEncodingService)
        {
            ByteBuffer buffer = new ByteBuffer(32);

            buffer.Append(smppEncodingService.GetBytesFromInt(vCommandLength));
            buffer.Append(smppEncodingService.GetBytesFromInt((uint)vCommandType));
            buffer.Append(smppEncodingService.GetBytesFromInt((uint)vErrorCode));
            buffer.Append(smppEncodingService.GetBytesFromInt(vSequenceNumber));
            return(buffer.ToBytes());
        }
Example #10
0
        public byte[] GetBytes(SmppEncodingService smppEncodingService)
        {
            //Approximate buffer required;
            int        capacity = 4 + vAddress == null ? 1 : vAddress.Length;
            ByteBuffer buffer   = new ByteBuffer(capacity);

            buffer.Append((byte)vTon);
            buffer.Append((byte)vNpi);
            buffer.Append(PDU.EncodeCString(vAddress, smppEncodingService));
            return(buffer.ToBytes());
        }
Example #11
0
 internal BindRequest(PDUHeader header, SmppEncodingService smppEncodingService)
     : base(header, smppEncodingService)
 {
     vSystemID         = "";
     vPassword         = "";
     vSystemType       = "";
     vAddressTon       = TypeOfNumber.International;  //International
     vAddressNpi       = NumberingPlanIndicator.ISDN; //ISDN
     vInterfaceVersion = 34;                          //SMPP 3.4 version
     vAddressRange     = "";
 }
Example #12
0
        internal static SmppAddress Parse(ByteBuffer buffer, SmppEncodingService smppEncodingService)
        {
            //We require at least 3 bytes for SMPPAddress instance to be craeted
            if (buffer.Length < 3)
            {
                throw new NotEnoughBytesException("SMPPAddress requires at least 3 bytes");
            }
            TypeOfNumber           ton = (TypeOfNumber)PDU.GetByte(buffer);
            NumberingPlanIndicator npi = (NumberingPlanIndicator)PDU.GetByte(buffer);
            string address             = PDU.DecodeCString(buffer, smppEncodingService);

            return(new SmppAddress(ton, npi, address));
        }
Example #13
0
        private static string TlvCollectionToString(TlvCollection tlvCollection, SmppEncodingService encodingService)
        {
            var tags = new StringBuilder();

            tags.Append("[");
            foreach (var tlv in tlvCollection)
            {
                tags.AppendFormat("{0}:{1} ", tlv.Tag, BytesToString(tlv.RawValue, encodingService));
            }
            tags.Append("]");

            return(tags.ToString());
        }
Example #14
0
        public virtual byte[] GetBytes(SmppEncodingService smppEncodingService)
        {
            if (vRawValue == null || vRawValue.Length != vLength)
            {
                throw new TlvException("Tlv value length inconsistent with length field or has no data set");
            }
            ByteBuffer buffer = new ByteBuffer(vLength + 4); //Reserve enough capacity for tag, length and value fields

            buffer.Append(smppEncodingService.GetBytesFromShort((ushort)vTag));
            buffer.Append(smppEncodingService.GetBytesFromShort(vLength));
            buffer.Append(vRawValue);
            return(buffer.ToBytes());
        }
Example #15
0
 internal static string DecodeString(ByteBuffer buffer, int length, SmppEncodingService smppEncodingService)
 {
     try { string value = smppEncodingService.GetStringFromBytes(buffer.Remove(length)); return(value); }
     catch (ArgumentException ex)
     {
         //ByteBuffer.Remove(int count) throw ArgumentException if the buffer length is less than count
         //This is the indication that the amount of bytes required could not be met
         //We wrap this exception as NotEnoughtBytesException exception
         throw new NotEnoughBytesException(
                   "Octet String field could not be decoded because no enough bytes are evailable in the buffer",
                   ex);
     }
 }
Example #16
0
 public SubmitSm(PDUHeader header, SmppEncodingService smppEncodingService)
     : base(header, smppEncodingService)
 {
     vServiceType          = Protocol.ServiceType.DEFAULT;
     vProtocolId           = 0;
     vPriorityFlag         = PriorityFlag.Level0;
     vScheduleDeliveryTime = "";
     vValidityPeriod       = "";
     vRegisteredDelivery   = RegisteredDelivery.None;
     vReplaceIfPresent     = false;
     vDataCoding           = DataCoding.ASCII;
     vSmDefalutMessageId   = 0;
 }
Example #17
0
        public static Tlv Parse(ByteBuffer buffer, SmppEncodingService smppEncodingService)
        {
            //Buffer must have at least 4 bytes for tag and length plus at least one byte for the value field
            if (buffer.Length < 5)
            {
                throw new TlvException("Tlv required at least 5 bytes");
            }
            Tag    tag = (Tag)smppEncodingService.GetShortFromBytes(buffer.Remove(2));
            ushort len = smppEncodingService.GetShortFromBytes(buffer.Remove(2));
            Tlv    tlv = new Tlv(tag, len);

            tlv.ParseValue(buffer, len);
            return(tlv);
        }
Example #18
0
        public static TlvCollection Parse(ByteBuffer buffer, SmppEncodingService smppEncodingService)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            TlvCollection tlvs = new TlvCollection();

            while (buffer.Length > 0)
            {
                Tlv tlv = Tlv.Parse(buffer, smppEncodingService);
                tlvs.Add(tlv);
            }
            return(tlvs);
        }
Example #19
0
 public static string DumpStringWithTry(object obj, SmppEncodingService encodingService = null)
 {
     try
     {
         return(DumpStringDefault(obj, encodingService));
     }
     catch (Exception ex)
     {
         if (_Log.IsErrorEnabled)
         {
             _Log.Error(ex);
         }
         return(null);
     }
 }
Example #20
0
 public SmppClient()
 {
     vProperties          = new SmppConnectionProperties();
     vSmppEncodingService = new SmppEncodingService();
     vConnSyncRoot        = new object();
     vAutoReconnectDelay  = 10000;
     vTimeOut             = 5000;
     //--
     vTimer = new System.Threading.Timer(AutoReconnectTimerEventHandler, null, Timeout.Infinite, vAutoReconnectDelay);
     //--
     vName              = "";
     vState             = SmppConnectionState.Closed;
     vKeepAliveInterval = 30000;
     //--
     vSendMessageCallBack += SendMessage;
 }
Example #21
0
        private static string BytesToString(byte[] value, SmppEncodingService encodingService)
        {
            try
            {
                if (encodingService != null)
                {
                    return(encodingService.GetCStringFromBytes(value));
                }

                return(BytesToStringHex(value));
            }
            catch (Exception)
            {
                return(BytesToStringHex(value));
            }
        }
Example #22
0
        public static PDUHeader Parse(ByteBuffer buffer, SmppEncodingService smppEncodingService)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (buffer.Length < 16)
            {
                throw new ArgumentException("Buffer length must not be less than 16 bytes");
            }
            uint          cmdLength = smppEncodingService.GetIntFromBytes(buffer.Remove(4));
            CommandType   cmdType   = (CommandType)smppEncodingService.GetIntFromBytes(buffer.Remove(4));
            SmppErrorCode errorCode = (SmppErrorCode)smppEncodingService.GetIntFromBytes(buffer.Remove(4));
            uint          seqNumber = smppEncodingService.GetIntFromBytes(buffer.Remove(4));
            PDUHeader     header    = new PDUHeader(cmdType, seqNumber, errorCode, cmdLength);

            return(header);
        }
Example #23
0
        internal static string DecodeCString(ByteBuffer buffer, SmppEncodingService smppEncodingService)
        {
            //Get next terminating null value
            int pos = buffer.Find(0x00);

            if (pos < 0)
            {
                throw new PDUFormatException("CString type field could not be read. The terminating charactor is missing");
            }
            try { string value = smppEncodingService.GetCStringFromBytes(buffer.Remove(pos + 1)); return(value); }
            catch (ArgumentException ex)
            {
                //ByteBuffer.Remove(int count) throw ArgumentException if the buffer length is less than count
                //This is the indication that the amount of bytes required could not be met
                //We wrap this exception as NotEnoughtBytesException exception
                throw new NotEnoughBytesException("PDU requires more bytes than supplied", ex);
            }
        }
Example #24
0
 protected abstract IEnumerable <SendSmPDU> GetPDUs(DataCoding defaultEncoding, SmppEncodingService smppEncodingService);
Example #25
0
 internal IEnumerable <SendSmPDU> GetMessagePDUs(DataCoding defaultEncoding, SmppEncodingService smppEncodingService)
 {
     return(GetPDUs(defaultEncoding, smppEncodingService));
 }
Example #26
0
 internal BindReceiver(PDUHeader header, SmppEncodingService smppEncodingService)
     : base(header, smppEncodingService)
 {
 }
Example #27
0
 public BindReceiver(SmppEncodingService smppEncodingService)
     : base(new PDUHeader(CommandType.BindReceiver), smppEncodingService)
 {
 }
 internal BindTransceiverResp(PDUHeader header, SmppEncodingService smppEncodingService)
     : base(header, smppEncodingService)
 {
 }
Example #29
0
 internal DataSm(PDUHeader header, SmppEncodingService smppEncodingService)
     : base(header, smppEncodingService)
 {
 }
Example #30
0
 public DataSm(SmppEncodingService smppEncodingService)
     : base(new PDUHeader(CommandType.DataSm), smppEncodingService)
 {
 }