Esempio n. 1
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(AdManagerUser user)
        {
            using (ProductPackageService productPackageService =
                       user.GetService <ProductPackageService>())
            {
                long productPackageId = long.Parse(_T("INSERT_PRODUCT_PACKAGE_ID_HERE"));

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

                try
                {
                    // Get the product package.
                    ProductPackagePage page =
                        productPackageService.getProductPackagesByStatement(statementBuilder
                                                                            .ToStatement());

                    ProductPackage productPackage = page.results[0];

                    // Update the product package object by changing its notes.
                    productPackage.notes =
                        "This product package is not to be sold before the end of the " + "month.";

                    // Update the product packages on the server.
                    ProductPackage[] productPackages = productPackageService.updateProductPackages(
                        new ProductPackage[]
                    {
                        productPackage
                    });

                    if (productPackages != null)
                    {
                        foreach (ProductPackage updatedProductPackage in productPackages)
                        {
                            Console.WriteLine(
                                "Product package with ID = \"{0}\", name = \"{1}\", and " +
                                "notes = \"{2}\" was updated.", updatedProductPackage.id,
                                updatedProductPackage.name, updatedProductPackage.notes);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No product packages updated.");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to update product packages. Exception says \"{0}\"",
                                      e.Message);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            ProductPackageService productPackageService =
                (ProductPackageService)user.GetService(DfpService.v201605.ProductPackageService);

            // Create a statement to select product packages.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("status = :status")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("status", ProductPackageStatus.ACTIVE.ToString());

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

            try {
                do
                {
                    page = productPackageService.getProductPackagesByStatement(
                        statementBuilder.ToStatement());

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

                    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 packages. Exception says \"{0}\"",
                                  e.Message);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser dfpUser)
        {
            ProductPackageService productPackageService =
                (ProductPackageService)dfpUser.GetService(DfpService.v201705.ProductPackageService);

            // Create a statement to select product packages.
            int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT;
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("status = :status")
                                                .OrderBy("id ASC")
                                                .Limit(pageSize)
                                                .AddValue("status", ProductPackageStatus.ACTIVE.ToString());

            // Retrieve a small amount of product packages at a time, paging through until all
            // product packages have been retrieved.
            int totalResultSetSize = 0;

            do
            {
                ProductPackagePage page = productPackageService.getProductPackagesByStatement(
                    statementBuilder.ToStatement());

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

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

            Console.WriteLine("Number of results found: {0}", totalResultSetSize);
        }
Esempio n. 4
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the ProductPackageService.
            ProductPackageService productPackageService =
                (ProductPackageService)user.GetService(DfpService.v201511.ProductPackageService);

            // Create a statement to only select active product packages.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("status = :status")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("status", ProductPackageStatus.ACTIVE.ToString());

            // Set default for page.
            ProductPackagePage page = new ProductPackagePage();

            try {
                do
                {
                    // Get product packages by statement.
                    page =
                        productPackageService.getProductPackagesByStatement(statementBuilder.ToStatement());

                    if (page.results != null && page.results.Length > 0)
                    {
                        int i = page.startIndex;
                        foreach (ProductPackage productPackage in page.results)
                        {
                            Console.WriteLine("{0}) Product package with ID = \"{1}\" and name = \"{2}\" was " +
                                              "found.", i++, productPackage.id, productPackage.name);
                        }
                    }
                    statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
                } while(statementBuilder.GetOffset() < page.totalResultSetSize);
                Console.WriteLine("Number of results found: " + page.totalResultSetSize);
            } catch (Exception e) {
                Console.WriteLine("Failed to get product packages. Exception says \"{0}\"",
                                  e.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            using (ProductPackageService productPackageService =
                       (ProductPackageService)user.GetService(DfpService.v201708.ProductPackageService)) {
                // Set the ID of the product package.
                long productPackageId = long.Parse(_T("INSERT_PRODUCT_PACKAGE_ID_HERE"));

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

                // Set default for page.
                ProductPackagePage page = new ProductPackagePage();
                List <string>      productPackageIds = new List <string>();
                int i = 0;

                try {
                    do
                    {
                        // Get product packages by statement.
                        page = productPackageService.getProductPackagesByStatement(
                            statementBuilder.ToStatement());

                        if (page.results != null)
                        {
                            foreach (ProductPackage productPackage in page.results)
                            {
                                Console.WriteLine("{0}) Product package with ID = '{1}', name = '{2}', and " +
                                                  "status ='{3}' will be activated.", i++, productPackage.id,
                                                  productPackage.name, productPackage.status);
                                productPackageIds.Add(productPackage.id.ToString());
                            }
                        }

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

                    Console.WriteLine("Number of product packages to be activated: {0}",
                                      productPackageIds.Count);

                    if (productPackageIds.Count > 0)
                    {
                        // Modify statement for action.
                        statementBuilder.RemoveLimitAndOffset();

                        // Create action.
                        ActivateProductPackages action = new ActivateProductPackages();

                        // Perform action.
                        UpdateResult result = productPackageService.performProductPackageAction(action,
                                                                                                statementBuilder.ToStatement());

                        // Display results.
                        if (result != null && result.numChanges > 0)
                        {
                            Console.WriteLine("Number of product packages activated: {0}", result.numChanges);
                        }
                        else
                        {
                            Console.WriteLine("No product packages were activated.");
                        }
                    }
                } catch (Exception e) {
                    Console.WriteLine("Failed to activate product packages. Exception says \"{0}\"",
                                      e.Message);
                }
            }
        }