public void Close()
        {
            lock (commitLock) {
                CleanUp();

                StoreSystem.SetCheckPoint();

                // Go through and close all the committed tables.
                foreach (var source in tableSources.Values)
                {
                    source.Close(false);
                }

                StateStore.Flush();
                StoreSystem.CloseStore(stateStore);

                //tableSources = null;
                IsClosed = true;
            }

            // Release the storage system
            StoreSystem.Unlock(StateStoreName);

            if (LargeObjectStore != null)
            {
                StoreSystem.CloseStore(lobStore);
            }
        }
        public void Delete()
        {
            lock (commitLock) {
                // We possibly have things to clean up.
                CleanUp();

                // Go through and delete and close all the committed tables.
                foreach (var source in tableSources.Values)
                {
                    source.Drop();
                }

                // Delete the state file
                StateStore.Flush();
                StoreSystem.CloseStore(stateStore);
                StoreSystem.DeleteStore(stateStore);

                // Delete the blob store
                if (LargeObjectStore != null)
                {
                    StoreSystem.CloseStore(lobStore);
                    StoreSystem.DeleteStore(lobStore);
                }

                //tableSources = null;
                IsClosed = true;
            }

            // Release the storage system.
            StoreSystem.Unlock(StateStoreName);
        }
        public void Open()
        {
            if (!Exists())
            {
                throw new IOException("Table composite does not exist");
            }

            // Check the file Lock
            if (!IsReadOnly)
            {
                // Obtain the Lock (generate error if this is not possible)
                StoreSystem.Lock(StateStoreName);
            }

            // Open the state store
            stateStore = StoreSystem.OpenStore(StateStoreName);
            StateStore = new TableStateStore(stateStore);

            // Get the fixed 64 byte area.
            var  fixedArea = stateStore.GetArea(-1);
            long headP     = fixedArea.ReadInt8();

            StateStore.Open(headP);

            Setup();

            InitObjectStore();

            ReadVisibleTables();
            ReadDroppedTables();

            CleanUp();
        }
    public void Buy(int id)
    {
        if (id < 0 || id >= packList.Length || packList[id].pack == null)
        {
            return;
        }

        StoreSystem.BuyItem(packList[id].pack);
    }
        internal void Close(bool dropPending)
        {
            if (IsClosed)
            {
                return;
            }

            lock (this) {
                // NOTE: This method MUST be synchronized over the table to prevent
                //   establishing a root Lock on this table.  If a root Lock is established
                //   then the collection event could fail.

                lock (recordList) {
                    // If we are root locked, we must become un root locked.
                    ClearLocks();

                    try {
                        try {
                            Store.Lock();

                            // Force a garbage collection event.
                            if (!IsReadOnly)
                            {
                                GC.Collect(true);
                            }

                            // If we are closing pending a drop, we need to remove all blob
                            // references input the table.
                            // NOTE: This must only happen after the above collection event.
                            if (dropPending)
                            {
                                // Scan and remove all blob references for this dropped table.
                                ReleaseObjects();
                            }
                        } finally {
                            Store.Unlock();
                        }
                    } catch (Exception) {
                        // TODO: Register the error to the logs
                    }

                    // Synchronize the store
                    indexSetStore.Close();

                    // Close the store input the store system.
                    StoreSystem.CloseStore(Store);

                    // TableInfo = null;
                    IsClosed = true;
                }
            }
        }
Exemple #6
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (StoreSystem != null)
                {
                    StoreSystem.Dispose();
                }
            }

            StoreSystem = null;

            base.Dispose(disposing);
        }
Exemple #7
0
    void Start()
    {
        uiController = UiController.instance;
        storeSystem  = GetComponentInParent <StoreSystem>();

        if (itensSO != null)
        {
            typeImage.sprite = itensSO.productTypeImage;
            nameText.text    = itensSO.productName;
            valueText.text   = "x " + itensSO.productValue.ToString();
            thisTypeItem     = itensSO.thisType;
            mainImage.sprite = itensSO.productImage;
            stats            = PlayerBehaviour.instance;
        }
    }
