/// <summary> /// Sends message /// </summary> /// <param name="message_id">Unique message id</param> /// <param name="sender">Sender</param> /// <param name="recipient">Recipient</param> /// <param name="body">body</param> /// <param name="body_format">Body format. unicode,ascii,wap_push</param> /// <param name="delivery_report">Request delivery report</param> /// <returns>0 if successful, /// 1 - No active connection, /// 2 - Too many messages per second /// 3 - Duplicate sequence number </returns> public virtual int SubmitSm(int message_id, string sender, string recipient, string body, string body_format = "ascii", bool delivery_report = true) { if (!connected) { Events.LogMessageChangeStatusEvent(message_id, Common.MessageStatus.received_route_failure); return(1); } // check for max sms count if (max_threads != 0) { int now_second = DateTime.Now.Second; if (now_second != last_second) { last_second = now_second; sent_during_last_second = 0; } else { sent_during_last_second++; } if (max_threads < sent_during_last_second) { // messages should be resubmitted later Events.LogMessageChangeStatusEvent(message_id, Common.MessageStatus.queued); return(2); // too many SMS per second } } var submit_sm = new SubmitSm(); while (submitted_messages.ContainsKey(sequence_number)) { sequence_number++; } submit_sm.sequence_number = sequence_number; var sm = new submitted_message(); sm.message_id = message_id; sm.submitted_time = DateTime.Now; sm.registered_delivery = delivery_report; try { submitted_messages.Add(submit_sm.sequence_number, sm); } catch (ArgumentException) { Events.LogChannelEvent(channel_name, "Duplicate sequence number."); Events.LogMessageChangeStatusEvent(message_id, Common.MessageStatus.queued); return(3); } submit_sm.Sender = sender; submit_sm.Recipient = recipient; submit_sm.Body = body; submit_sm.BodyFormat = body_format; submit_sm.Is8bit = use8bit; submit_sm.ServiceType = system_type; submit_sm.SourceAddrTON = source_ton; submit_sm.SourceAddrNPI = source_npi; submit_sm.DestAddrTON = destination_ton; submit_sm.DestAddrNPI = destination_npi; submit_sm.SplitBaseASCII = split_base_ascii; submit_sm.RegisteredDelivery = delivery_report ? 1 : 0; submit_sm.LargeMessageHandleMethod = large_message; multipart_sequence_number++; if (multipart_sequence_number == 255) { multipart_sequence_number = 1; } submit_sm.MultipartSequenceNumber = multipart_sequence_number; string[] pdu = submit_sm.EncodeM(); Events.LogChannelEvent(channel_name, "Sending from " + sender + " to " + recipient); var k = pdu.Length; foreach (var part in pdu) { Events.LogChannelEvent(channel_name, "Sending [submit_sm]", debug ? part : ""); SendPDU(part); if (k != 1) { Thread.Sleep(multypart_delay); } k--; if (registered_delivery == 1 && delivery_report) { Events.LogMessageChangeStatusEvent(message_id, Common.MessageStatus.submitted_waiting_for_ACK); } else { Events.LogMessageChangeStatusEvent(message_id, Common.MessageStatus.received_routed); } } return(0); }
private int DataSm(int message_id, string sender, string recipient, string body, string body_format, bool delivery_report) { if (!connected) { Events.LogMessageChangeStatusEvent(message_id, Common.MessageStatus.received_route_failure); return(1); } // check for max sms count if (max_threads != 0) { int now_second = DateTime.Now.Second; if (now_second != last_second) { last_second = now_second; sent_during_last_second = 0; } else { sent_during_last_second++; } if (max_threads < sent_during_last_second) { Events.LogMessageChangeStatusEvent(message_id, Common.MessageStatus.queued); return(2); // too many SMS per second } } var data_sm = new DataSm(); while (submitted_messages.ContainsKey(sequence_number)) { sequence_number++; } data_sm.sequence_number = sequence_number; var sm = new submitted_message(); sm.message_id = message_id; sm.submitted_time = DateTime.Now; sm.registered_delivery = delivery_report; try { submitted_messages.Add(data_sm.sequence_number, sm); } catch (ArgumentException) { Events.LogChannelEvent(channel_name, "Duplicate sequence number."); Events.LogMessageChangeStatusEvent(message_id, Common.MessageStatus.queued); return(3); } data_sm.Sender = sender; data_sm.Recipient = recipient; data_sm.Body = body; data_sm.BodyFormat = body_format; data_sm.ServiceType = system_type; data_sm.SourceAddrTON = source_ton; data_sm.SourceAddrNPI = source_npi; data_sm.DestAddrTON = destination_ton; data_sm.DestAddrNPI = destination_npi; if (registered_delivery == 1 && delivery_report) { data_sm.RegisteredDelivery = registered_delivery; } else { data_sm.RegisteredDelivery = 0; } var pdu = data_sm.EncodeM(); Events.LogChannelEvent(channel_name, "Sending from " + sender + " to " + recipient); var retVal = 0; var k = pdu.Length; foreach (string part in pdu) { Events.LogChannelEvent(channel_name, "Sending [data_sm]", debug ? part : ""); retVal += SendPDU(part); if (k != 1) { Thread.Sleep(multypart_delay); } k--; if (registered_delivery == 1 && delivery_report) { Events.LogMessageChangeStatusEvent(message_id, Common.MessageStatus.submitted_waiting_for_ACK); } else { Events.LogMessageChangeStatusEvent(message_id, Common.MessageStatus.received_routed); } } return(0); }