Beispiel #1
0
        private async void Poll(IRatesLineExtractor ratesLineExtractor)
        {
            var tid = Thread.CurrentThread.ManagedThreadId;

            _logFile.AppendLine($"{ratesLineExtractor.BankTitle} extractor started in thread {tid}");
            while (true)
            {
                KomBankRatesLine rate;
                while (true)
                {
                    rate = await ratesLineExtractor.GetRatesLineAsync();

                    if (rate != null)
                    {
                        break;
                    }
                    await Task.Delay(2000);
                }

                var unused = await Persist(rate);

                await Task.Delay(ratesLineExtractor.BankTitle == "БНБ"? 60000 : 15000);
            }
            // ReSharper disable once FunctionNeverReturns
        }
Beispiel #2
0
        private async Task GetOneLast()
        {
            var webApiUrl = $@"http://{_baliApiUrl}/bali/get-one-last/" + KomBank.ToString().ToUpper();

            try
            {
                var response = await((HttpWebRequest)WebRequest.Create(webApiUrl)).GetDataAsync();

                if (string.IsNullOrEmpty(response))
                {
                    var lastLine = Rows.Last();
                    lastLine.SetIfExpired();
                    return;
                }

                var oneLine = JsonConvert.DeserializeObject <KomBankRatesLine>(response);

                var newLine = Mapper.Map <KomBankRateVm>(oneLine);
                var last    = Rows.FirstOrDefault(r => r.Id == newLine.Id);
                Application.Current.Dispatcher.Invoke(() =>
                {
                    if (last == null)
                    {
                        newLine.State = "Fresh";
                        if (Rows.Any())
                        {
                            Rows.Last().State = "";
                        }
                        Rows.Add(newLine);

                        _changesViewModel.AddNewLine(newLine);
                        if (!_changesViewModel.IsOpen)
                        {
                            _windowManager.ShowWindow(_changesViewModel);
                        }


                        // var notify = new Changes
                        // {
                        //     MessageBlock = { Text = newLine.Bank + " " + newLine.StartedFrom }
                        // };
                        // notify.Show();
                    }
                    else
                    {
                        last.SetIfExpired();
                        last.LastCheck = newLine.LastCheck;
                    }
                });
            }
            catch (Exception e)
            {
                _logFile.AppendLine(e.Message);
            }
        }
Beispiel #3
0
        private async Task GetOneLast(KomBankE komBank)
        {
            var webApiUrl = $@"http://{_baliApiUrl}/bali/get-one-last/" + komBank.ToString().ToUpper();

            try
            {
                var response = await((HttpWebRequest)WebRequest.Create(webApiUrl)).GetDataAsync();
                Application.Current.Dispatcher.Invoke(() =>
                {
                    OneToGui(komBank, response);
                });
            }
            catch (Exception e)
            {
                _logFile.AppendLine(e.Message);
            }
        }
Beispiel #4
0
        private async Task Poll()
        {
            _logFile.AppendLine("Banki24 archive extractor started");
            var date = new DateTime(1, 1, 1);

            while (true)
            {
                if (date.Date < DateTime.Today.Date || (DateTime.Now.Hour >= 10 && DateTime.Now.Hour <= 13))
                {
                    date = await UpdateDatabase();
                }
                else
                {
                    _logFile.AppendLine("Banki24: it is not a time to check archive.");
                }
                await Task.Delay(15 * 60 * 1000);
            }
            // ReSharper disable once FunctionNeverReturns
        }
Beispiel #5
0
        public async void Start(IniFile iniFile, IMyLog logFile, IWindowManager windowManager, ChangesViewModel changesViewModel)
        {
            _logFile = logFile;
            _logFile.AppendLine("Kom banks listening started");

            foreach (var komBank in _firstPageList)
            {
                var viewModel = await new KomBankViewModel(iniFile, komBank, _logFile, windowManager, changesViewModel).GetSomeLast();
                Application.Current.Dispatcher.Invoke(() => Banks.Add(viewModel));
                var unused = await Task.Factory.StartNew(viewModel.StartPolling);
            }
        }
Beispiel #6
0
        public async Task <List <KomBankRatesLine> > Get()
        {
            _logFile.AppendLine("Used to check in browser. Type   http://localhost:11082/bali   ");
            await using BanksListenerContext db = new BanksListenerContext(_dbPath);

            var result = new List <KomBankRatesLine>();

            foreach (var komBank in (KomBankE[])Enum.GetValues(typeof(KomBankE)))
            {
                result.Add(await db.KomBankRates
                           .Where(r => r.Bank == komBank.ToString().ToUpper())
                           .OrderByDescending(l => l.LastCheck)
                           .FirstOrDefaultAsync());
            }
            return(result);
        }
Beispiel #7
0
 public async Task StartAsync(CancellationToken cancellationToken)
 {
     _logFile.AppendLine("we are starting kom banks poller");
     _komBanksPoller.StartThreads();
     await Task.Delay(1, cancellationToken);
 }
Beispiel #8
0
 public async Task StartAsync(CancellationToken cancellationToken)
 {
     _logFile.AppendLine("we are starting banki24 archive manager");
     _banki24ArchiveManager.StartThread();
     await Task.Delay(1, cancellationToken);
 }