コード例 #1
0
ファイル: IoTService.cs プロジェクト: tgiachi/Neon
        private async Task InitEntitiesDatabase()
        {
            _logger.LogInformation($"Starting Entities database: {_config.EntitiesDb.Name} - {_config.EntitiesDb.ConnectionString}");
            _entitiesConnector = _noSqlService.GetNoSqlConnector(_config.EntitiesDb.Name);
            await _entitiesConnector.Configure(_config.EntitiesDb.ConnectionString);

            await _entitiesConnector.Start();
        }
コード例 #2
0
 public MoviesIndexerService(ILogger <MoviesIndexerService> logger, ILoggerFactory loggerFactory, IHttpClientFactory httpClientFactory, ITaskQueueService taskQueueService, INoSqlService noSqlService)
 {
     _logger           = logger;
     _loggerFactory    = loggerFactory;
     HttpClientFactory = httpClientFactory;
     _taskQueueService = taskQueueService;
     _noSqlConnector   = noSqlService.GetNoSqlConnector("mongo_db");
     _noSqlConnector.Configure("mongodb://localhost:27017/movies_db");
 }
コード例 #3
0
        public async Task <bool> Start()
        {
            if (_telegramConfig.ApiKey == "change_me")
            {
                _logger.LogError($"Telegram notifier need api on config!");
                _userInteractionService.AddUserInteractionData(new UserInteractionData()
                {
                    Name   = GetType().Name,
                    Fields = new List <UserInteractionField>()
                    {
                        new UserInteractionField()
                        {
                            FieldName = "Api key", Description = "Telegram bot Api key", FieldType = UserInteractionFieldTypeEnum.String, IsRequired = true,
                        }
                    }
                }, data =>
                {
                });

                return(false);
            }
            else
            {
                _persistenceConnector = _noSqlService.GetNoSqlConnector(_telegramConfig.PersistenceConnector);
                await _persistenceConnector.Configure(Path.Combine(_neonConfig.NotifierConfig.DirectoryConfig.DirectoryName,
                                                                   "telegram.json"));

                _telegramBotClient = new TelegramBotClient(_telegramConfig.ApiKey);
                _logger.LogInformation($"Connecting to telegram");
                var user = await _telegramBotClient.GetMeAsync();

                _logger.LogInformation($"Telegram connected, Write me @{user.Username}");

                _telegramBotClient.OnMessage += async(sender, args) =>
                {
                    if (args.Message.Text != null)
                    {
                        _logger.LogDebug($"Message from @{args.Message.From.Username}: {args.Message.Text}");

                        if (args.Message.Text.ToLower() == "/version")
                        {
                            await SendVersion(args.Message.Chat.Id);
                        }

                        if (args.Message.Text.ToLower() == "/help")
                        {
                            await SendHelp(args.Message.Chat.Id);
                        }

                        if (args.Message.Text.ToLower() == "/myip")
                        {
                            await SendMyIp(args.Message.Chat.Id);
                        }

                        if (args.Message.Text.ToLower().StartsWith("/exec"))
                        {
                            await ExecuteCode(args.Message.Chat.Id, args.Message.Text);
                        }

                        if (args.Message.Text.ToLower() == "/enable_notify")
                        {
                            await EnableNotification(args.Message.Chat.Id);
                        }
                    }
                };
                _telegramBotClient.StartReceiving();
            }

            return(true);
        }