public async void SendSMS(RockSMSMessage smsMessage, string phoneNumber, string ipAddress, double delay)
        {
            await Task.Delay(( int )delay);

            try
            {
                smsMessage.Send();
            }
            catch
            {
                //Nom Nom Nom
            }
            SMSRecords.ReleaseItems(ipAddress, phoneNumber);
        }
        protected void btnGenerate_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            pnlPhoneNumber.Visible = false;
            RockContext        rockContext        = new RockContext();
            PhoneNumberService phoneNumberService = new PhoneNumberService(rockContext);
            var numberOwners = phoneNumberService.Queryable()
                               .Where(pn => pn.Number == PhoneNumber)
                               .Select(pn => pn.Person)
                               .DistinctBy(p => p.Id)
                               .ToList();

            if (numberOwners.Count == 0)
            {
                lbNoNumber.Text     = GetAttributeValue("NoNumberMessage");
                pnlNoNumber.Visible = true;
                return;
            }

            if (numberOwners.Count > 1)
            {
                if (GetAttributeValue("DuplicateNumberPage").AsGuidOrNull() == null)
                {
                    btnResolution.Visible = false;
                }
                lbDuplicateNumber.Text     = GetAttributeValue("DuplicateMessage");
                pnlDuplicateNumber.Visible = true;
                return;
            }

            var person = numberOwners.FirstOrDefault();

            UserLoginService userLoginService = new UserLoginService(rockContext);
            var userLogin = userLoginService.Queryable()
                            .Where(u => u.UserName == ("__PHONENUMBER__" + PhoneNumber))
                            .FirstOrDefault();

            if (userLogin == null)
            {
                var entityTypeId = EntityTypeCache.Read("Avalanche.Security.Authentication.PhoneNumber").Id;

                userLogin = new UserLogin()
                {
                    UserName     = "******" + PhoneNumber,
                    EntityTypeId = entityTypeId,
                };
                userLoginService.Add(userLogin);
            }

            userLogin.PersonId = person.Id;
            userLogin.LastPasswordChangedDateTime = Rock.RockDateTime.Now;
            userLogin.FailedPasswordAttemptWindowStartDateTime = Rock.RockDateTime.Now;
            userLogin.FailedPasswordAttemptCount = 0;
            userLogin.IsConfirmed = true;
            userLogin.Password    = new Random().Next(100000, 999999).ToString();

            rockContext.SaveChanges();

            var recipients = new List <RecipientData>();

            recipients.Add(new RecipientData(PhoneNumber));

            var smsMessage = new RockSMSMessage();

            smsMessage.SetRecipients(recipients);

            // Get the From value
            Guid?fromGuid = GetAttributeValue("From").AsGuidOrNull();

            if (fromGuid.HasValue)
            {
                var fromValue = DefinedValueCache.Read(fromGuid.Value, rockContext);
                if (fromValue != null)
                {
                    smsMessage.FromNumber = DefinedValueCache.Read(fromValue.Id);
                }
            }

            var mergeObjects = new Dictionary <string, object> {
                { "password", userLogin.Password }
            };
            var message = GetAttributeValue("Message").ResolveMergeFields(mergeObjects, null);

            smsMessage.Message = message;

            var ipAddress = GetIpAddress();

            if (SMSRecords.ReserveItems(ipAddress, PhoneNumber))
            {
                pnlCode.Visible = true;
                var delay = SMSRecords.GetDelay(ipAddress, PhoneNumber);
                Task.Run(() => { SendSMS(smsMessage, ipAddress, PhoneNumber, delay); });
            }
            else
            {
                LogException(new Exception(string.Format("Unable to reserve for SMS message: IP: {0} PhoneNumber: {1}", ipAddress, PhoneNumber)));
                pnlRateLimited.Visible = true;
            }
        }