/// <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 ContactService. ContactService contactService = (ContactService) user.GetService(DfpService.v201403.ContactService); // Create a statement to get all contacts. StatementBuilder statementBuilder = new StatementBuilder() .OrderBy("id ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT); // Set default for page. ContactPage page = new ContactPage(); try { do { // Get contacts by statement. page = contactService.getContactsByStatement(statementBuilder.ToStatement()); if (page.results != null) { int i = page.startIndex; foreach (Contact contact in page.results) { Console.WriteLine("{0}) Contact with ID \"{1}\" and name \"{2}\" was found.", i, contact.id, contact.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 contacts. 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 ContactService. ContactService contactService = (ContactService) user.GetService(DfpService.v201403.ContactService); Statement filterStatement = new StatementBuilder("").AddValue( "status", ContactStatus.UNINVITED.ToString()).ToStatement(); // Set defaults for page and filterStatement. ContactPage page = new ContactPage(); int offset = 0; try { do { // Create a statement to get all contacts. filterStatement.query = "where status = :status LIMIT 500 OFFSET " + offset.ToString(); // Get contacts by statement. page = contactService.getContactsByStatement(filterStatement); if (page.results != null) { int i = page.startIndex; foreach (Contact contact in page.results) { Console.WriteLine("{0}) Contact with ID \"{1}\" and name \"{2}\" was found.", i, contact.id, contact.name); i++; } } offset += 500; } while (offset < page.totalResultSetSize); Console.WriteLine("Number of results found: " + page.totalResultSetSize); } catch (Exception ex) { Console.WriteLine("Failed to get contacts. Exception says \"{0}\"", ex.Message); } }