public async static Task ConnectToGatewayDb() { //connecting to DB bool connected = false; if (Convert.ToBoolean(ConfigurationManager.AppSettings["UseDB"])) { Console.WriteLine("Connecting to gateway database... "); string connectionString = ConfigurationManager.ConnectionStrings["DbConnection"].ConnectionString; gatewayDb = new GatewayRepositoryDapper(connectionString); gatewayDb.SetWriteInterval(Convert.ToInt32(ConfigurationManager.AppSettings["WritingToDbInterwal"])); gatewayDb.ShowDebugInConsole(Convert.ToBoolean(ConfigurationManager.AppSettings["ShowDBDebug"])); gatewayDb.SetStoreTxRxMessages(Convert.ToBoolean(ConfigurationManager.AppSettings["StoreTxRxMessagesInDB"])); while (!connected) { gatewayDb.ConnectToGateway(gateway); connected = (gatewayDb.IsDbExist()); if (!connected) await Task.Delay(5000); } } }
public static void ConnectToDB() { //connecting to DB if (!dataBaseEnabled) return; OnDebugStateMessage("DATABASE: Connecting... "); if (dataBaseConnectionString == null) { OnDebugStateMessage("DATABASE: Connection failed. Set ConnectionString in appsettings.json file."); return; } gatewayDb = new GatewayRepositoryDapper(dataBaseConnectionString); historyDb = new SensorsHistoryRepositoryDapper(dataBaseConnectionString); sensorsTasksDb = new SensorsTasksRepositoryDapper(dataBaseConnectionString); sensorsLinksDb = new SensorsLinksRepositoryDapper(dataBaseConnectionString); //todo logicalNodesRepository = new logicalNodesRepositoryDapper(dataBaseConnectionString); gatewayDb.SetWriteInterval(dataBaseWriteInterval); gatewayDb.ShowDebugInConsole(dataBaseDebugState); gatewayDb.SetStoreTxRxMessages(dataBaseWriteTxRxMessages); gatewayDb.ConnectToGateway(gateway); historyDb.SetWriteInterval(dataBaseWriteInterval); historyDb.ConnectToGateway(gateway); OnDebugStateMessage("DATABASE: Connected"); }