Exemple #1
0
        //helper function for showDBbyCategory
        public void queryByCategory(int category, DBEngine1 <DBElement1 <int, string> > db)
        {
            List <int>        foundKeys = new List <int>();
            IEnumerable <int> keys      = db.Keys();

            foreach (int key in keys)
            {
                DBElement1 <int, string> elem = new DBElement1 <int, string>();

                db.getValue(key, out elem);

                if (elem.category.Contains(category))
                {
                    foundKeys.Add(key);
                }
            }
            foreach (int key1 in foundKeys)
            {
                Console.WriteLine("Key={0}", key1);
                DBElement1 <int, string> elem = new DBElement1 <int, string>();
                db.getValue(key1, out elem);
                Console.WriteLine("Name: {0}", elem.name);                      // Printing DB contents grouped by category
                Console.WriteLine("Description ={0}", elem.descr);
                Console.WriteLine("timeStamp : {0}", elem.timeStamp);
                Console.Write("Children:");
                foreach (int child in elem.children)
                {
                    Console.Write("{0} ", child);
                }
                //WriteLine();
                Console.WriteLine("Payload : {0}", elem.payload);
                WriteLine();
            }
        }
Exemple #2
0
        public void showDBbyCategory(DBEngine1 <DBElement1 <int, string> > db)
        {
            List <int>        cats      = new List <int>();
            List <int>        foundKeys = new List <int>();
            IEnumerable <int> keys      = db.Keys();

            foreach (int key in keys)
            {
                DBElement1 <int, string> elem = new DBElement1 <int, string>();

                db.getValue(key, out elem);

                foreach (int cat in elem.category)
                {
                    if (cats.Contains(cat))                             // Skip for repeated categories
                    {
                        continue;
                    }
                    WriteLine("\nCategory = {0}", cat);
                    WriteLine("- - - - - - ");
                    queryByCategory(cat, db);                       // Querying DB by category
                    cats.Add(cat);
                }
            }
        }
Exemple #3
0
 public void show(DBEngine1 <Value> db)
 {
     foreach (int key in db.Keys())
     {
         Value value;
         db.getValue(key, out value);
         DBElement1 <int, string> elem = value as DBElement1 <int, string>;
         Write("\n\n  -- key = {0} --", key);
         Write(showElement(elem));
     }
 }
Exemple #4
0
        public Bonus()
        {
            DBEngine1 <DBElement1 <int, string> > db = new DBEngine1 <DBElement1 <int, string> >();
            DBElement1 <int, string> elem            = new DBElement1 <int, string>();               //Populating DBEngine1

            elem.name      = "Element2";                                                             //object db
            elem.descr     = "test element2";                                                        //for testing data int and string type.
            elem.timeStamp = DateTime.Now;
            elem.children.AddRange(new List <int> {
            });
            elem.payload = "Varun";
            elem.category.AddRange(new List <int> {
                1, 2, 3
            });
            db.insert(1, elem);
            DBElement1 <int, string> elem1 = new DBElement1 <int, string>();                        //Populating DBEngine1

            elem1.name      = "Key/Value pair to be edited";                                        //object db
            elem1.descr     = "test element3";                                                      //for testing data int and string type.
            elem1.timeStamp = DateTime.Now;
            elem1.children.AddRange(new List <int> {
                4, 5, 6
            });
            elem1.payload = "EDIT !";
            elem1.category.AddRange(new List <int> {
                1, 2, 5
            });
            db.insert(2, elem1);
            DBElement1 <int, string> elem2 = new DBElement1 <int, string>();                        //Populating DBEngine1

            elem2.name      = "Key/Value pair to be edited";                                        //object db
            elem2.descr     = "test element3";                                                      //for testing data int and string type.
            elem2.timeStamp = DateTime.Now;
            elem2.children.AddRange(new List <int> {
                4, 5, 6
            });
            elem2.payload = "EDIT !";
            elem2.category.AddRange(new List <int> {
            });
            db.insert(3, elem2);


            Console.WriteLine("DATABASE CONTENTS");
            Console.WriteLine("_ _ _ _ _ _ _ _ _ ");
            db.show(db);
            WriteLine("\n");

            //db.queryByCategory(1,db);
            Console.WriteLine("DATABASE BY CATEGORY");
            Console.WriteLine("_ _ _ _ _ _ _ _ _ _ _");
            db.showDBbyCategory(db);                        // Publishing DB
        }