/// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public void Run(DfpUser user)
        {
            ProductTemplateService productTemplateService =
                (ProductTemplateService)user.GetService(DfpService.v201605.ProductTemplateService);

            // Create a statement to select product templates.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("lineItemType = :lineItemType")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("lineItemType", LineItemType.SPONSORSHIP.ToString());

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

            try {
                do
                {
                    page = productTemplateService.getProductTemplatesByStatement(
                        statementBuilder.ToStatement());

                    if (page.results != null)
                    {
                        // Print out some information for each product template.
                        int i = page.startIndex;
                        foreach (ProductTemplate productTemplate in page.results)
                        {
                            Console.WriteLine("{0}) Product template with ID \"{1}\" and name \"{2}\" was found.",
                                              i++,
                                              productTemplate.id,
                                              productTemplate.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 templates. Exception says \"{0}\"",
                                  e.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public void Run(DfpUser dfpUser)
        {
            ProductTemplateService productTemplateService =
                (ProductTemplateService)dfpUser.GetService(DfpService.v201608.ProductTemplateService);

            // Create a statement to select product templates.
            int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT;
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("lineItemType = :lineItemType")
                                                .OrderBy("id ASC")
                                                .Limit(pageSize)
                                                .AddValue("lineItemType", LineItemType.SPONSORSHIP.ToString());

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

            do
            {
                ProductTemplatePage page = productTemplateService.getProductTemplatesByStatement(
                    statementBuilder.ToStatement());

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

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

            Console.WriteLine("Number of results found: {0}", totalResultSetSize);
        }
示例#3
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 ProductTemplateService.
            ProductTemplateService productTemplateService =
                (ProductTemplateService)user.GetService(DfpService.v201502.ProductTemplateService);

            // Create a statement to get all product templates.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

            // Sets default for page.
            ProductTemplatePage page = new ProductTemplatePage();

            try {
                do
                {
                    // Get product templates by statement.
                    page =
                        productTemplateService.getProductTemplatesByStatement(statementBuilder.ToStatement());

                    if (page.results != null && page.results.Length > 0)
                    {
                        int i = page.startIndex;
                        foreach (ProductTemplate productTemplate in page.results)
                        {
                            Console.WriteLine("{0}) Product template with ID = '{1}' and name '{2}' was" +
                                              " found.", i++, productTemplate.id, productTemplate.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 templates. Exception says \"{0}\"",
                                  e.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public void Run(DfpUser user)
        {
            // Get the ProductTemplateService.
            ProductTemplateService productTemplateService =
                (ProductTemplateService)user.GetService(DfpService.v201602.ProductTemplateService);

            // Create a statement to select all sponsorship product templates.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("lineItemType = :lineItemType")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("lineItemType", LineItemType.SPONSORSHIP.ToString());

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

            try {
                do
                {
                    // Get product templates by statement.
                    page = productTemplateService
                           .getProductTemplatesByStatement(statementBuilder.ToStatement());

                    if (page.results != null && page.results.Length > 0)
                    {
                        int i = page.startIndex;
                        foreach (ProductTemplate proposalLineItem in page.results)
                        {
                            Console.WriteLine("{0}) Product template with ID ='{1}' and name '{2}' was found.",
                                              i++, proposalLineItem.id, proposalLineItem.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 templates by statement. Exception says \"{0}\"",
                                  e.Message);
            }
        }
        /// <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 ProductTemplateService.
            ProductTemplateService productTemplateService =
                (ProductTemplateService)user.GetService(DfpService.v201511.ProductTemplateService);

            // Set the ID of the product template.
            long productTemplateId = long.Parse(_T("INSERT_PRODUCT_TEMPLATE_ID_HERE"));

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

            try {
                // Get product templates by statement.
                ProductTemplatePage page = productTemplateService
                                           .getProductTemplatesByStatement(statementBuilder.ToStatement());

                ProductTemplate productTemplate = page.results[0];

                // Add geo targeting for Canada to the product template.
                Location countryLocation = new Location();
                countryLocation.id = 2124L;

                Targeting    productTemplateTargeting = productTemplate.builtInTargeting;
                GeoTargeting geoTargeting             = productTemplateTargeting.geoTargeting;

                List <Location> existingTargetedLocations = new List <Location>();

                if (geoTargeting == null)
                {
                    geoTargeting = new GeoTargeting();
                }
                else if (geoTargeting.targetedLocations != null)
                {
                    existingTargetedLocations = new List <Location>(geoTargeting.targetedLocations);
                }

                existingTargetedLocations.Add(countryLocation);

                Location[] newTargetedLocations = new Location[existingTargetedLocations.Count];
                existingTargetedLocations.CopyTo(newTargetedLocations);
                geoTargeting.targetedLocations = newTargetedLocations;

                productTemplateTargeting.geoTargeting = geoTargeting;
                productTemplate.builtInTargeting      = productTemplateTargeting;

                // Update the product template on the server.
                ProductTemplate[] productTemplates = productTemplateService
                                                     .updateProductTemplates(new ProductTemplate[] { productTemplate });

                if (productTemplates != null)
                {
                    foreach (ProductTemplate updatedProductTemplate in productTemplates)
                    {
                        Console.WriteLine("A product template with ID = '{0}' and name '{1}' was updated.",
                                          updatedProductTemplate.id, updatedProductTemplate.name);
                    }
                }
                else
                {
                    Console.WriteLine("No product templates updated.");
                }
            } catch (Exception e) {
                Console.WriteLine("Failed to update product templates. Exception says \"{0}\"",
                                  e.Message);
            }
        }
示例#6
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 ProductTemplateService.
            ProductTemplateService productTemplateService =
                (ProductTemplateService)user.GetService(DfpService.v201505.ProductTemplateService);

            // Set the ID of the product template to activate.
            long productTemplateId = long.Parse(_T("INSERT_PRODUCT_TEMPLATE_ID_HERE"));

            // Create statement to select a product template by ID.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("id = :id")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("id", productTemplateId);

            // Set default for page.
            ProductTemplatePage page = new ProductTemplatePage();
            List <string>       productTemplateIds = new List <string>();

            try {
                do
                {
                    // Get product templates by statement.
                    page = productTemplateService.getProductTemplatesByStatement(
                        statementBuilder.ToStatement());

                    if (page.results != null && page.results.Length > 0)
                    {
                        int i = page.startIndex;
                        foreach (ProductTemplate productTemplate in page.results)
                        {
                            Console.WriteLine("{0}) Product template with ID ='{1}' will be activated.",
                                              i++, productTemplate.id);
                            productTemplateIds.Add(productTemplate.id.ToString());
                        }
                    }

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

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

                if (productTemplateIds.Count > 0)
                {
                    // Modify statement.
                    statementBuilder.RemoveLimitAndOffset();

                    // Create action.
                    Google.Api.Ads.Dfp.v201505.ActivateProductTemplates action =
                        new Google.Api.Ads.Dfp.v201505.ActivateProductTemplates();

                    // Perform action.
                    UpdateResult result = productTemplateService.performProductTemplateAction(action,
                                                                                              statementBuilder.ToStatement());

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