/// <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);

      // 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 ex) {
        Console.WriteLine("Failed to deactivate 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.v201408.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.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);
      }
    }