Пример #1
0
        public Task <object> DeserializeAsync(Type type, SmppReader reader, SmppSerializationSettings serializationSettings, CancellationToken cancellationToken)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            if (serializationSettings == null)
            {
                throw new ArgumentNullException(nameof(serializationSettings));
            }

            if (serializationSettings.SerializerResolver == null)
            {
                throw new InvalidOperationException($"Cannot resolve the serializer for type {type}: the resolver is not set");
            }

            var serializer = serializationSettings.SerializerResolver.ResolveForType(type);

            // TODO: if serializer not found, try to construct it from the type ...
            if (serializer == null)
            {
                throw new InvalidOperationException($"No serializer was resolved for the type {type} from the available ones");
            }

            return(serializer.DeserializeAsync(reader, serializationSettings, cancellationToken));
        }
Пример #2
0
 /// <summary>
 /// This method implements the ISupportSmppByteStream.GetFromStream
 /// method so that the PDU can serialize itself from the data stream.
 /// </summary>
 /// <param name="reader">StreamReader</param>
 public override void GetFromStream(SmppReader reader)
 {
     reader.ReadObject(mid_);
     reader.ReadObject(msgState_);
     reader.ReadObject(areaId_);
     reader.ReadObject(successRate_);
 }
Пример #3
0
 /// <summary>
 /// This method implements the ISupportSmppByteStream.GetFromStream
 /// method so that the PDU can serialize itself from the data stream.
 /// </summary>
 /// <param name="reader">StreamReader</param>
 public override void GetFromStream(SmppReader reader)
 {
     reader.ReadObject(stype_);
     reader.ReadObject(msgid_);
     reader.ReadObject(saddr_);
     reader.ReadObject(daddr_);
 }
Пример #4
0
 /// <summary>
 /// This method implements the ISupportSmppByteStream.GetFromStream
 /// method so that the PDU can serialize itself from the data stream.
 /// </summary>
 /// <param name="reader">StreamReader</param>
 public override void GetFromStream(SmppReader reader)
 {
     reader.ReadObject(mid_);
     reader.ReadObject(finalDate_);
     reader.ReadObject(msgState_);
     errCode_ = reader.ReadInt32();
 }
Пример #5
0
 /// <summary>
 /// This method retrieves the C-Octet string from the byte stream
 /// </summary>
 /// <param name="reader">Byte stream</param>
 public void GetFromStream(SmppReader reader)
 {
     ton_.GetFromStream(reader);
     npi_.GetFromStream(reader);
     addr_.GetFromStream(reader);
     ValidateData();
 }
Пример #6
0
        /// <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);
        }
Пример #7
0
        /// <summary>
        /// This method retrieves a PDU from a byte stream.
        /// </summary>
        /// <param name="stm">Byte stream</param>
        public void Deserialize(SmppReader stm)
        {
            state_ = PduStatus.invalid;
            try {
                // Get the header from the buffer
                length_ = stm.ReadInt32();
                int id = stm.ReadInt32();
                status_         = stm.ReadInt32();
                sequenceNumber_ = stm.ReadInt32();

                if (id != this.CommandId)
                {
                    throw new UnexpectedPduException(id);
                }

                state_ = PduStatus.validHeader;

                // Now read the body of the PDU
                if (length_ > REQUIRED_SIZE)
                {
                    this.GetFromStream(stm);
                    state_ |= PduStatus.validBody;

                    // Read any optional parameters that are present.
                    while (!((SmppByteStream)stm.Stream).EOS)
                    {
                        TlvParameter tlv = new TlvParameter();

                        try {
                            tlv.GetFromStream(stm);
                            TlvParameter tlvExisting = GetOptionalElement(tlv.Tag);
                            if (tlvExisting == null)
                            {
                                AddOptionalElements(tlv);
                            }
                            else
                            {
                                if (tlvExisting.Tag == tlv.Tag)
                                {
                                    tlvExisting.Data = tlv.Data;
                                }
                                else
                                {
                                    throw new TlvException("Read bad Tlv stream!");
                                }
                            }
                        } catch (ArgumentOutOfRangeException) {
                        }
                    }
                }
            } catch (InvalidOperationException e) {
                throw new IncompletePduException(this, e);
            } catch (PduException e) {
                e.PDU = this;
                throw e;
            } catch (System.Exception e) {
                throw new PduException(this, e);
            }
        }
