Ejemplo n.º 1
0
        protected override async System.Threading.Tasks.Task ExecuteAsync(CancellationToken stoppingToken)
        {
            logger.Info($"\r\n==========================================\r\n"
                        + "=== Загрузка бота Telegram для сервера ЛЭРС УЧЁТ...\r\n"
                        + "========================================== ");

            _lifeTime.ApplicationStopping.Register(() => logger.Info("Bot stopped."));

            try
            {
                logger.Info($"Starting bot.");

                _bot.AddCommandHandler(HandleStart, StartCommand);
                _bot.AddCommandHandler(ShowCurrents, GetCurrentsCommand);
                _bot.AddCommandHandler(ShowNodes, GetNodesCommand);
                _bot.AddCommandHandler(ShowMeasurePoints, GetMeasurePointsCommand);
                _bot.AddCommandHandler(_notifier.ProcessSetNotifyOn, SetNotifyOnCommand);
                _bot.AddCommandHandler(_notifier.ProcessSetNotifyOff, SetNotifyOffCommand);
                _bot.AddCommandHandler(SendSystemStateReport, SystemStateReport);
                _bot.AddCommandHandler(SendPortStatus, PortStatus);
                _bot.AddCommandHandler(GetMyJobs, GetMyJobsCommand);

                await _bot.Start();

                await _notifier.Start(stoppingToken);
            }
            catch (Exception exc)
            {
                logger.Info(exc, "Ошибка запуска бота.");

                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Вызывается при запуске службы.
        /// </summary>
        /// <param name="args"></param>
        protected override void OnStart(string[] args)
        {
            try
            {
                Config.Load();
                User.LoadList();

                Logger.Initialize(Config.LogFilePath);

                bot = new LersBot();

                notifier = new Notifier(bot);

                Logger.LogMessage($"Stariting {bot.UserName}");

                bot.AddCommandHandler(HandleStart, StartCommand);
                bot.AddCommandHandler(ShowCurrents, GetCurrentsCommand);
                bot.AddCommandHandler(ShowNodes, GetNodesCommand);
                bot.AddCommandHandler(ShowMeasurePoints, GetMeasurePointsCommand);
                bot.AddCommandHandler(notifier.ProcessSetNotifyOn, SetNotifyOnCommand);
                bot.AddCommandHandler(notifier.ProcessSetNotifyOff, SetNotifyOffCommand);

                bot.Start();

                notifier.Start();
            }
            catch (Exception exc)
            {
                Logger.LogMessage($"Ошибка запуска бота. {exc.ToString()}");
                throw;
            }
        }