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); } }
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); } }
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); }
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); }
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); } } }
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; }
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; }
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); } }
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; } }
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); } }