Example #1
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            // Get the InventoryService.
            InventoryService inventoryService =
                (InventoryService)user.GetService(DfpService.v201611.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)
                    {
                        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 e) {
                Console.WriteLine("Failed to deactivate ad units. Exception says \"{0}\"", e.Message);
            }
        }
Example #2
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 InventoryService.
            InventoryService inventoryService =
                (InventoryService)user.GetService(DfpService.v201311.InventoryService);

            // Create Statement text to select active ad units.
            string statementText = "WHERE status = :status LIMIT 500";

            Statement statement = new StatementBuilder("").AddValue("status",
                                                                    InventoryStatus.ACTIVE.ToString()).ToStatement();

            // Sets defaults for page and offset.
            AdUnitPage    page      = new AdUnitPage();
            int           offset    = 0;
            List <string> adUnitIds = new List <string>();

            try {
                do
                {
                    // Create a Statement to page through active ad units.
                    statement.query = string.Format("{0} OFFSET {1}", statementText, offset);

                    // Get ad units by Statement.
                    page = inventoryService.getAdUnitsByStatement(statement);

                    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++;
                        }
                    }

                    offset += 500;
                } while (offset < page.totalResultSetSize);

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

                if (adUnitIds.Count > 0)
                {
                    // Create action Statement.
                    statement = new StatementBuilder(
                        string.Format("WHERE id IN ({0})", string.Join(",", adUnitIds.ToArray()))).
                                ToStatement();

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

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

                    // 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);
            }
        }
    /// <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.v201411.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);
      }
    }
        /// <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.v201306.InventoryService);

              // Create Statement text to select active ad units.
              string statementText = "WHERE status = :status LIMIT 500";

              Statement statement = new StatementBuilder("").AddValue("status",
              InventoryStatus.ACTIVE.ToString()).ToStatement();

              // Sets defaults for page and offset.
              AdUnitPage page = new AdUnitPage();
              int offset = 0;
              List<string> adUnitIds = new List<string>();

              try {
            do {
              // Create a Statement to page through active ad units.
              statement.query = string.Format("{0} OFFSET {1}", statementText, offset);

              // Get ad units by Statement.
              page = inventoryService.getAdUnitsByStatement(statement);

              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++;
            }
              }

              offset += 500;
            } while (offset < page.totalResultSetSize);

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

            if (adUnitIds.Count > 0) {
              // Create action Statement.
              statement = new StatementBuilder(
              string.Format("WHERE id IN ({0})", string.Join(",", adUnitIds.ToArray()))).
              ToStatement();

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

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

              // 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);
              }
        }