コード例 #1
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.v201211.LineItemCreativeAssociationService);

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

              String statementText = "WHERE lineItemId = :lineItemId and status = :status LIMIT 500";
              Statement statement = new StatementBuilder("").AddValue("lineItemId", lineItemId).
              AddValue("status", LineItemCreativeAssociationStatus.INACTIVE.ToString()).ToStatement();

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

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

              // Get LICAs by Statement.
              page = licaService.getLineItemCreativeAssociationsByStatement(statement);

              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 activated.", i, lica.lineItemId, lica.creativeId,
                  lica.status);
              i++;
              creativeIds.Add(lica.creativeId.ToString());
            }
              }

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

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

            if (creativeIds.Count > 0) {
              // Create action Statement.
              statement = new StatementBuilder(
              string.Format("WHERE lineItemId = :lineItemId and creativeId IN ({0})",
                  string.Join(",", creativeIds.ToArray()))).
              AddValue("lineItemId", lineItemId).ToStatement();

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

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

              // Display results.
              if (result != null && result.numChanges > 0) {
            Console.WriteLine("Number of LICAs activated: {0}", result.numChanges);
              } else {
            Console.WriteLine("No LICAs were activated.");
              }
            }
              } catch (Exception ex) {
            Console.WriteLine("Failed to activate LICAs. Exception says \"{0}\"", ex.Message);
              }
        }
コード例 #2
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(AdManagerUser user)
        {
            using (LineItemCreativeAssociationService licaService =
                       user.GetService <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 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)
                        {
                            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 activated.", 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 activated: {0}", creativeIds.Count);

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

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

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

                        // Display results.
                        if (result != null && result.numChanges > 0)
                        {
                            Console.WriteLine("Number of LICAs activated: {0}", result.numChanges);
                        }
                        else
                        {
                            Console.WriteLine("No LICAs were activated.");
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to activate LICAs. Exception says \"{0}\"",
                                      e.Message);
                }
            }
        }
コード例 #3
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.v201405.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 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 activated.", 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 activated: {0}", creativeIds.Count);

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

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

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

          // Display results.
          if (result != null && result.numChanges > 0) {
            Console.WriteLine("Number of LICAs activated: {0}", result.numChanges);
          } else {
            Console.WriteLine("No LICAs were activated.");
          }
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to activate LICAs. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #4
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.v201311.LineItemCreativeAssociationService);

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

            String    statementText = "WHERE lineItemId = :lineItemId and status = :status LIMIT 500";
            Statement statement     = new StatementBuilder("").AddValue("lineItemId", lineItemId).
                                      AddValue("status", LineItemCreativeAssociationStatus.INACTIVE.ToString()).ToStatement();

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

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

                    // Get LICAs by Statement.
                    page = licaService.getLineItemCreativeAssociationsByStatement(statement);

                    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 activated.", i, lica.lineItemId, lica.creativeId,
                                              lica.status);
                            i++;
                            creativeIds.Add(lica.creativeId.ToString());
                        }
                    }

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

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

                if (creativeIds.Count > 0)
                {
                    // Create action Statement.
                    statement = new StatementBuilder(
                        string.Format("WHERE lineItemId = :lineItemId and creativeId IN ({0})",
                                      string.Join(",", creativeIds.ToArray()))).
                                AddValue("lineItemId", lineItemId).ToStatement();

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

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

                    // Display results.
                    if (result != null && result.numChanges > 0)
                    {
                        Console.WriteLine("Number of LICAs activated: {0}", result.numChanges);
                    }
                    else
                    {
                        Console.WriteLine("No LICAs were activated.");
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to activate LICAs. Exception says \"{0}\"", ex.Message);
            }
        }