Exemplo 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);
                    }
                }
            }
        }
Exemplo n.º 2
0
        static void connection_OnDeliverSm(object source, RoaminSMPP.EventObjects.DeliverSmEventArgs e)
        {
            string networkMessage = string.Empty;

            try
            {
                networkMessage = e.DeliverSmPdu.NetworkErrorCode;
            }
            catch
            {
                networkMessage = e.DeliverSmPdu.ShortMessage;
            }
            RoaminSMPP.SMPPCommunicator connection = source as RoaminSMPP.SMPPCommunicator;
            if (connection != null)
            {
                if (DeliveryRecieptRecieved != null)
                {
                    DeliveryRecieptRecieved(e.DeliverSmPdu.ReceiptedMessageId, connection.ProviderId, e.DeliverSmPdu.SequenceNumber, e.DeliverSmPdu.MessageState, networkMessage);
                }
                SmppDeliverSmResp resp = new SmppDeliverSmResp()
                {
                    CommandStatus  = (uint)SmppCommandStatus.ESME_ROK,
                    SequenceNumber = e.DeliverSmPdu.SequenceNumber
                };
                connection.SendPdu(resp);
            }
        }
Exemplo n.º 3
0
 static void connectionTimer_Elapsed(object sender, ElapsedEventArgs e)
 {
     if (sender is KeyedTimer <string> )
     {
         KeyedTimer <string> timer = sender as KeyedTimer <string>;
         lock (_syncLock)
         {
             if (_connections.ContainsKey(timer.Key))
             {
                 ConnectionItem item = _connections[timer.Key];
                 if (!item.IsRunning)
                 {
                     try
                     {
                         RoaminSMPP.SMPPCommunicator conn = _connections[timer.Key].Connection;
                         if (conn.IsBinded)
                         {
                             conn.SendPdu(new SmppEnquireLink());
                         }
                         else
                         {
                             conn.Bind();
                         }
                     }
                     catch (Exception ex)
                     {
                         Trace.TraceWarning("Ошибка соединения с поставщиком: {0}", ex);
                         item.ReconnectAttempts++;
                         if (item.ReconnectAttempts > Settings.Default.MaxReconnectAttempts)
                         {
                             item.ConnectionRefreshTimer.Enabled  = false;
                             item.ConnectionRefreshTimer.Elapsed -= connectionTimer_Elapsed;
                             _connections.Remove(timer.Key);
                             item.ConnectionRefreshTimer.Dispose();
                             item.Connection.Dispose();
                         }
                     }
                     finally
                     {
                         item.IsRunning = false;
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 4
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);
                }
            }
        }