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

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