Exemple #8
0
        private void InitObjectStore()
        {
            // Does the file already exist?
            bool blobStoreExists = StoreSystem.StoreExists(ObjectStoreName);

            // If the blob store doesn't exist and we are read_only, we can't do
            // anything further so simply return.
            if (!blobStoreExists && IsReadOnly)
            {
                return;
            }

            // The blob store,
            // TODO: Support store-level configuration?
            if (blobStoreExists)
            {
                lobStore = StoreSystem.OpenStore(ObjectStoreName, new Configuration());
            }
            else
            {
                lobStore = StoreSystem.CreateStore(ObjectStoreName, new Configuration());
            }

            try {
                lobStore.Lock();

                // TODO: have multiple BLOB stores
                LargeObjectStore = new LargeObjectStore(0, lobStore);

                // Get the 64 byte fixed area
                var fixedArea = lobStore.GetArea(-1, false);
                // If the blob store didn't exist then we need to create it here,
                if (!blobStoreExists)
                {
                    long headerP = LargeObjectStore.Create();
                    fixedArea.Write(headerP);
                    fixedArea.Flush();
                }
                else
                {
                    // Otherwise we need to initialize the blob store
                    long headerP = fixedArea.ReadInt64();
                    LargeObjectStore.Open(headerP);
                }
            } finally {
                lobStore.Unlock();
            }
        }
        internal bool Drop()
        {
            lock (this) {
                lock (recordList) {
                    if (!IsClosed)
                    {
                        Close(true);
                    }

                    if (StoreSystem.DeleteStore(Store))
                    {
                        // TODO: log this
                        return(true);
                    }

                    return(false);
                }
            }
        }
Exemple #10
0
        public void Commit(ITransaction transaction)
        {
            var selectedFromTables = transaction.State.SelectedTables;
            var touchedTables      = transaction.State.AccessedTables;

            var commit = new TransactionCommit(this, transaction, selectedFromTables, touchedTables, transaction.Registry);

            if (!commit.HasTableChanges)
            {
                CloseTransaction(transaction);
                return;
            }

            lock (commitLock) {
                var objectStates      = new List <ObjectCommitState>();
                var changedTablesList = commit.Execute(objectStates);

                // Flush the journals up to the minimum commit id for all the tables
                // that this transaction changed.
                long minCommitId = Database.OpenTransactions.MinimumCommitId(null);
                foreach (var master in changedTablesList)
                {
                    master.MergeChanges(minCommitId);
                }

                int nsjsz = objectStates.Count;
                for (int i = nsjsz - 1; i >= 0; --i)
                {
                    var namespaceJournal = objectStates[i];
                    // Remove if the commit id for the journal is less than the minimum
                    // commit id
                    if (namespaceJournal.CommitId < minCommitId)
                    {
                        objectStates.RemoveAt(i);
                    }
                }

                // Set a check point in the store system.  This means that the
                // persistance state is now stable.
                StoreSystem.SetCheckPoint();
            }
        }
        public void Dispose()
        {
            if (FieldCache != null)
            {
                FieldCache.Clear();
            }

            if (headerArea != null)
            {
                headerArea.Dispose();
            }

            if (recordList != null)
            {
                recordList.Dispose();
            }

            if (Registries != null)
            {
                Registries.Dispose();
            }

            if (indexSetStore != null)
            {
                indexSetStore.Dispose();
            }

            if (Store != null)
            {
                if (StoreSystem.CloseStore(Store))
                {
                    Store.Dispose();
                }
            }

            headerArea    = null;
            recordList    = null;
            Registries    = null;
            indexSetStore = null;
        }
        internal void Commit(Transaction transaction, IList <ITableSource> visibleTables,
                             IEnumerable <ITableSource> selectedFromTables,
                             IEnumerable <IMutableTable> touchedTables, TransactionRegistry journal)
        {
            var state = new TransactionWork(this, transaction, selectedFromTables, touchedTables, journal);

            // Exit early if nothing changed (this is a Read-only transaction)
            if (!state.HasChanges)
            {
                CloseTransaction(state.Transaction);
                return;
            }

            lock (commitLock) {
                var changedTablesList = state.Commit(objectStates);

                // Flush the journals up to the minimum commit id for all the tables
                // that this transaction changed.
                long minCommitId = Database.TransactionFactory.OpenTransactions.MinimumCommitId(null);
                foreach (var master in changedTablesList)
                {
                    master.MergeChanges(minCommitId);
                }
                int nsjsz = objectStates.Count;
                for (int i = nsjsz - 1; i >= 0; --i)
                {
                    var namespaceJournal = objectStates[i];
                    // Remove if the commit id for the journal is less than the minimum
                    // commit id
                    if (namespaceJournal.CommitId < minCommitId)
                    {
                        objectStates.RemoveAt(i);
                    }
                }

                // Set a check point in the store system.  This means that the
                // persistance state is now stable.
                StoreSystem.SetCheckPoint();
            }
        }
