static void Main(string[] args)
        {
            DBEngine <int, DBElement <int, string> > db = new DBEngine <int, DBElement <int, string> >();
            ItemFactory <int, string> itemFactory       = new ItemFactory <int, string>();

            "Demonstrating Requirement #2".title();
            DBElement <int, string> elem = itemFactory.Create();

            elem.name      = "element";
            elem.descr     = "test element";
            elem.timeStamp = DateTime.Now.AddDays(-4);
            elem.children.AddRange(new List <int> {
                1, 2, 3
            });
            elem.payload = "elem's payload";
            WriteLine("\n Item to be inserted.. \n");
            elem.showElement();
            db.insert(1, elem);
            db.showDB();
            WriteLine("\n Inserting second element into DB :");
            DBElement <int, string> elem2 = new DBElement <int, string>();

            elem2.name      = "element2";
            elem2.descr     = "test element2";
            elem2.timeStamp = DateTime.Now;
            elem2.children.AddRange(new List <int> {
                1, 2, 3, 4
            });
            elem2.payload = "elem2's payload";
            WriteLine("\nItem to be inserted.. \n");
            elem2.showElement();
            db.insert(2, elem2);
            WriteLine("\n\n DB after insertion:");
            db.showDB();
            WriteLine("\n\n DB after insertion:");
            db.showDB();
            var dict = new Dictionary <int, DBElement <int, string> >();
            var keys = db.searchForTimeStamp(DateTime.Now.AddDays(-6), DateTime.Now.AddDays(-3));

            Console.WriteLine("\nRunning a query on database..\n");
            Console.WriteLine("\n\nThe result are the following keys:\n\n");
            foreach (var item in keys)
            {
                dynamic result = db.searchValue(item);
                Console.Write("{0}, ", item);
                dict.Add(item, result);
            }
            DBFactory <int, DBElement <int, string> > dbFactory = new DBFactory <int, DBElement <int, string> >(dict);

            "Immutable database:".title('.');
            Console.WriteLine("\n\nImmutable database is of type DBFactory, which is immutable (Found in DBFactory.cs).");
        }
Esempio n. 2
0
        private void test3()
        {
            DBEngine <int, DBElement <int, string> > db = new DBEngine <int, DBElement <int, string> >();
            DBEngine <string, DBElement <string, List <string> > > dbString = new DBEngine <string, DBElement <string, List <string> > >();
            ItemFactory <int, string> itemFactory = new ItemFactory <int, string>();

            //---------------Search for data with specified time interval---------------
            "Search for data with specified time interval:".title('.');
            WriteLine("\n\n Elements in DB :");
            var elem = new DBElement <int, string>();

            elem.name      = "old element";
            elem.descr     = "old test element";
            elem.timeStamp = DateTime.Now.AddDays(-3);
            elem.children.AddRange(new List <int> {
                85, 27, 65
            });
            elem.payload = "old elem's payload";

            DBElement <int, string> elem1 = new DBElement <int, string>();

            elem1.name      = "old2 element";
            elem1.descr     = "old2 test element";
            elem1.timeStamp = DateTime.Now.AddDays(-2);
            elem1.children.AddRange(new List <int> {
                11, 12, 13
            });
            elem1.payload = "old2 elem's payload";

            WriteLine("\n\n Search for Key which is created between {0} and {1}:\n\n", DateTime.Now.AddDays(-5).Date, DateTime.Now.AddDays(-1).Date);
            db.insert(99, elem);
            db.insert(50, elem1);
            db.showDB();
            WriteLine();
            var resultkeys = db.searchForTimeStamp(DateTime.Now.AddDays(-5), DateTime.Now.AddDays(-1));

            WriteLine("\n\nThe result is:\n\n");
            foreach (var item in resultkeys)
            {
                Write("{0}, ", item);
            }
            //---------------Search for data with specified time interval---------------
        }