/// <summary> /// Run the code example. /// </summary> public void Run(DfpUser user) { using (ExchangeRateService exchangeRateService = (ExchangeRateService)user.GetService(DfpService.v201802.ExchangeRateService)) { // Set the ID of the exchange rate. long exchangeRateId = long.Parse(_T("INSERT_EXCHANGE_RATE_ID_HERE")); // Create a statement to get the exchange rate. StatementBuilder statementBuilder = new StatementBuilder() .Where("id = :exchangeRateId and refreshRate = :refreshRate").OrderBy("id ASC") .Limit(1).AddValue("exchangeRateId", exchangeRateId) .AddValue("refreshRate", ExchangeRateRefreshRate.FIXED.ToString()); try { // Get exchange rates by statement. ExchangeRatePage page = exchangeRateService.getExchangeRatesByStatement( statementBuilder.ToStatement()); ExchangeRate exchangeRate = page.results[0]; // Update the exchange rate value to 1.5. exchangeRate.exchangeRate = 15000000000L; // Update the exchange rate on the server. ExchangeRate[] exchangeRates = exchangeRateService.updateExchangeRates( new ExchangeRate[] { exchangeRate }); if (exchangeRates != null) { foreach (ExchangeRate updatedExchangeRate in exchangeRates) { Console.WriteLine( "An exchange rate with ID '{0}', currency code '{1}', " + "direction '{2}' and exchange rate '{3}' was updated.", exchangeRate.id, exchangeRate.currencyCode, exchangeRate.direction, (exchangeRate.exchangeRate / 10000000000f)); } } else { Console.WriteLine("No exchange rates updated."); } } catch (Exception e) { Console.WriteLine("Failed to update exchange rates. Exception says \"{0}\"", e.Message); } } }
/// <summary> /// Run the code example. /// </summary> public void Run(DfpUser dfpUser) { ExchangeRateService exchangeRateService = (ExchangeRateService)dfpUser.GetService(DfpService.v201708.ExchangeRateService); // Create a statement to select exchange rates. int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT; StatementBuilder statementBuilder = new StatementBuilder() .OrderBy("id ASC") .Limit(pageSize); // Retrieve a small amount of exchange rates at a time, paging through until all // exchange rates have been retrieved. int totalResultSetSize = 0; do { ExchangeRatePage page = exchangeRateService.getExchangeRatesByStatement( statementBuilder.ToStatement()); // Print out some information for each exchange rate. if (page.results != null) { totalResultSetSize = page.totalResultSetSize; int i = page.startIndex; foreach (ExchangeRate exchangeRate in page.results) { Console.WriteLine( "{0}) Exchange rate with ID {1}, " + "currency code \"{2}\", " + "direction \"{3}\", " + "and exchange rate {4} was found.", i++, exchangeRate.id, exchangeRate.currencyCode, exchangeRate.direction, exchangeRate.exchangeRate ); } } 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 ExchangeRateService. ExchangeRateService exchangeRateService = (ExchangeRateService)user.GetService(DfpService.v201602.ExchangeRateService); // Set the currency code to get the exchange rate for. string currencyCode = "INSERT_CURRENCY_CODE_HERE"; // Create a statement to select a single exchange rate by currency code. StatementBuilder statementBuilder = new StatementBuilder() .Where("currencyCode = :currencyCode") .OrderBy("id ASC") .Limit(1) .AddValue("currencyCode", currencyCode); // Set default for page. ExchangeRatePage page = new ExchangeRatePage(); try { do { // Get exchange rates by statement. page = exchangeRateService .getExchangeRatesByStatement(statementBuilder.ToStatement()); if (page.results != null && page.results.Length > 0) { int i = page.startIndex; foreach (ExchangeRate exchangeRate in page.results) { Console.WriteLine("{0}) Exchange rate with ID '{1}', currency code '{2}', " + "direction '{3}' and exchange rate '{4}' was found.", i++, exchangeRate.id, exchangeRate.currencyCode, exchangeRate.direction, (exchangeRate.exchangeRate / 10000000000f)); } } 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 exchange rate 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 void Run(DfpUser user, string currencyCode) { ExchangeRateService exchangeRateService = (ExchangeRateService)user.GetService(DfpService.v201608.ExchangeRateService); // Create a statement to select exchange rates. StatementBuilder statementBuilder = new StatementBuilder() .Where("currencyCode = :currencyCode") .OrderBy("id ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("currencyCode", currencyCode); // Retrieve a small amount of exchange rates at a time, paging through // until all exchange rates have been retrieved. ExchangeRatePage page = new ExchangeRatePage(); try { do { page = exchangeRateService.getExchangeRatesByStatement(statementBuilder.ToStatement()); if (page.results != null) { // Print out some information for each exchange rate. int i = page.startIndex; foreach (ExchangeRate exchangeRate in page.results) { Console.WriteLine("{0}) Exchange rate with ID \"{1}\", currency code \"{2}\", " + "and exchange rate \"{3}\" was found.", i++, exchangeRate.id, exchangeRate.currencyCode, exchangeRate.exchangeRate / 10000000000); } } 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 exchange 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 ExchangeRateService. ExchangeRateService exchangeRateService = (ExchangeRateService) user.GetService(DfpService.v201511.ExchangeRateService); // Set the currency code to get the exchange rate for. string currencyCode = "INSERT_CURRENCY_CODE_HERE"; // Create a statement to select a single exchange rate by currency code. StatementBuilder statementBuilder = new StatementBuilder() .Where("currencyCode = :currencyCode") .OrderBy("id ASC") .Limit(1) .AddValue("currencyCode", currencyCode); // Set default for page. ExchangeRatePage page = new ExchangeRatePage(); try { do { // Get exchange rates by statement. page = exchangeRateService .getExchangeRatesByStatement(statementBuilder.ToStatement()); if (page.results != null && page.results.Length > 0) { int i = page.startIndex; foreach (ExchangeRate exchangeRate in page.results) { Console.WriteLine("{0}) Exchange rate with ID '{1}', currency code '{2}', " + "direction '{3}' and exchange rate '{4}' was found.", i++, exchangeRate.id, exchangeRate.currencyCode, exchangeRate.direction, (exchangeRate.exchangeRate / 10000000000f)); } } 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 exchange rate by Statement. Exception says \"{0}\"", e.Message); } }
public App() { InitializeComponent(); MainPage = new ExchangeRatePage(); }