Exemple #13
0
    void Start()
    {
        instance = this;

        int c = TableLocator.probsTable.Find("Prob").cars.Count;

        carProb = new float[c];

        for (int i = 0; i < c; i++)
        {
            carProb[i] = TableLocator.probsTable.Find("Prob").cars[i].Value;
        }

        int f = TableLocator.probsTable.Find("Prob").furnitures.Count;

        furnitureProb = new float[f];

        for (int i = 0; i < f; i++)
        {
            furnitureProb[i] = TableLocator.probsTable.Find("Prob").furnitures[i].Value;
        }
    }
        private void CreateTable()
        {
            // Initially set the table sequence_id to 1
            sequenceId = 1;

            // Create and open the store.
            // TODO: have a table-level configuration?
            Store = StoreSystem.CreateStore(StoreName, new Configuration());

            try {
                Store.Lock();

                // Setup the list structure
                recordList = new FixedRecordList(Store, 12);
            } finally {
                Store.Unlock();
            }

            // Initialize the store to an empty state,
            SetupInitialStore();
            indexSetStore.PrepareIndexes(TableInfo.Columns.Count + 1, 1, 1024);
        }
Exemple #15
0
        private void MinimalCreate(IEnumerable <ISystemFeature> features)
        {
            if (Exists())
            {
                throw new IOException("Composite already exists");
            }

            // Lock the store system (generates an IOException if exclusive Lock
            // can not be made).
            if (!IsReadOnly)
            {
                StoreSystem.Lock(StateStoreName);
            }

            // Create/Open the state store
            // TODO: Support store-level configuration?
            stateStore = StoreSystem.CreateStore(StateStoreName, new Configuration());
            try {
                stateStore.Lock();

                StateStore = new TableStateStore(stateStore);
                long headP = StateStore.Create();
                // Get the fixed area
                var fixedArea = stateStore.GetArea(-1);
                fixedArea.Write(headP);
                fixedArea.Flush();
            } finally {
                stateStore.Unlock();
            }

            Setup();

            // Init the conglomerate blob store
            InitObjectStore();

            // Create the system table (but don't initialize)
            CreateSystem(features);
        }
        internal void MinimalCreate()
        {
            if (Exists())
            {
                throw new IOException("Composite already exists");
            }

            // Lock the store system (generates an IOException if exclusive Lock
            // can not be made).
            if (!IsReadOnly)
            {
                StoreSystem.Lock(StateStoreName);
            }

            // Create/Open the state store
            stateStore = StoreSystem.CreateStore(StateStoreName);
            try {
                stateStore.Lock();

                StateStore = new TableStateStore(stateStore);
                long headP = StateStore.Create();
                // Get the fixed area
                var fixedArea = stateStore.GetArea(-1);
                fixedArea.WriteInt8(headP);
                fixedArea.Flush();
            } finally {
                stateStore.Unlock();
            }

            Setup();

            // Init the conglomerate blob store
            InitObjectStore();

            // Create the system table (but don't initialize)
            CreateSystemSchema();
        }
 public void Buy()
 {
     StoreSystem.BuyItem(pack);
 }
Exemple #18
0
 public bool Exists() => StoreSystem.StoreExists(StateStoreName);
 public bool Exists()
 {
     return(StoreSystem.StoreExists(StateStoreName));
 }