Exemplo n.º 1
0
        /// <summary>
        /// Sample code to show how to create nested Sorted Dictionaries.
        /// I.e. - Collections within Collection scenario.
        /// </summary>
        public void Run()
        {
            Console.WriteLine("{0}: NestedSortedDictionary demo started...", DateTime.Now);

            const int    CollCount = 50;
            ITransaction Trans;

            IStoreFactory Factory = new StoreFactory();

            //** Create/Get the Main Collection which we will store the nested "People" Sorted Dictionaries in below code...
            ISortedDictionary <string, GeneralPurpose <long, Person> > Collections =
                Factory.Get <string, GeneralPurpose <long, Person> >(Server.SystemFile.Store, "MainCollection");

            for (int i = 0; i < CollCount; i++)
            {
                string CollectionName = string.Format("People{0}", i);
                ISortedDictionary <long, Person> store = Factory.Get <long, Person>(Collections, CollectionName);
                Trans = store.Transaction;
                if (store.Count == 0)
                {
                    Populate(store);
                    store.Flush();
                    //store.Dispose();
                }
                //else
                //    store.Dispose();
                if (i >= 10)
                {
                    //** get the table 5 tables "ago"
                    store = Factory.Get <long, Person>(Collections, string.Format("People{0}", i - 5));
                    //** delete the table retrieved...
                    //store.Clear();

                    store.Rename("foo");

                    ISortedDictionary <long, Person> fooStore = Factory.Get <long, Person>(Collections, "foo");
                    //store.Delete();
                }
                Trans.Commit();
                server.BeginTransaction();
            }
            for (int i = 0; i < CollCount; i++)
            {
                string CollectionName = string.Format("People{0}", i);
                ISortedDictionary <long, Person> store = Factory.Get <long, Person>(Collections, CollectionName, createIfNotExist: false);
                if (store != null)
                {
                    ReadAll(store);
                    //store.Dispose();
                }
            }
            Console.WriteLine("{0}: NestedSortedDictionary demo ended...", DateTime.Now);
        }