public OpenWeatherMapClient(string configPath) { JsonFileContent config = new JsonFileContent(configPath); _client = new RestClient((string)config.Value("OpenWeatherMapUrl")); _key = (string)config.Value("OpenWeatherMapKey"); }
public LocationIqClient(string apiConfigPath) { _configs = new JsonFileContent(apiConfigPath); _client = new RestClient((string)_configs.Value("LocationIqUrl")); _key = (string)_configs.Value("LocationIqKey"); _apiRequestsLeft = int.Parse((string)_configs.Value("RequestsPerDay")); _requestsPerSecond = int.Parse((string)_configs.Value("RequestsPerSecond")); _currentDay = DateTime.UtcNow; }
public WeatherApiController(string configPath, IRepository <ApiResponse> databaseClient) { JsonFileContent config = new JsonFileContent(configPath); var rabbitAdress = (string)config.Value("RabbitMQ"); publisher = new Publisher(rabbitAdress, "TaskController", "TaskController"); consumer = new Consumer(rabbitAdress, "TaskController", "TaskController"); terminal = new ApiRequestTerminal(configPath, databaseClient); manager = new TaskManager(terminal, publisher, databaseClient); rabbitExchangeValue = (string)config.Value("QueueKey"); }
public void Update() { int now = Convert.ToInt32(DateTime.UtcNow.Ticks); if ((now - _updateTime) >= (_hour / _responsesPerHour)) { _publisher.SendQueue(_configs.Value("WeatherApiQueueKey").ToString(), _location); string response = RabbitFeedback(); _publisher.SendQueue(_configs.Value("TelegramBotQueueKey").ToString(), response); _updateTime = (int)DateTime.UtcNow.Ticks; } }
public SubscriptionFacade(string configPath, Consumer consumer, Publisher publisher, MySqlDatabaseClient database) { _configPath = configPath; _configContent = new JsonFileContent(configPath); _consumer = consumer; _publisher = publisher; _subject = new Subject(); _dbClien = database; _subscriptionQueueKey = Convert.ToString(_configContent.Value("SubscriotionQueueKey")); _subscriptionKey = Convert.ToString(_configContent.Value("SubscriotionKey")); _cancelSubscriptionKey = Convert.ToString(_configContent.Value("CanceledSubscriotionKey")); _unit = new SubscriptionUnitOfWork(_dbClien); Restart(); }
public MongoDatabaseClient(string configPath, string database, string collection) { var databaseConfig = new JsonFileContent(configPath); var url = databaseConfig.Value("databaseUrl").ToString(); _client = new MongoClient(url); _database = _client.GetDatabase(database); _collection = _database.GetCollection <BsonDocument>(collection); }
public Intialization() { var configPath = Path.Join(Directory.GetCurrentDirectory(), "configs.json"); configContent = new JsonFileContent(configPath); consumer = new Consumer( configContent.Value("RabbitUrl").ToString(), configContent.Value("RabbitLogin").ToString(), configContent.Value("RabbitPassword").ToString() ); publisher = new Publisher( configContent.Value("RabbitUrl").ToString(), configContent.Value("RabbitLogin").ToString(), configContent.Value("RabbitPassword").ToString() ); connection = new MySqlDatabaseConnection( configContent.Value("MySqlServer").ToString(), configContent.Value("MySqlDatabase").ToString(), configContent.Value("MySqlLogin").ToString(), configContent.Value("MySqlPassword").ToString() ); databaseClient = new MySqlDatabaseClient(connection); facade = new SubscriptionFacade("configs.json", consumer, publisher, databaseClient); }
private void QuantifyRequests() { var now = DateTime.UtcNow; if (_currentDay.Day != now.Day) { _currentDay = DateTime.UtcNow; _apiRequestsLeft = int.Parse((string)_configs.Value("RequestsPerDay")); } if (now.Ticks - _lastRequestTime.Ticks < 1000 / _requestsPerSecond) { int delay = (1000 / _requestsPerSecond) - (int)(now.Ticks - _lastRequestTime.Ticks); System.Threading.Thread.Sleep(delay); } if (_apiRequestsLeft <= 0) { throw new Exception("LocationIq: No more api requests."); } _apiRequestsLeft -= 1; }