Esempio n. 1
0
        private async Task SetContactProperties(StoredContact contact, User user, User originalUser = null)
        {
            if (contact != null)
            {
                contact.RemoteId   = ContactsManager.GetRemoteId(user);
                contact.GivenName  = user.first_name;
                contact.FamilyName = user.last_name;
                if (!string.IsNullOrWhiteSpace(user.photo_max) && !user.photo_max.EndsWith(".gif"))
                {
                    Stream responseStreamAsync = await HttpExtensions.TryGetResponseStreamAsync(user.photo_max);

                    if (responseStreamAsync == null)
                    {
                        throw new Exception("failed to download contact pic " + user.photo_max);
                    }
                    await contact.SetDisplayPictureAsync(responseStreamAsync.AsInputStream());
                }
                IDictionary <string, object> propertiesAsync = await contact.GetPropertiesAsync();

                if (!string.IsNullOrWhiteSpace(user.site))
                {
                    propertiesAsync[KnownContactProperties.Url] = (object)user.site;
                }
                if (!string.IsNullOrWhiteSpace(user.mobile_phone) && this.IsPhoneNumber(user.mobile_phone))
                {
                    List <string> phoneNumbers = BaseFormatterHelper.ParsePhoneNumbers(user.mobile_phone);
                    if (phoneNumbers.Count >= 1)
                    {
                        propertiesAsync[KnownContactProperties.MobileTelephone] = (object)phoneNumbers[0];
                    }
                    if (phoneNumbers.Count >= 2)
                    {
                        propertiesAsync[KnownContactProperties.AlternateMobileTelephone] = (object)phoneNumbers[1];
                    }
                }
                if (!string.IsNullOrWhiteSpace(user.home_phone) && this.IsPhoneNumber(user.home_phone))
                {
                    List <string> phoneNumbers = BaseFormatterHelper.ParsePhoneNumbers(user.home_phone);
                    if (phoneNumbers.Count >= 1)
                    {
                        propertiesAsync[KnownContactProperties.Telephone] = (object)phoneNumbers[0];
                    }
                    if (phoneNumbers.Count >= 2)
                    {
                        propertiesAsync[KnownContactProperties.AlternateTelephone] = (object)phoneNumbers[1];
                    }
                }
                DateTime dateTime;
                if (!string.IsNullOrWhiteSpace(user.bdate) && ContactsManager.TryParseDateTimeFromString(user.bdate, out dateTime))
                {
                    TimeSpan timeSpan = DateTime.Now - DateTime.UtcNow;
                    dateTime = dateTime.Add(timeSpan);
                    DateTimeOffset dateTimeOffset = new DateTimeOffset(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0, 0, TimeSpan.Zero);
                    propertiesAsync[KnownContactProperties.Birthdate] = (object)new DateTimeOffset(dateTime);
                }
            }
            if (originalUser == null)
            {
                return;
            }
            originalUser.first_name   = user.first_name;
            originalUser.last_name    = user.last_name;
            originalUser.site         = user.site;
            originalUser.mobile_phone = user.mobile_phone;
            originalUser.home_phone   = user.home_phone;
            originalUser.photo_max    = user.photo_max;
            originalUser.bdate        = user.bdate;
        }
Esempio n. 2
0
        private async Task SetContactProperties(StoredContact contact, User user, User originalUser = null)
        {
            if (contact != null)
            {
                contact.RemoteId   = (ContactsManager.GetRemoteId(user));
                contact.GivenName  = (user.first_name);
                contact.FamilyName = (user.last_name);
                if (!string.IsNullOrWhiteSpace(user.photo_max) && !user.photo_max.EndsWith(".gif"))
                {
                    Stream stream = await HttpExtensions.TryGetResponseStreamAsync(user.photo_max);

                    if (stream == null)
                    {
                        throw new Exception("failed to download contact pic " + user.photo_max);
                    }
                    await contact.SetDisplayPictureAsync(stream.AsInputStream());
                }
                IDictionary <string, object> dictionary = await contact.GetPropertiesAsync();

                if (!string.IsNullOrWhiteSpace(user.site))
                {
                    dictionary[KnownContactProperties.Url] = user.site;
                }
                if (!string.IsNullOrWhiteSpace(user.mobile_phone) && this.IsPhoneNumber(user.mobile_phone))
                {
                    List <string> var_6_262 = BaseFormatterHelper.ParsePhoneNumbers(user.mobile_phone);
                    if (var_6_262.Count >= 1)
                    {
                        dictionary[KnownContactProperties.MobileTelephone] = var_6_262[0];
                    }
                    if (var_6_262.Count >= 2)
                    {
                        dictionary[KnownContactProperties.AlternateMobileTelephone] = var_6_262[1];
                    }
                }
                if (!string.IsNullOrWhiteSpace(user.home_phone) && this.IsPhoneNumber(user.home_phone))
                {
                    List <string> var_7_2D8 = BaseFormatterHelper.ParsePhoneNumbers(user.home_phone);
                    if (var_7_2D8.Count >= 1)
                    {
                        dictionary[KnownContactProperties.Telephone] = var_7_2D8[0];
                    }
                    if (var_7_2D8.Count >= 2)
                    {
                        dictionary[KnownContactProperties.AlternateTelephone] = var_7_2D8[1];
                    }
                }
                DateTime var_8;
                if (!string.IsNullOrWhiteSpace(user.bdate) && ContactsManager.TryParseDateTimeFromString(user.bdate, out var_8))
                {
                    var_8 = var_8.Add(DateTime.Now - DateTime.UtcNow);
                    new DateTimeOffset(var_8.Year, var_8.Month, var_8.Day, 0, 0, 0, 0, TimeSpan.Zero);
                    dictionary[KnownContactProperties.Birthdate] = new DateTimeOffset(var_8);
                }
            }
            if (originalUser != null)
            {
                originalUser.first_name   = user.first_name;
                originalUser.last_name    = user.last_name;
                originalUser.site         = user.site;
                originalUser.mobile_phone = user.mobile_phone;
                originalUser.home_phone   = user.home_phone;
                originalUser.photo_max    = user.photo_max;
                originalUser.bdate        = user.bdate;
            }
        }