Пример #1
0
        public SingleFileStore CreateStore(string name)
        {
            lock (checkPointLock) {
                SingleFileStore store;
                if (TryFindStore(name, out store))
                {
                    throw new IOException(string.Format("The store '{0}' already exists in this database.", name));
                }

                if (nameIdMap == null)
                {
                    nameIdMap = new Dictionary <string, int>();
                }

                if (stores == null)
                {
                    stores = new Dictionary <int, SingleFileStore>();
                }

                var id = ++storeId;
                store = new SingleFileStore(this, name, id);
                store.Open();
                stores[id]      = store;
                nameIdMap[name] = id;
                return(store);
            }
        }
Пример #2
0
        public bool CloseStore(SingleFileStore store)
        {
            try {
                SingleFileStore fileStore;
                if (!TryFindStore(store.Name, out fileStore))
                {
                    throw new IOException("The store was not found in this database.");
                }

                fileStore.Close();
                return(true);
            } catch (IOException) {
                throw;
            } catch (Exception ex) {
                throw new IOException("Unable to close the store.", ex);
            }
        }
Пример #3
0
        private bool TryFindStore(string storeName, out SingleFileStore store)
        {
            int id;

            if (nameIdMap == null || !nameIdMap.TryGetValue(storeName, out id))
            {
                store = null;
                return(false);
            }

            if (stores == null || !stores.TryGetValue(id, out store))
            {
                store = null;
                return(false);
            }

            return(true);
        }
Пример #4
0
        private long WriteStoreInfo(BinaryWriter writer, long offset, SingleFileStore store)
        {
            var nameLength = store.Name.Length;
            var name       = store.Name;
            var id         = store.Id;
            var size       = store.DataLength;

            writer.Write(nameLength);
            writer.Write(name.ToCharArray());

            writer.Write(id);
            writer.Write(offset);
            writer.Write(size);

            storeInfo[store.Id] = new StoreInfo(name, id, offset, size);

            offset += store.DataLength;

            return(offset);
        }
Пример #5
0
        public bool DeleteStore(SingleFileStore store)
        {
            try {
                if (stores == null || !stores.ContainsKey(store.Id))
                {
                    return(false);
                }

                return(stores.Remove(store.Id));
            } catch (IOException) {
                throw;
            } catch (Exception ex) {
                throw new IOException("Unable to delete the store.", ex);
            } finally {
                if (nameIdMap != null)
                {
                    nameIdMap.Remove(store.Name);
                }
            }
        }
Пример #6
0
        private long WriteStoreInfo(BinaryWriter writer, long offset, SingleFileStore store)
        {
            var nameLength = store.Name.Length;
            var name = store.Name;
            var id = store.Id;
            var size = store.DataLength;

            writer.Write(nameLength);
            writer.Write(name.ToCharArray());

            writer.Write(id);
            writer.Write(offset);
            writer.Write(size);

            storeInfo[store.Id] = new StoreInfo(name, id, offset, size);

            offset += store.DataLength;

            return offset;
        }
Пример #7
0
        private bool TryFindStore(string storeName, out SingleFileStore store)
        {
            int id;
            if (nameIdMap == null || !nameIdMap.TryGetValue(storeName, out id)) {
                store = null;
                return false;
            }

            if (stores == null || !stores.TryGetValue(id, out store)) {
                store = null;
                return false;
            }

            return true;
        }
Пример #8
0
        public bool DeleteStore(SingleFileStore store)
        {
            try {
                if (stores == null || !stores.ContainsKey(store.Id))
                    return false;

                return stores.Remove(store.Id);
            } catch (IOException) {
                throw;
            } catch (Exception ex) {
                throw new IOException("Unable to delete the store.", ex);
            } finally {
                if (nameIdMap != null)
                    nameIdMap.Remove(store.Name);
            }
        }
Пример #9
0
        public SingleFileStore CreateStore(string name)
        {
            lock (checkPointLock) {
                SingleFileStore store;
                if (TryFindStore(name, out store))
                    throw new IOException(string.Format("The store '{0}' already exists in this database.", name));

                if (nameIdMap == null)
                    nameIdMap = new Dictionary<string, int>();

                if (stores == null)
                    stores = new Dictionary<int, SingleFileStore>();

                var id = ++storeId;
                store = new SingleFileStore(this, name, id);
                store.Open();
                stores[id] = store;
                nameIdMap[name] = id;
                return store;
            }
        }
Пример #10
0
        public bool CloseStore(SingleFileStore store)
        {
            try {
                SingleFileStore fileStore;
                if (!TryFindStore(store.Name, out fileStore))
                    throw new IOException("The store was not found in this database.");

                fileStore.Close();
                return true;
            } catch (IOException) {
                throw;
            } catch (Exception ex) {
                throw new IOException("Unable to close the store.", ex);
            }
        }