private void OpenAllExistingSensorDatabases() { List <string> databasesList = _environmentDatabase.GetMonitoringDatabases(); foreach (var databaseName in databasesList) { GetDatesFromFolderName(databaseName, out DateTime from, out DateTime to); if (from != DateTime.MinValue && to != DateTime.MinValue) { ISensorsDatabase database = LevelDBManager.GetSensorDatabaseInstance( _databaseSettings.GetPathToMonitoringDatabase(databaseName), from, to); _sensorsDatabases.AddDatabase(database); } } }
public ISensorsDatabase GetDatabase(DateTime time) { long ticks = time.Ticks; lock (_accessLock) { var correspondingItem = _sensorsDatabases.FirstOrDefault(i => i.DatabaseMinTicks <= ticks && i.DatabaseMaxTicks >= ticks); if (correspondingItem != null) { return(correspondingItem); } DateTime minDateTime = DateTimeMethods.GetMinDateTime(time); DateTime maxDateTime = DateTimeMethods.GetMaxDateTime(time); string newDatabaseName = CreateSensorsDatabaseName(minDateTime, maxDateTime); ISensorsDatabase newDatabase = LevelDBManager.GetSensorDatabaseInstance( _databaseSettings.GetPathToMonitoringDatabase(newDatabaseName), minDateTime, maxDateTime); _sensorsDatabases.Add(newDatabase); Task.Run(() => _environmentDatabase.AddMonitoringDatabaseToList(newDatabaseName)); return(newDatabase); } }