public void RegisterButton_Click()
 {
     try
     {
         string number = PhoneNumberFormatter.FormatE164(PhonePrefix, PhoneSuffix);
         if (!number.StartsWith("+"))
         {
             number = $"+{number}";
         }
         if (number != null && number.Length > 0 && number[0] == '+')
         {
             FinalNumber = number;
             View.Frame.Navigate(typeof(RegisterFinalizationPage));
         }
         else
         {
             var           title   = "Invalid Phone Number";
             var           content = "The phone number you supplied appears to be invalid. Please enter your correct phone number and try again.";
             MessageDialog dialog  = new MessageDialog(content, title);
             var           result  = dialog.ShowAsync();
         }
         Debug.WriteLine(number);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
         Debug.WriteLine(ex.StackTrace);
     }
 }
Beispiel #2
0
        private void UpdateCurrentNumber()
        {
            callButton.IsEnabled = !string.IsNullOrWhiteSpace(Number.ToString());
            PhoneNumberFormatter a = new PhoneNumberFormatter();

            numberToDialBox.Text = a.FormatPartialString(Number.ToString());
        }
        public override ProcessResult Add(ApiUser apiUser, PhoneNumber phoneNumber)
        {
            PhoneNumberFormatter formatter       = new PhoneNumberFormatter();
            PhoneNumber          formattedNumber = formatter.Format(phoneNumber);

            return(base.Add(apiUser, formattedNumber));
        }
Beispiel #4
0
        private static bool HasValidMobileNumber(UserAuth user)
        {
            // TODO SSH is this check valid?
            var formattedNumber = PhoneNumberFormatter.Format(user.PhoneNumber);

            return(formattedNumber.Length == 12 && formattedNumber.StartsWith("+"));
        }
Beispiel #5
0
        public IActionResult Customer(CustomerViewModel model)
        {
            if (ModelState.IsValid)
            {
                string        phone = PhoneNumberFormatter.FormatPhoneNumber(model.PhoneNumber);
                DonorCustomer donor = searchQuery.SpecificCustomerSearch(context, model.FirstName, model.LastName, phone);
                if (donor != null)
                {
                    if (query.GetBlacklistedCustomerById(context, donor.ID) != null)
                    {
                        return(RedirectToAction("BlacklistedCustomerTrigger", "Blacklist", new { customerId = donor.ID }));
                    }

                    return(RedirectToAction("Address", new { customerId = donor.ID }));
                }

                DonorCustomer newPerson = new DonorCustomer
                {
                    FirstName      = model.FirstName,
                    LastName       = model.LastName,
                    PhoneNumber    = phone,
                    PhoneNumberTwo = PhoneNumberFormatter.FormatPhoneNumber(model.PhoneNumberTwo),
                    Email          = model.Email,
                    FOT            = model.FOT
                };
                context.Add(newPerson);
                context.SaveChanges();

                return(RedirectToAction("Address", new { customerId = newPerson.ID }));
            }

            return(View("PickupDelivery/Customer", model));
        }
Beispiel #6
0
 private void PlatformCreate()
 {
     _formatter = new PhoneNumberFormatter()
     {
         TextField = Text.PlatformView
     };
 }
Beispiel #7
0
 public void RegisterButton_Click()
 {
     try
     {
         string number = PhoneNumberFormatter.FormatE164(PhonePrefix, PhoneSuffix);
         if (!number.StartsWith("+"))
         {
             number = $"+{number}";
         }
         if (number != null && number.Length > 0 && number[0] == '+')
         {
             FinalNumber = number;
             View.Frame.Navigate(typeof(RegisterFinalizationPage));
         }
         else
         {
             var           title   = "Invalid Phone Number";
             var           content = "The phone number you supplied appears to be invalid. Please enter your correct phone number and try again.";
             MessageDialog dialog  = new MessageDialog(content, title);
             var           result  = dialog.ShowAsync();
         }
     }
     catch (Exception ex)
     {
         var line = new StackTrace(ex, true).GetFrames()[0].GetFileLineNumber();
         Logger.LogError("RegisterButton_Click() failed in line {0}: {1}\n{2}", line, ex.Message, ex.StackTrace);
     }
 }
