Example #1
0
        /// <summary>
        /// Get a Store with Value object implementing the SOP IPersistent interface.
        /// Key is expected to be one of the simple types.
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="container"></param>
        /// <param name="storeName"></param>
        /// <param name="storeConfig"></param>
        /// <returns></returns>
        public ISortedDictionary <TKey, TValue> GetStorePersistentValue <TKey, TValue>(
            object container, string storeName, StoreParameters <TKey> storeConfig = null)
            where TValue : IPersistent, new()
        {
            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.GetPersistentValue <TKey, TValue>(container, storeName,
                                                                 storeConfig.StoreKeyComparer, storeConfig.CreateStoreIfNotExist,
                                                                 storeConfig.IsDataInKeySegment, storeConfig.MruManaged, storeConfig.IsUnique);
                    if (store != null)
                    {
                        store.AutoFlush = storeConfig.AutoFlush;
                    }
                    return store;
                }));
            }
        }
Example #2
0
        /// <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;
                }));
            }
        }
Example #3
0
        public ISortedDictionary <TKey, TValue> GetStore <TKey, TValue>(object container, string storeName,
                                                                        StoreParameters <TKey> storeConfig = null)
        {
            Sop.IStoreFactory sf = new Sop.StoreFactory();
            ISortedDictionary <TKey, TValue> store;

            if (storeConfig == null)
            {
                store = sf.Get <TKey, TValue>(container, storeName);
            }
            else
            {
                store = sf.Get <TKey, TValue>(container, storeName,
                                              storeConfig.StoreKeyComparer, storeConfig.CreateStoreIfNotExist,
                                              storeConfig.IsDataInKeySegment, storeConfig.MruManaged, storeConfig.IsUnique);
                if (store != null)
                {
                    store.AutoFlush = storeConfig.AutoFlush;
                }
            }
            return(store);
        }