Пример #8
0
 /// <summary>
 /// This method implements the ISupportSmppByteStream.GetFromStream
 /// method so that the PDU can serialize itself from the data stream.
 /// </summary>
 /// <param name="reader">StreamReader</param>
 public override void GetFromStream(SmppReader reader)
 {
     reader.ReadObject(sid_);
     reader.ReadObject(pwd_);
     reader.ReadObject(stype_);
     reader.ReadObject(ifver_);
     reader.ReadObject(addr_range_);
 }
        /// <inheritdoc />
        public override async Task <string> DeserializeAsync(SmppReader reader, CancellationToken cancellationToken)
        {
            var result = await reader.ReadStringAsync();

            await reader.ReadByteAsync();

            return(result);
        }
Пример #10
0
 /// <summary>
 /// This method implements the ISupportSmppByteStream.GetFromStream
 /// method so that the PDU can serialize itself from the data stream.
 /// </summary>
 /// <param name="reader">StreamReader</param>
 public override void GetFromStream(SmppReader reader)
 {
     reader.ReadObject(stype_);
     reader.ReadObject(saddr_);
     reader.ReadObject(daddr_);
     reader.ReadObject(esmclass_);
     reader.ReadObject(regDelivery_);
     reader.ReadObject(dataCoding_);
 }
Пример #11
0
        /// <summary>
        /// This method retrieves the C-Octet string from the byte stream
        /// </summary>
        /// <param name="reader">Byte stream</param>
        public void GetFromStream(SmppReader reader)
        {
            int len = (int)reader.ReadByte();

            if (len > 0)
            {
                data_ = reader.ReadString(len);
            }
            ValidateData();
        }
Пример #12
0
        /// <summary>
        /// This method implements the ISupportSmppByteStream.GetFromStream
        /// method so that the PDU can serialize itself from the data stream.
        /// </summary>
        /// <param name="reader">StreamReader</param>
        public override void GetFromStream(SmppReader reader)
        {
            distList_ = new List <string>();
            int count = (int)reader.ReadByte();

            for (int i = 0; i < count; i++)
            {
                distList_.Add(reader.ReadString());
            }
        }
Пример #13
0
        /// <inheritdoc />
        public override async Task <SmppTime> DeserializeAsync(SmppReader reader, CancellationToken cancellationToken)
        {
            var s = await reader.ReadStringAsync();

            if (SmppTime.TryParse(s, out var value))
            {
                return(value);
            }

            return(null);
        }
Пример #14
0
 /// <summary>
 /// This method implements the ISupportSmppByteStream.GetFromStream
 /// method so that the PDU can serialize itself from the data stream.
 /// </summary>
 /// <param name="reader">StreamReader</param>
 public override void GetFromStream(SmppReader reader)
 {
     reader.ReadObject(msgid_);
     reader.ReadObject(stype_);
     reader.ReadObject(saddr_);
     reader.ReadObject(deliveryTime_);
     reader.ReadObject(validPeriod_);
     reader.ReadObject(regDelivery_);
     reader.ReadObject(defMsgId_);
     reader.ReadObject(msg_);
 }
Пример #15
0
        /// <summary>
        /// This method retrieves the Tlv from a byte stream object.
        /// </summary>
        /// <param name="stm">Byte stream</param>
        public override void GetFromStream(SmppReader stm)
        {
            hasValue_ = true;
            Tag       = stm.ReadShort();
            int length = stm.ReadShort();

            if (length != 0)
            {
                throw new TlvException("Invalid length encountered for alert_on_message_delivery (was " + length.ToString() + ", should be zero.)");
            }
        }
