public async Task RunAsync(CancellationToken token)
        {
            var rows = await _tableStore.GetRowsAsync(_tableName, CancellationToken.None);

            while (await rows.MoveNext())
            {
                foreach (var row in rows.Current)
                {
                    var contactId = row.GetGuid(0);
                    var productId = row.GetInt64(1);
                    var score     = row.GetDouble(2);

                    var contact = await _xdbContext.GetContactAsync(contactId,
                                                                    new ContactExpandOptions(ProductRecommendationFacet.DefaultFacetKey));

                    var facet = contact.GetFacet <ProductRecommendationFacet>(ProductRecommendationFacet.DefaultFacetKey) ??
                                new ProductRecommendationFacet();

                    if (facet.ProductRecommendations.All(x => x.ProductId != productId))
                    {
                        facet.ProductRecommendations.Add(new ProductRecommend
                        {
                            ProductId = productId,
                            Score     = score
                        });

                        _xdbContext.SetFacet(contact, ProductRecommendationFacet.DefaultFacetKey, facet);
                        await _xdbContext.SubmitAsync(CancellationToken.None);
                    }
                }
            }

            await _tableStore.RemoveAsync(_tableName, CancellationToken.None);
        }
        public async Task RunAsync(CancellationToken token)
        {
            // Retrieve the recommendation data from the table.
            var rows = await _tableStore.GetRowsAsync(_tableName, CancellationToken.None);

            // Iterate the recommendation data.
            while (await rows.MoveNext())
            {
                foreach (var row in rows.Current)
                {
                    // Row schema
                    // new FieldDefinition("ContactID", FieldKind.Key, FieldDataType.Guid),
                    // new FieldDefinition("AlbumID", FieldKind.Key, FieldDataType.String),
                    // new FieldDefinition("AlbumName", FieldKind.Attribute, FieldDataType.String),
                    // new FieldDefinition("ArtistID", FieldKind.Attribute, FieldDataType.String),
                    // new FieldDefinition("ArtistName", FieldKind.Attribute, FieldDataType.String)

                    var contactId  = row.GetGuid(0);
                    var albumId    = row.GetString(1);
                    var albumName  = row.GetString(2);
                    var artistId   = row.GetString(3);
                    var artistName = row.GetString(4);

                    // Load the contact with their album recommendation facet.
                    var contact = await _xdbContext.GetContactAsync(contactId,
                                                                    new ContactExpandOptions(AlbumRecommendationFacet.DefaultFacetName));

                    var facet = contact.GetFacet <AlbumRecommendationFacet>(AlbumRecommendationFacet.DefaultFacetName) ??
                                new AlbumRecommendationFacet();

                    // Add the album to the facet if it doesn't already exist
                    if (facet.AlbumRecommendations.All(x => x.AlbumId != albumId))
                    {
                        facet.AlbumRecommendations.Add(new AlbumDescriptor
                        {
                            AlbumId    = albumId,
                            AlbumName  = albumName,
                            ArtistId   = artistId,
                            ArtistName = artistName
                        });

                        // Update the facet if it's been changed.
                        _xdbContext.SetFacet(contact, AlbumRecommendationFacet.DefaultFacetName, facet);
                        await _xdbContext.SubmitAsync(CancellationToken.None);
                    }
                }
            }

            // Delete the table now that we're done with it.
            await _tableStore.RemoveAsync(_tableName, CancellationToken.None);
        }
Пример #3
0
        public async Task RunAsync(CancellationToken token)
        {
            var rows = await _tableStore.GetRowsAsync(_tableName, CancellationToken.None);

            while (await rows.MoveNext())
            {
                foreach (var row in rows.Current)
                {
                    var contactId = row.GetGuid(0);
                    var movieId   = row.GetString(1);
                    var title     = row.GetString(2);
                    var overview  = row.GetString(3);
                    var image     = row.GetString(4);
                    var rating    = row.GetString(5);

                    var contact = await _xdbContext.GetContactAsync(contactId,
                                                                    new ContactExpandOptions(MovieRecommendationFacet.DefaultFacetKey));

                    var facet = contact.GetFacet <MovieRecommendationFacet>(MovieRecommendationFacet.DefaultFacetKey) ??
                                new MovieRecommendationFacet();

                    if (facet.MovieRecommendations.All(x => x.netflixid != movieId))
                    {
                        facet.MovieRecommendations.Add(new Movie
                        {
                            netflixid = movieId,
                            title     = title,
                            synopsis  = overview,
                            image     = image,
                            rating    = rating
                        });
                    }


                    _xdbContext.SetFacet(contact, MovieRecommendationFacet.DefaultFacetKey, facet);
                    await _xdbContext.SubmitAsync(CancellationToken.None);
                }
            }

            await _tableStore.RemoveAsync(_tableName, CancellationToken.None);

            System.Console.WriteLine("Finished Storing Recommendations for Contacts");
        }
Пример #4
0
        public async Task RunAsync(CancellationToken token)
        {
            var rows = await _tableStore.GetRowsAsync(_tableName, CancellationToken.None);

            while (await rows.MoveNext())
            {
                foreach (var row in rows.Current)
                {
                    var contactId  = row.GetGuid(0);
                    var movieId    = row.GetInt64(1);
                    var title      = row.GetString(2);
                    var overview   = row.GetString(3);
                    var posterPath = row.GetString(4);

                    var contact = await _xdbContext.GetContactAsync(contactId,
                                                                    new ContactExpandOptions(MovieRecommendationFacet.DefaultFacetName));

                    var facet = contact.GetFacet <MovieRecommendationFacet>(MovieRecommendationFacet.DefaultFacetName) ??
                                new MovieRecommendationFacet();

                    if (facet.MovieRecommendations.All(x => x.Id != movieId))
                    {
                        facet.MovieRecommendations.Add(new Movie
                        {
                            Id         = movieId,
                            Title      = title,
                            Overview   = overview,
                            PosterPath = posterPath
                        });

                        _xdbContext.SetFacet(contact, MovieRecommendationFacet.DefaultFacetName, facet);
                        await _xdbContext.SubmitAsync(CancellationToken.None);
                    }
                }
            }

            await _tableStore.RemoveAsync(_tableName, CancellationToken.None);
        }