Exemple #1
0
        static void Main(string[] args)
        {
            QueryEngine<int, DBElement<int, string>, string> qe = new QueryEngine<int, DBElement<int, string>, string>();
            QueryEngine<string, DBElement<string, List<string>>, List<string>> qeLOS = new QueryEngine<string, DBElement<string, List<string>>, List<string>>();
            DBEngine<int, DBElement<int, string>> db = new DBEngine<int, DBElement<int, string>>();
            DBElement<int, string> elem = new DBElement<int, string>();
            DBElement<int, string> Result = new DBElement<int, string>();
            
            elem.name = "Test";
            elem.descr = "Test descr";
            elem.timeStamp = DateTime.Now;
            elem.children.AddRange(new List<int> { 1, 2, 3 });
            elem.payload = "Test Payload";
            db.insert(0, elem);

            DBElement<int, string> elem1 = new DBElement<int, string>();
            elem1.name = "Test 1";
            elem1.descr = "Test descr 1";
            elem1.timeStamp = DateTime.Now;
            elem1.children.AddRange(new List<int> { 4, 5, 6 });
            elem1.payload = "Test Payload 1";
            db.insert(1, elem1);

            DBEngine<string, DBElement<string, List<string>>> dbLOS = new DBEngine<string, DBElement<string, List<string>>>();
            DBElement<string, List<string>> elemLOS = new DBElement<string, List<string>>();
            DBElement<string, List<string>> ResultLOS = new DBElement<string, List<string>>();
            elemLOS.name = "Test";
            elemLOS.descr = "Test descr";
            elemLOS.timeStamp = DateTime.Now;
            elemLOS.children = new List<string> { "One", "Two", "Three" };
            elemLOS.payload = new List<string> { "Test Payload", "Payload" };
            dbLOS.insert("One", elemLOS);

            DBElement<string, List<string>> elemLOS1 = new DBElement<string, List<string>>();
            elemLOS1.name = "Test 2";
            elemLOS1.descr = "Test descr 2";
            elemLOS1.timeStamp = DateTime.Now;
            elemLOS1.children = new List<string> { "Four", "Five", "Six" };
            elemLOS1.payload = new List<string> { "Test Payload 2", "Payload 2" };
            dbLOS.insert("Two", elemLOS1);

            if (qe.getValue(0, db, out Result))
                WriteLine("Value of key 0:\n{0}\n  Payload:  {1}", Result.showMetaData(), Result.payload.ToString());
            else
                WriteLine("Key not found");
            WriteLine();
            if (qeLOS.getValue("One", dbLOS, out ResultLOS))
                WriteLine("Value of key:\n{0}\n  Payload: {1}", ResultLOS.showMetaData(), qeLOS.ToString(ResultLOS.payload));
            else
                WriteLine("Key not found");
            WriteLine();

            if (qe.getChildren(0, db, out children))
                WriteLine("Children of specified key: {0}", qe.ToString(children));
            else
                WriteLine("Key not found");
            if (qeLOS.getChildren("One", dbLOS, out childrenLOS))
                WriteLine("Children of specified key: {0}", qeLOS.ToString(childrenLOS));
            else
                WriteLine("Key not found");
            WriteLine();

            if (qe.searchPattern(0, db, out Keys))
                Console.WriteLine("Set of Keys: {0}", qe.ToString(Keys));
            else
                Console.WriteLine("No Keys found!");
            if (qeLOS.searchPattern("O", dbLOS, out KeysLOS))
                Console.WriteLine("Set of Keys: {0}", qeLOS.ToString(KeysLOS));
            else
                Console.WriteLine("No Keys found!");
            WriteLine();

            if (qe.searchString("descr", db, out Keys))
                Console.WriteLine("Set of Keys: {0}", qe.ToString(Keys));
            else
                Console.WriteLine("\nNo Keys found!");
            if (qeLOS.searchString("Test", dbLOS, out KeysLOS))
                Console.WriteLine("Set of Keys: {0}", qeLOS.ToString(KeysLOS));
            else
                Console.WriteLine("No Keys found!");
            WriteLine();

            if (qe.searchInterval("10/7/1999 12:00:00 AM", "", db, out Keys))
                Console.WriteLine("Set of Keys: {0}", qe.ToString(Keys));
            else
                Console.WriteLine("\nNo Keys found!");
            if (qeLOS.searchInterval("10/7/1999 12:00:00 AM", "", dbLOS, out KeysLOS))
                Console.WriteLine("Set of Keys: {0}", qeLOS.ToString(KeysLOS));
            else
                Console.WriteLine("No Keys found!");
            WriteLine();
        }
