This project adds necessary classes to obtain curent and historic Exchange Rates from the following banks
- European Central Bank
- Bank of Canada
- Central Bank of the Russian Federation
- National Bank of Ukraine
Use clio (formely known as bpmcli) to install this project
clio reg-web-app EnvironmentName -u https://domain.creatio.com -l Supervisor -p Supervisor -m YourCompanyName
Make sure you are in the same directory as the package root folder.
clio push-pkg ExchangeRates -e EnvironmentName
If everythig went well you will see a similar result
Try going to the following url from the browser that is already authenticated It will return USD/CAD exchange rate for Nov 20, 2019 from the Bank of Canada
http://domain.creatio.com/0/rest/ExchangeRate_WS/ExecuteGet?bankId=0&date=2019-11-20¤cy=USD
Every bank implements IBank interface that is returned from the factory method BankFactory.GetBank(BankFactory.SupportedBanks). IBank declares GetRateAsync method that returns IBankResult.
Some banks do not return Fx Rates for the current day, thus GetRateAsync will get the latest known rate. For instance, Bank of Canada will not return rates for non-banking days, GetRateAsync will recursively ask for the previous day until there is a result.
using System;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Threading.Tasks;
using Terrasoft.Web.Common;
namespace ExchangeRates
{
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class ExchangeRate_WS: BaseService
{
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
public BankResult ExecuteGet(int bankId, string date, string currency)
{
DateTime.TryParse(date, out DateTime dt);
IBank bank = BankFactory.GetBank((BankFactory.SupportedBanks)bankId);
IBankResult bankResult = Task.Run(() => bank.GetRateAsync(currency.ToUpper(), dt)).Result;
BankResult result = new BankResult
{
ExchangeRate = bankResult.ExchangeRate,
RateDate = bankResult.RateDate,
HomeCurrency = bankResult.HomeCurrency,
BankName = bankResult.BankName
};
return result;
}
}
}
- Clio - CLI Library to create packages.
- Bpmonline.SDK - Provides project template for development code for bpm'online platform.