/// <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 ContentService.
      ContentService contentService =
          (ContentService) user.GetService(DfpService.v201403.ContentService);

      // Create a statement to get all content.
      StatementBuilder statementBuilder = new StatementBuilder()
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

      // Set default for page.
      ContentPage page = new ContentPage();

      try {
        do {
          // Get content by statement.
          page = contentService.getContentByStatement(statementBuilder.ToStatement());

          if (page.results != null) {
            int i = page.startIndex;
            foreach (Content content in page.results) {
              Console.WriteLine("{0}) Content with ID \"{1}\", name \"{2}\", and status \"{3}\" " +
                  "was found.", i, content.id, content.name, content.status);
              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 all content. 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 CompanyService.
      CompanyService companyService =
          (CompanyService) user.GetService(DfpService.v201403.CompanyService);

      // Set defaults for page and Statement.
      CompanyPage page = new CompanyPage();
      StatementBuilder statementBuilder = new StatementBuilder()
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

      try {
        do {
          // Get companies by Statement.
          page = companyService.getCompaniesByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (Company company in page.results) {
              Console.WriteLine("{0}) Company with ID = {1}, name = {2} and type = {3} was found",
                  i, company.id, company.name, company.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 companies. 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 InventoryService.
      InventoryService inventoryService =
          (InventoryService) user.GetService(DfpService.v201403.InventoryService);

      // Create a Statement to get all ad units.
      StatementBuilder statementBuilder = new StatementBuilder()
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

      // Set default for page.
      AdUnitPage page = new AdUnitPage();

      try {
        do {
          // Get ad units by Statement.
          page = inventoryService.getAdUnitsByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (AdUnit adUnit in page.results) {
              Console.WriteLine("{0}) Ad unit with ID = '{1}', name = '{2}' and status = '{3}' " +
                  "was found.", i, adUnit.id, adUnit.name, adUnit.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 ad unit. 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 CompanyService.
      CompanyService companyService =
          (CompanyService) user.GetService(DfpService.v201403.CompanyService);

      // Create a Statement to only select companies that are advertisers sorted
      // by name.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("type = :advertiser")
          .OrderBy("name ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("advertiser", CompanyType.ADVERTISER.ToString());

      CompanyPage page = new CompanyPage();

      try {
        do {
          // Get companies by Statement.
          page = companyService.getCompaniesByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (Company company in page.results) {
              Console.WriteLine("{0}) Company with ID = {1}, name = {2} and type = {3} was found",
                  i, company.id, company.name, company.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 companies. 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 TeamService.
      TeamService teamService = (TeamService) user.GetService(DfpService.v201403.TeamService);

      // Create a statement to order teams by name.
      StatementBuilder statementBuilder = new StatementBuilder()
          .OrderBy("name ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

      // Set default for page.
      TeamPage page = new TeamPage();

      try {
        do {
          // Get teams by statement.
          page = teamService.getTeamsByStatement(statementBuilder.ToStatement());

          // Display results.
          if (page.results != null) {
            int i = page.startIndex;
            foreach (Team team in page.results) {
              Console.WriteLine("{0}) Team with ID \"{1}\" and name \"{2}\" was found.",
                  i, team.id, team.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 teams by statement. 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 CreativeService.
      CreativeService creativeService =
          (CreativeService) user.GetService(DfpService.v201403.CreativeService);

      // Create a Statement to get all creatives.
      StatementBuilder statementBuilder = new StatementBuilder()
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

      // Set default for page.
      CreativePage page = new CreativePage();

      try {
        do {
          // Get creatives by Statement.
          page = creativeService.getCreativesByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (Creative creative in page.results) {
              Console.WriteLine("{0}) Creative with ID ='{1}', name ='{2}' and type ='{3}' " +
                  "was found.", i, creative.id, creative.name, creative.CreativeType);
              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 all creatives. 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 ActivityGroupService.
      ActivityGroupService activityGroupService =
          (ActivityGroupService) user.GetService(DfpService.v201403.ActivityGroupService);

      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("status = :status")
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("status", ActivityGroupStatus.ACTIVE.ToString());

      // Set default for page.
      ActivityGroupPage page;

      try {
        do {
          // Get contacts by statement.
          page = activityGroupService.getActivityGroupsByStatement(statementBuilder.ToStatement());

          if (page.results != null) {
            int i = page.startIndex;
            foreach (ActivityGroup activityGroup in page.results) {
              Console.WriteLine("{0}) Activity group with ID \"{1}\" and name \"{2}\" was found.",
                  i, activityGroup.id, activityGroup.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 activity groups. 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.v201403.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 UserService.
      UserService userService = (UserService) user.GetService(DfpService.v201403.UserService);

      // Create a Statement to get all active users sorted by name.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("status = :status")
          .OrderBy("name ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("status", "ACTIVE");

      // Set default for page.
      UserPage page = new UserPage();

      try {
        do {
          // Get users by Statement.
          page = userService.getUsersByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (User usr in page.results) {
              Console.WriteLine("{0}) User with ID = '{1}', email = '{2}', and role = '{3}'" +
                " was found.", i, usr.id, usr.email, usr.roleName);
            }
          }
          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 user by ID. Exception says \"{0}\"",
            ex.Message);
      }
    }
Exemplo n.º 10
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 OrderService.
      OrderService orderService = (OrderService) user.GetService(DfpService.v201403.OrderService);

      // Create a Statement to get all orders.
      StatementBuilder statementBuilder = new StatementBuilder()
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

      // Set default for page.
      OrderPage page = new OrderPage();

      try {
        do {
          // Get orders by Statement.
          page = orderService.getOrdersByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (Order order in page.results) {
              Console.WriteLine("{0}) Order with ID = '{1}', name = '{2}', and advertiser " +
                  "ID = '{3}' was found.", i, order.id, order.name, order.advertiserId);
              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 all orders. 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);

      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) {
      // 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 PlacementService.
      PlacementService placementService =
          (PlacementService) user.GetService(DfpService.v201403.PlacementService);

      // Create a Statement to only select active placements.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("status = :status")
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("status", InventoryStatus.ACTIVE.ToString());

      // Set default for page
      PlacementPage page = new PlacementPage();

      try {
        do {
          // Get placements by Statement.
          page = placementService.getPlacementsByStatement(statementBuilder.ToStatement());

          // Display results.
          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}' " +
                "was found.", i, placement.id, placement.name, placement.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 placement by Statement. Exception says \"{0}\"",
            ex.Message);
      }
    }
Exemplo n.º 15
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 LineItemCreativeAssociationService.
      LineItemCreativeAssociationService licaService = (LineItemCreativeAssociationService)
          user.GetService(DfpService.v201403.LineItemCreativeAssociationService);

       // Create a Statement to get all LICAs.
       StatementBuilder statementBuilder = new StatementBuilder()
          .OrderBy("lineItemId ASC, creativeId ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

      // Set default for page.
      LineItemCreativeAssociationPage page = new LineItemCreativeAssociationPage();

      try {
        do {
          // Get LICAs by Statement.
          page = licaService.getLineItemCreativeAssociationsByStatement(
              statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (LineItemCreativeAssociation lica in page.results) {
              Console.WriteLine("{0}) LICA with line item ID = '{1}', creative ID ='{2}' and " +
                  "status ='{3}' was found.", i, lica.lineItemId, lica.creativeId,
                  lica.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 all LICAs. 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(Lib.DfpUser user) {
      // Get the ContentMetadataKeyHierarchy service.
      ContentMetadataKeyHierarchyService contentMetadataKeyHierarchyService =
          (ContentMetadataKeyHierarchyService) user.GetService(
           DfpService.v201403.ContentMetadataKeyHierarchyService);

      // Create a statement to get all content metadata key hierarchies
      StatementBuilder statementBuilder = new StatementBuilder()
        .OrderBy("id ASC")
        .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

      try {
        int totalResultSetSize = 0;
        do {
          // Get content metadata key hierarchies by statement.
          ContentMetadataKeyHierarchyPage page = contentMetadataKeyHierarchyService
              .getContentMetadataKeyHierarchiesByStatement(statementBuilder.ToStatement());

          if (page.results != null) {
            totalResultSetSize = page.totalResultSetSize;
            int i = page.startIndex;
            foreach (ContentMetadataKeyHierarchy contentMetadataKeyHierarchy in page.results) {
              Console.WriteLine("{0}) Content metadata key hierarchy with ID \"{1}\", " +
                  "and name \"{2}\" was found.", i++, contentMetadataKeyHierarchy.id,
                  contentMetadataKeyHierarchy.name);
            }
          }

          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (statementBuilder.GetOffset() < totalResultSetSize);
        Console.WriteLine("Number of results found: {0}", totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get content metadata key hierarchies. 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 CustomFieldService.
      CustomFieldService customFieldService = (CustomFieldService) user.GetService(
          DfpService.v201403.CustomFieldService);

      // Create statement to select only custom fields that apply to line items.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("entityType = :entityType")
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("entityType", CustomFieldEntityType.LINE_ITEM.ToString());

      // Set default for page.
      CustomFieldPage page = new CustomFieldPage();
      int i = 0;

      try {
        do {
          // Get custom fields by statement.
          page = customFieldService.getCustomFieldsByStatement(statementBuilder.ToStatement());

          if (page.results != null) {
            foreach (CustomField customField in page.results) {
              Console.WriteLine("{0}) Custom field with ID \"{1}\" and name \"{2}\" was found.", i,
                  customField.id, customField.name);
              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 all line item custom fields. 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 LineItemService.
      LineItemService lineItemService =
          (LineItemService) user.GetService(DfpService.v201403.LineItemService);

      // Create a Statement to get all line items.
      StatementBuilder statementBuilder = new StatementBuilder()
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

      // Sets default for page.
      LineItemPage page = new LineItemPage();
      try {
        do {
          // Get line items by Statement.
          page = lineItemService.getLineItemsByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (LineItemSummary lineItem in page.results) {
              Console.WriteLine("{0}) Line item with ID = '{1}', belonging to order ID ='{2}'" +
                  " , and named '{3}' was found.", i, lineItem.id, lineItem.orderId,
                  lineItem.name);
              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 line items. 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 AudienceSegmentService.
      AudienceSegmentService audienceSegmentService =
          (AudienceSegmentService) user.GetService(DfpService.v201403.AudienceSegmentService);

      // Create a Statement to get all audience segments.
      StatementBuilder statementBuilder = new StatementBuilder()
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

      // Set default for page.
      AudienceSegmentPage page = new AudienceSegmentPage();

      try {
        do {
          // Get audience segment by Statement.
          page = audienceSegmentService.getAudienceSegmentsByStatement(
              statementBuilder.ToStatement());

          // Display results.
          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (AudienceSegment segment in page.results) {
              Console.WriteLine("{0}) 'Audience segment with id \"{1}\" and name \"{2}\" of " +
                  "size {3} was found.", i, segment.id, segment.name, segment.size);
              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 audience segment. 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.v201403.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);
      }
    }
Exemplo n.º 21
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 OrderService.
      OrderService orderService =
          (OrderService) user.GetService(DfpService.v201403.OrderService);

      // Set the ID of the order.
      long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE"));

      // Create Statement to select the order.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("id = :id")
          .OrderBy("id ASC")
          .Limit(1)
          .AddValue("id", orderId);

      // Set default for page.
      OrderPage page = new OrderPage();
      List<string> orderIds = new List<string>();
      int i = 0;

      try {
        do {
          // Get orders by Statement.
          page = orderService.getOrdersByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            foreach (Order order in page.results) {
              Console.WriteLine("{0}) Order with ID = '{1}', name = '{2}', and status ='{3}' " +
                  "will be approved.", i, order.id, order.name, order.status);
              orderIds.Add(order.id.ToString());
              i++;
            }
          }

          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (statementBuilder.GetOffset() < page.totalResultSetSize);

        Console.WriteLine("Number of orders to be approved: {0}", orderIds.Count);

        if (orderIds.Count > 0) {
          // Modify statement for action.
          statementBuilder.RemoveLimitAndOffset();

          // Create action.
          ApproveAndOverbookOrders action = new ApproveAndOverbookOrders();

          // Perform action.
          UpdateResult result = orderService.performOrderAction(action,
              statementBuilder.ToStatement());

          // Display results.
          if (result != null && result.numChanges > 0) {
            Console.WriteLine("Number of orders approved: {0}", result.numChanges);
          } else {
            Console.WriteLine("No orders were approved.");
          }
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to approve orders. 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 ContentService.
      ContentService contentService =
          (ContentService) user.GetService(DfpService.v201403.ContentService);

      // Get the NetworkService.
      NetworkService networkService = (NetworkService) user.GetService(
          DfpService.v201403.NetworkService);

      // Get the CustomTargetingService.
      CustomTargetingService customTargetingService = (CustomTargetingService) user.GetService(
          DfpService.v201403.CustomTargetingService);

      try {
        // Get content browse custom targeting key ID.
        long contentBrowseCustomTargetingKeyId =
            networkService.getCurrentNetwork().contentBrowseCustomTargetingKeyId;

        // Create a statement to select the categories matching the name comedy.
        Statement categoryFilterStatement = new StatementBuilder()
            .Where("customTargetingKeyId = :contentBrowseCustomTargetingKeyId " +
            " and name = :category")
            .OrderBy("id ASC")
            .Limit(1)
            .AddValue("contentBrowseCustomTargetingKeyId", contentBrowseCustomTargetingKeyId)
            .AddValue("category", "comedy")
            .ToStatement();

        // Get categories matching the filter statement.
        CustomTargetingValuePage customTargetingValuePage =
            customTargetingService.getCustomTargetingValuesByStatement(categoryFilterStatement);

        if (customTargetingValuePage.results != null) {
          // Get the custom targeting value ID for the comedy category.
          long categoryCustomTargetingValueId = customTargetingValuePage.results[0].id;

          // Create a statement to get all active content.
          StatementBuilder statementBuilder = new StatementBuilder()
            .Where("status = :status")
            .OrderBy("id ASC")
            .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
            .AddValue("status", "ACTIVE");

          // Set defaults for page and filterStatement.
          ContentPage page = new ContentPage();

          do {
            // Get content by statement.
            page = contentService.getContentByStatementAndCustomTargetingValue(
                statementBuilder.ToStatement(), categoryCustomTargetingValueId);

            if (page.results != null) {
              int i = page.startIndex;
              foreach (Content content in page.results) {
                Console.WriteLine("{0})  Content with ID \"{1}\", name \"{2}\", and status " +
                    "\"{3}\" was found.", i, content.id, content.name, content.status);
                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 content by category. 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 SuggestedAdUnitService.
      SuggestedAdUnitService suggestedAdUnitService = (SuggestedAdUnitService) user.GetService(
          DfpService.v201403.SuggestedAdUnitService);

      // Set the number of requests for suggested ad units greater than which to approve.
      long NUMBER_OF_REQUESTS = 50L;

      // Create statement to select all suggested ad units that are highly requested.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("numRequests > :numRequests")
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("numRequests", NUMBER_OF_REQUESTS);

      // Set default for page.
      SuggestedAdUnitPage page = new SuggestedAdUnitPage();

      try {
        do {
          // Get suggested ad units by statement.
          page = suggestedAdUnitService.getSuggestedAdUnitsByStatement(
              statementBuilder.ToStatement());

          int i = 0;
          if (page != null && page.results != null) {
            foreach (SuggestedAdUnit suggestedAdUnit in page.results) {
              Console.WriteLine("{0}) Suggested ad unit with ID \"{1}\", and \"{2}\" will be " +
                  "approved.", i, suggestedAdUnit.id, suggestedAdUnit.numRequests);
              i++;
            }
          }
          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while(statementBuilder.GetOffset() < page.totalResultSetSize);

        Console.WriteLine("Number of suggested ad units to be approved: " +
            page.totalResultSetSize);

        // Modify statement for action.
        statementBuilder.RemoveLimitAndOffset();

        // Create action.
        ApproveSuggestedAdUnit action = new ApproveSuggestedAdUnit();

        // Perform action.
        SuggestedAdUnitUpdateResult result = suggestedAdUnitService.performSuggestedAdUnitAction(
            action, statementBuilder.ToStatement());

        // Display results.
        if (result != null && result.numChanges > 0) {
          Console.WriteLine("Number of suggested ad units approved: " + result.numChanges);
        } else {
          Console.WriteLine("No suggested ad units were approved.");
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to approve suggested ad units. 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 CustomTargetingService.
      CustomTargetingService customTargetingService =
          (CustomTargetingService) user.GetService(DfpService.v201403.CustomTargetingService);

      // Create a statement to only select predefined custom targeting keys.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("type = :type")
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("type", CustomTargetingKeyType.PREDEFINED.ToString());

      // Set default for page.
      CustomTargetingKeyPage page = new CustomTargetingKeyPage();

      try {
        do {
          // Get custom targeting keys by statement.
          page = customTargetingService.getCustomTargetingKeysByStatement(
              statementBuilder.ToStatement());

          if (page.results != null) {
            int i = page.startIndex;
            foreach (CustomTargetingKey customTargetingKey in page.results) {
              Console.WriteLine("{0}) Custom targeting key with ID \"{1}\", name \"{2}\", and " +
                  "display name \"{3}\" was found.", i, customTargetingKey.id,
                  customTargetingKey.name, customTargetingKey.displayName);
              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 predefined custom targeting keys. 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 OrderService.
      LineItemService lineItemService = (LineItemService) user.GetService(
          DfpService.v201403.LineItemService);

      long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE"));

      // Create statement to only select line items for the given order that
      // have been modified in the last 3 days.
      DateTime threeDaysAgo = DateTimeUtilities.FromDateTime(System.DateTime.Now.AddDays(-3));
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("lastModifiedDateTime >= :lastModifiedDateTime AND orderId = :orderId")
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("lastModifiedDateTime", threeDaysAgo)
          .AddValue("orderId", orderId);

      // Set default for page.
      LineItemPage page = new LineItemPage();

      try {
        do {
          // Get line items by statement.
          page = lineItemService.getLineItemsByStatement(statementBuilder.ToStatement());

          // Display results.
          if (page != null && page.results != null) {
            foreach (LineItem lineItem in page.results) {
              Console.WriteLine("Line item with id \"{0}\", belonging to order id \"{1}\" and " +
                  "named \"{2}\" was found.", lineItem.id, lineItem.orderId, lineItem.name);
            }
          }
          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while(statementBuilder.GetOffset() < page.totalResultSetSize);

        Console.WriteLine("Number of results found: {1}.", page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get line items. 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 LabelService.
      LabelService labelService =
          (LabelService) user.GetService(DfpService.v201403.LabelService);

      // Set the ID of the label to deactivate.
      int labelId = int.Parse(_T("INSERT_LABEL_ID_HERE"));

      // Create statement text to select the label.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("id = :id")
          .OrderBy("id ASC")
          .Limit(1)
          .AddValue("id", labelId);

      // Set default for page.
      LabelPage page = new LabelPage();

      try {
        do {
          // Get labels by statement.
          page = labelService.getLabelsByStatement(statementBuilder.ToStatement());

          if (page.results != null) {
            int i = page.startIndex;
            foreach (Label label in page.results) {
              Console.WriteLine("{0}) Label with ID '{1}', name '{2}' will be deactivated.",
                  i, label.id, label.name);
              i++;
            }
          }
          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (statementBuilder.GetOffset() < page.totalResultSetSize);

        Console.WriteLine("Number of labels to be deactivated: " + page.totalResultSetSize);

        // Modify statement for action.
        statementBuilder.RemoveLimitAndOffset();

        // Create action.
        DeactivateLabels action = new DeactivateLabels();

        // Perform action.
        UpdateResult result = labelService.performLabelAction(action,
            statementBuilder.ToStatement());

        // Display results.
        if (result != null && result.numChanges > 0) {
          Console.WriteLine("Number of labels deactivated: " + result.numChanges);
        } else {
          Console.WriteLine("No labels were deactivated.");
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to deactivate labels. 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 LineItemService.
      LineItemService lineItemService =
          (LineItemService) user.GetService(DfpService.v201403.LineItemService);

      // Set the ID of the order to get line items from.
      long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE"));

      // Create a statement to only select line items that need creatives from a
      // given order.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("orderId = :orderId AND status = :status")
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("orderId", orderId)
          .AddValue("status", ComputedStatus.NEEDS_CREATIVES.ToString());

      // Set default for page.
      LineItemPage page = new LineItemPage();

      try {
        do {
          // Get line items by Statement.
          page = lineItemService.getLineItemsByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (LineItem lineItem in page.results) {
              Console.WriteLine("{0}) Line item with ID ='{1}', belonging to order ID = '{2}' " +
                   "and named '{3}' was found.", i, lineItem.id, lineItem.orderId, lineItem.name);
              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 line item by Statement. 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 LineItemService.
      LineItemService lineItemService =
          (LineItemService) user.GetService(DfpService.v201403.LineItemService);

      // Set the ID of the order to get line items from.
      long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE"));

      // Create Statement to select approved line items from a given order.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("orderId = :orderId and status = :status")
          .AddValue("orderId", orderId)
          .AddValue("status", ComputedStatus.NEEDS_CREATIVES.ToString());

      // Set default for page.
      LineItemPage page = new LineItemPage();
      List<string> lineItemIds = new List<string>();

      try {
        do {
          // Get line items by Statement.
          page = lineItemService.getLineItemsByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (LineItemSummary lineItem in page.results) {
              // Archived line items cannot be activated.
              if (!lineItem.isArchived) {
                Console.WriteLine("{0}) Line item with ID ='{1}', belonging to order ID ='{2}' " +
                    "and name ='{2}' will be activated.", i, lineItem.id, lineItem.orderId,
                    lineItem.name);
                lineItemIds.Add(lineItem.id.ToString());
                i++;
              }
            }
          }

          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (statementBuilder.GetOffset() < page.totalResultSetSize);


        Console.WriteLine("Number of line items to be activated: {0}", lineItemIds.Count);

        if (lineItemIds.Count > 0) {
          // Modify Statement.
          statementBuilder.RemoveLimitAndOffset();

          // Create action.
          ActivateLineItems action = new ActivateLineItems();

          // Perform action.
          UpdateResult result = lineItemService.performLineItemAction(action,
              statementBuilder.ToStatement());

          // Display results.
          if (result != null && result.numChanges > 0) {
            Console.WriteLine("Number of line items activated: {0}", result.numChanges);
          } else {
            Console.WriteLine("No line items were activated.");
          }
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to activate line items. 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 LineItemCreativeAssociationService.
      LineItemCreativeAssociationService licaService = (LineItemCreativeAssociationService)
          user.GetService(DfpService.v201403.LineItemCreativeAssociationService);

      // Set the line item to get LICAs by.
      long lineItemId = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE"));

      // Create a Statement to page through active LICAs.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("lineItemId = :lineItemId")
          .OrderBy("lineItemId ASC, creativeId ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("lineItemId", lineItemId);

      // Set default for page.
      LineItemCreativeAssociationPage page = new LineItemCreativeAssociationPage();
      List<string> creativeIds = new List<string>();

      try {
        do {
          // Get LICAs by Statement.
          page = licaService.getLineItemCreativeAssociationsByStatement(
              statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (LineItemCreativeAssociation lica in page.results) {
              Console.WriteLine("{0}) LICA with line item ID = '{1}', creative ID ='{2}' and " +
                  "status ='{3}' will be deactivated.", i, lica.lineItemId, lica.creativeId,
                  lica.status);
              i++;
              creativeIds.Add(lica.creativeId.ToString());
            }
          }

          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (statementBuilder.GetOffset() < page.totalResultSetSize);

        Console.WriteLine("Number of LICAs to be deactivated: {0}", creativeIds.Count);

        if (creativeIds.Count > 0) {
          // Modify statement for action.
          statementBuilder.RemoveLimitAndOffset();

          // Create action.
          DeactivateLineItemCreativeAssociations action =
              new DeactivateLineItemCreativeAssociations();

          // Perform action.
          UpdateResult result = licaService.performLineItemCreativeAssociationAction(action,
              statementBuilder.ToStatement());

          // Display results.
          if (result != null && result.numChanges > 0) {
            Console.WriteLine("Number of LICAs deactivated: {0}", result.numChanges);
          } else {
            Console.WriteLine("No LICAs were deactivated.");
          }
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to deactivate LICAs. 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 InventoryService.
      InventoryService inventoryService =
          (InventoryService) user.GetService(DfpService.v201403.InventoryService);

      // Set the ID of the ad unit to deactivate.
      int adUnitId = int.Parse(_T("INSERT_AD_UNIT_ID_HERE"));

      // Create a statement to select the ad unit.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("id = :id")
          .OrderBy("id ASC")
          .Limit(1)
          .AddValue("id", adUnitId);

      // Set default for page.
      AdUnitPage page = new AdUnitPage();
      List<string> adUnitIds = new List<string>();

      try {
        do {
          // Get ad units by Statement.
          page = inventoryService.getAdUnitsByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (AdUnit adUnit in page.results) {
              Console.WriteLine("{0}) Ad unit with ID ='{1}', name = {2} and status = {3} will" +
                  " be deactivated.", i, adUnit.id, adUnit.name, adUnit.status);
              adUnitIds.Add(adUnit.id);
              i++;
            }
          }

          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (statementBuilder.GetOffset() < page.totalResultSetSize);

        Console.WriteLine("Number of ad units to be deactivated: {0}", adUnitIds.Count);

        // Modify statement for action.
        statementBuilder.RemoveLimitAndOffset();

        // Create action.
        DeactivateAdUnits action = new DeactivateAdUnits();

        // Perform action.
        UpdateResult result = inventoryService.performAdUnitAction(action,
            statementBuilder.ToStatement());

        // Display results.
        if (result != null && result.numChanges > 0) {
          Console.WriteLine("Number of ad units deactivated: {0}", result.numChanges);
        } else {
          Console.WriteLine("No ad units were deactivated.");
        }

      } catch (Exception ex) {
        Console.WriteLine("Failed to deactivate ad units. Exception says \"{0}\"", ex.Message);
      }
    }