Example #1
0
        public TelegramManager(IServiceProvider serviceProvider, string apiToken, long chatId)
        {
            _apiToken        = apiToken;
            _services        = serviceProvider;
            _mainModel       = serviceProvider.GetRequiredService <IMainModel>();
            Settings         = serviceProvider.GetRequiredService <ISettingsProvider>().Settings;
            _logger          = (ILogger <TelegramManager>)serviceProvider.GetService(typeof(ILogger <TelegramManager>));
            _eventAggregator = (IEventAggregator2)serviceProvider.GetService(typeof(IEventAggregator2));
            try
            {
                _bot    = new TelegramBotClient(_apiToken);
                _chatId = chatId;

                _messageQueueLoopTask = Task.Factory
                                        .StartNew(() => BotMessageQueueLoopAsync()
                                                  .ConfigureAwait(false),
                                                  _cancellationTokenSource.Token,
                                                  TaskCreationOptions.LongRunning,
                                                  TaskScheduler.Default);
            }
            catch (Exception ex)
            {
                _logger.LogError("Telegram init error: {exception}", ex.Message);
            }
        }
        private void SetChatId(INgineSettings settings)
        {
            if (long.TryParse(settings.TgArbitrageLongUSAChatId, out var result))
            {
                _chatIdLong = result;
            }
            else
            {
                _chatIdLong = 0;
            }

            if (long.TryParse(settings.TgArbitrageShortUSAChatId, out result))
            {
                _chatIdShort = result;
            }
            else
            {
                _chatIdShort = 0;
            }
        }
Example #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);
     }
 }
Example #4
0
 public virtual void SaveSettings(INgineSettings settings)
 {
 }
Example #5
0
 public virtual INgineSettings ReadSettings()
 {
     LastSettings = this.Clone() as INgineSettings;
     return(this);
 }
 public Task HandleAsync(INgineSettings message, CancellationToken cancellationToken)
 {
     SetChatId(message);
     return(Task.CompletedTask);
 }
Example #7
0
 protected virtual void LoadAppSettings()
 {
     Settings = _settingsProvider.ReadSettings();
 }