Пример #16
0
        /// <summary>
        /// This method implements the ISupportSmppByteStream.GetFromStream
        /// method so that the PDU can serialize itself from the data stream.
        /// </summary>
        /// <param name="reader">StreamReader</param>
        public override void GetFromStream(SmppReader reader)
        {
            distList_.Clear();
            int count = reader.ReadByte();

            for (int i = 0; i < count; i++)
            {
                dl_member_details dtls = new dl_member_details();
                dtls.GetFromStream(reader);
                distList_.Add(dtls);
            }
        }
Пример #17
0
 /// <summary>
 /// This method retrieves the provisioning record from the byte stream
 /// </summary>
 /// <param name="reader">Byte stream</param>
 public void GetFromStream(SmppReader reader)
 {
     customerId_.GetFromStream(reader);
     name_.GetFromStream(reader);
     address_.GetFromStream(reader);
     sourceAddress_.GetFromStream(reader);
     svcLevel_.GetFromStream(reader);
     barStatus_.GetFromStream(reader);
     ocos_.GetFromStream(reader);
     tcos_.GetFromStream(reader);
     password_.GetFromStream(reader);
 }
Пример #18
0
        /// <inheritdoc />
        public override async Task <byte> DeserializeAsync(SmppReader reader, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var result = await reader.ReadByteAsync();

            if (result < 0)
            {
                throw new SerializationException();
            }

            return((byte)result);
        }
Пример #19
0
        /// <summary>
        /// This method retrieves the address array from the byte stream
        /// </summary>
        /// <param name="reader">Byte stream</param>
        public void GetFromStream(SmppReader reader)
        {
            int count = (int)reader.ReadByte();

            for (int i = 0; i < count; ++i)
            {
                unsuccess_sme addr = new unsuccess_sme();
                addr.GetFromStream(reader);
                Add(addr);
            }
            if (this.Count > MAX_COUNT)
            {
                throw new ArgumentException("Too many address objects in collection, max count allowed is " + MAX_COUNT.ToString());
            }
        }
Пример #20
0
 /// <summary>
 /// This method implements the ISupportSmppByteStream.GetFromStream
 /// method so that the PDU can serialize itself from the data stream.
 /// </summary>
 /// <param name="reader">StreamReader</param>
 public override void GetFromStream(SmppReader reader)
 {
     reader.ReadObject(sourceAddr_);
     reader.ReadObject(dlname_);
     type_ = (DistributionListModifyType)reader.ReadByte();
     if (type_ == DistributionListModifyType.AddMember)
     {
         reader.ReadObject(memberDetails_);
     }
     else
     {
         memberDetails_.Address     = new address();
         memberDetails_.Description = reader.ReadString();
     }
 }
Пример #21
0
        /// <inheritdoc />
        public override async Task <bool> DeserializeAsync(SmppReader reader, SmppSerializationSettings serializationSettings, CancellationToken cancellationToken)
        {
            var result = await reader.ReadByteAsync();

            if (result == 1)
            {
                return(true);
            }

            if (result == 0)
            {
                return(false);
            }

            throw new FormatException();
        }
Пример #22
0
 /// <summary>
 /// This method implements the ISupportSmppByteStream.GetFromStream
 /// method so that the PDU can serialize itself from the data stream.
 /// </summary>
 /// <param name="reader">StreamReader</param>
 public override void GetFromStream(SmppReader reader)
 {
     reader.ReadObject(stype_);
     reader.ReadObject(saddr_);
     reader.ReadObject(daddr_);
     reader.ReadObject(esmclass_);
     reader.ReadObject(protid_);
     reader.ReadObject(pflag_);
     reader.ReadObject(deliveryTime_);
     reader.ReadObject(validPeriod_);
     reader.ReadObject(regDelivery_);
     reader.ReadObject(repPresent_);
     reader.ReadObject(dataCoding_);
     reader.ReadObject(defMsgId_);
     reader.ReadObject(msg_);
 }
