/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public override void Run(DfpUser user) { // Create the CreativeWrapperService. CreativeWrapperService creativeWrapperService = (CreativeWrapperService) user.GetService( DfpService.v201403.CreativeWrapperService); long labelId = long.Parse(_T("INSERT_CREATIVE_WRAPPER_LABEL_ID_HERE")); try { // Create a query to select the active creative wrapper for the given // label. StatementBuilder statementBuilder = new StatementBuilder() .Where ("labelId = :labelId AND status = :status") .OrderBy("id ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("status", CreativeWrapperStatus.ACTIVE.ToString()) .AddValue("labelId", labelId); // Set default for page. CreativeWrapperPage page = new CreativeWrapperPage(); do { page = creativeWrapperService.getCreativeWrappersByStatement(statementBuilder.ToStatement()); CreativeWrapper[] creativeWrappers = page.results; if (creativeWrappers != null) { foreach (CreativeWrapper wrapper in creativeWrappers) { Console.WriteLine("Creative wrapper with ID \'{0}\' applying to label \'{1}\' with " + "status \'{2}\' will be deactivated.", wrapper.id, wrapper.labelId, wrapper.status); } } statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while (statementBuilder.GetOffset() < page.totalResultSetSize); Console.WriteLine("Number of creative wrappers to be deactivated: {0}", page.totalResultSetSize); // Modify statement for action. statementBuilder.RemoveLimitAndOffset(); // Perform action. CreativeWrapperAction action = new DeactivateCreativeWrappers(); UpdateResult result = creativeWrapperService.performCreativeWrapperAction(action, statementBuilder.ToStatement()); // Display results. if (result.numChanges > 0) { Console.WriteLine("Number of creative wrappers deactivated: {0}", result.numChanges); } else { Console.WriteLine("No creative wrappers were deactivated."); } } catch (Exception ex) { Console.WriteLine("Failed to create creative wrappers. 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) { // Create the CreativeWrapperService. CreativeWrapperService creativeWrapperService = (CreativeWrapperService) user.GetService( DfpService.v201403.CreativeWrapperService); // Create a Statement to get all active creative wrappers. StatementBuilder statementBuilder = new StatementBuilder() .Where("status = :status") .OrderBy("id ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("status", CreativeWrapperStatus.ACTIVE.ToString()); // Set default for page. CreativeWrapperPage page = new CreativeWrapperPage(); try { do { // Get creative wrappers by Statement. page = creativeWrapperService.getCreativeWrappersByStatement( statementBuilder.ToStatement()); if (page.results != null && page.results.Length > 0) { int i = page.startIndex; foreach (CreativeWrapper wrapper in page.results) { Console.WriteLine("Creative wrapper with ID \'{0}\' applying to label \'{1}\' with " + "status \'{2}\' was found.", wrapper.id, wrapper.labelId, wrapper.status); 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 active creative wrappers. 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) { // Create the CreativeWrapperService. CreativeWrapperService creativeWrapperService = (CreativeWrapperService) user.GetService( DfpService.v201403.CreativeWrapperService); // Set defaults for page and Statement. CreativeWrapperPage page = new CreativeWrapperPage(); Statement statement = new StatementBuilder("") .AddValue("status", CreativeWrapperStatus.ACTIVE.ToString()) .ToStatement(); int offset = 0; try { do { // Create a Statement to get all active creative wrappers. statement.query = string.Format("WHERE status = :status LIMIT 500 OFFSET {0}", offset); // Get creative wrappers by Statement. page = creativeWrapperService.getCreativeWrappersByStatement(statement); if (page.results != null && page.results.Length > 0) { int i = page.startIndex; foreach (CreativeWrapper wrapper in page.results) { Console.WriteLine("Creative wrapper with ID \'{0}\' applying to label \'{1}\' with " + "status \'{2}\' was found.", wrapper.id, wrapper.labelId, wrapper.status); i++; } } offset += 500; } while (offset < page.totalResultSetSize); Console.WriteLine("Number of results found: {0}", page.totalResultSetSize); } catch (Exception ex) { Console.WriteLine("Failed to get active creative wrappers. Exception says \"{0}\"", ex.Message); } }