コード例 #1
0
ファイル: OAuthController.cs プロジェクト: maxmus/IronPigeon
        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();
        }
コード例 #2
0
ファイル: OAuthController.cs プロジェクト: AArnott/IronPigeon
        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();
        }