コード例 #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 OrderService.
      OrderService orderService = (OrderService) user.GetService(DfpService.v201403.OrderService);

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

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

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

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

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

        Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get all orders. Exception says \"{0}\"",
            ex.Message);
      }
    }
コード例 #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 OrderService.
      OrderService orderService = (OrderService) user.GetService(DfpService.v201403.OrderService);

      // Set the name of the advertiser (company) to get orders for.
      String advertiserId = _T("INSERT_ADVERTISER_COMPANY_ID_HERE");

      // Create a Statement to only select orders for a given advertiser.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("advertiserId = :advertiserId")
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("advertiserId", advertiserId);

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

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

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (Order order in page.results) {
              Console.WriteLine("{0}) Order with ID = '{1}', name = '{2}', and advertiser " +
                  "ID = '{3}' was found.", i, order.id, order.name, order.advertiserId);
              i++;
            }
          }
          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while(statementBuilder.GetOffset() < page.totalResultSetSize);
        Console.WriteLine("Number of results found: " + page.totalResultSetSize);
      } catch (Exception ex) {
        Console.WriteLine("Failed to get orders by Statement. Exception says \"{0}\"",
            ex.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 OrderService.
              OrderService orderService = (OrderService) user.GetService(DfpService.v201403.OrderService);

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

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

              // Get orders by Statement.
              page = orderService.getOrdersByStatement(statement);

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

              offset += 500;
            } while (page.results != null && page.results.Length == 500);

            Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
              } catch (Exception ex) {
            Console.WriteLine("Failed to get all orders. 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 OrderService.
      OrderService orderService =
          (OrderService) user.GetService(DfpService.v201403.OrderService);

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

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

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

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

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

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

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

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

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

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

          // Display results.
          if (result != null && result.numChanges > 0) {
            Console.WriteLine("Number of orders approved: {0}", result.numChanges);
          } else {
            Console.WriteLine("No orders were approved.");
          }
        }
      } catch (Exception ex) {
        Console.WriteLine("Failed to approve orders. Exception says \"{0}\"",
            ex.Message);
      }
    }
コード例 #5
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the OrderService.
              OrderService orderService =
              (OrderService) user.GetService(DfpService.v201403.OrderService);

              // Create Statement text to select all draft orders.
              string statementText = "WHERE status IN (:status1, :status2) and endDateTime >= :today " +
              "AND isArchived = FALSE LIMIT 500";
              Statement statement = new StatementBuilder("").
              AddValue("status1", OrderStatus.DRAFT.ToString()).
              AddValue("status2", OrderStatus.PENDING_APPROVAL.ToString()).
              AddValue("today", System.DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss")).ToStatement();

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

              try {
            do {
              // Create a Statement to page through draft orders.
              statement.query = string.Format("{0} OFFSET {1}", statementText, offset);
              // Get orders by Statement.
              page = orderService.getOrdersByStatement(statement);

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

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

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

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

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

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

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