/// <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 InventoryService.
      InventoryService inventoryService =
          (InventoryService) user.GetService(DfpService.v201405.InventoryService);

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

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

      try {
        do {
          // Get ad units by Statement.
          page = inventoryService.getAdUnitsByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (AdUnit adUnit in page.results) {
              Console.WriteLine("{0}) Ad unit with ID = '{1}', name = '{2}' and status = '{3}' " +
                  "was found.", i, adUnit.id, adUnit.name, adUnit.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 ad unit. 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 InventoryService.
      InventoryService inventoryService =
          (InventoryService) user.GetService(DfpService.v201405.InventoryService);

      // Set the ID of the ad unit to deactivate.
      int adUnitId = int.Parse(_T("INSERT_AD_UNIT_ID_HERE"));

      // Create a statement to select the ad unit.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("id = :id")
          .OrderBy("id ASC")
          .Limit(1)
          .AddValue("id", adUnitId);

      // Set default for page.
      AdUnitPage page = new AdUnitPage();
      List<string> adUnitIds = new List<string>();

      try {
        do {
          // Get ad units by Statement.
          page = inventoryService.getAdUnitsByStatement(statementBuilder.ToStatement());

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

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

        Console.WriteLine("Number of ad units to be deactivated: {0}", adUnitIds.Count);

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

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

        // Perform action.
        UpdateResult result = inventoryService.performAdUnitAction(action,
            statementBuilder.ToStatement());

        // Display results.
        if (result != null && result.numChanges > 0) {
          Console.WriteLine("Number of ad units deactivated: {0}", result.numChanges);
        } else {
          Console.WriteLine("No ad units were deactivated.");
        }

      } catch (Exception ex) {
        Console.WriteLine("Failed to deactivate ad units. Exception says \"{0}\"", ex.Message);
      }
    }
    /// <summary>
    /// Gets all ad units for this user.
    /// </summary>
    /// <param name="user">The DfpUser to get the ad units for.</param>
    /// <returns>All ad units for this user.</returns>
    private static AdUnit[] GetAllAdUnits(DfpUser user) {
      // Create list to hold all ad units.
      List<AdUnit> adUnits = new List<AdUnit>();

      // Get InventoryService.
      InventoryService inventoryService =
          (InventoryService) user.GetService(DfpService.v201405.InventoryService);

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

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

      do {
        // Get ad units by Statement.
        page = inventoryService.getAdUnitsByStatement(statementBuilder.ToStatement());

        if (page.results != null && page.results.Length > 0) {
          adUnits.AddRange(page.results);
        }
        statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
      } while (statementBuilder.GetOffset() < page.totalResultSetSize);
      return adUnits.ToArray();
    }