/// <summary> /// Navigate, instantiate and return the Store as referenced by the storePath. /// Following conditions apply: /// - if any element in the storePath is not found and can't be created even if flag /// is set to true, this throws exception. /// - if any element in the storePath is not found and create flag is false, this returns null. /// </summary> /// <typeparam name="TKey"></typeparam> /// <typeparam name="TValue"></typeparam> /// <param name="storePath"></param> /// <param name="createStoreIfNotExist"></param> /// <param name="storeKeyComparer"></param> /// <param name="isDataInKeySegment"></param> /// <returns></returns> public ISortedDictionary <TKey, TValue> GetStorePersistent <TKey, TValue>( string storePath, StoreParameters <TKey> storeConfig = null, Profile fileConfig = null) where TKey : IPersistent, new() where TValue : IPersistent, new() { string s; ISortedDictionaryOnDisk container = getContainerWithRootStoreCheck(storePath, out s, config: fileConfig); if (container == null) { throw new ArgumentException(string.Format("Can't get a valid Store Container from storePath {0}.", storePath)); } Sop.IStoreFactory sf = new Sop.StoreFactory(); ISortedDictionary <TKey, TValue> store; if (storeConfig == null) { return(container.Locker.Invoke(() => { return sf.Get <TKey, TValue>(container, s); })); } else { return(container.Locker.Invoke(() => { store = sf.GetPersistent <TKey, TValue>(container, s, storeConfig.StoreKeyComparer, storeConfig.CreateStoreIfNotExist, storeConfig.IsDataInKeySegment, storeConfig.MruManaged, storeConfig.IsUnique); if (store != null) { ((Sop.SpecializedDataStore.SimpleKeyValue <TKey, TValue>)store).Path = storePath; store.AutoFlush = storeConfig.AutoFlush; } return store; })); } }
public EnumeratorEnumeratorFilter(ISortedDictionary <TKey, TValue> target, IEnumerable <KeyValuePair <TSourceKey, TSourceValue> > source, ExtractKey <TSourceKey, TSourceValue, TKey> sourceKeyExtractor = null, bool lockWrap = false) { if (target == null) { throw new ArgumentNullException("target"); } if (source == null) { throw new ArgumentNullException("source"); } if (lockWrap) { target.Locker.Lock(OperationType.Read); } _target = (ISortedDictionaryOnDisk)((SpecializedStoreBase)target).Collection.Clone(); _source = source.GetEnumerator(); _sourceKeyExtractor = sourceKeyExtractor; _lockWrap = lockWrap; if (_sourceKeyExtractor == null) { _sourceKeyExtractor = DefaultKeyExtractor <TSourceKey, TSourceValue, TKey>; } }
/// <summary> /// Sample code that uses this VirtualCache. /// </summary> public static void Run() { Console.WriteLine("{0}: Virtual Cache demo started...", DateTime.Now); MemoryExtender.ServerPath = "SopBin\\"; MemoryExtender vc = new MemoryExtender(); ISortedDictionaryOnDisk cache1 = vc.GetObjectCache(1); const int MaxCount = 40000; for (int i = 0; i < MaxCount; i++) { cache1.Add(i, string.Format("{0} cached data", i)); } Console.WriteLine("{0}: Finished inserting {1} records, reading 'em starts now...", DateTime.Now, MaxCount); cache1.MoveFirst(); cache1.HintSequentialRead = true; for (int i = 0; i < MaxCount; i++) { string s = cache1.CurrentValue as string; if (string.IsNullOrEmpty(s) || s != string.Format("{0} cached data", i)) { Console.WriteLine("Error, data not found."); } cache1.MoveNext(); } Console.WriteLine("{0}: Virtual Cache demo ended... {1} records were read.", DateTime.Now, MaxCount); }
internal GeneralPurpose(object container, IComparer <TKey> comparer, string name, DataStoreType dataStoreType, ISortedDictionaryOnDisk dataStore, bool isDataInKeySegment) : base( container, comparer, name, dataStoreType, dataStore, isDataInKeySegment) { }
internal PersistentTypeValueSimpleKey(object container, IComparer <TKey> comparer, string came, DataStoreType dataStoreType, ISortedDictionaryOnDisk dataStore, bool isDataInKeySegment) : base( container, comparer, came, dataStoreType, dataStore, isDataInKeySegment) { }
private ISortedDictionaryOnDisk getContainerWithRootStoreCheck(string storePath, out string storeName, bool createStoreIfNotExist = true, Profile config = null) { ISortedDictionaryOnDisk container = getContainer(storePath, out storeName, config: config); //if (storeName == storePath) // throw new SopException(string.Format("{0} refers to the File's root Store and it can't be cast as a strongly typed Store.", storePath)); return(container); }
/// <summary> /// Override SimpleKeyValue GetCollection to add support for IPersistent Value POCO (de)serialization. /// </summary> /// <param name="container"></param> /// <param name="comparer"></param> /// <param name="came"></param> /// <param name="isDataInKeySegment"></param> /// <returns></returns> protected override ISortedDictionaryOnDisk GetCollection( ISortedDictionaryOnDisk container, GenericComparer <TKey> comparer, string came, bool isDataInKeySegment) { var o = (OnDisk.Algorithm.SortedDictionary.ISortedDictionaryOnDisk) base.GetCollection(container, comparer, came, isDataInKeySegment); o.OnValuePack += new OnObjectPack(Collection_OnPack); o.OnValueUnpack += new OnObjectUnpack(Collection_OnValueUnpack); return(o); }
private ISortedDictionaryOnDisk getContainer(string storePath, out string storeName, bool createStoreIfNotExist = true, Profile config = null) { if (string.IsNullOrWhiteSpace(storePath)) { throw new ArgumentNullException("storePath"); } storeName = null; string[] parts = storePath.Split(new char[] { storeUriSeparator }, StringSplitOptions.RemoveEmptyEntries); if (parts == null || parts.Length == 0) { return(null); } var f = _server.GetFile(parts[0]); if (f == null) { // if storePath is a Store name (no File in path), simply return the SystemFile's default Store... if (parts.Length == 1) { storeName = parts[0]; return(_server.SystemFile.Store); } else if (!createStoreIfNotExist) { return(null); } else { // auto create the File if createStoreIfNotExist is true... f = _server.FileSet.Add(parts[0], profile: config); } } ISortedDictionaryOnDisk container = f.Store; for (int i = 1; i < parts.Length - 1; i++) { if (container.Contains(parts[i])) { container = (ISortedDictionaryOnDisk)container.GetValue(parts[i], null); if (container == null) { throw new SopException(string.Format("Can't recreate Store {0}", parts[i])); } continue; } if (!createStoreIfNotExist) { return(null); } container = CreateCollection(container, parts[i]); } storeName = parts[parts.Length - 1]; return(container); }
/// <summary> /// Remove a Data Store referenced by storePath. /// </summary> /// <param name="storePath"></param> public void Remove(string storePath) { string s; ISortedDictionaryOnDisk container = getContainerWithRootStoreCheck(storePath, out s); if (container == null) { throw new ArgumentException(string.Format("Can't get a valid Store Container from storePath {0}.", storePath)); } Sop.IStoreFactory sf = new Sop.StoreFactory(); container.Locker.Invoke(() => { sf.Remove(container, s); }); }
/// <summary> /// Override SimpleKeyValue GetCollection to add support for IPersistent Key POCO (de)serialization. /// </summary> /// <param name="container"></param> /// <param name="comparer"></param> /// <param name="name"></param> /// <param name="isDataInKeySegment"></param> /// <returns></returns> protected override ISortedDictionaryOnDisk GetCollection( ISortedDictionaryOnDisk container, GenericComparer <TKey> comparer, string name, bool isDataInKeySegment) { var o = (OnDisk.Algorithm.SortedDictionary.ISortedDictionaryOnDisk) base.GetCollection(container, comparer, name, isDataInKeySegment); o.OnKeyPack += new OnObjectPack(Collection_OnPack); o.OnKeyUnpack += new OnObjectUnpack(Collection_OnKeyUnpack); if (((SortedDictionaryOnDisk)o).BTreeAlgorithm.RootNeedsReload) { ((SortedDictionaryOnDisk)o).ReloadRoot(); } return(o); }
/// <summary> /// Override SimpleKeyValue GetCollection to add support for IPersistent Value POCO (de)serialization. /// </summary> /// <param name="container"></param> /// <param name="comparer"></param> /// <param name="came"></param> /// <param name="isDataInKeySegment"></param> /// <returns></returns> protected override ISortedDictionaryOnDisk GetCollection( ISortedDictionaryOnDisk container, GenericComparer <TKey> comparer, string came, bool isDataInKeySegment) { var o = (OnDisk.Algorithm.SortedDictionary.ISortedDictionaryOnDisk) base.GetCollection(container, comparer, came, isDataInKeySegment); // pack/unpack for Xml Serializable objects... o.OnKeyPack += Collection_XmlSerOnPack; o.OnKeyUnpack += Collection_XmlSerOnUnpack; // pack/unpack for IPersistent implementing objects... o.OnValuePack += new OnObjectPack(Collection_OnPack); o.OnValueUnpack += new OnObjectUnpack(Collection_OnValueUnpack); return(o); }
public EnumeratorKeysFilter(ISortedDictionary <TKey, TValue> store, TKey[] keys, bool lockWrap = false) { if (keys == null || keys.Length == 0) { throw new ArgumentNullException("keys"); } if (store == null) { throw new ArgumentNullException("store"); } _lockWrap = lockWrap; if (lockWrap) { store.Locker.Lock(OperationType.Read); } _store = (ISortedDictionaryOnDisk)((SpecializedStoreBase)store).Collection.Clone(); _keys = keys; }
public void Dispose() { if (_store == null) { return; } if (_lockWrap) { _store.Dispose(); _store.Locker.Unlock(OperationType.Read); } else { _store.Locker.Invoke(() => { _store.Dispose(); }, OperationType.Read); } _store = null; }
public void Dispose() { if (_target == null) { return; } if (_lockWrap) { _target.Dispose(); _target.Locker.Unlock(OperationType.Read); } else { _target.Locker.Invoke(() => { _target.Dispose(); }, OperationType.Read); } _target = null; _source.Dispose(); _source = null; }
private ISortedDictionaryOnDisk CreateCollection(ISortedDictionaryOnDisk container, string storeName) { return(container.Locker.Invoke(() => { ISortedDictionaryOnDisk o; if (container.Transaction != null) { o = ((Transaction.ITransactionLogger)container.Transaction).CreateCollection( container.File, null, storeName, true); } else { o = OnDisk.ObjectServer.CreateDictionaryOnDisk( ((OnDisk.Algorithm.SortedDictionary.ISortedDictionaryOnDisk)container).File, null, storeName, true); } o.Open(); o.Flush(); container.Add(o.Name, o); o.Container = container; return o; })); }
/// <summary> /// Retrieves the raw (unwrapped), object Typed Key/Value Store as referenced by storePath. /// </summary> /// <param name="storePath"></param> /// <returns>ISortedDictionaryOnDisk object</returns> public ISortedDictionaryOnDisk GetUnwrappedStore(string storePath) { string s; ISortedDictionaryOnDisk container = getContainer(storePath, out s, false); // if storePath references the File object, 'just return container as it should be the File's default Store. if (s == storePath) { return(container); } if (container == null || !container.Contains(s)) { return(null); } var v = container.GetValue(s, null); var sf = new Sop.StoreFactory(); container = sf.GetContainer(v); if (container == null) { throw new SopException(string.Format("Can't recreate Store {0}", s)); } return(container); }
internal PersistentTypeValueSimpleKey(object container, IComparer <TKey> comparer, string came, DataStoreType dataStoreType, ISortedDictionaryOnDisk dataStore) : this(container, comparer, came, dataStoreType, dataStore, false) { }
public GenericCollection(ISortedDictionaryOnDisk collection) { this.Collection = (SortedDictionaryOnDisk)collection; }
internal GeneralPurpose(object container, IComparer <TKey> comparer, string name, DataStoreType dataStoreType, ISortedDictionaryOnDisk dataStore) : this(container, comparer, name, dataStoreType, dataStore, false) { }