Esempio n. 1
0
        protected override void Process(Timer timer)
        {
            List <SMSQueue> queue = Context.GetSMSToUpdateStatus(Settings.Default.SMSCheckStatusBatchSize, DateTime.Now.Add(-Settings.Default.CheckStatusInterval)).ToList();

            foreach (SMSQueue sms in queue)
            {
                if (!string.IsNullOrEmpty(sms.SMSId))
                {
                    try
                    {
                        RoaminSMPP.SMPPCommunicator connection = SMPPPool.GetConnection(sms.ProviderId.Value, sms.source_addr);
                        SmppQuerySm queryPdu = new SmppQuerySm()
                        {
                            MessageId        = sms.SMSId,
                            SourceAddress    = sms.source_addr,
                            SourceAddressNpi = connection.NpiType,
                            SourceAddressTon = connection.TonType
                        };
                        connection.SendPdu(queryPdu);
                        lock (_syncLock)
                        {
                            if (!_sentMessages.ContainsKey(sms.SMSId))
                            {
                                _sentMessages.Add(sms.SMSId, sms.Id);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceWarning("Невозможно отправить сообщение с Id = {0}, ошибка: {1}", sms.Id, ex);
                    }
                }
            }
        }
Esempio n. 2
0
        protected override void Process(Timer timer)
        {
            List <SMSQueue> queue = Context.GetSMSToSend(Settings.Default.SMSSendBatchSize).ToList();

            foreach (SMSQueue sms in queue)
            {
                try
                {
                    Trace.TraceInformation("Отправка сообщения {0}", sms.Id);
                    DestinationAddress[] dests = sms.DestinationMap.Select
                                                 (
                        item =>
                        item.IsDistributionList ?
                        new DestinationAddress(item.destination_addr) :
                        new DestinationAddress(
                            (Pdu.TonType)item.dest_addr_ton,
                            (Pdu.NpiType)item.dest_addr_npi,
                            item.destination_addr)
                                                 ).ToArray();
                    MessageLcd2 sendPdu;
                    if (sms.number_of_dests > 1)
                    {
                        RoaminSMPP.Packet.Request.SmppSubmitMulti multi = new RoaminSMPP.Packet.Request.SmppSubmitMulti();
                        multi.DestinationAddresses = dests;
                        sendPdu = multi;
                    }
                    else
                    {
                        DestinationAddress dest = dests[0];
                        RoaminSMPP.Packet.Request.SmppSubmitSm single = new RoaminSMPP.Packet.Request.SmppSubmitSm()
                        {
                            DestinationAddress    = dest.DestAddress,
                            DestinationAddressNpi = dest.DestinationAddressNpi,
                            DestinationAddressTon = dest.DestinationAddressTon
                        };
                        sendPdu = single;
                    }
                    Hashtable tlvTable = new Hashtable();
                    sms.SMSTLV.ToList().ForEach(item => tlvTable.Add(Convert.ToUInt16(item.Tag), Convert.FromBase64String(item.Value)));
                    sendPdu.TlvTable.tlvTable    = tlvTable;
                    sendPdu.SequenceNumber       = (uint)sms.sequence_number;
                    sendPdu.ServiceType          = sms.service_type;
                    sendPdu.SourceAddress        = sms.source_addr;
                    sendPdu.EsmClass             = (byte)sms.esm_class;
                    sendPdu.ProtocolId           = (Pdu.SmppVersionType)sms.protocol_id;
                    sendPdu.PriorityFlag         = (Pdu.PriorityType)sms.priority_flag;
                    sendPdu.ScheduleDeliveryTime = sms.schedule_delivery_time;
                    sendPdu.ValidityPeriod       = sms.validity_period;
                    sendPdu.RegisteredDelivery   = (Pdu.RegisteredDeliveryType)sms.registered_delivery;
                    sendPdu.ReplaceIfPresentFlag = sms.replace_if_present_flag >= 1 ? true : false;
                    sendPdu.DataCoding           = (Pdu.DataCodingType)sms.data_coding;
                    sendPdu.SmDefaultMessageId   = (byte)(sms.sm_default_msg_id ?? 0);
                    sendPdu.ShortMessage         = sms.short_message.GetBytesFromHex();
                    RoaminSMPP.SMPPCommunicator connection = SMPPPool.GetConnection(sms.ProviderId.Value, sms.source_addr);
                    sendPdu.SourceAddressNpi   = connection.NpiType;
                    sendPdu.SourceAddressTon   = connection.TonType;
                    sendPdu.RegisteredDelivery = (Pdu.RegisteredDeliveryType)sms.registered_delivery;
                    connection.SendPdu(sendPdu);
                    Context.GetStatusUpdater().UpdateSMSStatus(sms.Id, null, SMSStatus.Send, null, RoaminSMPP.Packet.Pdu.MessageStateType.Accepted);
                    lock (_syncLock)
                    {
                        _sentMessages.Add(sendPdu.SequenceNumber, sms.Id);
                    }
                }
                catch (Exception ex)
                {
                    //TODO: Реализовать логику RetryCount
                    Trace.TraceWarning("Невозможно отправить сообщение с Id = {0}, ошибка: {1}", sms.Id, ex);
                }
            }
        }