Exemple #1
0
        private async Task SaveAccountInfoAsync(MicrosoftAccountInfo microsoftAccountInfo)
        {
            Requires.NotNull(microsoftAccountInfo, "microsoftAccountInfo");
            Requires.That(microsoftAccountInfo.Emails != null && microsoftAccountInfo.Emails.Count > 0, "microsoftAccountInfo", "No emails were provided by Live Connect.");

            var entity = await this.ClientTable.GetAsync(AddressBookEntity.MicrosoftProvider, microsoftAccountInfo.Id);

            if (entity == null)
            {
                entity          = new AddressBookEntity();
                entity.Provider = AddressBookEntity.MicrosoftProvider;
                entity.UserId   = microsoftAccountInfo.Id;
                this.ClientTable.AddObject(entity);
            }
            else
            {
                this.ClientTable.UpdateObject(entity);
            }

            entity.FirstName = microsoftAccountInfo.FirstName;
            entity.LastName  = microsoftAccountInfo.LastName;

            var previouslyRecordedEmails = await this.ClientTable.GetEmailAddressesAsync(entity);

            var previouslyRecordedEmailAddresses = new HashSet <string>(previouslyRecordedEmails.Select(e => e.Email));

            previouslyRecordedEmailAddresses.ExceptWith(microsoftAccountInfo.Emails.Values);

            var freshEmailAddresses = new HashSet <string>(microsoftAccountInfo.Emails.Values.Where(v => v != null));

            freshEmailAddresses.ExceptWith(previouslyRecordedEmails.Select(e => e.Email));

            foreach (var previouslyRecordedEmailAddress in previouslyRecordedEmailAddresses)
            {
                this.ClientTable.DeleteObject(
                    previouslyRecordedEmails.FirstOrDefault(e => e.Email == previouslyRecordedEmailAddress));
            }

            foreach (var freshEmailAddress in freshEmailAddresses)
            {
                var newEmailEntity = new AddressBookEmailEntity
                {
                    Email = freshEmailAddress,
                    MicrosoftEmailHash      = MicrosoftTools.GetEmailHash(freshEmailAddress),
                    AddressBookEntityRowKey = entity.RowKey,
                };
                this.ClientTable.AddObject(newEmailEntity);
            }

            await this.ClientTable.SaveChangesAsync();
        }
Exemple #2
0
 public void GetEmailHash()
 {
     Assert.Equal(
         "c56c97c675466cdbecaa76cb43cf41756ec510d1faa58e382d10c66723c310f0",
         MicrosoftTools.GetEmailHash("*****@*****.**"));
 }