예제 #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;
                }));
            }
        }
예제 #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;
                }));
            }
        }
예제 #3
0
        /// <summary>
        /// Sample code that tests creation and population of 400 tables with 5000 records each.
        /// </summary>
        public void Run()
        {
            Console.WriteLine("{0}: Collection400 demo started...", DateTime.Now);
            const int CollCount = 40;

            StoreFactory StoreFactory = new Sop.StoreFactory();

            for (int i = 0; i < CollCount; i++)
            {
                string CollectionName = string.Format("People{0}", i);
                ISortedDictionary <long, Person> store = StoreFactory.Get <long, Person>(Server.SystemFile.Store, CollectionName);
                if (store.Count == 0)
                {
                    Populate(store);
                    store.Transaction.Commit();
                    server.BeginTransaction();
                }
            }
            for (int i = 0; i < CollCount; i++)
            {
                string CollectionName = string.Format("People{0}", i);
                if (Server.SystemFile.Store.Contains(CollectionName))
                {
                    ISortedDictionary <long, Person> store = StoreFactory.Get <long, Person>(Server.SystemFile.Store, CollectionName);
                    ReadAll(store);
                }
            }
            Console.WriteLine("{0}: Collection400 demo ended...", DateTime.Now);
        }
예제 #4
0
        /// <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); });
        }
예제 #5
0
        void LoadData()
        {
            if (BayWind == null)
            {
                BayWind = new BayWind();
            }

            //** Create a Dictionary Factory
            Sop.StoreFactory StoreFactory = new Sop.StoreFactory();

            //** retrieve the Object Stores from BayWind DB...
            PeopleStore =
                StoreFactory.Get <BayWind.PersonKey, BayWind.Person>(BayWind.Server.SystemFile.Store, "People", new BayWind.PersonComparer());
            AddressStore =
                StoreFactory.Get <int, BayWind.Address>(BayWind.Server.SystemFile.Store, "Address");
            PeopleStore.MoveFirst();
            DisplayPage();
        }
예제 #6
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);
        }
예제 #7
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);
        }