/// <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.v201311.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 get line items with even delivery rates.
            Statement statement = new StatementBuilder("WHERE deliveryRateType = :deliveryRateType and " +
                                                       "orderId = :orderId LIMIT 500").AddValue("deliveryRateType",
                                                                                                DeliveryRateType.EVENLY.ToString()).AddValue("orderId", orderId).ToStatement();

            try {
                // Get line items by Statement.
                LineItemPage page = lineItemService.getLineItemsByStatement(statement);

                if (page.results != null && page.results.Length > 0)
                {
                    LineItem[]      lineItems         = page.results;
                    List <LineItem> lineItemsToUpdate = new List <LineItem>();

                    // Update each local line item object by changing its delivery rate.
                    foreach (LineItem lineItem in lineItems)
                    {
                        // Archived line items cannot be updated.
                        if (!lineItem.isArchived)
                        {
                            lineItem.deliveryRateType = DeliveryRateType.AS_FAST_AS_POSSIBLE;
                            lineItemsToUpdate.Add(lineItem);
                        }
                    }

                    // Update the line items on the server.
                    lineItems = lineItemService.updateLineItems(lineItemsToUpdate.ToArray());

                    if (lineItems != null)
                    {
                        foreach (LineItem lineItem in lineItems)
                        {
                            Console.WriteLine("A line item with ID = '{0}', belonging to order ID = '{1}', " +
                                              "named '{2}', and having delivery rate = '{3}' was updated.",
                                              lineItem.id, lineItem.orderId, lineItem.name, lineItem.deliveryRateType);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No line items updated.");
                    }
                }
                else
                {
                    Console.WriteLine("No line items found to update.");
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to update line items. Exception says \"{0}\"",
                                  ex.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            using (LineItemService lineItemService =
                       (LineItemService)user.GetService(DfpService.v201802.LineItemService))
            {
                // Set the ID of the line item.
                long lineItemId = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE"));

                // Create a statement to get the line item.
                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .Where("id = :lineItemId")
                                                    .OrderBy("id ASC")
                                                    .Limit(1)
                                                    .AddValue("lineItemId", lineItemId);

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

                    LineItem lineItem = page.results[0];

                    // Update line item object by changing its delivery rate.
                    lineItem.deliveryRateType = DeliveryRateType.AS_FAST_AS_POSSIBLE;

                    // Update the line item on the server.
                    LineItem[] lineItems = lineItemService.updateLineItems(new LineItem[]
                    {
                        lineItem
                    });

                    if (lineItems != null)
                    {
                        foreach (LineItem updatedLineItem in lineItems)
                        {
                            Console.WriteLine(
                                "A line item with ID = '{0}', belonging to order ID = '{1}', " +
                                "named '{2}', and having delivery rate = '{3}' was updated.",
                                updatedLineItem.id, updatedLineItem.orderId, updatedLineItem.name,
                                updatedLineItem.deliveryRateType);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No line items updated.");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to update line items. Exception says \"{0}\"",
                                      e.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.v201511.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), "America/New_York");
            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 e) {
                Console.WriteLine("Failed to get line items. Exception says \"{0}\"", e.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 LineItemService.
            LineItemService lineItemService =
                (LineItemService)user.GetService(DfpService.v201405.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 void Run(DfpUser dfpUser)
        {
            LineItemService lineItemService =
                (LineItemService)dfpUser.GetService(DfpService.v201702.LineItemService);

            // Create a statement to select line items.
            int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT;
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("lastModifiedDateTime >= :lastModifiedDateTime")
                                                .OrderBy("id ASC")
                                                .Limit(pageSize)
                                                .AddValue("lastModifiedDateTime",
                                                          DateTimeUtilities.FromDateTime(System.DateTime.Now.AddDays(-1), "America/New_York"));

            // Retrieve a small amount of line items at a time, paging through until all
            // line items have been retrieved.
            int totalResultSetSize = 0;

            do
            {
                LineItemPage page = lineItemService.getLineItemsByStatement(
                    statementBuilder.ToStatement());

                // Print out some information for each line item.
                if (page.results != null)
                {
                    totalResultSetSize = page.totalResultSetSize;
                    int i = page.startIndex;
                    foreach (LineItem lineItem in page.results)
                    {
                        Console.WriteLine(
                            "{0}) Line item with ID {1} and name \"{2}\" was found.",
                            i++,
                            lineItem.id,
                            lineItem.name
                            );
                    }
                }

                statementBuilder.IncreaseOffsetBy(pageSize);
            } while (statementBuilder.GetOffset() < totalResultSetSize);

            Console.WriteLine("Number of results found: {0}", totalResultSetSize);
        }
Пример #6
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            LineItemService lineItemService =
                (LineItemService)user.GetService(DfpService.v201608.LineItemService);

            // Create a statement to select line items.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("lastModifiedDateTime >= :lastModifiedDateTime")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("lastModifiedDateTime",
                                                          DateTimeUtilities.FromDateTime(System.DateTime.Now.AddDays(-1), "America/New_York"));

            // Retrieve a small amount of line items at a time, paging through
            // until all line items have been retrieved.
            LineItemPage page = new LineItemPage();

            try {
                do
                {
                    page = lineItemService.getLineItemsByStatement(statementBuilder.ToStatement());

                    if (page.results != null)
                    {
                        // Print out some information for each line item.
                        int i = page.startIndex;
                        foreach (LineItem lineItem in page.results)
                        {
                            Console.WriteLine("{0}) Line item with ID \"{1}\" and name \"{2}\" was found.",
                                              i++,
                                              lineItem.id,
                                              lineItem.name);
                        }
                    }

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

                Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
            } catch (Exception e) {
                Console.WriteLine("Failed to get line items. Exception says \"{0}\"",
                                  e.Message);
            }
        }
        public void TestGetLineItemsByStatement()
        {
            Statement statement = new Statement();

            statement.query = string.Format("WHERE id = '{0}' LIMIT 1", lineItem1.id);

            LineItemPage page = null;

            Assert.DoesNotThrow(delegate() {
                page = lineItemService.getLineItemsByStatement(statement);
            });

            Assert.NotNull(page);
            Assert.AreEqual(page.totalResultSetSize, 1);
            Assert.NotNull(page.results);
            Assert.AreEqual(page.results[0].id, lineItem1.id);
            Assert.AreEqual(page.results[0].name, lineItem1.name);
            Assert.AreEqual(page.results[0].orderId, lineItem1.orderId);
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser dfpUser)
        {
            using (LineItemService lineItemService =
                       (LineItemService)dfpUser.GetService(DfpService.v201805.LineItemService)) {
                // Create a statement to select line items.
                int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT;
                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .Where("isMissingCreatives = :isMissingCreatives")
                                                    .OrderBy("id ASC")
                                                    .Limit(pageSize)
                                                    .AddValue("isMissingCreatives", true);

                // Retrieve a small amount of line items at a time, paging through until all
                // line items have been retrieved.
                int totalResultSetSize = 0;
                do
                {
                    LineItemPage page = lineItemService.getLineItemsByStatement(
                        statementBuilder.ToStatement());

                    // Print out some information for each line item.
                    if (page.results != null)
                    {
                        totalResultSetSize = page.totalResultSetSize;
                        int i = page.startIndex;
                        foreach (LineItem lineItem in page.results)
                        {
                            Console.WriteLine(
                                "{0}) Line item with ID {1} and name \"{2}\" was found.",
                                i++,
                                lineItem.id,
                                lineItem.name
                                );
                        }
                    }

                    statementBuilder.IncreaseOffsetBy(pageSize);
                } while (statementBuilder.GetOffset() < totalResultSetSize);

                Console.WriteLine("Number of results found: {0}", totalResultSetSize);
            }
        }
        /// <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.v201311.LineItemService);

            // Sets defaults for page and Statement.
            LineItemPage page      = new LineItemPage();
            Statement    statement = new Statement();
            int          offset    = 0;

            try {
                do
                {
                    // Create a Statement to get all line items.
                    statement.query = string.Format("LIMIT 500 OFFSET {0}", offset);

                    // Get line items by Statement.
                    page = lineItemService.getLineItemsByStatement(statement);

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

                    offset += 500;
                } while (offset < 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 LineItemService.
      LineItemService lineItemService =
          (LineItemService) user.GetService(DfpService.v201511.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 isMissingCreatives = :isMissingCreatives")
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("orderId", orderId)
          .AddValue("isMissingCreatives", true);

      // 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 e) {
        Console.WriteLine("Failed to get line item by statement. Exception says \"{0}\"",
            e.Message);
      }
    }
Пример #11
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 LineItemService.
            LineItemService lineItemService =
                (LineItemService)user.GetService(DfpService.v201602.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 e) {
                Console.WriteLine("Failed to get line items. Exception says \"{0}\"",
                                  e.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.v201511.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), "America/New_York");
      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 e) {
        Console.WriteLine("Failed to get line items. Exception says \"{0}\"", e.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.v201311.LineItemService);

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

            try {
                // 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));
                Statement filterStatement = new StatementBuilder(
                    "WHERE lastModifiedDateTime >= :lastModifiedDateTime AND orderId = :orderId LIMIT 500").
                                            AddValue("lastModifiedDateTime", threeDaysAgo).
                                            AddValue("orderId", orderId).ToStatement();


                // Get line items by statement.
                LineItemPage page = lineItemService.getLineItemsByStatement(filterStatement);

                // 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);
                    }
                    Console.WriteLine("Number of results found: {1}.", page.totalResultSetSize);
                }
                else
                {
                    Console.WriteLine("No line items were found.");
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to get line items. Exception says \"{0}\"", ex.Message);
            }
        }
Пример #14
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 LineItemService.
            LineItemService lineItemService =
                (LineItemService)user.GetService(DfpService.v201311.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.
            Statement filterStatement =
                new StatementBuilder("WHERE orderId = :orderId AND status = :status LIMIT 500")
                .AddValue("orderId", orderId)
                .AddValue("status", ComputedStatus.NEEDS_CREATIVES.ToString())
                .ToStatement();

            try {
                // Get line items by Statement.
                LineItemPage page = lineItemService.getLineItemsByStatement(filterStatement);

                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++;
                    }
                }
                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.v201508.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 e) {
        Console.WriteLine("Failed to get line items. Exception says \"{0}\"",
            e.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.v201511.LineItemService);
      // Get the ReportService.
      ReportService reportService =
          (ReportService) user.GetService(DfpService.v201511.ReportService);

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

        // Set the file path where the report will be saved.
        String filePath = _T("INSERT_FILE_PATH_HERE");

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

        // Create a statement to only select line items from a given order.
        StatementBuilder statementBuilder = new StatementBuilder()
            .Where("orderId = :orderId")
            .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
            .AddValue("orderId", orderId);


        // Collect all line item custom field IDs for an order.
        List<long> customFieldIds = new List<long>();
        do {
          // Get line items by statement.
          page = lineItemService.getLineItemsByStatement(statementBuilder.ToStatement());

          // Get custom field IDs from the line items of an order.
          if (page.results != null) {
            foreach (LineItem lineItem in page.results) {
              if (lineItem.customFieldValues != null) {
                foreach (BaseCustomFieldValue customFieldValue in lineItem.customFieldValues) {
                  if (!customFieldIds.Contains(customFieldValue.customFieldId)) {
                    customFieldIds.Add(customFieldValue.customFieldId);
                  }
                }
              }
            }
          }

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


        // Create statement to filter for an order.
        statementBuilder.RemoveLimitAndOffset();

        // Create report job.
        ReportJob reportJob = new ReportJob();

        // Create report query.
        ReportQuery reportQuery = new ReportQuery();
        reportQuery.dateRangeType = DateRangeType.LAST_MONTH;
        reportQuery.dimensions = new Dimension[] {Dimension.LINE_ITEM_ID, Dimension.LINE_ITEM_NAME};
        reportQuery.statement = statementBuilder.ToStatement();
        reportQuery.customFieldIds = customFieldIds.ToArray();
        reportQuery.columns = new Column[] {Column.AD_SERVER_IMPRESSIONS};
        reportJob.reportQuery = reportQuery;

        // Run report job.
        reportJob = reportService.runReportJob(reportJob);

        ReportUtilities reportUtilities = new ReportUtilities(reportService, reportJob.id);

        // Set download options.
        ReportDownloadOptions options = new ReportDownloadOptions();
        options.exportFormat = ExportFormat.CSV_DUMP;
        options.useGzipCompression = true;
        reportUtilities.reportDownloadOptions = options;

        // Download the report.
        using (ReportResponse reportResponse = reportUtilities.GetResponse()) {
          reportResponse.Save(filePath);
        }
        Console.WriteLine("Report saved to \"{0}\".", filePath);

      } catch (Exception e) {
        Console.WriteLine("Failed to run cusom fields report. Exception says \"{0}\"",
            e.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.v201508.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.INACTIVE.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 e) {
        Console.WriteLine("Failed to activate line items. Exception says \"{0}\"",
            e.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.v201408.LineItemService);

            long lineItemId = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE"));

            long[] customCriteriaIds1 =
                new long[] { long.Parse(_T("INSERT_CUSTOM_TARGETING_KEY_ID_HERE")),
                             long.Parse(_T("INSERT_CUSTOM_TARGETING_VALUE_ID_HERE")) };
            long[] customCriteriaIds2 =
                new long[] { long.Parse(_T("INSERT_CUSTOM_TARGETING_KEY_ID_HERE")),
                             long.Parse(_T("INSERT_CUSTOM_TARGETING_VALUE_ID_HERE")) };
            long[] customCriteriaIds3 =
                new long[] { long.Parse(_T("INSERT_CUSTOM_TARGETING_KEY_ID_HERE")),
                             long.Parse(_T("INSERT_CUSTOM_TARGETING_VALUE_ID_HERE")) };

            // Create custom criteria.
            CustomCriteria customCriteria1 = new CustomCriteria();

            customCriteria1.keyId     = customCriteriaIds1[0];
            customCriteria1.valueIds  = new long[] { customCriteriaIds1[1] };
            customCriteria1.@operator = CustomCriteriaComparisonOperator.IS;

            CustomCriteria customCriteria2 = new CustomCriteria();

            customCriteria2.keyId     = customCriteriaIds2[0];
            customCriteria2.valueIds  = new long[] { customCriteriaIds2[1] };
            customCriteria2.@operator = CustomCriteriaComparisonOperator.IS_NOT;

            CustomCriteria customCriteria3 = new CustomCriteria();

            customCriteria3.keyId     = customCriteriaIds3[0];
            customCriteria3.valueIds  = new long[] { customCriteriaIds3[1] };
            customCriteria3.@operator = CustomCriteriaComparisonOperator.IS;

            // Create the custom criteria set that will resemble:
            //
            // (customCriteria1.key == customCriteria1.value OR
            //     (customCriteria2.key != customCriteria2.value AND
            //         customCriteria3.key == customCriteria3.value))
            CustomCriteriaSet topCustomCriteriaSet = new CustomCriteriaSet();

            topCustomCriteriaSet.logicalOperator = CustomCriteriaSetLogicalOperator.OR;

            CustomCriteriaSet subCustomCriteriaSet = new CustomCriteriaSet();

            subCustomCriteriaSet.logicalOperator = CustomCriteriaSetLogicalOperator.AND;
            subCustomCriteriaSet.children        =
                new CustomCriteriaNode[] { customCriteria2, customCriteria3 };
            topCustomCriteriaSet.children =
                new CustomCriteriaNode[] { customCriteria1, subCustomCriteriaSet };

            try {
                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .Where("id = :id")
                                                    .OrderBy("id ASC")
                                                    .Limit(1)
                                                    .AddValue("id", lineItemId);
                // Set the custom criteria targeting on the line item.
                LineItemPage page     = lineItemService.getLineItemsByStatement(statementBuilder.ToStatement());
                LineItem     lineItem = page.results[0];
                lineItem.targeting.customTargeting = topCustomCriteriaSet;

                // Update the line items on the server.
                LineItem[] updatedLineItems = lineItemService.updateLineItems(new LineItem[] { lineItem });

                foreach (LineItem updatedLineItem in updatedLineItems)
                {
                    // Display the updated line item.
                    Console.WriteLine("Line item with ID {0} updated with custom criteria targeting \n{1}\n",
                                      updatedLineItem.id,
                                      getCustomCriteriaSetString(updatedLineItem.targeting.customTargeting, 0));
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to add custom target criteria. Exception says \"{0}\"",
                                  ex.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            using (LineItemService lineItemService =
                       (LineItemService)user.GetService(DfpService.v201802.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.INACTIVE.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)
                        {
                            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 ='{3}' 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 e) {
                    Console.WriteLine("Failed to activate line items. Exception says \"{0}\"",
                                      e.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.v201502.CustomFieldService);

            // Get the LineItemService.
            LineItemService lineItemService = (LineItemService)user.GetService(
                DfpService.v201502.LineItemService);

            // Set the IDs of the custom fields, custom field option, and line item.
            long customFieldId       = long.Parse(_T("INSERT_STRING_CUSTOM_FIELD_ID_HERE"));
            long customFieldOptionId = long.Parse(_T("INSERT_CUSTOM_FIELD_OPTION_ID_HERE"));
            long lineItemId          = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE"));

            try {
                // Get the drop-down custom field id.
                long dropDownCustomFieldId =
                    customFieldService.getCustomFieldOption(customFieldOptionId).customFieldId;

                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .Where("id = :id")
                                                    .OrderBy("id ASC")
                                                    .Limit(1)
                                                    .AddValue("id", lineItemId);

                // Get the line item.
                LineItemPage lineItemPage = lineItemService.getLineItemsByStatement(
                    statementBuilder.ToStatement());
                LineItem lineItem = lineItemPage.results[0];

                // Create custom field values.
                List <BaseCustomFieldValue> customFieldValues = new List <BaseCustomFieldValue>();
                TextValue textValue = new TextValue();
                textValue.value = "Custom field value";

                CustomFieldValue customFieldValue = new CustomFieldValue();
                customFieldValue.customFieldId = customFieldId;
                customFieldValue.value         = textValue;
                customFieldValues.Add(customFieldValue);

                DropDownCustomFieldValue dropDownCustomFieldValue = new DropDownCustomFieldValue();
                dropDownCustomFieldValue.customFieldId       = dropDownCustomFieldId;
                dropDownCustomFieldValue.customFieldOptionId = customFieldOptionId;
                customFieldValues.Add(dropDownCustomFieldValue);

                // Only add existing custom field values for different custom fields than
                // the ones you are setting.
                if (lineItem.customFieldValues != null)
                {
                    foreach (BaseCustomFieldValue oldCustomFieldValue in lineItem.customFieldValues)
                    {
                        if (!(oldCustomFieldValue.customFieldId == customFieldId) &&
                            !(oldCustomFieldValue.customFieldId == dropDownCustomFieldId))
                        {
                            customFieldValues.Add(oldCustomFieldValue);
                        }
                    }
                }

                lineItem.customFieldValues = customFieldValues.ToArray();

                // Update the line item on the server.
                LineItem[] lineItems = lineItemService.updateLineItems(new LineItem[] { lineItem });

                if (lineItems != null)
                {
                    foreach (LineItem updatedLineItem in lineItems)
                    {
                        List <String> customFieldValueStrings = new List <String>();
                        foreach (BaseCustomFieldValue baseCustomFieldValue in lineItem.customFieldValues)
                        {
                            if (baseCustomFieldValue is CustomFieldValue &&
                                ((CustomFieldValue)baseCustomFieldValue).value is TextValue)
                            {
                                customFieldValueStrings.Add("{ID: '" + baseCustomFieldValue.customFieldId
                                                            + "', value: '"
                                                            + ((TextValue)((CustomFieldValue)baseCustomFieldValue).value).value
                                                            + "'}");
                            }
                            else if (baseCustomFieldValue is DropDownCustomFieldValue)
                            {
                                customFieldValueStrings.Add("{ID: '" + baseCustomFieldValue.customFieldId
                                                            + "', custom field option ID: '"
                                                            + ((DropDownCustomFieldValue)baseCustomFieldValue).customFieldOptionId
                                                            + "'}");
                            }
                        }
                        Console.WriteLine("A line item with ID \"{0}\" set with custom field values \"{1}\".",
                                          updatedLineItem.id, string.Join(", ", customFieldValueStrings.ToArray()));
                    }
                }
                else
                {
                    Console.WriteLine("No line items were updated.");
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to update line items. Exception says \"{0}\"", ex.Message);
            }
        }
Пример #21
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            using (LineItemService lineItemService =
                       (LineItemService)user.GetService(DfpService.v201802.LineItemService))
                using (ReportService reportService =
                           (ReportService)user.GetService(DfpService.v201802.ReportService)) {
                    try {
                        // Set the ID of the order to get line items from.
                        long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE"));

                        // Set the file path where the report will be saved.
                        String filePath = _T("INSERT_FILE_PATH_HERE");

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

                        // Create a statement to only select line items from a given order.
                        StatementBuilder statementBuilder = new StatementBuilder()
                                                            .Where("orderId = :orderId")
                                                            .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                            .AddValue("orderId", orderId);


                        // Collect all line item custom field IDs for an order.
                        List <long> customFieldIds = new List <long>();
                        do
                        {
                            // Get line items by statement.
                            page = lineItemService.getLineItemsByStatement(statementBuilder.ToStatement());

                            // Get custom field IDs from the line items of an order.
                            if (page.results != null)
                            {
                                foreach (LineItem lineItem in page.results)
                                {
                                    if (lineItem.customFieldValues != null)
                                    {
                                        foreach (BaseCustomFieldValue customFieldValue in lineItem.customFieldValues)
                                        {
                                            if (!customFieldIds.Contains(customFieldValue.customFieldId))
                                            {
                                                customFieldIds.Add(customFieldValue.customFieldId);
                                            }
                                        }
                                    }
                                }
                            }

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


                        // Create statement to filter for an order.
                        statementBuilder.RemoveLimitAndOffset();

                        // Create report job.
                        ReportJob reportJob = new ReportJob();

                        // Create report query.
                        ReportQuery reportQuery = new ReportQuery();
                        reportQuery.dateRangeType = DateRangeType.LAST_MONTH;
                        reportQuery.dimensions    = new Dimension[] {
                            Dimension.LINE_ITEM_ID,
                            Dimension.LINE_ITEM_NAME
                        };
                        reportQuery.statement      = statementBuilder.ToStatement();
                        reportQuery.customFieldIds = customFieldIds.ToArray();
                        reportQuery.columns        = new Column[] { Column.AD_SERVER_IMPRESSIONS };
                        reportJob.reportQuery      = reportQuery;

                        // Run report job.
                        reportJob = reportService.runReportJob(reportJob);

                        ReportUtilities reportUtilities = new ReportUtilities(reportService, reportJob.id);

                        // Set download options.
                        ReportDownloadOptions options = new ReportDownloadOptions();
                        options.exportFormat                  = ExportFormat.CSV_DUMP;
                        options.useGzipCompression            = true;
                        reportUtilities.reportDownloadOptions = options;

                        // Download the report.
                        using (ReportResponse reportResponse = reportUtilities.GetResponse()) {
                            reportResponse.Save(filePath);
                        }
                        Console.WriteLine("Report saved to \"{0}\".", filePath);
                    } catch (Exception e) {
                        Console.WriteLine("Failed to run cusom fields report. Exception says \"{0}\"",
                                          e.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.v201408.LineItemService);
            // Get the ReportService.
            ReportService reportService =
                (ReportService)user.GetService(DfpService.v201408.ReportService);

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

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

                // Create a statement to only select line items from a given order.
                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .Where("orderId = :orderId")
                                                    .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                    .AddValue("orderId", orderId);


                // Collect all line item custom field IDs for an order.
                List <long> customFieldIds = new List <long>();
                do
                {
                    // Get line items by statement.
                    page = lineItemService.getLineItemsByStatement(statementBuilder.ToStatement());

                    // Get custom field IDs from the line items of an order.
                    if (page.results != null)
                    {
                        foreach (LineItem lineItem in page.results)
                        {
                            if (lineItem.customFieldValues != null)
                            {
                                foreach (BaseCustomFieldValue customFieldValue in lineItem.customFieldValues)
                                {
                                    if (!customFieldIds.Contains(customFieldValue.customFieldId))
                                    {
                                        customFieldIds.Add(customFieldValue.customFieldId);
                                    }
                                }
                            }
                        }
                    }

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


                // Create statement to filter for an order.
                statementBuilder.RemoveLimitAndOffset();

                // Create report job.
                ReportJob reportJob = new ReportJob();

                // Create report query.
                ReportQuery reportQuery = new ReportQuery();
                reportQuery.dateRangeType  = DateRangeType.LAST_MONTH;
                reportQuery.dimensions     = new Dimension[] { Dimension.LINE_ITEM_ID, Dimension.LINE_ITEM_NAME };
                reportQuery.statement      = statementBuilder.ToStatement();
                reportQuery.customFieldIds = customFieldIds.ToArray();
                reportQuery.columns        = new Column[] { Column.AD_SERVER_IMPRESSIONS };
                reportJob.reportQuery      = reportQuery;

                // Run report job.
                reportJob = reportService.runReportJob(reportJob);

                do
                {
                    Console.WriteLine("Report with ID '{0}' is still running.", reportJob.id);
                    Thread.Sleep(30000);
                    // Get report job.
                    reportJob = reportService.getReportJob(reportJob.id);
                } while (reportJob.reportJobStatus == ReportJobStatus.IN_PROGRESS);

                if (reportJob.reportJobStatus == ReportJobStatus.FAILED)
                {
                    Console.WriteLine("Report job with ID '{0}' failed to finish successfully.",
                                      reportJob.id);
                }
                else
                {
                    Console.WriteLine("Report job with ID '{0}' completed successfully.", reportJob.id);
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to run cusom fields report. Exception says \"{0}\"",
                                  ex.Message);
            }
        }
Пример #23
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 LineItemService.
            LineItemService lineItemService =
                (LineItemService)user.GetService(DfpService.v201311.LineItemService);

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

            // Create Statement text to select approved line items from a given order.
            string    statementText = "WHERE orderId = :orderId and status = :status LIMIT 500";
            Statement statement     = new StatementBuilder("").AddValue("orderId", orderId).
                                      AddValue("status", ComputedStatus.NEEDS_CREATIVES.ToString()).ToStatement();

            // Set defaults for page and offset.
            LineItemPage  page        = new LineItemPage();
            int           offset      = 0;
            int           i           = 0;
            List <string> lineItemIds = new List <string>();

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

                    // Get line items by Statement.
                    page = lineItemService.getLineItemsByStatement(statement);

                    if (page.results != null && page.results.Length > 0)
                    {
                        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++;
                            }
                        }
                    }

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

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

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

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

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

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