/// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            using (CreativeWrapperService creativeWrapperService =
                       (CreativeWrapperService)user.GetService(
                           DfpService.v201802.CreativeWrapperService)) {
                long creativeWrapperId = long.Parse(_T("INSERT_CREATIVE_WRAPPER_ID_HERE"));

                try {
                    StatementBuilder statementBuilder = new StatementBuilder()
                                                        .Where("id = :id")
                                                        .OrderBy("id ASC")
                                                        .Limit(1)
                                                        .AddValue("id", creativeWrapperId);
                    CreativeWrapperPage page = creativeWrapperService.getCreativeWrappersByStatement(
                        statementBuilder.ToStatement());
                    CreativeWrapper wrapper = page.results[0];

                    wrapper.ordering = CreativeWrapperOrdering.OUTER;
                    // Update the creative wrappers on the server.
                    CreativeWrapper[] creativeWrappers = creativeWrapperService.updateCreativeWrappers(
                        new CreativeWrapper[] { wrapper });

                    // Display results.
                    foreach (CreativeWrapper createdCreativeWrapper in creativeWrappers)
                    {
                        Console.WriteLine("Creative wrapper with ID '{0}' and wrapping order '{1}' was " +
                                          "updated.", createdCreativeWrapper.id, createdCreativeWrapper.ordering);
                    }
                } catch (Exception e) {
                    Console.WriteLine("Failed to update creative wrappers. 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)
        {
            // Create the CreativeWrapperService.
            CreativeWrapperService creativeWrapperService = (CreativeWrapperService)user.GetService(
                DfpService.v201311.CreativeWrapperService);

            long labelId = long.Parse(_T("INSERT_CREATIVE_WRAPPER_LABEL_ID_HERE"));

            try {
                // Create a query to select the active creative wrapper for the given
                // label.
                Statement statement = new StatementBuilder("WHERE status = :status AND labelId = :labelId")
                                      .AddValue("labelId", labelId)
                                      .AddValue("status", CreativeWrapperStatus.ACTIVE.ToString())
                                      .ToStatement();
                CreativeWrapperPage page             = creativeWrapperService.getCreativeWrappersByStatement(statement);
                CreativeWrapper[]   creativeWrappers = page.results;
                if (creativeWrappers != null)
                {
                    foreach (CreativeWrapper wrapper in creativeWrappers)
                    {
                        Console.WriteLine("Creative wrapper with ID \'{0}\' applying to label \'{1}\' with " +
                                          "status \'{2}\' will be deactivated.", wrapper.id, wrapper.labelId, wrapper.status);
                    }
                    Console.WriteLine("Number of creative wrappers to be deactivated: {0}",
                                      creativeWrappers.Length);

                    // Perform action.
                    CreativeWrapperAction action = new DeactivateCreativeWrappers();
                    UpdateResult          result =
                        creativeWrapperService.performCreativeWrapperAction(action, statement);

                    // Display results.
                    if (result.numChanges > 0)
                    {
                        Console.WriteLine("Number of creative wrappers deactivated: {0}", result.numChanges);
                    }
                    else
                    {
                        Console.WriteLine("No creative wrappers were deactivated.");
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to create creative wrappers. Exception says \"{0}\"", ex.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public void Run(DfpUser user)
        {
            CreativeWrapperService creativeWrapperService =
                (CreativeWrapperService)user.GetService(DfpService.v201608.CreativeWrapperService);

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

            // Retrieve a small amount of creative wrappers at a time, paging through
            // until all creative wrappers have been retrieved.
            CreativeWrapperPage page = new CreativeWrapperPage();

            try {
                do
                {
                    page = creativeWrapperService.getCreativeWrappersByStatement(
                        statementBuilder.ToStatement());

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

                    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 creative wrappers. Exception says \"{0}\"",
                                  e.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser dfpUser)
        {
            CreativeWrapperService creativeWrapperService =
                (CreativeWrapperService)dfpUser.GetService(DfpService.v201705.CreativeWrapperService);

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

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

            do
            {
                CreativeWrapperPage page = creativeWrapperService.getCreativeWrappersByStatement(
                    statementBuilder.ToStatement());

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

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

            Console.WriteLine("Number of results found: {0}", totalResultSetSize);
        }
Пример #5
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)
        {
            // Create the CreativeWrapperService.
            CreativeWrapperService creativeWrapperService = (CreativeWrapperService)user.GetService(
                DfpService.v201403.CreativeWrapperService);

            // Create a Statement to get all active creative wrappers.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("status = :status")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("status", CreativeWrapperStatus.ACTIVE.ToString());

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

            try {
                do
                {
                    // Get creative wrappers by Statement.
                    page = creativeWrapperService.getCreativeWrappersByStatement(
                        statementBuilder.ToStatement());

                    if (page.results != null && page.results.Length > 0)
                    {
                        int i = page.startIndex;
                        foreach (CreativeWrapper wrapper in page.results)
                        {
                            Console.WriteLine("Creative wrapper with ID \'{0}\' applying to label \'{1}\' with " +
                                              "status \'{2}\' was found.", wrapper.id, wrapper.labelId, wrapper.status);
                            i++;
                        }
                    }

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

                Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
            } catch (Exception ex) {
                Console.WriteLine("Failed to get active creative wrappers. Exception says \"{0}\"",
                                  ex.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)
        {
            // Create the CreativeWrapperService.
            CreativeWrapperService creativeWrapperService = (CreativeWrapperService)user.GetService(
                DfpService.v201311.CreativeWrapperService);

            // Set defaults for page and Statement.
            CreativeWrapperPage page      = new CreativeWrapperPage();
            Statement           statement = new StatementBuilder("")
                                            .AddValue("status", CreativeWrapperStatus.ACTIVE.ToString())
                                            .ToStatement();
            int offset = 0;

            try {
                do
                {
                    // Create a Statement to get all active creative wrappers.
                    statement.query = string.Format("WHERE status = :status LIMIT 500 OFFSET {0}", offset);

                    // Get creative wrappers by Statement.
                    page = creativeWrapperService.getCreativeWrappersByStatement(statement);

                    if (page.results != null && page.results.Length > 0)
                    {
                        int i = page.startIndex;
                        foreach (CreativeWrapper wrapper in page.results)
                        {
                            Console.WriteLine("Creative wrapper with ID \'{0}\' applying to label \'{1}\' with " +
                                              "status \'{2}\' was found.", wrapper.id, wrapper.labelId, wrapper.status);
                            i++;
                        }
                    }

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

                Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
            } catch (Exception ex) {
                Console.WriteLine("Failed to get active creative wrappers. Exception says \"{0}\"",
                                  ex.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            // Create the CreativeWrapperService.
            CreativeWrapperService creativeWrapperService = (CreativeWrapperService)user.GetService(
                DfpService.v201702.CreativeWrapperService);

            long labelId = long.Parse(_T("INSERT_CREATIVE_WRAPPER_LABEL_ID_HERE"));

            try {
                // Create a query to select the active creative wrapper for the given
                // label.
                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .Where("labelId = :labelId AND status = :status")
                                                    .OrderBy("id ASC")
                                                    .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                    .AddValue("status", CreativeWrapperStatus.ACTIVE.ToString())
                                                    .AddValue("labelId", labelId);

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

                do
                {
                    page =
                        creativeWrapperService.getCreativeWrappersByStatement(statementBuilder.ToStatement());
                    CreativeWrapper[] creativeWrappers = page.results;
                    if (creativeWrappers != null)
                    {
                        foreach (CreativeWrapper wrapper in creativeWrappers)
                        {
                            Console.WriteLine("Creative wrapper with ID \'{0}\' applying to label \'{1}\' with " +
                                              "status \'{2}\' will be deactivated.", wrapper.id, wrapper.labelId,
                                              wrapper.status);
                        }
                    }
                    statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
                } while (statementBuilder.GetOffset() < page.totalResultSetSize);

                Console.WriteLine("Number of creative wrappers to be deactivated: {0}",
                                  page.totalResultSetSize);

                // Modify statement for action.
                statementBuilder.RemoveLimitAndOffset();

                // Perform action.
                CreativeWrapperAction action = new DeactivateCreativeWrappers();
                UpdateResult          result = creativeWrapperService.performCreativeWrapperAction(action,
                                                                                                   statementBuilder.ToStatement());

                // Display results.
                if (result.numChanges > 0)
                {
                    Console.WriteLine("Number of creative wrappers deactivated: {0}", result.numChanges);
                }
                else
                {
                    Console.WriteLine("No creative wrappers were deactivated.");
                }
            } catch (Exception e) {
                Console.WriteLine("Failed to create creative wrappers. Exception says \"{0}\"", e.Message);
            }
        }