Beispiel #1
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser dfpUser, long productPackageId)
        {
            using (ProductPackageItemService productPackageItemService =
                       (ProductPackageItemService)dfpUser.GetService(
                           DfpService.v201802.ProductPackageItemService)) {
                // Create a statement to select product package items.
                int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT;
                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .Where("productPackageId = :productPackageId")
                                                    .OrderBy("id ASC")
                                                    .Limit(pageSize)
                                                    .AddValue("productPackageId", productPackageId);

                // Retrieve a small amount of product package items at a time, paging through until all
                // product package items have been retrieved.
                int totalResultSetSize = 0;
                do
                {
                    ProductPackageItemPage page =
                        productPackageItemService.getProductPackageItemsByStatement(
                            statementBuilder.ToStatement());

                    // Print out some information for each product package item.
                    if (page.results != null)
                    {
                        totalResultSetSize = page.totalResultSetSize;
                        int i = page.startIndex;
                        foreach (ProductPackageItem productPackageItem in page.results)
                        {
                            Console.WriteLine(
                                "{0}) Product package item with ID {1}, " +
                                "product ID {2}, " +
                                "and product package ID {3} was found.",
                                i++,
                                productPackageItem.id,
                                productPackageItem.productId,
                                productPackageItem.productPackageId
                                );
                        }
                    }

                    statementBuilder.IncreaseOffsetBy(pageSize);
                } while (statementBuilder.GetOffset() < totalResultSetSize);

                Console.WriteLine("Number of results found: {0}", totalResultSetSize);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user, long productPackageId)
        {
            ProductPackageItemService productPackageItemService =
                (ProductPackageItemService)user.GetService(DfpService.v201605.ProductPackageItemService);

            // Create a statement to select product package items.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("productPackageId = :productPackageId")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("productPackageId", productPackageId);

            // Retrieve a small amount of product package items at a time, paging through
            // until all product package items have been retrieved.
            ProductPackageItemPage page = new ProductPackageItemPage();

            try {
                do
                {
                    page = productPackageItemService.getProductPackageItemsByStatement(
                        statementBuilder.ToStatement());

                    if (page.results != null)
                    {
                        // Print out some information for each product package item.
                        int i = page.startIndex;
                        foreach (ProductPackageItem productPackageItem in page.results)
                        {
                            Console.WriteLine("{0}) Product package item with ID \"{1}\", product ID \"{2}\", "
                                              + "and product package ID \"{3}\" was found.",
                                              i++,
                                              productPackageItem.id,
                                              productPackageItem.productId,
                                              productPackageItem.productPackageId);
                        }
                    }

                    statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
                } while (statementBuilder.GetOffset() < page.totalResultSetSize);

                Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
            } catch (Exception e) {
                Console.WriteLine("Failed to get product package items. Exception says \"{0}\"",
                                  e.Message);
            }
        }