/// <summary> /// Decodes an outgoing SMS PDU stream. /// </summary> /// <param name="pdu">The PDU string to decode</param> /// <param name="includesSmscData">Specify true if the PDU data contains an SMSC header, otherwise false.</param> /// <param name="actualLength">The length of the PDU in bytes, not including the SMSC header.</param> /// <returns>An <see cref="T:GsmComm.PduConverter.OutgoingSmsPdu" /> object representing the decoded message.</returns> public static OutgoingSmsPdu Decode(string pdu, bool includesSmscData, int actualLength) { if (pdu != string.Empty) { int num = 0; if (includesSmscData) { int num1 = num; num = num1 + 1; byte num2 = BcdWorker.GetByte(pdu, num1); if (num2 > 0) { num = num + num2; } } int num3 = num; OutgoingMessageType messageType = OutgoingSmsPdu.GetMessageType(BcdWorker.GetByte(pdu, num3)); OutgoingMessageType outgoingMessageType = messageType; if (outgoingMessageType != OutgoingMessageType.SmsSubmit) { throw new NotSupportedException(string.Concat("Message type ", messageType.ToString(), " recognized, but not supported by the SMS decoder.")); } else { return(new SmsSubmitPdu(pdu, includesSmscData, actualLength)); } } else { throw new ArgumentException("pdu must not be an empty string."); } }
private void SendMultiple(OutgoingSmsPdu[] pdus) { int num = pdus.Length; try { // Send the created messages int i = 0; foreach (OutgoingSmsPdu pdu in pdus) { i++; logger("Sending message " + i.ToString() + " of " + num.ToString() + "..."); comm.SendMessage(pdu); } logger("Done."); } catch (Exception ex) { ShowException(ex); logger("Message sending aborted because of an error."); } }
/// <summary> /// Sends multiple messages in succession. Sending stops at the first error. /// </summary> /// <param name="pdus">The messages to send.</param> /// <remarks> /// <seealso cref="M:GsmComm.GsmCommunication.GsmCommMain.SendMessage(GsmComm.PduConverter.OutgoingSmsPdu,System.Boolean)" /> /// <seealso cref="M:GsmComm.GsmCommunication.GsmCommMain.SendMessage(GsmComm.PduConverter.OutgoingSmsPdu)" /> /// </remarks> public void SendMessages(OutgoingSmsPdu[] pdus) { if (pdus != null) { if ((int)pdus.Length != 0) { int length = (int)pdus.Length; this.LogIt(LogLevel.Info, string.Concat(length.ToString(), " message(s) to send.")); for (int i = 0; i < (int)pdus.Length; i++) { OutgoingSmsPdu outgoingSmsPdu = pdus[i]; string[] str = new string[5]; str[0] = "Sending message "; int num = i + 1; str[1] = num.ToString(); str[2] = " of "; int length1 = (int)pdus.Length; str[3] = length1.ToString(); str[4] = "..."; this.LogIt(LogLevel.Info, string.Concat(str)); this.SendMessage(outgoingSmsPdu); } return; } else { this.LogIt(LogLevel.Warning, "Nothing to do!"); return; } } else { this.LogIt(LogLevel.Error, "Failed. Message array is null."); throw new ArgumentNullException("pdus"); } }
/// <summary> /// Sends a short message. /// </summary> /// <param name="pdu">The object containing the message to send.</param> /// <remarks> /// <para>This method sends the short message contained in the PDU object. /// The message reference returned by the phone is stored in the MessageReference /// property of the PDU object. If there is an error, an exception will be thrown.</para> /// <para>Additionally, this function also fires the <see cref="E:GsmComm.GsmCommunication.GsmCommMain.MessageSendFailed" /> event /// upon an error and the <see cref="E:GsmComm.GsmCommunication.GsmCommMain.MessageSendComplete" /> event upon success.</para> /// <para>To send multiple messages in succession, use the <see cref="M:GsmComm.GsmCommunication.GsmCommMain.SendMessages(GsmComm.PduConverter.OutgoingSmsPdu[])" /> function.</para> /// <seealso cref="M:GsmComm.GsmCommunication.GsmCommMain.SendMessages(GsmComm.PduConverter.OutgoingSmsPdu[])" /> /// </remarks> public void SendMessage(OutgoingSmsPdu pdu) { this.SendMessage(pdu, true); }
/// <summary> /// Sends a short message. /// </summary> /// <param name="pdu">The object containing the message to send.</param> /// <param name="throwExceptions">Indicates whether an exception should be /// thrown upon an error.</param> /// <remarks> /// <para>This method sends the short message contained in the PDU object. /// The message reference returned by the phone is stored in the MessageReference /// property of the PDU object. If there is an error, an exception will be thrown.</para> /// <para>Additionally, this function also fires the <see cref="E:GsmComm.GsmCommunication.GsmCommMain.MessageSendFailed" /> event /// upon an error and the <see cref="E:GsmComm.GsmCommunication.GsmCommMain.MessageSendComplete" /> event upon success. /// Set the <b>throwExceptions</b> parameter to false if your message handling /// uses only the events fired by this method.</para> /// <para>To send multiple messages in succession, use the <see cref="M:GsmComm.GsmCommunication.GsmCommMain.SendMessages(GsmComm.PduConverter.OutgoingSmsPdu[])" /> function.</para> /// <seealso cref="M:GsmComm.GsmCommunication.GsmCommMain.SendMessages(GsmComm.PduConverter.OutgoingSmsPdu[])" /> /// </remarks> public void SendMessage(OutgoingSmsPdu pdu, bool throwExceptions) { this.LogIt(LogLevel.Info, "Sending message..."); this.OnMessageSendStarting(pdu); byte num = 0; try { num = this.theDevice.SendMessage(pdu.ToString(), pdu.ActualLength); } catch (Exception exception1) { Exception exception = exception1; this.LogIt(LogLevel.Error, string.Concat("Error while sending the message: ", exception.Message)); this.OnMessageSendFailed(pdu, exception); if (!throwExceptions) { return; } else { throw; } } if (pdu.MessageReference == 0) { pdu.MessageReference = num; } this.LogIt(LogLevel.Info, "Message sent successfully."); this.OnMessageSendComplete(pdu); }
private void OnMessageSendStarting(OutgoingSmsPdu pdu) { if (this.MessageSendStarting != null) { this.LogIt(LogLevel.Info, "Firing async MessageSendStarting event."); MessageEventArgs messageEventArg = new MessageEventArgs(pdu); this.MessageSendStarting.BeginInvoke(this, messageEventArg, new AsyncCallback(this.AsyncCallback), null); } }
private void OnMessageSendFailed(OutgoingSmsPdu pdu, Exception exception) { if (this.MessageSendFailed != null) { this.LogIt(LogLevel.Info, "Firing async MessageSendFailed event."); MessageErrorEventArgs messageErrorEventArg = new MessageErrorEventArgs(pdu, exception); this.MessageSendFailed.BeginInvoke(this, messageErrorEventArg, new AsyncCallback(this.AsyncCallback), null); } }
/// <summary> /// Initializes a new instance of the <see cref="T:GsmComm.GsmCommunication.MessageErrorEventArgs" />. /// </summary> /// <param name="pdu">The message that failed sending.</param> /// <param name="exception">The exception that caused the error.</param> public MessageErrorEventArgs(OutgoingSmsPdu pdu, Exception exception) : base(pdu) { this.exception = exception; }
/// <summary> /// Decodes an outgoing SMS PDU stream. /// </summary> /// <param name="pdu">The PDU string to decode.</param> /// <param name="includesSmscData">Specify true if the PDU data contains an SMSC header, otherwise false.</param> /// <returns>An <see cref="T:GsmComm.PduConverter.OutgoingSmsPdu" /> object representing the decoded message.</returns> /// <remarks>Use this method when the actual length of the message is not known.</remarks> public static OutgoingSmsPdu Decode(string pdu, bool includesSmscData) { return(OutgoingSmsPdu.Decode(pdu, includesSmscData, -1)); }
private void SendMultiple(OutgoingSmsPdu[] pdus) { var num = pdus.Length; try { // Send the created messages comm.EnableTemporarySmsBatchMode(); foreach (OutgoingSmsPdu pdu in pdus) { comm.SendMessage(pdu); } } catch { } }
/// <summary> /// Initializes a new instance of the <see cref="T:GsmComm.GsmCommunication.MessageEventArgs" />. /// </summary> /// <param name="pdu">The message that was dealt with.</param> public MessageEventArgs(OutgoingSmsPdu pdu) { this.pdu = pdu; }