/// <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 CustomTargetingService.
      CustomTargetingService customTargetingService =
          (CustomTargetingService) user.GetService(DfpService.v201403.CustomTargetingService);

      // Create a statement to only select predefined custom targeting keys.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("type = :type")
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("type", CustomTargetingKeyType.PREDEFINED.ToString());

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

      try {
        do {
          // Get custom targeting keys by statement.
          page = customTargetingService.getCustomTargetingKeysByStatement(
              statementBuilder.ToStatement());

          if (page.results != null) {
            int i = page.startIndex;
            foreach (CustomTargetingKey customTargetingKey in page.results) {
              Console.WriteLine("{0}) Custom targeting key with ID \"{1}\", name \"{2}\", and " +
                  "display name \"{3}\" was found.", i, customTargetingKey.id,
                  customTargetingKey.name, customTargetingKey.displayName);
              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 predefined custom targeting keys. 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 CustomTargetingService.
      CustomTargetingService customTargetingService =
          (CustomTargetingService) user.GetService(DfpService.v201403.CustomTargetingService);

      // Create a statement to get all custom targeting keys.
      StatementBuilder keyStatementBuilder = new StatementBuilder()
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

      // Set default for page.
      CustomTargetingKeyPage keyPage = new CustomTargetingKeyPage();

      try {
        do {
          // Get custom targeting keys by statement.
          keyPage = customTargetingService.getCustomTargetingKeysByStatement(
              keyStatementBuilder.ToStatement());

          if (keyPage.results != null) {
            int i = keyPage.startIndex;
            foreach (CustomTargetingKey key in keyPage.results) {
              Console.WriteLine("{0}) Custom targeting key with ID \"{1}\", name \"{2}\", " +
                  "display name \"{3}\", and type \"{4}\" was found.", i, key.id, key.name,
                  key.displayName, key.type);

              // Create a statement to get all custom targeting values for a
              // custom targeting key (required) by its ID.
              StatementBuilder valueStatementBuilder = new StatementBuilder()
                  .Where("customTargetingKeyId = :customTargetingKeyId")
                  .OrderBy("id ASC")
                  .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                  .AddValue("customTargetingKeyId", key.id);

              // Set default for page.
              CustomTargetingValuePage valuePage = new CustomTargetingValuePage();

              do {
                // Get custom targeting values by statement.
                valuePage = customTargetingService.getCustomTargetingValuesByStatement(
                    valueStatementBuilder.ToStatement());

                if (valuePage.results != null) {
                  int j = valuePage.startIndex;
                  foreach (CustomTargetingValue value in valuePage.results) {
                    Console.WriteLine("\t{0}) Custom targeting value with ID \"{1}\", name " +
                        "\"{2}\", and display name \"{3}\" was found.", j, value.id, value.name,
                        value.displayName);
                    j++;
                  }
                }
                valueStatementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
              } while (valueStatementBuilder.GetOffset() < valuePage.totalResultSetSize);
              i++;
            }
          }
          keyStatementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (keyStatementBuilder.GetOffset() < keyPage.totalResultSetSize);
        Console.WriteLine("Number of results found: {0}", keyPage.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get custom targeting keys and the values. 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 CreativeService.
              CustomTargetingService customTargetingService =
              (CustomTargetingService) user.GetService(DfpService.v201403.CustomTargetingService);

              // Sets defaults for page and filter.
              CustomTargetingKeyPage keyPage = new CustomTargetingKeyPage();
              Statement keyFilterStatement = new Statement();
              int keyOffset = 0;

              try {
            do {
              // Create a statement to get all custom targeting keys.
              keyFilterStatement.query = "LIMIT 500 OFFSET " + keyOffset;

              // Get custom targeting keys by statement.
              keyPage = customTargetingService.getCustomTargetingKeysByStatement(keyFilterStatement);

              if (keyPage.results != null) {
            int i = keyPage.startIndex;
            foreach (CustomTargetingKey key in keyPage.results) {
              Console.WriteLine("{0}) Custom targeting key with ID \"{1}\", name \"{2}\", " +
                  "display name \"{3}\", and type \"{4}\" was found.", i, key.id, key.name,
                  key.displayName, key.type);

              // Sets defaults for page and filter.
              CustomTargetingValuePage valuePage = new CustomTargetingValuePage();
              Statement valueFilterStatement = new Statement();
              int valueOffset = 0;

              do {
                // Create a statement to get all custom targeting values for a
                // custom targeting key (required) by its ID.
                valueFilterStatement.query = string.Format("WHERE customTargetingKeyId = {0} " +
                    "LIMIT 500 OFFSET {1}", key.id, valueOffset);

                // Get custom targeting values by statement.
                valuePage = customTargetingService.getCustomTargetingValuesByStatement(
                    valueFilterStatement);

                if (valuePage.results != null) {
                  int j = valuePage.startIndex;
                  foreach (CustomTargetingValue value in valuePage.results) {
                    Console.WriteLine("\t{0}) Custom targeting value with ID \"{1}\", name " +
                        "\"{2}\", and display name \"{3}\" was found.", j, value.id, value.name,
                        value.displayName);
                    j++;
                  }
                }
                valueOffset += 500;
              } while (valuePage.results != null && valuePage.results.Length == 500);
              i++;
            }
              }
              keyOffset += 500;
            } while (keyPage.results != null && keyPage.results.Length == 500);
            Console.WriteLine("Number of results found: {0}", keyPage.totalResultSetSize);
              } catch (Exception ex) {
            Console.WriteLine("Failed to get custom targeting keys and the values. Exception " +
            "says \"{0}\"", ex.Message);
              }
        }