/// <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 BaseRateService.
      BaseRateService baseRateService =
          (BaseRateService) user.GetService(DfpService.v201511.BaseRateService);

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

      // Sets default for page.
      BaseRatePage page = new BaseRatePage();
      try {
        do {
          // Get base rates by statement.
          page = baseRateService.getBaseRatesByStatement(statementBuilder.ToStatement());

          if (page.results != null && page.results.Length > 0) {
            int i = page.startIndex;
            foreach (BaseRate baseRate in page.results) {
              Console.WriteLine("{0}) Base rate with ID ='{1}' and type '{2}' belonging to rate " +
                  "card '{3}' was found.", i++, baseRate.id, baseRate.GetType().Name,
                  baseRate.rateCardId);
            }
          }

          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 base rates. 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 BaseRateService.
            BaseRateService baseRateService =
                (BaseRateService)user.GetService(DfpService.v201605.BaseRateService);

            long baseRateId = long.Parse(_T("INSERT_BASE_RATE_ID_HERE"));

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

            try {
                // Get base rates by statement.
                BaseRatePage page =
                    baseRateService.getBaseRatesByStatement(statementBuilder.ToStatement());

                BaseRate baseRate = page.results[0];

                // Update base rate value to $3 USD.
                Money newRate = new Money()
                {
                    currencyCode = "USD", microAmount = 3000000L
                };

                if (baseRate is ProductTemplateBaseRate)
                {
                    ((ProductTemplateBaseRate)baseRate).rate = newRate;
                }
                else if (baseRate is ProductBaseRate)
                {
                    ((ProductBaseRate)baseRate).rate = newRate;
                }

                // Update the base rates on the server.
                BaseRate[] baseRates = baseRateService.updateBaseRates(new BaseRate[] { baseRate });

                if (baseRates != null)
                {
                    foreach (BaseRate updatedBaseRate in baseRates)
                    {
                        Console.WriteLine("Base rate with ID ='{0}' and type '{1}' belonging to rate card " +
                                          "'{2}' was updated.", baseRate.id, baseRate.GetType().Name, baseRate.rateCardId);
                    }
                }
                else
                {
                    Console.WriteLine("No base rates updated.");
                }
            } catch (Exception e) {
                Console.WriteLine("Failed to update base rates. Exception says \"{0}\"",
                                  e.Message);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public void Run(DfpUser user, long rateCardId)
        {
            BaseRateService baseRateService =
                (BaseRateService)user.GetService(DfpService.v201605.BaseRateService);

            // Create a statement to select base rates belonging to a single rate card.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("rateCardId = :rateCardId")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("rateCardId", rateCardId);

            // Retrieve a small amount of base rates at a time, paging through
            // until all base rates have been retrieved.
            BaseRatePage page = new BaseRatePage();

            try {
                do
                {
                    page = baseRateService.getBaseRatesByStatement(statementBuilder.ToStatement());

                    if (page.results != null)
                    {
                        // Print out some information for each base rate.
                        int i = page.startIndex;
                        foreach (BaseRate baseRate in page.results)
                        {
                            Console.WriteLine("{0}) Base rate with ID \"{1}\", type \"{2}\", "
                                              + "and rate card ID \"{3}\" was found.",
                                              i++,
                                              baseRate.id,
                                              baseRate.GetType().Name,
                                              baseRate.rateCardId);
                        }
                    }

                    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 base rates. Exception says \"{0}\"",
                                  e.Message);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public void Run(DfpUser dfpUser, long rateCardId)
        {
            BaseRateService baseRateService =
                (BaseRateService)dfpUser.GetService(DfpService.v201702.BaseRateService);

            // Create a statement to select base rates.
            int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT;
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("rateCardId = :rateCardId")
                                                .OrderBy("id ASC")
                                                .Limit(pageSize)
                                                .AddValue("rateCardId", rateCardId);

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

            do
            {
                BaseRatePage page = baseRateService.getBaseRatesByStatement(
                    statementBuilder.ToStatement());

                // Print out some information for each base rate.
                if (page.results != null)
                {
                    totalResultSetSize = page.totalResultSetSize;
                    int i = page.startIndex;
                    foreach (BaseRate baseRate in page.results)
                    {
                        Console.WriteLine(
                            "{0}) Base rate with ID {1}, type \"{2}\", and rate card ID {3} was found.",
                            i++,
                            baseRate.id,
                            baseRate.GetType().Name,
                            baseRate.rateCardId
                            );
                    }
                }

                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 BaseRateService.
            BaseRateService baseRateService =
                (BaseRateService)user.GetService(DfpService.v201511.BaseRateService);

            // Set the rate card ID to filter base rates on.
            long rateCardId = long.Parse(_T("INSERT_RATE_CARD_ID_HERE"));

            // Create a statement to select base rates belonging to a single rate card.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("rateCardId = :rateCardId")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("rateCardId", rateCardId);

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

            try {
                do
                {
                    // Get base rates by statement.
                    page = baseRateService.getBaseRatesByStatement(statementBuilder.ToStatement());

                    if (page.results != null && page.results.Length > 0)
                    {
                        int i = page.startIndex;
                        foreach (BaseRate baseRate in page.results)
                        {
                            Console.WriteLine("{0}) Base rate with ID ='{1}' and type '{2}' belonging to rate " +
                                              "card '{3}' was found.", i++, baseRate.id, baseRate.GetType().Name,
                                              baseRate.rateCardId);
                        }
                    }
                    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 base rates 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 BaseRateService.
            BaseRateService baseRateService =
                (BaseRateService)user.GetService(DfpService.v201411.BaseRateService);

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

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

            try {
                do
                {
                    // Get base rates by statement.
                    page = baseRateService.getBaseRatesByStatement(statementBuilder.ToStatement());

                    if (page.results != null && page.results.Length > 0)
                    {
                        int i = page.startIndex;
                        foreach (BaseRate baseRate in page.results)
                        {
                            Console.WriteLine("{0}) Base rate with ID ='{1}' and type '{2}' belonging to rate " +
                                              "card '{3}' was found.", i++, baseRate.id, baseRate.BaseRateType,
                                              baseRate.rateCardId);
                        }
                    }

                    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 base rates. Exception says \"{0}\"",
                                  e.Message);
            }
        }