public IPersistentStorage GetStorage(Solution solution, bool checkBranchId) { if (!DatabaseSupported(solution, checkBranchId)) { return(NoOpPersistentStorage.Instance); } lock (_lock) { // Do we already have storage for this? if (solution.Id == _currentPersistentStorageSolutionId) { // We do, great return(PersistentStorageReferenceCountedDisposableWrapper.AddReferenceCountToAndCreateWrapper(_currentPersistentStorage)); } if (!SolutionSizeAboveThreshold(solution)) { return(NoOpPersistentStorage.Instance); } string workingFolder = _locationService.TryGetStorageLocation(solution.Id); if (workingFolder == null) { return(NoOpPersistentStorage.Instance); } if (!_subscribedToLocationServiceChangeEvents) { _locationService.StorageLocationChanging += LocationServiceStorageLocationChanging; _subscribedToLocationServiceChangeEvents = true; } // If we already had some previous cached service, let's let it start cleaning up if (_currentPersistentStorage != null) { var storageToDispose = _currentPersistentStorage; Task.Run(() => storageToDispose.Dispose()); _currentPersistentStorage = null; _currentPersistentStorageSolutionId = null; } _currentPersistentStorage = TryCreatePersistentStorage(solution, workingFolder); if (_currentPersistentStorage == null) { return(NoOpPersistentStorage.Instance); } _currentPersistentStorageSolutionId = solution.Id; return(PersistentStorageReferenceCountedDisposableWrapper.AddReferenceCountToAndCreateWrapper(_currentPersistentStorage)); } }
internal IChecksummedPersistentStorage GetStorageWorker(Solution solution) { lock (_lock) { // Do we already have storage for this? if (solution.Id == _currentPersistentStorageSolutionId) { // We do, great return(PersistentStorageReferenceCountedDisposableWrapper.AddReferenceCountToAndCreateWrapper(_currentPersistentStorage)); } if (!SolutionSizeAboveThreshold(solution)) { return(NoOpPersistentStorage.Instance); } var workingFolder = _locationService.TryGetStorageLocation(solution); if (workingFolder == null) { return(NoOpPersistentStorage.Instance); } // If we already had some previous cached service, let's let it start cleaning up if (_currentPersistentStorage != null) { var storageToDispose = _currentPersistentStorage; Task.Run(() => storageToDispose.Dispose()); _currentPersistentStorage = null; _currentPersistentStorageSolutionId = null; } _currentPersistentStorage = TryCreatePersistentStorage(solution, workingFolder); if (_currentPersistentStorage == null) { return(NoOpPersistentStorage.Instance); } _currentPersistentStorageSolutionId = solution.Id; return(PersistentStorageReferenceCountedDisposableWrapper.AddReferenceCountToAndCreateWrapper(_currentPersistentStorage)); } }