コード例 #1
0
ファイル: ExchangeRate.cs プロジェクト: Kanris/ExchangeRate
        //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));
        }
コード例 #2
0
ファイル: ExchangeRate.cs プロジェクト: Kanris/ExchangeRate
        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));
        }
コード例 #3
0
ファイル: ExchangeRate.cs プロジェクト: Kanris/ExchangeRate
        //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));
        }
コード例 #4
0
ファイル: BankInfo.cs プロジェクト: Kanris/ExchangeRate
        }                                           //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;
        }
コード例 #5
0
ファイル: BankInfo.cs プロジェクト: Kanris/ExchangeRate
        public void ChangeID(BankID bankID)
        {
            CheckParameter(bankID, nameof(bankID));

            this.ID = bankID;
        }
コード例 #6
0
ファイル: ExchangeRate.cs プロジェクト: Kanris/ExchangeRate
 //get sell exchange rate by Bank ID
 public async Task <string> GetSellRate(BankID bankID)
 {
     return(await GetRate(bankID, Operations.Sell));
 }
コード例 #7
0
ファイル: ExchangeRate.cs プロジェクト: Kanris/ExchangeRate
 //get buy exchange rate by Bank ID
 public async Task <string> GetBuyRate(BankID bankID)
 {
     return(await GetRate(bankID, Operations.Buy));
 }
コード例 #8
0
ファイル: ExchangeRate.cs プロジェクト: Kanris/ExchangeRate
 //remove bank info by ID
 public void RemoveBankInfo(BankID bankID)
 {
     banksInfo.Remove(bankID);
 }