public void Initialize(ServiceContext context) { this.context = context; string Database = context.ConfigReader.GetCheckedValue <string, ParrotConfig>("database", "database"); string Host = context.ConfigReader.GetCheckedValue <string, ParrotConfig>("database", "host"); string AppName = context.ConfigReader.GetCheckedValue <string, ParrotConfig>("database", "appname"); string Username = context.ConfigReader.GetCheckedValue <string, ParrotConfig>("database", "username"); string Password = context.ConfigReader.GetCheckedValue <string, ParrotConfig>("database", "password"); int Port = context.ConfigReader.GetCheckedValue <int, ParrotConfig>("database", "port"); provider = new PostgresqlDataProvider(Database, Host, AppName, Username, Password, Port); repository = new PostgresqlParrotRepository(provider); handler = new DatabaseHandler(repository); webHandler = new ParrotWebHandler(model, handler); repository.Configure(context); context.RestfulServer.UseRoute((RouteBuilder routeBuilder) => { routeBuilder .MapGet("message/recent", webHandler.GetRecent) .MapGet("message/current", webHandler.GetCurrent) .MapPost("message/new", webHandler.PostMessage) .MapGet("message/database/getrecord/{id}", webHandler.GetRecord) .MapGet("message/database/getmaxkey", webHandler.GetMaxId) ; }); broadcastInterval = context.ConfigReader.GetCheckedValueOrDefault <int, ParrotConfig>( new[] { "parrot", "broadcastInterval" }, 1000); recentIntervalCount = context.ConfigReader.GetCheckedValueOrDefault <int, ParrotConfig>( new[] { "parrot", "recentIntervalCount" }, 5); context.PubSubClient.Subscribe(ParrotTopics.Broadcast, (topic, message) => { logger.DebugFormat("Pub/sub echo {0}: {1}", topic, message); }); }
public DatabaseHandler(IParrotRepository parrotRepository) { _parrotRepository = parrotRepository; }