private IPersistentStorage GetStorage(Solution solution, string workingFolderPath) { lock (_lookupAccessLock) { // see whether we have something we can use AbstractPersistentStorage storage; if (_lookup.TryGetValue(solution.FilePath, out storage)) { // previous attempt to create esent storage failed. if (storage == null && !SolutionSizeAboveThreshold(solution)) { return(NoOpPersistentStorageInstance); } // everything seems right, use what we have if (storage?.WorkingFolderPath == workingFolderPath) { storage.AddRefUnsafe(); return(storage); } } // either this is the first time, or working folder path has changed. // remove existing one _lookup.Remove(solution.FilePath); var dbFile = EsentPersistentStorage.GetDatabaseFile(workingFolderPath); if (!File.Exists(dbFile) && !SolutionSizeAboveThreshold(solution)) { _lookup.Add(solution.FilePath, storage); return(NoOpPersistentStorageInstance); } // try create new one storage = TryCreateEsentStorage(workingFolderPath, solution.FilePath); _lookup.Add(solution.FilePath, storage); if (storage != null) { RegisterPrimarySolutionStorageIfNeeded(solution, storage); storage.AddRefUnsafe(); return(storage); } return(NoOpPersistentStorageInstance); } }