Пример #23
0
 /// <summary>
 /// This method implements the ISupportSmppByteStream.GetFromStream
 /// method so that the PDU can serialize itself from the data stream.
 /// </summary>
 /// <param name="reader">StreamReader</param>
 public override void GetFromStream(SmppReader reader)
 {
     reader.ReadObject(stype_);
     reader.ReadObject(saddr_);
     reader.ReadObject(mid_);
     reader.ReadObject(pflag_);
     reader.ReadObject(deliveryTime_);
     reader.ReadObject(validPeriod_);
     reader.ReadObject(repPresent_);
     reader.ReadObject(dataCoding_);
     reader.ReadObject(defMsgId_);
     reader.ReadObject(areaId_);
     reader.ReadObject(contentType_);
     reader.ReadObject(repNum_);
     reader.ReadObject(freqInt_);
 }
Пример #24
0
        /// <summary>
        /// This method retrieves the C-Octet string from the byte stream
        /// </summary>
        /// <param name="reader">Byte stream</param>
        public void GetFromStream(SmppReader reader)
        {
            flag_.GetFromStream(reader);
            switch (flag_.Value)
            {
            case DestinationType.DL_NAME:
                elem_ = new dl_name();
                break;

            case DestinationType.SME_ADDRESS:
                elem_ = new address();
                break;

            default:
                elem_ = null;
                break;
            }

            if (elem_ != null)
            {
                ISupportSmppByteStream isb = (ISupportSmppByteStream)elem_;
                isb.GetFromStream(reader);
            }
        }
Пример #25
0
 /// <summary>
 /// This method retrieves the C-Octet string from the byte stream
 /// </summary>
 /// <param name="reader">Byte stream</param>
 public void GetFromStream(SmppReader reader)
 {
     data_ = reader.ReadString();
     ValidateData();
 }
Пример #26
0
 /// <summary>
 /// This method retrieves the C-Octet string from the byte stream
 /// </summary>
 /// <param name="reader">Byte stream</param>
 public void GetFromStream(SmppReader reader)
 {
     addr_.GetFromStream(reader);
     status_ = reader.ReadInt32();
 }
Пример #27
0
 /// <summary>
 /// This method implements the ISupportSmppByteStream.GetFromStream
 /// method so that the PDU can serialize itself from the data stream.
 /// </summary>
 /// <param name="reader">StreamReader</param>
 public override void GetFromStream(SmppReader reader)
 {
     reader.ReadObject(saddr_);
     reader.ReadObject(esmeaddr_);
 }
Пример #28
0
 /// <summary>
 /// This method implements the ISupportSmppByteStream.GetFromStream
 /// method so that the PDU can serialize itself from the data stream.
 /// </summary>
 /// <param name="reader">StreamReader</param>
 public override void GetFromStream(SmppReader reader)
 {
     reader.ReadObject(sid_);
     reader.ReadObject(pwd_);
 }
Пример #29
0
 /// <summary>
 /// This method implements the ISupportSmppByteStream.GetFromStream
 /// method so that the PDU can serialize itself from the data stream.
 /// </summary>
 /// <param name="reader">StreamReader</param>
 public override void GetFromStream(SmppReader reader)
 {
     id_ = reader.ReadString();
 }
Пример #30
0
 /// <summary>
 /// This method implements the ISupportSmppByteStream.GetFromStream
 /// method so that the PDU can serialize itself from the data stream.
 /// </summary>
 /// <param name="reader">StreamReader</param>
 public override void GetFromStream(SmppReader reader)
 {
     reader.ReadObject(sourceAddr_);
     reader.ReadObject(dlname_);
 }