//get buy and sell exchange rate by Bank ID public async Task <Tuple <string, string> > GetBuySellRate(BankID bankID) { string buyRate = await GetBuyRate(bankID); //get buy rate string sellRate = await GetSellRate(bankID); //get sell rate return(new Tuple <string, string>(buyRate, sellRate)); }
private BankInfo CreateBankInfo(int ID, string name, string URI, string pattern, int buy, int sell) { var bankID = BankID.Create(ID); var bankName = BankName.Create(name); var bankURI = BankURI.Create(URI); var bankPattern = BankPattern.Create(pattern); var bankBuy = BankIndex.Create(buy); var bankSell = BankIndex.Create(sell); return(new BankInfo(bankID, bankName, bankURI, bankPattern, bankBuy, bankSell)); }
//get exchange rate private async Task <string> GetRate(BankID bankID, Operations operation) { if (!banksInfo.ContainsKey(bankID)) //if Bank ID is not in collection throw exception { throw new KeyNotFoundException("Can't find Bank with this ID ({bankID})"); } var URI = banksInfo[bankID].URI; //bank website var pattern = banksInfo[bankID].Pattern; //exchange pattern var neededIndex = operation == Operations.Sell ? banksInfo[bankID].Sell : banksInfo[bankID].Buy; //get needed index return(await ParseHTMLPage(URI, pattern, neededIndex)); }
} //which Regex.Match corresponds to the sell rate public BankInfo(BankID id, BankName name, BankURI uri, BankPattern pattern, BankIndex buy, BankIndex sell) { CheckParameter(id, nameof(id)); CheckParameter(name, nameof(name)); CheckParameter(uri, nameof(uri)); CheckParameter(pattern, nameof(pattern)); CheckParameter(buy, nameof(buy)); CheckParameter(sell, nameof(sell)); this.ID = id; this.Name = name; this.URI = uri; this.Pattern = pattern; this.Buy = buy; this.Sell = sell; }
public void ChangeID(BankID bankID) { CheckParameter(bankID, nameof(bankID)); this.ID = bankID; }
//get sell exchange rate by Bank ID public async Task <string> GetSellRate(BankID bankID) { return(await GetRate(bankID, Operations.Sell)); }
//get buy exchange rate by Bank ID public async Task <string> GetBuyRate(BankID bankID) { return(await GetRate(bankID, Operations.Buy)); }
//remove bank info by ID public void RemoveBankInfo(BankID bankID) { banksInfo.Remove(bankID); }