Example #1
0
        private async Task <DateTime> GetDateToStartFrom()
        {
            using (BanksListenerContext db = new BanksListenerContext(_dbPath))
            {
                var lastDateLine = db.BelStockArchive.OrderBy(d => d.Date).LastOrDefault();
                if (lastDateLine == null)
                {
                    return(new DateTime(2015, 6, 1));
                }

                db.BelStockArchive.RemoveRange(db.BelStockArchive.Where(l => l.Date.Date == lastDateLine.Date.Date));
                await db.SaveChangesAsync();

                return(lastDateLine.Date.Date);
            }
        }
Example #2
0
        private async Task <int> Persist(KomBankRatesLine rate)
        {
            using (BanksListenerContext db = new BanksListenerContext(_dbPath))
            {
                var tid  = Thread.CurrentThread.ManagedThreadId;
                var last = await db.KomBankRates.Where(l => l.Bank == rate.Bank).OrderBy(c => c.LastCheck).LastOrDefaultAsync();

                if (last == null || last.IsDifferent(rate))
                {
                    if (rate.Bank == "BIB" || rate.Bank == "BNB")
                    {
                        rate.StartedFrom = DateTime.Now; // Bib page does not contain date from
                    }
                    if (rate.Bank == "BVEB" && rate.StartedFrom.Hour == 0 && DateTime.Now.Hour != 0)
                    {
                        rate.StartedFrom = DateTime.Now; // Bveb often returns 00:10 or 00:15 as start time
                    }
                    _logFile.AppendLine($"Thread id {tid}: {rate.Bank} new rate, usd {rate.UsdA} - {rate.UsdB},  euro {rate.EurA} - {rate.EurB},  rub {rate.RubA} - {rate.RubB}");

                    const double TOLERANCE = 0.00001;
                    if (rate.Bank == "BNB" && Math.Abs(rate.UsdA - 2.619) < TOLERANCE &&
                        Math.Abs(rate.UsdB - 2.625) < TOLERANCE &&
                        Math.Abs(rate.EurA - 3.168) < TOLERANCE &&
                        Math.Abs(rate.EurB - 3.175) < TOLERANCE)
                    {
                        return(0);
                    }

                    await db.KomBankRates.AddAsync(rate);
                }
                else
                {
                    last.LastCheck = DateTime.Now;
                    _logFile.AppendLine($"Thread id {tid}: Poller of {rate.Bank} - rate checked");
                }

                return(await db.SaveChangesAsync());
            }
        }
Example #3
0
 private async Task PersistRangeOfLines(List <BelStockArchiveOneCurrencyDay> newLines)
 {
     await using BanksListenerContext db = new BanksListenerContext(_dbPath);
     db.BelStockArchive.AddRange(newLines);
     await db.SaveChangesAsync();
 }