private bool TryCreatePersistentStorage(
            Solution solution, string workingFolderPath,
            out AbstractPersistentStorage persistentStorage)
        {
            persistentStorage = null;
            AbstractPersistentStorage database = null;

            try
            {
                database = OpenDatabase(solution, workingFolderPath);
                database.Initialize(solution);

                persistentStorage = database;
                return(true);
            }
            catch (Exception ex)
            {
                StorageDatabaseLogger.LogException(ex);

                if (database != null)
                {
                    database.Close();
                }

                if (ShouldDeleteDatabase(ex))
                {
                    // this was not a normal exception that we expected during DB open.
                    // Report this so we can try to address whatever is causing this.
                    FatalError.ReportWithoutCrash(ex);
                    IOUtilities.PerformIO(() => Directory.Delete(database.DatabaseDirectory, recursive: true));
                }

                return(false);
            }
        }
 protected void Release(AbstractPersistentStorage storage)
 {
     lock (_primaryStorageAccessLock)
     {
         if (storage.ReleaseRefUnsafe())
         {
             storage.Close();
         }
     }
 }
            public void EnsureStorage(Solution solution, AbstractPersistentStorage storage)
            {
                if (Storage != null || solution.Id != SolutionId)
                {
                    return;
                }

                // hold onto the primary solution when it is used the first time.
                Storage = storage;
                storage.AddRefUnsafe();
            }
        public void UnregisterPrimarySolution(SolutionId solutionId, bool synchronousShutdown)
        {
            AbstractPersistentStorage storage = null;

            lock (_primaryStorageAccessLock)
            {
                _primaryStorage.UnregisterPrimarySolution(solutionId, out storage);
            }

            ReleaseStorage(storage, synchronousShutdown);
        }
示例#5
0
 private void Release(AbstractPersistentStorage storage)
 {
     lock (_lookupAccessLock)
     {
         if (storage.ReleaseRefUnsafe())
         {
             _lookup.Remove(storage.SolutionFilePath);
             storage.Close();
         }
     }
 }
示例#6
0
        private void RegisterPrimarySolutionStorageIfNeeded(Solution solution, AbstractPersistentStorage storage)
        {
            if (_primarySolutionStorage != null || solution.Id != _primarySolutionId)
            {
                return;
            }

            // hold onto the primary solution when it is used the first time.
            _primarySolutionStorage = storage;
            storage.AddRefUnsafe();
        }
示例#7
0
        public PersistentStorageService(IOptionService optionService)
        {
            _optionService = optionService;

            _lookupAccessLock = new object();
            _lookup           = new Dictionary <string, AbstractPersistentStorage>();

            _lastSolutionPath = null;

            _primarySolutionId      = null;
            _primarySolutionStorage = null;
        }
示例#8
0
        protected AbstractPersistentStorageService(
            IOptionService optionService,
            SolutionSizeTracker solutionSizeTracker)
        {
            OptionService        = optionService;
            _solutionSizeTracker = solutionSizeTracker;

            _lookupAccessLock = new object();
            _lookup           = new Dictionary <string, AbstractPersistentStorage>();

            _lastSolutionPath = null;

            _primarySolutionId      = null;
            _primarySolutionStorage = null;
        }
            public void UnregisterPrimarySolution(SolutionId solutionId, out AbstractPersistentStorage storage)
            {
                storage = null;
                if (SolutionId == null)
                {
                    // primary solution is never registered or already unregistered
                    Contract.ThrowIfTrue(Storage != null);
                    return;
                }

                Contract.ThrowIfFalse(SolutionId == solutionId);

                storage = Storage;

                SolutionId = null;
                Storage    = null;
            }
        private static void ReleaseStorage(AbstractPersistentStorage storage, bool synchronousShutdown)
        {
            if (storage == null)
            {
                return;
            }

            if (synchronousShutdown)
            {
                // dispose storage outside of the lock
                storage.Dispose();
            }
            else
            {
                // make it to shutdown asynchronously
                Task.Run(() => storage.Dispose());
            }
        }
示例#11
0
        protected override bool TryOpenDatabase(
            Solution solution, string workingFolderPath, string databaseFilePath, out AbstractPersistentStorage storage)
        {
            storage = null;

            // try to get db ownership lock. if someone else already has the lock. it will throw
            var dbOwnershipLock = TryGetDatabaseOwnership(databaseFilePath);

            if (dbOwnershipLock == null)
            {
                return(false);
            }

            storage = new SQLitePersistentStorage(
                OptionService, workingFolderPath, solution.FilePath, databaseFilePath, this.Release, dbOwnershipLock, _faultInjectorOpt);

            return(true);
        }
示例#12
0
        public void UnregisterPrimarySolution(SolutionId solutionId, bool synchronousShutdown)
        {
            AbstractPersistentStorage storage = null;

            lock (_lookupAccessLock)
            {
                if (_primarySolutionId == null)
                {
                    // primary solution is never registered or already unregistered
                    Contract.ThrowIfTrue(_primarySolutionStorage != null);
                    return;
                }

                Contract.ThrowIfFalse(_primarySolutionId == solutionId);

                _primarySolutionId = null;
                if (_primarySolutionStorage == null)
                {
                    // primary solution is registered but no C#/VB project was added
                    return;
                }

                storage = _primarySolutionStorage;
                _primarySolutionStorage = null;
            }

            if (storage != null)
            {
                if (synchronousShutdown)
                {
                    // dispose storage outside of the lock
                    storage.Dispose();
                }
                else
                {
                    // make it to shutdown asynchronously
                    Task.Run(() => storage.Dispose());
                }
            }
        }
            public bool TryGetStorage(
                string solutionFilePath,
                string workingFolderPath,
                out AbstractPersistentStorage storage)
            {
                storage = null;

                if (Storage == null)
                {
                    return(false);
                }

                if (Storage.SolutionFilePath != solutionFilePath ||
                    Storage.WorkingFolderPath != workingFolderPath)
                {
                    return(false);
                }

                storage = Storage;
                storage.AddRefUnsafe();

                return(true);
            }
 protected abstract bool TryOpenDatabase(Solution solution, string workingFolderPath, string databaseFilePath, out AbstractPersistentStorage storage);
示例#15
0
        private bool TryCreateEsentStorage(string workingFolderPath, string solutionPath, out AbstractPersistentStorage esentStorage)
        {
            esentStorage = null;
            EsentPersistentStorage esent = null;

            try
            {
                esent = new EsentPersistentStorage(_optionService, workingFolderPath, solutionPath, this.Release);
                esent.Initialize();

                esentStorage = esent;
                return(true);
            }
            catch (EsentAccessDeniedException ex)
            {
                // esent db is already in use by someone.
                if (esent != null)
                {
                    esent.Close();
                }

                EsentLogger.LogException(ex);

                return(false);
            }
            catch (Exception ex)
            {
                if (esent != null)
                {
                    esent.Close();
                }

                EsentLogger.LogException(ex);
            }

            try
            {
                if (esent != null)
                {
                    Directory.Delete(esent.EsentDirectory, recursive: true);
                }
            }
            catch
            {
                // somehow, we couldn't delete the directory.
            }

            return(false);
        }