Beispiel #8
0
        public IActionResult EditCustomer(int customerId, int pickupId)
        {
            ViewBag.Title  = "Edit Customer Information";
            ViewBag.Button = ViewBag.Title;

            DonorCustomer donorCustomer = query.GetCustomer(context, customerId);

            if (donorCustomer == null)
            {
                return(View("ErrorPage"));
            }

            CustomerViewModel model = new CustomerViewModel()
            {
                PickupID       = pickupId,
                CustomerId     = donorCustomer.ID,
                FirstName      = donorCustomer.FirstName,
                LastName       = donorCustomer.LastName,
                PhoneNumber    = PhoneNumberFormatter.FormatPhoneNumber(donorCustomer.PhoneNumber),
                PhoneNumberTwo = PhoneNumberFormatter.FormatPhoneNumber(donorCustomer.PhoneNumberTwo),
                FOT            = donorCustomer.FOT
            };

            return(View("PickupDelivery/Customer", model));
        }
Beispiel #9
0
        private string GetDescriptionWithPhone()
        {
            string phone = null;

            if (!_phoneNumber.IsNullOrEmtpy())
            {
                if (_phoneNumber.Length > 10)
                {
                    var cleanPhone = PhoneNumberFormatter.GetCleanStrWithoutFormat(_phoneNumber, false);
                    phone = $"+7 {cleanPhone.Substring(1, 3)}...{cleanPhone.Substring(cleanPhone.Length - 2, 2)}";
                }
                else
                {
                    phone = _phoneNumber;
                }
            }
            if (phone != null)
            {
                return($"{LocalizationService.GetLocalizableString(AuthConst.RESX_NAME, "Password_Sms_CodeFromSms")}\n{LocalizationService.GetLocalizableString(AuthConst.RESX_NAME, "Password_Sms_SentToPhone")} {phone}");
            }
            else
            {
                return(LocalizationService.GetLocalizableString(AuthConst.RESX_NAME, "Password_Sms_CodeFromSms"));
            }
        }
