Пример #1
0
        public void MergeStores()
        {
            var newMemoryStore = new PropertyDatabaseMemoryStore();

            using (m_MemoryStore.LockUpgradeableRead())
                using (m_FileStore.LockUpgradeableRead())
                    using (var newMemoryStoreView = (PropertyDatabaseMemoryStoreView)newMemoryStore.GetView())
                    {
                        // Merge both stores
                        newMemoryStoreView.MergeWith(m_FileStoreView);
                        newMemoryStoreView.MergeWith(m_MemoryStoreView);

                        // Write new memory store to file.
                        var tempFilePath = GetTempFilePath(m_FileStore.filePath);
                        newMemoryStoreView.SaveToFile(tempFilePath);

                        // Swap file store with new one
                        m_FileStore.SwapFile(tempFilePath);

                        // Clear the memory store after file was swapped. If you do it before, you risk
                        // entering a state where another thread could try to read between the moment the clear is done
                        // and the new file is written and opened.
                        m_MemoryStoreView.Clear();
                    }
        }
Пример #2
0
 public void Dispose()
 {
     if (m_Disposed)
     {
         return;
     }
     m_Store     = null;
     m_StoreData = null;
     m_Disposed  = true;
 }
Пример #3
0
 public PropertyDatabaseView(PropertyDatabase propertyDatabase, PropertyDatabaseVolatileMemoryStore volatileMemoryStore, PropertyDatabaseMemoryStore memoryStore, PropertyDatabaseFileStore fileStore, PropertyStringTable stringTable, bool delayedSync)
 {
     m_PropertyDatabase        = propertyDatabase;
     m_MemoryStore             = memoryStore;
     m_FileStore               = fileStore;
     m_VolatileMemoryStoreView = (PropertyDatabaseVolatileMemoryStoreView)volatileMemoryStore.GetView();
     m_MemoryStoreView         = (PropertyDatabaseMemoryStoreView)memoryStore.GetView();
     m_FileStoreView           = (PropertyDatabaseFileStoreView)fileStore.GetView();
     m_StringTableView         = stringTable.GetView(delayedSync);
     m_Disposed    = false;
     m_DelayedSync = delayedSync;
 }
Пример #4
0
        public PropertyDatabase(string filePath, bool autoBackgroundUpdate, double backgroundUpdateDebounceInSeconds = k_DefaultBackgroundUpdateDebounceInSeconds)
        {
            this.filePath        = filePath;
            stringTableFilePath  = GetStringTablePath(filePath);
            m_LocalVolatileStore = new PropertyDatabaseVolatileMemoryStore();
            m_LocalStore         = new PropertyDatabaseMemoryStore();
            m_FileStore          = new PropertyDatabaseFileStore(filePath);
            m_StringTable        = new PropertyStringTable(stringTableFilePath, 30);

            // Do not allow automatic background updates while running tests. The writing of the file
            // causes an assembly leak during the test Unity.IntegrationTests.Scripting.AssemblyReloadTest.AssemblyReloadDoesntLeakAssemblies
            // on MacOs. I haven't found out why exactly does the writing of a file causes an assembly to be held, so instead I deactivate
            // the automatic update during tests.
            this.autoBackgroundUpdate = autoBackgroundUpdate && !Utils.IsRunningTests();

            m_Debounce = Delayer.Debounce(_ => TriggerPropertyDatabaseBackgroundUpdate(), backgroundUpdateDebounceInSeconds);
        }
Пример #5
0
        public void Dispose()
        {
            if (m_Disposed)
            {
                return;
            }

            if (m_DelayedSync)
            {
                Sync();
            }

            m_PropertyDatabase = null;
            m_MemoryStore      = null;
            m_FileStore        = null;
            m_VolatileMemoryStoreView.Dispose();
            m_MemoryStoreView.Dispose();
            m_FileStoreView.Dispose();
            m_StringTableView.Dispose();
            m_DelayedSync = false;
            m_Disposed    = true;
        }
Пример #6
0
 public PropertyDatabaseMemoryStoreView(List <PropertyDatabaseRecord> storeData, PropertyDatabaseMemoryStore store)
 {
     m_StoreData = storeData;
     m_Store     = store;
     m_Disposed  = false;
 }