コード例 #1
0
        static void Main(string[] args)
        {
            QueryEngine <int, string>    QE  = new QueryEngine <int, string>();
            QueryEngine <string, string> QE1 = new QueryEngine <string, string>();

            DBEngine <int, DBElement <int, List <string> > >       dbPay    = new DBEngine <int, DBElement <int, List <string> > >();
            DBEngine <string, DBElement <string, List <string> > > dbString = new DBEngine <string, DBElement <string, List <string> > >();
            DBElement <string, List <String> > elemString = new DBElement <string, List <String> >(); //Populating DBEngine

            elemString.name      = "Element2";                                                        //object dbString
            elemString.descr     = "testelement2";                                                    //for testing data string and list of string type.
            elemString.timeStamp = DateTime.Now;
            elemString.children.AddRange(new List <string> {
                "SMA1", "Syracuse2", "NY3"
            });
            elemString.payload = new List <string>();
            elemString.payload.AddRange(new List <string> {
                "we", "rock", "the ", "world"
            });
            dbString.insert("Prohject2", elemString);
            DBElement <string, List <String> > elemString2 = new DBElement <string, List <String> >(); //Populating DBEngine

            elemString2.name      = "Element3";                                                        //object dbString
            elemString2.descr     = "test element3";                                                   //for testing data string and list of string type.
            elemString2.timeStamp = DateTime.Now;
            elemString2.children.AddRange(new List <string> {
                "SMA2", "Syracuse22", "NY33"
            });
            elemString2.payload = new List <string>();
            elemString2.payload.AddRange(new List <string> {
                "Thug", "Life"
            });
            dbString.insert("Thug3", elemString2);
            DBElement <int, List <string> > elemPayload = new DBElement <int, List <string> >();    //Populating DBEngine

            elemPayload.name      = "Element4";                                                     //object dbPay
            elemPayload.descr     = "test element4";                                                //for testing data int and list of string type.
            elemPayload.timeStamp = DateTime.Now;
            elemPayload.children.AddRange(new List <int> {
                1, 2, 3
            });
            elemPayload.payload = new List <string>();
            elemPayload.payload.AddRange(new List <string> {
                "Project 2", " ", "demo", " ", "starts"
            });
            dbPay.insert(1, elemPayload);
            DBElement <int, List <string> > elemPayload2 = new DBElement <int, List <string> >();   //Populating DBEngine

            elemPayload2.name      = "Element5";                                                    //object dbPay
            elemPayload2.descr     = "test element5";                                               //for testing data int and list of string type.
            elemPayload2.timeStamp = DateTime.Now;
            elemPayload2.children.AddRange(new List <int> {
                98, 22, 35
            });
            elemPayload2.payload = new List <string>();
            elemPayload2.payload.AddRange(new List <string> {
                "we", "rock", "the", "world"
            });
            dbPay.insert(2, elemPayload2);

            QE.valueByKey(1, dbPay);
            WriteLine();

            QE.childrenByKey(1, dbPay);


            WriteLine();
            QE1.keyPattern(".*hjbbj.*", dbString);
            WriteLine();
            QE.metaDataPattern("t2", dbString);


            DateTime toDate   = new DateTime(2015, 10, 7);
            DateTime fromDate = new DateTime(2015, 10, 1);


            QE.dateTimeSearch(fromDate, toDate, dbString);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            "Testing QueryEngine Package".title('=');
            WriteLine();
            QueryEngine sendQuery = new QueryEngine();

            DBElement <int, string> elem1 = new DBElement <int, string>("Element-1", "Description of Element-1");

            elem1.payload = "Payload of element-1.";
            elem1.children.AddRange(new List <int> {
                9, 10, 11, 79
            });
            DBElement <int, string> elem2 = new DBElement <int, string>("Element-2", "Description of Element-2");

            elem2.payload = "Payload of element-2.";
            DBElement <int, string> elem3 = new DBElement <int, string>("Element-3", "Description of Element-3");

            elem3.payload = "Payload of element-3.";

            DBEngine <int, DBElement <int, string> > db = new DBEngine <int, DBElement <int, string> >();

            db.insert(1, elem1);
            db.insert(2, elem2);
            db.insert(3, elem3);
            db.showDB();

            DBElement <int, string> result_elem  = new DBElement <int, string>();
            DBElement <int, string> result_elem2 = new DBElement <int, string>();

            //DBElement<int, string> result_elem = new DBElement<int, string>();
            Write("\n\n  Send query -> Find element with key = 2");

            result_elem = sendQuery.findValue <int, DBElement <int, string>, string>(db, 2);
            if (result_elem == null)
            {
                WriteLine("\n  Element with Key= 2 was not found in the database.");
            }
            else
            {
                result_elem.showElement();
            }

            Write("\n\n  Send query -> Find element with key = 5");
            result_elem = sendQuery.findValue <int, DBElement <int, string>, string>(db, 5);
            if (result_elem == null)
            {
                WriteLine("\n  Element with Key= 5 was not found in the database.");
            }
            else
            {
                result_elem.showElement();
            }

            Write("\n  Send query -> Get children of element with key = 1");
            List <int> x1 = sendQuery.getChildren <int, DBElement <int, string>, string>(db, 1);

            Write("\n  Children of element with key=1 are ");
            foreach (int i in x1)
            {
                Write("{0} ", i);
            }

            Write("\n\n  Send query -> Get children of element with key = 3");
            List <int> y1 = sendQuery.getChildren <int, DBElement <int, string>, string>(db, 3);

            if (y1.Count() > 0)
            {
                Write("\n  Children of element with key=3 are ");
                foreach (int i in y1)
                {
                    Write("{0} ", i);
                }
            }
            else
            {
                WriteLine("\n  Element with key=3 has no children.");
            }

            WriteLine("\n  Send query -> Get keys with string -\"blah\" in metadata section.");
            List <int> m1 = sendQuery.get_keys_with_metadata <int, DBElement <int, string>, string>(db, "18779");

            if (m1.Count() > 0)
            {
                Write("  Keys that contain the string \"ent-2\" in their metadata section are: ");
                foreach (int i in m1)
                {
                    Write("{0} ", i);
                }
            }
            else
            {
                WriteLine("  No keys found having \"ent-2\" in their metadata section.");
            }

            //WriteLine("Type of x = {0}", x.ToString());



            //----< Test query methods for DBEngine<string, DBElement<string, List<string>>>  >----------
            Write("\n\n --- Test Query methods for DBEngine<string, DBElement<string,List<string>>> ---");
            DBElement <string, List <string> > new_elem1 = new DBElement <string, List <string> >("Element-One", "Description of Element-One");

            new_elem1.payload = new List <string> {
                "First string in payload of Element-One", "Second string in payload of Element-One", "Third string"
            };
            new_elem1.children.AddRange(new List <string> {
                "Nine", "Ten", "Eleven"
            });
            System.Threading.Thread.Sleep(1200);
            DateTime tm1 = DateTime.Now;

            System.Threading.Thread.Sleep(1200);
            DBElement <string, List <string> > new_elem2 = new DBElement <string, List <string> >("Element-Two", "Description of Element-Two");

            new_elem2.payload = new List <string> {
                "First string in payload of Element-Two", "Mars", "Venus"
            };
            System.Threading.Thread.Sleep(1200);
            DBElement <string, List <string> > new_elem3 = new DBElement <string, List <string> >("Element-Three", "Description of Element-Three");

            new_elem3.payload = new List <string> {
                "First string in payload of element-3", "Beta", "Gamma"
            };

            DBEngine <string, DBElement <string, List <string> > > new_db = new DBEngine <string, DBElement <string, List <string> > >();

            new_db.insert("One", new_elem1);
            new_db.insert("Two", new_elem2);
            new_db.insert("Three", new_elem3);

            DateTime tm2 = DateTime.Now;

            new_db.showEnumerableDB();

            Write("\n\n  Send query -> Find element with key = One");
            if (sendQuery.findValue <string, DBElement <string, List <string> >, List <string> >(new_db, "One") == null)
            {
                WriteLine("\n  Element with Key= \"One\" was not found in the database.");
            }
            else
            {
                sendQuery.findValue <string, DBElement <string, List <string> >, List <string> >(new_db, "One").showEnumerableElement();
            }

            Write("\n\n  Send query -> Find element with key = Five");
            if (sendQuery.findValue <string, DBElement <string, List <string> >, List <string> >(new_db, "Five") == null)
            {
                WriteLine("\n  Element with Key= \"Five\" was not found in the database.");
            }
            else
            {
                sendQuery.findValue <string, DBElement <string, List <string> >, List <string> >(new_db, "Five").showEnumerableElement();
            }

            Write("\n  Send query -> Get children of element with key = \"One\"");
            //List<int> x = sendQuery.getChildren<int, DBElement<int, string>, string>(db, 1);
            List <string> x = sendQuery.getChildren <string, DBElement <string, List <string> >, List <string> >(new_db, "One");

            if (x.Count() > 0)
            {
                Write("\n  Children of element with key=\"One\" are ");
                foreach (string i in x)
                {
                    Write("{0} ", i);
                }
            }
            else
            {
                WriteLine("\n  Element with key=\"One\"  has no children.");
            }


            Write("\n\n  Send query -> Get children list of element with key = \"Three\"");
            //List<int> x = sendQuery.getChildren<int, DBElement<int, string>, string>(db, 1);
            List <string> y = sendQuery.getChildren <string, DBElement <string, List <string> >, List <string> >(new_db, "Three");

            if (y.Count > 0)
            {
                Write("\n  Children of element with key=\"Three\" are ");
                foreach (string i in y)
                {
                    Write("{0} ", i);
                }
            }
            else
            {
                WriteLine("\n  Element with key=\"Three\"  has no children.");
            }

            List <string> search_pat = new List <string> {
                "UnKnown", "lement"
            };

            foreach (string pattern_in_metadata in search_pat)
            {
                WriteLine("\n  Send query -> Get all keys containing string - \"{0}\" in their metadata section.", pattern_in_metadata);
                List <string> res1 = sendQuery.get_keys_with_metadata <string, DBElement <string, List <string> >, List <string> >(new_db, pattern_in_metadata);
                if (res1.Count > 0)
                {
                    Write("  Keys containing string \"{0}\" in their metadata section are: ", pattern_in_metadata);
                    foreach (string i in res1)
                    {
                        Write("{0} ", i);
                    }
                }
                else
                {
                    WriteLine("  No keys found containing pattern \"{0}\" in their metadata section.", pattern_in_metadata);
                }
            }

            WriteLine("\n\n  Send query -> Get all keys written within time intervals \"{0}\" and \"{1}\"", tm1, tm2);
            List <string> result1 = sendQuery.get_keys_within_timeInterval <string, DBElement <string, List <string> >, List <string> >(new_db, tm1);

            if (result1.Count > 0)
            {
                Write("  Keys written within specified time intervals are: ");
                //Write("  Keys are: ");
                foreach (string i in result1)
                {
                    Write("{0} ", i);
                }
            }
            else
            {
                WriteLine("  No keys found written withing specified time interevals tm1 and tm2.");
            }
            //WriteLine("tm1 = {0}\ntm2 = {1}", tm1, tm2);
        }