Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        /// <summary>
        /// Forward a SMS Send request to the gateway
        /// Made a private method to allow refreshing of the 
        /// session id - if session is expired, it attempts
        /// 1 time only, then if the error persists 
        /// does not retry anymore
        /// </summary>
        /// <param name="sms">The sms to be sent</param>
        /// <param name="refresingSession">
        /// true if the session id is expired and a new send attempt is
        /// being done after reconnecting with a new session id
        /// </param>
        /// <returns></returns>
        private ISmsStatusCollection Send(ISms sms, bool refresingSession)
        {
            ISmsStatusCollection status;
            SmsStatus smsStatus;
            string[] errorMessages;
            bool retry = false;

            if (Provider.TestMode == false)
            {
                string[] recipients;

                recipients = new string[sms.Recipients.Count];
                for (int count = 0; count < sms.Recipients.Count; ++count)
                    recipients[count] = sms.Recipients[count];

                lock (_server)
                {
                    errorMessages = _server.sendmsg(_sessionId, _apiId, null, null, recipients, sms.Sender, sms.Message, 0, 1, 0, 0, 3, 0, 3, 1, 0, sms.ReferenceId.ToString(), 0, "SMS_TEXT", string.Empty, string.Empty, 1440);
                    if ((errorMessages.Length == 1) && (IsSessionError(errorMessages[0]) && (refresingSession == false)))
                    {
                        Connect();
                        retry = true;
                    }
                }
            }
            else
                errorMessages = new string[sms.Recipients.Count];

            if (retry)
                status = Send(sms, true);
            else
            {
                status = new SmsStatusCollection(sms);
                for (int count = 0; count < sms.Recipients.Count; ++count)
                {
                    smsStatus = new SmsStatus(sms.Recipients[count]);
                    smsStatus.TestMode = Provider.TestMode;

                    CheckResponse(smsStatus, errorMessages[count]);

                    status.Add(smsStatus);
                }
            }

            return status;
        }