The Azure table storage entity tracking address book entries.
Inheritance: TableStorageEntity
Exemplo n.º 1
0
		public async Task<ReadOnlyListOfAddressBookEmailEntity> GetEmailAddressesAsync(AddressBookEntity entity) {
			var query = (from address in this.CreateQuery<AddressBookEmailEntity>(this.EmailAddressTableName)
						 where address.AddressBookEntityRowKey == entity.RowKey
						 select address).AsTableServiceQuery(this);
			var result = await query.ExecuteSegmentedAsync();
			
			return result.ToList();
		}
Exemplo n.º 2
0
        public async Task <AddressBookEntity> GetAsync(string provider, string userId)
        {
            Requires.NotNullOrEmpty(provider, "provider");
            Requires.NotNullOrEmpty(userId, "userId");

            var query = (from inbox in this.CreateQuery <AddressBookEntity>(this.PrimaryTableName)
                         where inbox.RowKey == AddressBookEntity.ConstructRowKey(provider, userId)
                         select inbox).AsTableServiceQuery(this);
            var result = await query.ExecuteSegmentedAsync();

            return(result.FirstOrDefault());
        }
Exemplo n.º 3
0
 public void AddObject(AddressBookEntity entity)
 {
     this.AddObject(this.PrimaryTableName, entity);
 }
Exemplo n.º 4
0
        public async Task <ReadOnlyListOfAddressBookEmailEntity> GetEmailAddressesAsync(AddressBookEntity entity)
        {
            var query = (from address in this.CreateQuery <AddressBookEmailEntity>(this.EmailAddressTableName)
                         where address.AddressBookEntityRowKey == entity.RowKey
                         select address).AsTableServiceQuery(this);
            var result = await query.ExecuteSegmentedAsync();

            return(result.ToList());
        }
Exemplo n.º 5
0
		public async Task<ActionResult> PutMicrosoftAccount(string id) {
			string addressBookBlobUri = this.Request.Form["addressBookBlobUri"];
			new Uri(addressBookBlobUri, UriKind.Absolute); // throws if invalid arg

			if (id != this.HttpContext.User.Identity.Name) {
				return new HttpUnauthorizedResult();
			}

			var entity = await this.ClientTable.GetAsync(AddressBookEntity.MicrosoftProvider, this.HttpContext.User.Identity.Name);
			if (entity == null) {
				entity = new AddressBookEntity();
				entity.Provider = AddressBookEntity.MicrosoftProvider;
				entity.UserId = this.HttpContext.User.Identity.Name;
				this.ClientTable.AddObject(entity);
			} else {
				this.ClientTable.UpdateObject(entity);
			}

			entity.AddressBookUrl = addressBookBlobUri;

			await this.ClientTable.SaveChangesAsync();
			return new EmptyResult();
		}
Exemplo n.º 6
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();
        }
Exemplo n.º 7
0
		public void AddObject(AddressBookEntity entity) {
			this.AddObject(this.PrimaryTableName, entity);
		}