Exemplo n.º 1
0
        public ISortedDictionary <TKey, TValue> GetStorePersistent <TKey, TValue>(object container,
                                                                                  string storeName, StoreParameters <TKey> storeConfig = null)
            where TKey : IPersistent, new()
            where TValue : IPersistent, new()
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }
            var sf   = new Sop.StoreFactory();
            var cont = sf.GetContainer(container);
            ISortedDictionary <TKey, TValue> store;

            if (storeConfig == null)
            {
                return(cont.Locker.Invoke(() => { return sf.Get <TKey, TValue>(container, storeName); }));
            }
            else
            {
                return(cont.Locker.Invoke(() =>
                {
                    store = sf.GetPersistent <TKey, TValue>(container, storeName,
                                                            storeConfig.StoreKeyComparer, storeConfig.CreateStoreIfNotExist,
                                                            storeConfig.IsDataInKeySegment, storeConfig.MruManaged, storeConfig.IsUnique);
                    if (store != null)
                    {
                        store.AutoFlush = storeConfig.AutoFlush;
                    }
                    return store;
                }));
            }
        }
Exemplo n.º 2
0
        /// <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);
        }