private async Task SubmitBatchMessages() { var sourceAddress = new SmeAddress(tbSrcAdr.Text, (AddressTON)byte.Parse(tbSrcAdrTON.Text), (AddressNPI)byte.Parse(tbSrcAdrNPI.Text)); var destinationAddress = new SmeAddress(tbDestAdr.Text, (AddressTON)byte.Parse(tbDestAdrTON.Text), (AddressNPI)byte.Parse(tbDestAdrNPI.Text)); string messageText = tbMessageText.Text; SubmitMode mode = GetSubmitMode(); DataCodings coding = GetDataCoding(); int count = int.Parse(tbRepeatTimes.Text); _log.Info("Submit message batch. Count: {0}. Text: {1}", count, messageText); // bulk sms test List <SubmitSm> batch = new List <SubmitSm>(); for (int i = 0; i < count; i++) { ISubmitSmBuilder builder = SMS.ForSubmit() .Text(messageText) .From(sourceAddress) .To(destinationAddress) .Coding(coding); switch (mode) { case SubmitMode.Payload: builder.MessageInPayload(); break; case SubmitMode.ShortMessageWithSAR: builder.ConcatenationInSAR(); break; } batch.AddRange(builder.Create(_client)); } try { Stopwatch watch = Stopwatch.StartNew(); var resp = (await _client.Submit(batch)).ToArray(); watch.Stop(); if (resp.All(x => x.Header.Status == CommandStatus.ESME_ROK)) { _log.Info("Batch sending completed. Submitted: {0}, Elapsed: {1} ms, Performance: {2} m/s", batch.Count, watch.ElapsedMilliseconds, batch.Count * 1000f / watch.ElapsedMilliseconds); } else { var wrongStatuses = resp.Where(x => x.Header.Status != CommandStatus.ESME_ROK) .Select(x => x.Header.Status).Distinct(); _log.Warn("Submit failed. Wrong Status: {0}", string.Join(", ", wrongStatuses)); } } catch (Exception ex) { _log.Error("Submit failed. Error: {0}", ex.Message); } }
private async Task SubmitSingleMessage() { DataCodings coding = GetDataCoding(); var sourceAddress = new SmeAddress(tbSrcAdr.Text, (AddressTON)byte.Parse(tbSrcAdrTON.Text), (AddressNPI)byte.Parse(tbSrcAdrNPI.Text)); var destinationAddress = new SmeAddress(tbDestAdr.Text, (AddressTON)byte.Parse(tbDestAdrTON.Text), (AddressNPI)byte.Parse(tbDestAdrNPI.Text)); _log.Info("Submit message To: {0}. Text: {1}", tbDestAdr.Text, tbMessageText.Text); ISubmitSmBuilder builder = SMS.ForSubmit() .From(sourceAddress) .To(destinationAddress) .Coding(coding) .Text(tbMessageText.Text) //Or you can set data //.Data(HexStringToByteArray("024A3A6949A59194813D988151A004004D215D2690568698A22820C49A4106288A126A8A22C2A820C22820C2A82342AC30820C4984106288A12628A22C2A420800")) //Apply italic style for all text (mobile device should support basic EMS) //.Set(delegate(SubmitSm sm) // { // sm.UserDataPdu.Headers.Add( // InformationElementIdentifiers.TextFormatting, new byte[] {0, 1, ToByte("00100011")}); // }) // Set ValidityPeriod expired in 2 days .ExpireIn(TimeSpan.FromDays(2)) //Request delivery receipt .DeliveryReceipt(); //Add custom TLV parameter //.AddParameter(0x1403, "free") //Change SubmitSm sequence to your own number. //.Set(delegate(SubmitSm sm) { sm.Sequence = _client.SequenceGenerator.NextSequenceNumber();}) SubmitMode mode = GetSubmitMode(); switch (mode) { case SubmitMode.Payload: builder.MessageInPayload(); break; case SubmitMode.ShortMessageWithSAR: builder.ConcatenationInSAR(); break; } try { IList <SubmitSmResp> resp = await _client.Submit(builder); if (resp.All(x => x.Header.Status == CommandStatus.ESME_ROK)) { _log.Info("Submit succeeded. MessageIds: {0}", string.Join(",", resp.Select(x => x.MessageId))); } else { _log.Warn("Submit failed. Status: {0}", string.Join(",", resp.Select(x => x.Header.Status.ToString()))); } } catch (Exception ex) { _log.Error("Submit failed. Error: {0}", ex.Message); } // When you received success result, you can later query message status on SMSC // if (resp.Count > 0 && resp[0].Status == CommandStatus.ESME_ROK) // { // _log.Info("QuerySm for message " + resp[0].MessageId); // QuerySmResp qresp = _client.Query(resp[0].MessageId, // srcTon, srcNpi,srcAdr); // } }