public void TestPerformPlacementAction() { Statement statement = new Statement(); statement.query = string.Format("WHERE status = '{0}'", InventoryStatus.ACTIVE); DeactivatePlacements action = new DeactivatePlacements(); UpdateResult result = null; Assert.DoesNotThrow(delegate() { result = placementService.performPlacementAction(action, statement); }); Assert.NotNull(result); Assert.GreaterOrEqual(result.numChanges, 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 PlacementService. PlacementService placementService = (PlacementService) user.GetService(DfpService.v201408.PlacementService); // Create Statement to select active placements. StatementBuilder statementBuilder = new StatementBuilder() .Where("status = :status") .OrderBy("id ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("status", InventoryStatus.ACTIVE.ToString()); // Sets default for page. PlacementPage page = new PlacementPage(); List<string> placementIds = new List<string>(); try { do { // Get placements by Statement. page = placementService.getPlacementsByStatement(statementBuilder.ToStatement()); if (page.results != null && page.results.Length > 0) { int i = page.startIndex; foreach (Placement placement in page.results) { Console.WriteLine("{0}) Placement with ID ='{1}', name ='{2}', and status ='{3}'" + " will be deactivated.", i, placement.id, placement.name, placement.status); placementIds.Add(placement.id.ToString()); i++; } } statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while (statementBuilder.GetOffset() < page.totalResultSetSize); Console.WriteLine("Number of placements to be deactivated: {0}", placementIds.Count); if (placementIds.Count > 0) { // Modify statement for action. statementBuilder.RemoveLimitAndOffset(); // Create action. DeactivatePlacements action = new DeactivatePlacements(); // Perform action. UpdateResult result = placementService.performPlacementAction(action, statementBuilder.ToStatement()); // Display results. if (result != null && result.numChanges > 0) { Console.WriteLine("Number of placements deactivated: {0}", result.numChanges); } else { Console.WriteLine("No placements were deactivated."); } } } catch (Exception ex) { Console.WriteLine("Failed to deactivate placements. Exception says \"{0}\"", ex.Message); } }
/// <summary> /// Run the code example. /// </summary> public void Run(AdManagerUser user) { using (PlacementService placementService = user.GetService <PlacementService>()) { // Create statement to select active placements. StatementBuilder statementBuilder = new StatementBuilder() .Where("status = :status") .OrderBy("id ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("status", InventoryStatus.ACTIVE.ToString()); // Sets default for page. PlacementPage page = new PlacementPage(); List <string> placementIds = new List <string>(); try { do { // Get placements by statement. page = placementService.getPlacementsByStatement(statementBuilder .ToStatement()); if (page.results != null) { int i = page.startIndex; foreach (Placement placement in page.results) { Console.WriteLine( "{0}) Placement with ID ='{1}', name ='{2}', and " + "status ='{3}' will be deactivated.", i, placement.id, placement.name, placement.status); placementIds.Add(placement.id.ToString()); i++; } } statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while (statementBuilder.GetOffset() < page.totalResultSetSize); Console.WriteLine("Number of placements to be deactivated: {0}", placementIds.Count); if (placementIds.Count > 0) { // Modify statement for action. statementBuilder.RemoveLimitAndOffset(); // Create action. DeactivatePlacements action = new DeactivatePlacements(); // Perform action. UpdateResult result = placementService.performPlacementAction(action, statementBuilder.ToStatement()); // Display results. if (result != null && result.numChanges > 0) { Console.WriteLine("Number of placements deactivated: {0}", result.numChanges); } else { Console.WriteLine("No placements were deactivated."); } } } catch (Exception e) { Console.WriteLine("Failed to deactivate placements. Exception says \"{0}\"", e.Message); } } }
public void TestPerformPlacementAction() { Statement statement = new Statement(); statement.query = string.Format("WHERE status = '{0}'", InventoryStatus.ACTIVE); DeactivatePlacements action = new DeactivatePlacements(); UpdateResult result = null; Assert.DoesNotThrow(delegate() { result = placementService.performPlacementAction(action, statement); }); Assert.NotNull(result); Assert.GreaterOrEqual(result.numChanges, 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 PlacementService. PlacementService placementService = (PlacementService) user.GetService(DfpService.v201308.PlacementService); // Create Statement text to select active placements. String statementText = "WHERE status = :status LIMIT 500"; Statement statement = new StatementBuilder("").AddValue("status", InventoryStatus.ACTIVE.ToString()).ToStatement(); // Sets defaults for page and offset. PlacementPage page = new PlacementPage(); int offset = 0; List<string> placementIds = new List<string>(); try { do { // Create a Statement to page through active placements. statement.query = string.Format("{0} OFFSET {1}", statementText, offset); // Get placements by Statement. page = placementService.getPlacementsByStatement(statement); if (page.results != null && page.results.Length > 0) { int i = page.startIndex; foreach (Placement placement in page.results) { Console.WriteLine("{0}) Placement with ID ='{1}', name ='{2}', and status ='{3}'" + " will be deactivated.", i, placement.id, placement.name, placement.status); placementIds.Add(placement.id.ToString()); i++; } } offset += 500; } while (offset < page.totalResultSetSize); Console.WriteLine("Number of placements to be deactivated: {0}", placementIds.Count); if (placementIds.Count > 0) { // Create action Statement. statement = new StatementBuilder( string.Format("WHERE id IN ({0})", string.Join(",", placementIds.ToArray()))). ToStatement(); // Create action. DeactivatePlacements action = new DeactivatePlacements(); // Perform action. UpdateResult result = placementService.performPlacementAction(action, statement); // Display results. if (result != null && result.numChanges > 0) { Console.WriteLine("Number of placements deactivated: {0}", result.numChanges); } else { Console.WriteLine("No placements were deactivated."); } } } catch (Exception ex) { Console.WriteLine("Failed to deactivate placements. 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 PlacementService. PlacementService placementService = (PlacementService)user.GetService(DfpService.v201311.PlacementService); // Create Statement text to select active placements. String statementText = "WHERE status = :status LIMIT 500"; Statement statement = new StatementBuilder("").AddValue("status", InventoryStatus.ACTIVE.ToString()).ToStatement(); // Sets defaults for page and offset. PlacementPage page = new PlacementPage(); int offset = 0; List <string> placementIds = new List <string>(); try { do { // Create a Statement to page through active placements. statement.query = string.Format("{0} OFFSET {1}", statementText, offset); // Get placements by Statement. page = placementService.getPlacementsByStatement(statement); if (page.results != null && page.results.Length > 0) { int i = page.startIndex; foreach (Placement placement in page.results) { Console.WriteLine("{0}) Placement with ID ='{1}', name ='{2}', and status ='{3}'" + " will be deactivated.", i, placement.id, placement.name, placement.status); placementIds.Add(placement.id.ToString()); i++; } } offset += 500; } while (offset < page.totalResultSetSize); Console.WriteLine("Number of placements to be deactivated: {0}", placementIds.Count); if (placementIds.Count > 0) { // Create action Statement. statement = new StatementBuilder( string.Format("WHERE id IN ({0})", string.Join(",", placementIds.ToArray()))). ToStatement(); // Create action. DeactivatePlacements action = new DeactivatePlacements(); // Perform action. UpdateResult result = placementService.performPlacementAction(action, statement); // Display results. if (result != null && result.numChanges > 0) { Console.WriteLine("Number of placements deactivated: {0}", result.numChanges); } else { Console.WriteLine("No placements were deactivated."); } } } catch (Exception ex) { Console.WriteLine("Failed to deactivate placements. Exception says \"{0}\"", ex.Message); } }