コード例 #1
0
        private static async Task AddBatchToIndex(Listing[] listings)
        {
            //guard against more than 1000
            if (listings.Length < 1000)
            {
                var managementClient = GetIndexManagementClient();
                List<IndexOperation> operations = new List<IndexOperation>();

                //rip through collection and make a batch of operations
                foreach (Listing l in listings)
                {
                    var flatOptions = string.Concat(l.Options.Select(o => o.Name));
                    var op = new IndexOperation(IndexOperationType.Upload, "Id", l.Id.ToString())
                        .WithProperty("Color", l.Color)
                        .WithProperty("Options", flatOptions)
                        .WithProperty("Package", l.Package)
                        .WithProperty("Type", l.Type)
                        .WithProperty("Image", l.Image);
                    operations.Add(op);
                }

                //TODO: should be able to batch up the operations
                var result = await managementClient.PopulateAsync(Keys.ListingsServiceIndexName, operations.ToArray());
                if (!result.IsSuccess)
                {
                    Console.WriteLine("Adding records to the index failed!");
                }
            }
        }
コード例 #2
0
        private Listing GetListing()
        {
            Listing l = new Listing();
            l.Id = Guid.NewGuid();
            l.Color = GetColor();
            l.Options = GetOptions();
            l.Package = GetPackage();
            l.Type = GetType();
            l.Image = GetImage(l.Color, l.Type, l.Package);
            l.Dealer = GetDealer();

            return l;
        }
コード例 #3
0
 public static async Task AddRecordsToIndex(Listing[] listings)
 {
     //determine batch size
     if (listings.Length < 1000)
     {
         await AddBatchToIndex(listings);
     }
     //else break up list into chunks of 1000
     else
     {
         for (int i = 0; i < (listings.Length / 1000); i++)
         {
             await AddBatchToIndex(listings.Skip(i).Take(1000).ToArray());
         }
     }
 }
コード例 #4
0
        public static async Task CreateDatabase(Listing[] listings)
        {
            var client = GetClient();

            Database database = await RetrieveOrCreateDatabaseAsync(Keys.ListingsDbName);

            Console.Write("Self link for new database: ");
            Console.WriteLine(database.SelfLink);

            DocumentCollection documentCollection = await RetrieveOrCreateCollectionAsync(database.SelfLink, Keys.ListingDbCollectionName);

            foreach (Listing listing in listings)
            {
                await client.CreateDocumentAsync(documentCollection.SelfLink, listing);
            }
        }