Exemple #2
0
 void TestR7()
 {
     //---------< Demonstrating queries >---------
     "Demonstrating Requirement #7".title();
     WriteLine();
     //--------< Searching for key=0 and key=Four >----------
     int key = 0; string keyLOS = "Four";
     if (qe.getValue(key, db, out Result))
         WriteLine("Value of key \"{2}\" in <int, string> database:\n{0}\n  Payload:  {1}", Result.showMetaData(), Result.payload.ToString(), key);
     else
         WriteLine("Value of key \"{0}\" in <int, string> database: Key not found", key);
     WriteLine();
     if (qeLOS.getValue(keyLOS, dbLOS, out ResultLOS))
         WriteLine("Value of key \"{2}\" in <string, List<string>> database:\n{0}\n  Payload: {1}", ResultLOS.showMetaData(), qeLOS.ToString(ResultLOS.payload), keyLOS);
     else
         WriteLine("Children of key \"{0}\" in <string, List<string>> database: Key not found", keyLOS);
     WriteLine();
     //-----------< Searching for children of key=0 and key=Four >------------
     if (qe.getChildren(key, db, out children))
         WriteLine("Children of key \"{1}\"  in <int, string> database: {0}", qe.ToString(children), key);
     else
         WriteLine("Children of key \"{0}\"  in <int, string> database: Key not found", key);
     if (qeLOS.getChildren(keyLOS, dbLOS, out childrenLOS))
         WriteLine("Children of key \"{1}\": {0} in <string, List<string>> database", qeLOS.ToString(childrenLOS), keyLOS);
     else
         WriteLine("Children of key \"{0}\" in <string, List<string>> database: Key not found", keyLOS);
     WriteLine();
     //------------< Searching for keys starting with 1 and "F" >----------
     key = 1; keyLOS = "F";
     if (qe.searchPattern(key, db, out Keys))
         Console.WriteLine("Set of Keys starting with \"{1}\"  in <int, string> database: {0}", qe.ToString(Keys), key);
     else
         Console.WriteLine("Set of Keys starting with \"{0}\"  in <int, string> database: No Keys found!", key);
     if (qeLOS.searchPattern(keyLOS, dbLOS, out KeysLOS))
         Console.WriteLine("Set of Keys starting with \"{1}\" in <string, List<string>> database: {0}", qeLOS.ToString(KeysLOS), keyLOS);
     else
         Console.WriteLine("Set of Keys starting with \"{0}\" in <string, List<string>> database: No Keys found!", keyLOS);
     WriteLine();
     //----------< Searching for keys whose metadata contain "Descr" and "Test" >------------
     string string1 = "Descr", string2 = "Test";
     if (qe.searchString(string1, db, out Keys))
         Console.WriteLine("Set of Keys containg \"{1}\" in their metadata  for <int, string> database: {0}", qe.ToString(Keys), string1);
     else
         Console.WriteLine("Set of Keys containg \"{0}\" in their metadata  for <int, string> database: No Keys found!", string1);
     if (qeLOS.searchString(string2, dbLOS, out KeysLOS))
         Console.WriteLine("Set of Keys containg \"{1}\" in their metadata for <string, List<string>> database: {0}", qeLOS.ToString(KeysLOS), string2);
     else
         Console.WriteLine("Set of Keys containg \"{0}\" in their metadata for <string, List<string>> database: No Keys found!", string2);
     WriteLine();
     //----------< Searching for keys entered From 01 Oct 2015 to date >-----------
     string1 = "10/1/2015 12:00:00 AM";
     if (qe.searchInterval(string1, "", db, out Keys))
         Console.WriteLine("Set of Keys entered from {1} to date  in <int, string> database: {0}", qe.ToString(Keys), string1);
     else
         Console.WriteLine("Set of Keys entered from {0} to date  in <int, string> database: No Keys found!", string1);
     if (qeLOS.searchInterval(string1, "", dbLOS, out KeysLOS))
         Console.WriteLine("Set of Keys entered from {1} to date  in <string, List<string>> database: {0}", qeLOS.ToString(KeysLOS), string1);
     else
         Console.WriteLine("Set of Keys entered from {0} to date in <string, List<string>> database: No Keys found!", string1);
     WriteLine();
 }