/// <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 ActivityService. ActivityService activityService = (ActivityService) user.GetService(DfpService.v201502.ActivityService); int totalResultsCounter = 0; try { StatementBuilder statementBuilder = new StatementBuilder() .OrderBy("id ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT); ActivityPage page = new ActivityPage(); do { // Get activities by statement. page = activityService.getActivitiesByStatement(statementBuilder.ToStatement()); // Display results. if (page.results != null) { foreach (Activity activity in page.results) { Console.WriteLine("{0}) Activity with ID \"{1}\", name \"{2}\" and type \"{3}\" " + "was found.\n", totalResultsCounter, activity.id, activity.name, activity.type); totalResultsCounter++; } } statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while (statementBuilder.GetOffset() < page.totalResultSetSize); Console.WriteLine("Number of results found: {0}.", totalResultsCounter); } 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 ActivityService. ActivityService activityService = (ActivityService) user.GetService(DfpService.v201502.ActivityService); // Create a statement to select active activities. StatementBuilder statementBuilder = new StatementBuilder() .Where("status = :status") .OrderBy("id") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("status", ActivityStatus.ACTIVE.ToString()); ActivityPage page = new ActivityPage(); try { do { page = activityService.getActivitiesByStatement(statementBuilder.ToStatement()); // Display results. if (page.results != null) { int i = page.startIndex; foreach (Activity activity in page.results) { Console.WriteLine("{0}) Activity with ID \"{1}\", name \"{2}\", and type \"{3}\" " + "was found.", i, activity.id, activity.name, activity.type); 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 activities. Exception says \"{0}\"", ex.Message); } }