/// <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 PlacementService.
      PlacementService placementService =
          (PlacementService) user.GetService(DfpService.v201511.PlacementService);

      // Create statement to select active placements.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("status = :status")
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("status", InventoryStatus.ACTIVE.ToString());

      // Sets default for page.
      PlacementPage page = new PlacementPage();
      List<string> placementIds = new List<string>();

      try {
        do {
          // Get placements by statement.
          page = placementService.getPlacementsByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (Placement placement in page.results) {
              Console.WriteLine("{0}) Placement with ID ='{1}', name ='{2}', and status ='{3}'" +
                  " will be deactivated.", i, placement.id, placement.name, placement.status);
              placementIds.Add(placement.id.ToString());
              i++;
            }
          }

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

        Console.WriteLine("Number of placements to be deactivated: {0}", placementIds.Count);

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

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

          // Perform action.
          UpdateResult result = placementService.performPlacementAction(action,
              statementBuilder.ToStatement());

          // Display results.
          if (result != null && result.numChanges > 0) {
            Console.WriteLine("Number of placements deactivated: {0}", result.numChanges);
          } else {
            Console.WriteLine("No placements were deactivated.");
          }
        }
      } catch (Exception e) {
        Console.WriteLine("Failed to deactivate placements. 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 PlacementService.
            PlacementService placementService =
                (PlacementService)user.GetService(DfpService.v201403.PlacementService);

            // Create a statement to select first 500 placements.
            Statement filterStatement = new Statement();

            filterStatement.query = "LIMIT 500";

            try {
                // Get placements by statement.
                PlacementPage page = placementService.getPlacementsByStatement(filterStatement);

                if (page.results != null)
                {
                    Placement[] placements = page.results;

                    // Update each local placement object by enabling AdSense targeting.
                    foreach (Placement placement in placements)
                    {
                        placement.targetingDescription = (string.IsNullOrEmpty(placement.description))?
                                                         "Generic description" : placement.description;
                        placement.targetingAdLocation       = "All images on sports pages.";
                        placement.targetingSiteName         = "http://code.google.com";
                        placement.isAdSenseTargetingEnabled = true;
                    }

                    // Update the placements on the server.
                    placements = placementService.updatePlacements(placements);

                    // Display results.
                    if (placements != null)
                    {
                        foreach (Placement placement in placements)
                        {
                            Console.WriteLine("A placement with ID \"{0}\", name \"{1}\", and AdSense targeting" +
                                              " enabled \"{2}\" was updated.", placement.id, placement.name,
                                              placement.isAdSenseTargetingEnabled);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No placements updated.");
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to update placements. Exception says \"{0}\"",
                                  ex.Message);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user, long placementId)
        {
            using (PlacementService placementService =
                       (PlacementService)user.GetService(DfpService.v201708.PlacementService)) {
                // Create a statement to select a placement by ID.
                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .Where("id = :id")
                                                    .OrderBy("id ASC")
                                                    .Limit(1)
                                                    .AddValue("id", placementId);

                try {
                    // Get placements by statement.
                    PlacementPage page = placementService.getPlacementsByStatement(
                        statementBuilder.ToStatement());

                    if (page.results != null)
                    {
                        Placement placement = page.results[0];

                        // Update local placement object by changing the description.
                        placement.description = "This placement includes all leaderboards.";

                        // Update the placement on the server.
                        Placement[] placements = placementService.updatePlacements(
                            new Placement[] { placement });

                        // Display results.
                        if (placements != null)
                        {
                            foreach (Placement updatedPlacement in placements)
                            {
                                Console.WriteLine("A placement with ID \"{0}\", name \"{1}\", and description " +
                                                  "\"{2}\" was updated.", updatedPlacement.id, updatedPlacement.name,
                                                  updatedPlacement.description);
                            }
                        }
                        else
                        {
                            Console.WriteLine("No placements updated.");
                        }
                    }
                } catch (Exception e) {
                    Console.WriteLine("Failed to update placements. 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)
        {
            PlacementService placementService =
                (PlacementService)dfpUser.GetService(DfpService.v201611.PlacementService);

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

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

            do
            {
                PlacementPage page = placementService.getPlacementsByStatement(
                    statementBuilder.ToStatement());

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

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

            Console.WriteLine("Number of results found: {0}", totalResultSetSize);
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public void Run(DfpUser user)
        {
            PlacementService placementService =
                (PlacementService)user.GetService(DfpService.v201605.PlacementService);

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

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

            try {
                do
                {
                    page = placementService.getPlacementsByStatement(statementBuilder.ToStatement());

                    if (page.results != null)
                    {
                        // Print out some information for each placement.
                        int i = page.startIndex;
                        foreach (Placement placement in page.results)
                        {
                            Console.WriteLine("{0}) Placement with ID \"{1}\" and name \"{2}\" was found.",
                                              i++,
                                              placement.id,
                                              placement.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 placements. Exception says \"{0}\"",
                                  e.Message);
            }
        }
Exemplo n.º 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 PlacementService.
            PlacementService placementService =
                (PlacementService)user.GetService(DfpService.v201505.PlacementService);

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

            // Set default for page
            PlacementPage page = new PlacementPage();

            try {
                do
                {
                    // Get placements by statement.
                    page = placementService.getPlacementsByStatement(statementBuilder.ToStatement());

                    // Display results.
                    if (page.results != null && page.results.Length > 0)
                    {
                        int i = page.startIndex;
                        foreach (Placement placement in page.results)
                        {
                            Console.WriteLine("{0}) Placement with ID = '{1}', name ='{2}', and status = '{3}' " +
                                              "was found.", i, placement.id, placement.name, placement.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 placement by statement. 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)
        {
            // Get the PlacementService.
            PlacementService placementService =
                (PlacementService)user.GetService(DfpService.v201511.PlacementService);

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

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

            try {
                do
                {
                    // Get placements by statement.
                    page = placementService.getPlacementsByStatement(statementBuilder.ToStatement());

                    if (page.results != null && page.results.Length > 0)
                    {
                        int i = page.startIndex;
                        foreach (Placement placement in page.results)
                        {
                            Console.WriteLine("{0}) Placement with ID = '{1}' and name = '{2}' was found.",
                                              i, placement.id, placement.name);
                            i++;
                        }
                    }

                    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 all placements. 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 PlacementService.
            PlacementService placementService =
                (PlacementService)user.GetService(DfpService.v201408.PlacementService);

            // Sets defaults for page and Statement.
            PlacementPage page      = new PlacementPage();
            Statement     statement = new Statement();
            int           offset    = 0;

            try {
                do
                {
                    // Create a Statement to get all ad units.
                    statement.query = string.Format("LIMIT 500 OFFSET {0}", offset);

                    // Get ad units by Statement.
                    page = placementService.getPlacementsByStatement(statement);

                    if (page.results != null && page.results.Length > 0)
                    {
                        int i = page.startIndex;
                        foreach (Placement placement in page.results)
                        {
                            Console.WriteLine("{0}) Placement with ID = '{1}' and name = '{2}' was found.",
                                              i, placement.id, placement.name);
                            i++;
                        }
                    }

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

                Console.WriteLine("Number of results found: {0}" + page.totalResultSetSize);
            } catch (Exception ex) {
                Console.WriteLine("Failed to get all placements. 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) {
      // Get the PlacementService.
      PlacementService placementService =
          (PlacementService) user.GetService(DfpService.v201508.PlacementService);

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

      // Set default for page
      PlacementPage page = new PlacementPage();

      try {
        do {
          // Get placements by statement.
          page = placementService.getPlacementsByStatement(statementBuilder.ToStatement());

          // Display results.
          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (Placement placement in page.results) {
              Console.WriteLine("{0}) Placement with ID = '{1}', name ='{2}', and status = '{3}' " +
                "was found.", i, placement.id, placement.name, placement.status);
              i++;
            }
          }

          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 placement by statement. Exception says \"{0}\"",
            e.Message);
      }
    }
Exemplo n.º 10
0
        public void TestGetPlacementsByStatement()
        {
            // Create a Statement to only select active placements.
            Statement statement = new Statement();

            statement.query = string.Format("WHERE id = '{0}'", placement.id);

            PlacementPage page = null;

            Assert.DoesNotThrow(delegate() {
                page = placementService.getPlacementsByStatement(statement);
            });

            Assert.NotNull(page);
            Assert.NotNull(page.results);
            Assert.AreEqual(page.results.Length, 1);

            Assert.AreEqual(page.results[0].id, placement.id);
            Assert.AreEqual(page.results[0].name, placement.name);
            Assert.AreEqual(page.results[0].description, placement.description);
            Assert.Contains(adUnit1.id, page.results[0].targetedAdUnitIds);
            Assert.Contains(adUnit2.id, page.results[0].targetedAdUnitIds);
        }
    /// <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 PlacementService.
      PlacementService placementService =
          (PlacementService) user.GetService(DfpService.v201511.PlacementService);

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

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

      try {
        do {
          // Get placements by statement.
          page = placementService.getPlacementsByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (Placement placement in page.results) {
              Console.WriteLine("{0}) Placement with ID = '{1}' and name = '{2}' was found.",
                  i, placement.id, placement.name);
              i++;
            }
          }

          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 all placements. Exception says \"{0}\"",
            e.Message);
      }
    }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(AdManagerUser user)
        {
            using (PlacementService placementService = user.GetService <PlacementService>())
            {
                // Create statement to select active placements.
                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .Where("status = :status")
                                                    .OrderBy("id ASC")
                                                    .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                    .AddValue("status", InventoryStatus.ACTIVE.ToString());

                // Sets default for page.
                PlacementPage page         = new PlacementPage();
                List <string> placementIds = new List <string>();

                try
                {
                    do
                    {
                        // Get placements by statement.
                        page = placementService.getPlacementsByStatement(statementBuilder
                                                                         .ToStatement());

                        if (page.results != null)
                        {
                            int i = page.startIndex;
                            foreach (Placement placement in page.results)
                            {
                                Console.WriteLine(
                                    "{0}) Placement with ID ='{1}', name ='{2}', and " +
                                    "status ='{3}' will be deactivated.",
                                    i, placement.id, placement.name, placement.status);
                                placementIds.Add(placement.id.ToString());
                                i++;
                            }
                        }

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

                    Console.WriteLine("Number of placements to be deactivated: {0}",
                                      placementIds.Count);

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

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

                        // Perform action.
                        UpdateResult result =
                            placementService.performPlacementAction(action,
                                                                    statementBuilder.ToStatement());

                        // Display results.
                        if (result != null && result.numChanges > 0)
                        {
                            Console.WriteLine("Number of placements deactivated: {0}",
                                              result.numChanges);
                        }
                        else
                        {
                            Console.WriteLine("No placements were deactivated.");
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to deactivate placements. Exception says \"{0}\"",
                                      e.Message);
                }
            }
        }
Exemplo n.º 13
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 PlacementService.
            PlacementService placementService =
                (PlacementService)user.GetService(DfpService.v201311.PlacementService);

            // Create Statement text to select active placements.
            String    statementText = "WHERE status = :status LIMIT 500";
            Statement statement     = new StatementBuilder("").AddValue("status",
                                                                        InventoryStatus.ACTIVE.ToString()).ToStatement();

            // Sets defaults for page and offset.
            PlacementPage page         = new PlacementPage();
            int           offset       = 0;
            List <string> placementIds = new List <string>();

            try {
                do
                {
                    // Create a Statement to page through active placements.
                    statement.query = string.Format("{0} OFFSET {1}", statementText, offset);

                    // Get placements by Statement.
                    page = placementService.getPlacementsByStatement(statement);

                    if (page.results != null && page.results.Length > 0)
                    {
                        int i = page.startIndex;
                        foreach (Placement placement in page.results)
                        {
                            Console.WriteLine("{0}) Placement with ID ='{1}', name ='{2}', and status ='{3}'" +
                                              " will be deactivated.", i, placement.id, placement.name, placement.status);
                            placementIds.Add(placement.id.ToString());
                            i++;
                        }
                    }

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

                Console.WriteLine("Number of placements to be deactivated: {0}", placementIds.Count);

                if (placementIds.Count > 0)
                {
                    // Create action Statement.
                    statement = new StatementBuilder(
                        string.Format("WHERE id IN ({0})", string.Join(",", placementIds.ToArray()))).
                                ToStatement();

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

                    // Perform action.
                    UpdateResult result = placementService.performPlacementAction(action, statement);

                    // Display results.
                    if (result != null && result.numChanges > 0)
                    {
                        Console.WriteLine("Number of placements deactivated: {0}", result.numChanges);
                    }
                    else
                    {
                        Console.WriteLine("No placements were deactivated.");
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to deactivate placements. Exception says \"{0}\"",
                                  ex.Message);
            }
        }