/// <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.v201411.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("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);
              }
        }
        /// <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.v201411.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 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.v201411.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.v201411.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 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 LineItemService.
              LineItemService lineItemService =
              (LineItemService) user.GetService(DfpService.v201411.LineItemService);
              // Get the ReportService.
              ReportService reportService =
              (ReportService) user.GetService(DfpService.v201411.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 e) {
            Console.WriteLine("Failed to run cusom fields report. Exception says \"{0}\"",
            e.Message);
              }
        }