protected override ISmsStatusCollection OnSend(ISms sms) { SmsStatusCollection status; SmsStatus smsStatus; int? failCode = null; if (sms.CustomProperties.ContainsKey("FailCode")) failCode = int.Parse(sms.CustomProperties["FailCode"].ToString() ); status = new SmsStatusCollection(sms); for (int count = 0; count < sms.Recipients.Count; ++count) { smsStatus = new SmsStatus(sms.Recipients[count]); smsStatus.ProviderReference = sms.ReferenceId.ToString(); if (failCode != null) smsStatus.SetError(EnMtStatus.Failure, (int) failCode, "Error forced for testing purposes"); else { if (sms.CustomProperties.ContainsKey(count.ToString())) smsStatus.SetError(EnMtStatus.Failure, -1, "Error forced using sms custom properties"); } status.Add(smsStatus); } return status; }
protected override ISmsStatusCollection OnSend(ISms sms) { ASPSMSNET aspsms; SmsStatusCollection status; SmsStatus smsStatus; aspsms = new ASPSMSNET { UserKey = Provider.Configuration.Settings["userKey"], Password = Provider.Configuration.Settings["password"], Originator = sms.Sender, MessageData = sms.Message, }; foreach (string recipient in sms.Recipients) aspsms.Recipients.Add(recipient, ToInt(sms.ReferenceId)); if (Provider.TestMode == false) aspsms.SendTextSMS(); status = new SmsStatusCollection(sms); if ((aspsms.ErrorCode != 1) && (Provider.TestMode == false)) status.SetError(aspsms.ErrorCode, aspsms.ErrorDescription); foreach (string recipient in sms.Recipients) { smsStatus = new SmsStatus(recipient) {TestMode = Provider.TestMode}; if (status.Successful == false) smsStatus.SetError(EnMtStatus.Failure, status.ErrorCode, status.ErrorMessage); status.Add(smsStatus); } return status; }
private void CheckResponse(SmsStatus status, string errorMessage) { if (status.TestMode == false) { if (errorMessage == null) status.SetError(EnMtStatus.Failure, -1, "No response from the server"); else if (_regexMessageId.IsMatch(errorMessage)) status.ProviderReference = _regexMessageId.Match(errorMessage).Result("${reference}"); else if (_regexErrorMessage.IsMatch(errorMessage)) { Match match; match = _regexErrorMessage.Match(errorMessage); status.SetError(EnMtStatus.Failure, int.Parse(match.Result("${errorcode}")), match.Result("${errormessage}")); } } }