/// <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 CreativeTemplateService.
            CreativeTemplateService creativeTemplateService =
                (CreativeTemplateService)user.GetService(DfpService.v201411.CreativeTemplateService);

            // Create a statement to only select system defined creative templates.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("type = :creativeTemplateType")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("creativeTemplateType", CreativeTemplateType.SYSTEM_DEFINED.ToString());

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

            try {
                do
                {
                    // Get creative templates by statement.
                    page = creativeTemplateService.getCreativeTemplatesByStatement(
                        statementBuilder.ToStatement());

                    if (page.results != null)
                    {
                        int i = page.startIndex;
                        foreach (CreativeTemplate creativeTemplate in page.results)
                        {
                            Console.WriteLine("{0}) Creative template with ID \"{1}\", name \"{2}\", and type " +
                                              "\"{3}\" was found.", i, creativeTemplate.id, creativeTemplate.name,
                                              creativeTemplate.type);
                            i++;
                        }
                    }
                    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 creative templates. Exception says \"{0}\"",
                                  e.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser dfpUser)
        {
            using (CreativeTemplateService creativeTemplateService =
                       (CreativeTemplateService)dfpUser.GetService(DfpService.v201802.CreativeTemplateService)) {
                // Create a statement to select creative templates.
                int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT;
                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .Where("type = :type")
                                                    .OrderBy("id ASC")
                                                    .Limit(pageSize)
                                                    .AddValue("type", CreativeTemplateType.SYSTEM_DEFINED.ToString());

                // Retrieve a small amount of creative templates at a time, paging through until all
                // creative templates have been retrieved.
                int totalResultSetSize = 0;
                do
                {
                    CreativeTemplatePage page = creativeTemplateService.getCreativeTemplatesByStatement(
                        statementBuilder.ToStatement());

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

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

                Console.WriteLine("Number of results found: {0}", totalResultSetSize);
            }
        }
Exemple #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 CreativeTemplateService.
            CreativeTemplateService creativeTemplateService =
                (CreativeTemplateService)user.GetService(DfpService.v201311.CreativeTemplateService);

            // Set defaults for page and filterStatement.
            CreativeTemplatePage page            = new CreativeTemplatePage();
            Statement            filterStatement = new Statement();
            int offset = 0;

            try {
                do
                {
                    // Create a statement to get all creative templates.
                    filterStatement.query = "LIMIT 500 OFFSET " + offset.ToString();

                    // Get creative templates by statement.
                    page = creativeTemplateService.getCreativeTemplatesByStatement(filterStatement);

                    if (page.results != null)
                    {
                        int i = page.startIndex;
                        foreach (CreativeTemplate creativeTemplate in page.results)
                        {
                            Console.WriteLine("{0}) Creative template with ID \"{1}\", name \"{2}\", and type " +
                                              "\"{3}\" was found.", i, creativeTemplate.id, creativeTemplate.name,
                                              creativeTemplate.type);
                            i++;
                        }
                    }

                    offset += 500;
                } while (offset < page.totalResultSetSize);

                Console.WriteLine("Number of results found: " + page.totalResultSetSize);
            } catch (Exception ex) {
                Console.WriteLine("Failed to get all creative templates. Exception says \"{0}\"",
                                  ex.Message);
            }
        }