Пример #1
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 TeamService.
      TeamService teamService = (TeamService) user.GetService(DfpService.v201403.TeamService);

      // Set defaults for page and filterStatement.
      TeamPage page = new TeamPage();
      Statement filterStatement = new Statement();
      int offset = 0;

      try {
        do {
          // Create a statement to get all teams.
          filterStatement.query = "LIMIT 500 OFFSET " + offset;

          // Get teams by statement.
          page = teamService.getTeamsByStatement(filterStatement);

          if (page.results != null) {
            int i = page.startIndex;
            foreach (Team team in page.results) {
              Console.WriteLine("{0}) Team with ID \"{1}\", name \"{2}\" was found.",
                  i, team.id, team.name);
              i++;
            }
          }
          offset += 500;
        } while (offset < page.totalResultSetSize);

        Console.WriteLine("Number of results found: " + page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get all teams. 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 TeamService.
      TeamService teamService = (TeamService) user.GetService(DfpService.v201403.TeamService);

      // Create a statement to order teams by name.
      StatementBuilder statementBuilder = new StatementBuilder()
          .OrderBy("name ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

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

      try {
        do {
          // Get teams by statement.
          page = teamService.getTeamsByStatement(statementBuilder.ToStatement());

          // Display results.
          if (page.results != null) {
            int i = page.startIndex;
            foreach (Team team in page.results) {
              Console.WriteLine("{0}) Team with ID \"{1}\" and name \"{2}\" was found.",
                  i, team.id, team.name);
              i++;
            }
          }

          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while(statementBuilder.GetOffset() < page.totalResultSetSize);
      Console.WriteLine("Number of results found: " + page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get teams by statement. Exception says \"{0}\"", ex.Message);
      }
    }