예제 #1
0
        private async Task BotMessageQueueLoopAsync()
        {
            var cancellationToken = _cancellationTokenSource.Token;

            while (!cancellationToken.IsCancellationRequested)
            {
                while (!cancellationToken.IsCancellationRequested && _botMessageQueue.TryDequeue(out var msg))
                {
                    try
                    {
                        await msg.Send(this);
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex.Message);
                        _bot = new TelegramBotClient(_apiToken);
                    }

                    await _eventAggregator.PublishOnCurrentThreadAsync(new CommonInfoMessage()
                    {
                        TelegramMessageQuery = _botMessageQueue.Count
                    });

                    await Task.Delay(300);
                }
                await Task.Delay(100);
            }
        }
예제 #2
0
        private async Task UpdateCounters()
        {
            _recentUpdatedStocksCount =
                _mainModel.Stocks.Count(s => DateTime.Now.Subtract(s.Value.LastUpdate).TotalSeconds <= 5);
            var updatePerSecond = _mainModel.Stocks.Count(s => DateTime.Now.Subtract(s.Value.LastUpdate).TotalSeconds <= 1);

            await EventAggregator.PublishOnCurrentThreadAsync(new CommonInfoMessage()
            {
                TotalStocksUpdatedInFiveSec = _recentUpdatedStocksCount, TotalStocksUpdatedInLastSec = updatePerSecond
            });

            _lastUIUpdate = DateTime.Now;
        }
예제 #3
0
 public override void SaveSettings(INgineSettings settings)
 {
     try
     {
         if (settings is SettingsModel sm)
         {
             if (String.IsNullOrWhiteSpace(sm.ChartUrlTemplate))
             {
                 sm.ChartUrlTemplate = "!disabled";
             }
             System.IO.File.WriteAllText("settings.json",
                                         JsonConvert.SerializeObject(sm.AnonymousSettingsObj, Formatting.Indented));
             _eventAggregator.PublishOnCurrentThreadAsync(new SettingsChangeEventArgs(LastSettings, settings));
             LastSettings = settings.Clone() as INgineSettings;
         }
     }
     catch (Exception ex)
     {
         _logger.LogCritical(ex, ex.Message);
     }
 }
예제 #4
0
파일: MainModel.cs 프로젝트: DBKai/RcktMon
 public virtual async Task OnStockUpdated(IStockModel stock)
 {
     await _eventAggregator.PublishOnCurrentThreadAsync(stock);
 }