Beispiel #10
0
        public static bool ArePhoneNumbersMostLikelyTheSame(string num1, string num2)
        {
            var formatter = new PhoneNumberFormatter();

            var fnum1 = formatter.FormatPartialString(num1);
            var fnum2 = formatter.FormatPartialString(num2);

            if (fnum1 == fnum2)
            {
                return(true);
            }

            var inum1 = new PhoneNumberInfo(fnum1);
            var inum2 = new PhoneNumberInfo(fnum2);

            var match = inum1.CheckNumberMatch(inum2);

            if (match == PhoneNumberMatchResult.ExactMatch || match == PhoneNumberMatchResult.NationalSignificantNumberMatch || match == PhoneNumberMatchResult.ShortNationalSignificantNumberMatch)
            {
                return(true);
            }

            var info = GetPhoneNumberInformation(num1);

            string number      = info.Number;
            string countrycode = info.CountryCode;

            if (string.IsNullOrEmpty(countrycode))
            {
                if (num2.ToLower().Replace(" ", "").Replace("(", "").Replace(")", "") == number.ToLower().Replace(" ", "").Replace("(", "").Replace(")", ""))
                {
                    return(true);
                }
            }
            else
            {
                var info2 = GetPhoneNumberInformation(num1);

                string number2      = info2.Number;
                string countrycode2 = info2.CountryCode;

                if (number == number2 && countrycode == countrycode2)
                {
                    return(true);
                }
                else if (string.IsNullOrEmpty(countrycode2))
                {
                    if (num2.Replace(" ", "").Replace("(", "").Replace(")", "") == number.ToLower().Replace(" ", "").Replace("(", "").Replace(")", ""))
                    {
                        return(true);
                    }
                }
                else if (number == number2)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #11
0
        private async Task ReloadLocalContacts(string localNumber)
        {
            try
            {
                var contactStore = await ContactManager.RequestStoreAsync();

                var contacts = await contactStore.FindContactsAsync();

                foreach (var contact in contacts)
                {
                    //Debug.WriteLine($"Name: {contact.DisplayName}");
                    foreach (var number in contact.Phones)
                    {
                        //Debug.WriteLine($"Number: {number.Number}");
                        try
                        {
                            string e164number = PhoneNumberFormatter.formatNumber(number.Number, localNumber);

                            var directory = GetForNumber(e164number);

                            if (directory != null)
                            {
                                directory.Name      = contact.DisplayName;
                                directory.Time      = TimeUtil.GetDateTimeMillis();
                                directory.ContactId = contact.Id;

                                conn.Update(directory);
                            }
                            else
                            {
                                var newdir = new Directory()
                                {
                                    Name       = contact.DisplayName,
                                    Number     = e164number,
                                    Relay      = null,
                                    Registered = 0,
                                    Time       = TimeUtil.GetDateTimeMillis(),
                                    ContactId  = contact.Id
                                };
                                conn.Insert(newdir);
                            }
                        }
                        catch (InvalidNumberException e)
                        {
                            Debug.WriteLine($"Directory: Invalid number: {number}");
                        }
                        catch (SQLiteException e)
                        {
                            if (e.Message.Equals("Constraint"))
                            {
                                continue;
                            }
                        }
                    }
                }
            }
            catch (Exception e) { }
        }
 protected override bool IsViewModelPropertiesValid()
 {
     return(!Password.IsNullOrEmtpy()
            &&
            (
                (!Identity.IsNullOrEmpty() && Identity.IsMail() && Config.IdentifyUserByEmail) ||
                (PhoneNumberFormatter.IsValid(Identity) && !Config.IdentifyUserByEmail)
            ));
 }
 private string getNumber()
 {
     try
     {
         return(PhoneNumberFormatter.formatE164(CountryCode, PhoneNumber.TrimStart('0')));
     }
     catch (Exception)
     {
         return(string.Empty);
     }
 }
Beispiel #14
0
        public void TestFormatRemoteNumberE164()
        {
            Assert.AreEqual(LOCAL_NUMBER_US, PhoneNumberFormatter.FormatNumber(LOCAL_NUMBER_US, NUMBER_UK));
            Assert.AreEqual(LOCAL_NUMBER_US, PhoneNumberFormatter.FormatNumber(LOCAL_NUMBER_US, LOCAL_NUMBER_US));

            Assert.AreEqual(NUMBER_UK, PhoneNumberFormatter.FormatNumber(NUMBER_UK, NUMBER_UK));
            Assert.AreEqual(NUMBER_CH, PhoneNumberFormatter.FormatNumber(NUMBER_CH, NUMBER_CH));
            Assert.AreEqual(NUMBER_DE, PhoneNumberFormatter.FormatNumber(NUMBER_DE, NUMBER_DE));
            Assert.AreEqual(NUMBER_MOBILE_DE, PhoneNumberFormatter.FormatNumber(NUMBER_MOBILE_DE, NUMBER_DE));

            Assert.AreEqual(NUMBER_UK, PhoneNumberFormatter.FormatNumber("+4402079460018", LOCAL_NUMBER_US));
        }
 public void testFormatNumberEmail()
 {
     try
     {
         PhoneNumberFormatter.formatNumber("*****@*****.**", LOCAL_NUMBER_US);
         throw new AssertFailedException("should have thrown on email");
     }
     catch (InvalidNumberException ine)
     {
         // success
     }
 }
Beispiel #16
0
        public async Task <ActionResult> OnPostFilterAsync()
        {
            // ------- request cookie ---------------------
            var    cookieValue = Request.Cookies["MyCookieId"];
            string _pass       = await _settingsClient.GetPasswordAsync();

            if (cookieValue == null || cookieValue != _pass)
            {
                return(RedirectToPage("/LoginPage", "Index"));
            }
            // --------------------------------------------
            bool     isValid  = true;
            DateTime date     = DateTime.Today;
            TimeSpan timeFrom = TimeSpan.Zero;
            TimeSpan timeTo   = TimeSpan.FromDays(1).Subtract(TimeSpan.FromSeconds(1));

            if (!DateTime.TryParse(Date, out date))
            {
                isValid = false;
                ModelState.AddModelError(nameof(Date), "Bitte gültiges Datumformat eingeben (dd.MM.yyyy)");
            }

            if (!String.IsNullOrWhiteSpace(From) && !TimeSpan.TryParse(From, out timeFrom))
            {
                isValid = false;
                ModelState.AddModelError(nameof(From), "Bitte gültiges Zeitformat eingeben (hh:mm)");
            }

            if (!String.IsNullOrWhiteSpace(To) && !TimeSpan.TryParse(To, out timeTo))
            {
                isValid = false;
                ModelState.AddModelError(nameof(To), "Bitte gültiges Zeitformat eingeben (hh:mm)");
            }

            if (!isValid)
            {
                PeopleOverview = await _pc.GetAllPersonsAsync();

                return(Page());
            }

            DateTime from = date + timeFrom;
            DateTime to   = date + timeTo;

            PeopleOverview = await _pc.GetPersonsForTimespanAsync(from, to);

            foreach (var person in PeopleOverview)
            {
                person.PhoneNumber = PhoneNumberFormatter.FormatPhoneNumber(person.PhoneNumber);
            }

            return(Page());
        }
Beispiel #17
0
 public void TestFormatNumberEmail()
 {
     try
     {
         PhoneNumberFormatter.FormatNumber("*****@*****.**", LOCAL_NUMBER_US);
         Assert.Fail("should have thrown on email");
     }
     catch (InvalidNumberException)
     {
         // success
     }
 }
        public static async Task readList(ObservableCollection <Models.EmployeeContact> tcl)
        {
            var           employeeContactList = new List <EmployeeContact>();
            StorageFolder localFolder         = ApplicationData.Current.LocalFolder;

            if (!(File.Exists($"{localFolder.Path.ToString()}\\{Utility.TEXT_FILE_NAME}")))
            {
                await localFolder.CreateFileAsync(Utility.TEXT_FILE_NAME, CreationCollisionOption.OpenIfExists);
            }
            StorageFile textFile = await localFolder.GetFileAsync(Utility.TEXT_FILE_NAME);

            var file = new StreamReader(textFile.Path);
            var line = string.Empty;

            //Phone number formatter
            PhoneNumberFormatter currentFormatter;

            currentFormatter = new PhoneNumberFormatter();

            try
            {
                while ((line = file.ReadLine()) != null || string.IsNullOrWhiteSpace((line = file.ReadLine())))
                {
                    var employee = JsonConvert.DeserializeObject <EmployeeContact>(line);

                    if (!Utility.IsAnyNullOrEmpty(employee))
                    {
                        employeeContactList.Add(employee);
                        tcl.Add(new Models.EmployeeContact {
                            FirstName = employee.FirstName, LastName = employee.LastName, EmailAddress = employee.EmailAddress, JobTitle = employee.JobTitle, Location = employee.Location, PhoneNumber = currentFormatter.FormatPartialString(employee.PhoneNumber), EmployeeID = employee.EmployeeId
                        });
                    }
                }
            }
            catch (Exception)
            {
                file.Close();
            }

            finally
            {
                file.Close();
            }
        }
Beispiel #19
0
        public void TestIsValidNumber()
        {
            Assert.IsTrue(PhoneNumberFormatter.IsValidNumber("+6831234", "683"));
            Assert.IsTrue(PhoneNumberFormatter.IsValidNumber("+35851234", "358"));
            Assert.IsTrue(PhoneNumberFormatter.IsValidNumber("+358512345", "358"));

            Assert.IsTrue(PhoneNumberFormatter.IsValidNumber("+5521912345678", "55"));
            Assert.IsTrue(PhoneNumberFormatter.IsValidNumber("+552112345678", "55"));
            Assert.IsTrue(PhoneNumberFormatter.IsValidNumber("+16105880522", "1"));

            Assert.IsFalse(PhoneNumberFormatter.IsValidNumber("+014085041212", "0"));
            Assert.IsFalse(PhoneNumberFormatter.IsValidNumber("+014085041212", "1"));
            Assert.IsFalse(PhoneNumberFormatter.IsValidNumber("+5512345678", "55"));
            Assert.IsFalse(PhoneNumberFormatter.IsValidNumber("+161058805220", "1"));
            Assert.IsFalse(PhoneNumberFormatter.IsValidNumber("+1610588052", "1"));
            Assert.IsFalse(PhoneNumberFormatter.IsValidNumber("+15880522", "1"));

            Assert.IsTrue(PhoneNumberFormatter.IsValidNumber("+971812345678901", "971"));
            Assert.IsFalse(PhoneNumberFormatter.IsValidNumber("+9718123456789012", "971"));
        }
Beispiel #20
0
        public IActionResult EditCustomer(CustomerViewModel model)
        {
            DonorCustomer donorCustomer = query.GetCustomer(context, model.CustomerId);

            if (donorCustomer == null && !ModelState.IsValid)
            {
                return(View("PickupDelivery/Customer", model));
            }

            donorCustomer.FirstName      = model.FirstName;
            donorCustomer.LastName       = model.LastName;
            donorCustomer.PhoneNumber    = PhoneNumberFormatter.FormatPhoneNumber(model.PhoneNumber);
            donorCustomer.PhoneNumberTwo = PhoneNumberFormatter.FormatPhoneNumber(model.PhoneNumberTwo);
            donorCustomer.Email          = model.Email;
            donorCustomer.FOT            = model.FOT;

            context.SaveChanges();

            return(RedirectToAction("View", "Home", new { pid = model.PickupID }));
        }
Beispiel #21
0
        public void TestFormatNumberE164()
        {
            Assert.AreEqual(NUMBER_UK, PhoneNumberFormatter.FormatE164(COUNTRY_CODE_UK, "(020) 7946 0018"));
            //Assert.AreEqual(NUMBER_UK, PhoneNumberFormatter.FormatE164(COUNTRY_CODE_UK, "044 20 7946 0018"));
            Assert.AreEqual(NUMBER_UK, PhoneNumberFormatter.FormatE164(COUNTRY_CODE_UK, "+442079460018"));
            Assert.AreEqual(NUMBER_UK, PhoneNumberFormatter.FormatE164(COUNTRY_CODE_UK, "+4402079460018"));

            Assert.AreEqual(NUMBER_CH, PhoneNumberFormatter.FormatE164(COUNTRY_CODE_CH, "+41 44 668 18 00"));
            Assert.AreEqual(NUMBER_CH, PhoneNumberFormatter.FormatE164(COUNTRY_CODE_CH, "+41 (044) 6681800"));

            Assert.AreEqual(NUMBER_DE, PhoneNumberFormatter.FormatE164(COUNTRY_CODE_DE, "0049 030 123456"));
            Assert.AreEqual(NUMBER_DE, PhoneNumberFormatter.FormatE164(COUNTRY_CODE_DE, "0049 (0)30123456"));
            Assert.AreEqual(NUMBER_DE, PhoneNumberFormatter.FormatE164(COUNTRY_CODE_DE, "0049((0)30)123456"));
            Assert.AreEqual(NUMBER_DE, PhoneNumberFormatter.FormatE164(COUNTRY_CODE_DE, "+49 (0) 30  1 2  3 45 6 "));
            Assert.AreEqual(NUMBER_DE, PhoneNumberFormatter.FormatE164(COUNTRY_CODE_DE, "030 123456"));

            Assert.AreEqual(NUMBER_MOBILE_DE, PhoneNumberFormatter.FormatE164(COUNTRY_CODE_DE, "0171123456"));
            Assert.AreEqual(NUMBER_MOBILE_DE, PhoneNumberFormatter.FormatE164(COUNTRY_CODE_DE, "0171/123456"));
            Assert.AreEqual(NUMBER_MOBILE_DE, PhoneNumberFormatter.FormatE164(COUNTRY_CODE_DE, "+490171/123456"));
            Assert.AreEqual(NUMBER_MOBILE_DE, PhoneNumberFormatter.FormatE164(COUNTRY_CODE_DE, "00490171/123456"));
            Assert.AreEqual(NUMBER_MOBILE_DE, PhoneNumberFormatter.FormatE164(COUNTRY_CODE_DE, "0049171/123456"));
        }
Beispiel #22
0
        public async Task <ActionResult> OnGetAsync(string handler)
        {
            // ------- request cookie ---------------------
            var    cookieValue = Request.Cookies["MyCookieId"];
            string _pass       = await _settingsClient.GetPasswordAsync();

            // --------------------------------------------
            if (handler == null || cookieValue == null || cookieValue != _pass)
            {
                return(RedirectToPage("/LoginPage", "Index"));
            }

            ViewData["Message"] = "Personal Data";

            //await PrepareDb();
            PeopleOverview = await _pc.GetAllPersonsAsync();

            foreach (var person in PeopleOverview)
            {
                person.PhoneNumber = PhoneNumberFormatter.FormatPhoneNumber(person.PhoneNumber);
            }

            return(Page());
        }
        private bool CheckItems(bool markInvalidFields)
        {
            bool valid = true;

            foreach (var item in Items)
            {
                if (!item.Internal)
                {
                    bool valueValid;
                    switch (item.RegistrationField.Type)
                    {
                    case AppRopio.Models.Auth.Enums.RegistrationFieldType.Email:
                        valueValid = item.GetValue()?.IsMail() ?? false;
                        break;

                    case AppRopio.Models.Auth.Enums.RegistrationFieldType.Phone:
                        valueValid = PhoneNumberFormatter.IsValid(item.GetValue());
                        break;

                    case AppRopio.Models.Auth.Enums.RegistrationFieldType.Password:
                        valueValid = !item.GetValue().IsNullOrEmtpy();
                        break;

                    case AppRopio.Models.Auth.Enums.RegistrationFieldType.Date:
                        valueValid = !item.Value.IsNullOrEmtpy();
                        break;

                    default:
                        valueValid = !item.GetValue().IsNullOrEmtpy();
                        break;
                    }
                    bool itemInvalid = !(valueValid || !item.RegistrationField.Required);
                    if (markInvalidFields)
                    {
                        item.Invalid = itemInvalid;
                    }

                    if (itemInvalid)
                    {
                        valid = false;
                    }
                }
                else
                {
                    bool valueValid = true;
                    switch (item.RegistrationField.Type)
                    {
                    case AppRopio.Models.Auth.Enums.RegistrationFieldType.Password:
                        if (Config.RequireConfirmPassword)
                        {
                            var password = Items
                                           .FirstOrDefault(p =>
                                                           p.RegistrationField.Type == AppRopio.Models.Auth.Enums.RegistrationFieldType.Password &&
                                                           p != item);

                            valueValid = !item.GetValue().IsNullOrEmtpy() && password.GetValue() == item.GetValue();
                        }

                        break;
                    }
                    bool itemInvalid = !(valueValid || !item.RegistrationField.Required);
                    if (markInvalidFields)
                    {
                        item.Invalid = itemInvalid;
                    }

                    if (itemInvalid)
                    {
                        valid = false;
                    }
                }
            }

            return(valid);
        }
Beispiel #24
0
        public void Test1(string input)
        {
            var output = PhoneNumberFormatter.Format(input);

            Assert.AreEqual("+41797532816", output);
        }
Beispiel #25
0
        /// <summary>   parameterized phone number formatter test method. </summary>
        /// <remarks>   Sander.struijk, 25.02.2014. </remarks>
        /// <param name="phoneNumberInput">             The phone number. </param>
        /// <param name="countryInput">                 The country. </param>
        /// <param name="phoneNumberExpectedResult">    The expected phone number result. </param>
        private static void ParameterizedPhoneNumberFormatterTest(string phoneNumberInput, string countryInput, string phoneNumberExpectedResult)
        {
            var result = PhoneNumberFormatter.Format(phoneNumberInput, countryInput);

            result.Should().Be(phoneNumberExpectedResult);
        }
Beispiel #26
0
        public static String canonicalizeNumber(String number)
        {
            String localNumber = TextSecurePreferences.getLocalNumber();

            return(PhoneNumberFormatter.formatNumber(number, localNumber));
        }
Beispiel #27
0
        internal async void PickButton_Click(object sender, RoutedEventArgs e)
        {
            if (UIEnabled)
            {
                UIEnabled = false;
                ContactPicker contactPicker = new ContactPicker();
                contactPicker.SelectionMode = ContactSelectionMode.Fields;
                contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);
                var contact = await contactPicker.PickContactAsync();

                if (contact != null)
                {
                    // The contact we just got doesn't contain the contact picture so we need to fetch it
                    // see https://stackoverflow.com/questions/33401625/cant-get-contact-profile-images-in-uwp
                    ContactStore contactStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly);

                    // If we do not have access to contacts the ContactStore will be null, we can still use the contact the user
                    // seleceted however
                    if (contactStore != null)
                    {
                        Contact realContact = await contactStore.GetContactAsync(contact.Id);

                        if (realContact.SourceDisplayPicture != null)
                        {
                            using (var stream = await realContact.SourceDisplayPicture.OpenReadAsync())
                            {
                                BitmapImage bitmapImage = new BitmapImage();
                                await bitmapImage.SetSourceAsync(stream);

                                ContactPhoto = bitmapImage;
                            }
                        }
                        else
                        {
                            ContactPhoto = null;
                        }
                    }
                    ContactName = contact.Name;
                    if (contact.Phones.Count > 0)
                    {
                        var originalNumber = contact.Phones[0].Number;
                        if (originalNumber[0] != '+')
                        {
                            // need a better way of determining the "default" country code here
                            var formattedPhoneNumber = PhoneNumberFormatter.FormatE164("1", originalNumber);
                            if (string.IsNullOrEmpty(formattedPhoneNumber))
                            {
                                ContactNumber = originalNumber;
                                MessageDialog message = new MessageDialog("Please format the number in E.164 format.", "Could not format number");
                                await message.ShowAsync();
                            }
                            else
                            {
                                ContactNumber = formattedPhoneNumber;
                            }
                        }
                    }
                }
                UIEnabled = true;
            }
        }
Beispiel #28
0
 public void TestFormatNumber()
 {
     Assert.AreEqual(LOCAL_NUMBER_US, PhoneNumberFormatter.FormatNumber("(555) 555-5555", LOCAL_NUMBER_US));
     Assert.AreEqual(LOCAL_NUMBER_US, PhoneNumberFormatter.FormatNumber("555-5555", LOCAL_NUMBER_US));
     Assert.AreNotEqual(LOCAL_NUMBER_US, PhoneNumberFormatter.FormatNumber("(123) 555-5555", LOCAL_NUMBER_US));
 }
 protected override bool IsViewModelPropertiesValid()
 {
     return((Config.IdentifyUserByEmail && Identity.IsMail()) ||
            (!Config.IdentifyUserByEmail && PhoneNumberFormatter.IsValid(Identity)));
 }
 private static void VerifyPhoneNumberFormatMatches(string phoneNumberUnformatted, string country, string phoneNumberFormattedExpected)
 {
     Assert.AreEqual(phoneNumberFormattedExpected, PhoneNumberFormatter.FormatForContactList(new PhoneNumber(phoneNumberUnformatted, country)));
 }