示例#1
0
        private static async Task InsertBulkProductAsync(ProductProtoService.ProductProtoServiceClient client)
        {
            Console.WriteLine("InsertBulkProductAsync started...");

            using var clientBulk = client.InsertBulkProduct();

            for (int i = 0; i < 3; i++)
            {
                var product = new ProductModel
                {
                    Name        = $"Product{i}",
                    Description = "Bulk inserted product.",
                    Price       = 399,
                    Status      = ProductStatus.InStock,
                    CreatedDate = Timestamp.FromDateTime(DateTime.UtcNow)
                };

                await clientBulk.RequestStream.WriteAsync(product);
            }

            await clientBulk.RequestStream.CompleteAsync();

            InsertBulkProductResponse response = await clientBulk;

            Console.WriteLine($"Status: {response.Success}. Insert count: {response.InsertCount}");
        }
        private static async Task InsertBulkProductAsync(ProductProtoService.ProductProtoServiceClient client)
        {
            using var clientBulk = client.InsertBulkProduct();

            var listProduct = new List <ProductModel> {
                new ProductModel {
                    Name = "Product_1", Description = "Description_1", Price = 100, Status = ProductStatus.Instock, CreatedTime = Timestamp.FromDateTime(DateTime.UtcNow)
                },
                new ProductModel {
                    Name = "Product_2", Description = "Description_2", Price = 200, Status = ProductStatus.Instock, CreatedTime = Timestamp.FromDateTime(DateTime.UtcNow)
                },
                new ProductModel {
                    Name = "Product_3", Description = "Description_3", Price = 300, Status = ProductStatus.Instock, CreatedTime = Timestamp.FromDateTime(DateTime.UtcNow)
                },
                new ProductModel {
                    Name = "Product_4", Description = "Description_4", Price = 400, Status = ProductStatus.Instock, CreatedTime = Timestamp.FromDateTime(DateTime.UtcNow)
                }, new ProductModel {
                    Name = "Product_", Description = "Description_", Price = 100, Status = ProductStatus.Instock, CreatedTime = Timestamp.FromDateTime(DateTime.UtcNow)
                },
                new ProductModel {
                    Name = "Product_5", Description = "Description_5", Price = 500, Status = ProductStatus.Instock, CreatedTime = Timestamp.FromDateTime(DateTime.UtcNow)
                },
                new ProductModel {
                    Name = "Product_6", Description = "Description_6", Price = 600, Status = ProductStatus.Instock, CreatedTime = Timestamp.FromDateTime(DateTime.UtcNow)
                },
                new ProductModel {
                    Name = "Product_7", Description = "Description_7", Price = 700, Status = ProductStatus.Instock, CreatedTime = Timestamp.FromDateTime(DateTime.UtcNow)
                },
                new ProductModel {
                    Name = "Product_8", Description = "Description_8", Price = 800, Status = ProductStatus.Instock, CreatedTime = Timestamp.FromDateTime(DateTime.UtcNow)
                }, new ProductModel {
                    Name = "Product_", Description = "Description_", Price = 100, Status = ProductStatus.Instock, CreatedTime = Timestamp.FromDateTime(DateTime.UtcNow)
                },
                new ProductModel {
                    Name = "Product_9", Description = "Description_9", Price = 900, Status = ProductStatus.Instock, CreatedTime = Timestamp.FromDateTime(DateTime.UtcNow)
                },
            };

            foreach (var product in listProduct)
            {
                await clientBulk.RequestStream.WriteAsync(product);
            }

            await clientBulk.RequestStream.CompleteAsync();

            var response = await clientBulk;

            Console.WriteLine("Total Inserted Product: " + response.InsertCount + " Status: " + response.Success);
        }
示例#3
0
        private static async Task InsertBulkProduct(ProductProtoService.ProductProtoServiceClient client)
        {
            // InsertBulkProduct
            Console.WriteLine("InsertBulkProduct started...");
            using var clientBulk = client.InsertBulkProduct();
            for (var i = 0; i < 3; i++)
            {
                var productModel = new ProductModel
                {
                    Name        = $"Product{i}",
                    Description = "Bulk inserted product",
                    Price       = 399,
                    Status      = ProductStatus.Instock,
                    CreatedTime = Timestamp.FromDateTime(DateTime.UtcNow)
                };
                await clientBulk.RequestStream.WriteAsync(productModel);
            }
            await clientBulk.RequestStream.CompleteAsync();

            var responseBulk = await clientBulk;

            Console.WriteLine($"Status: {responseBulk.Success}. Insert Count: {responseBulk.InsertCount}");
            Thread.Sleep(1000);
        }