/// <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 CreativeTemplateService. CreativeTemplateService creativeTemplateService = (CreativeTemplateService) user.GetService(DfpService.v201403.CreativeTemplateService); // Create a statement to only select system defined creative templates. StatementBuilder statementBuilder = new StatementBuilder() .Where("type = :creativeTemplateType") .OrderBy("id ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("creativeTemplateType", CreativeTemplateType.SYSTEM_DEFINED.ToString()); // Set default for page. CreativeTemplatePage page = new CreativeTemplatePage(); try { do { // Get creative templates by statement. page = creativeTemplateService.getCreativeTemplatesByStatement( statementBuilder.ToStatement()); if (page.results != null) { int i = page.startIndex; foreach (CreativeTemplate creativeTemplate in page.results) { Console.WriteLine("{0}) Creative template with ID \"{1}\", name \"{2}\", and type " + "\"{3}\" was found.", i, creativeTemplate.id, creativeTemplate.name, creativeTemplate.type); 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 creative templates. 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 CreativeTemplateService. CreativeTemplateService creativeTemplateService = (CreativeTemplateService) user.GetService(DfpService.v201403.CreativeTemplateService); // Set defaults for page and filterStatement. CreativeTemplatePage page = new CreativeTemplatePage(); Statement filterStatement = new Statement(); int offset = 0; try { do { // Create a statement to get all creative templates. filterStatement.query = "LIMIT 500 OFFSET " + offset.ToString(); // Get creative templates by statement. page = creativeTemplateService.getCreativeTemplatesByStatement(filterStatement); if (page.results != null) { int i = page.startIndex; foreach (CreativeTemplate creativeTemplate in page.results) { Console.WriteLine("{0}) Creative template with ID \"{1}\", name \"{2}\", and type " + "\"{3}\" was found.", i, creativeTemplate.id, creativeTemplate.name, creativeTemplate.type); i++; } } offset += 500; } while (offset < page.totalResultSetSize); Console.WriteLine("Number of results found: " + page.totalResultSetSize); } catch (Exception ex) { Console.WriteLine("Failed to get all creative templates. Exception says \"{0}\"", ex.Message); } }