예제 #1
0
        //----< process query1 message and parse xdocument and take action.>-----
        public string processQuery1Message(XDocument xdoc)
        {
            string content               = "";
            IEnumerable <string> keys    = db.Keys();
            List <string>        keyList = keys.ToList();
            //string keyToSearch = getKey(xdoc);
            string keyToSearch = keyList.First();

            if (!keyList.Contains(keyToSearch))
            {
                content = "  Key " + keyToSearch + " is not present in the DB";
            }
            else
            {
                int type = getKeyValueType(xdoc);
                if (type == 1)
                {
                    DBElement <string, List <string> >          element;
                    QueryProcessEngine <string, List <string> > queryEngine = new QueryProcessEngine <string, List <string> >(db);
                    queryEngine.processValueQuery(keyToSearch, out element);
                    if (element != null)
                    {
                        content = "\n  Result of Query1 : " + "Value of " + keyToSearch + " is :\n" + element.showMetaData();
                    }
                }
                else
                {
                    content = "  Key " + keyToSearch + "'s value not found from database.";
                }
            }
            return(content);
        }
예제 #2
0
        //----< process query3 message and parse xdocument and take action.>-----
        public string processQuery3Message(XDocument xdoc)
        {
            string content = "";
            string pattern = getPattern(xdoc);
            int    type    = getKeyValueType(xdoc);

            if (type == 1)
            {
                QueryProcessEngine <string, List <string> > queryEngine = new QueryProcessEngine <string, List <string> >(db);
                List <string> results;
                if (queryEngine.processPatternMatchInKeysQuery(queryEngine.defineQueryKeyPatternSearch(pattern), out results))
                {
                    if (results.Count() > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (string str in results)
                        {
                            sb.Append(str);
                            sb.Append("\n");
                        }
                        content = "\n  Result of Query3 : " + "Keys with pattern like " + pattern + " are :\n" + sb;
                    }
                    else
                    {
                        content = "\n  Keys with pattern like  " + pattern + " not found";
                    }
                }
                else
                {
                    content = "\n  Keys with pattern like  " + pattern + " not found";
                }
            }
            return(content);
        }
예제 #3
0
        //----< process query4 message and parse xdocument and take action.>-----
        public string processQuery4Message(XDocument xdoc)
        {
            string content  = "";
            string keywords = getSeachKeyWords(xdoc);
            int    type     = getKeyValueType(xdoc);

            if (type == 1)
            {
                List <string> results;
                QueryProcessEngine <string, List <string> > queryEngine = new QueryProcessEngine <string, List <string> >(db);
                queryEngine.processPatternMatchInMetaDataQuery(queryEngine.defineQueryValuePatternSearch(keywords), out results);
                if (results.Count() > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (string str in results)
                    {
                        sb.Append(str);
                        sb.Append("\n");
                        content = "\n  Result of Query4 : " + "Keys with pattern like " + keywords + " in the metadata are :\n" + sb;
                    }
                }
                else
                {
                    content = "\n  Keys with date keywords like  " + keywords + " in the metadata not found";
                }
            }
            return(content);
        }
예제 #4
0
        //----< process query 5 message request. >-----
        public string processQuery5Message(XDocument xdoc)
        {
            string   content   = "";
            DateTime startDate = getStartDate(xdoc);
            DateTime endData   = getEndDate(xdoc);
            int      type      = getKeyValueType(xdoc);

            if (type == 1)
            {
                List <string> results;
                QueryProcessEngine <string, List <string> > queryEngine = new QueryProcessEngine <string, List <string> >(db);
                queryEngine.processTimeIntervalQuery(queryEngine.defineTimeStampQuery(startDate, endData), out results);
                if (results.Count() > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (string str in results)
                    {
                        sb.Append(str);
                        sb.Append("\n");
                        content = "\n  Result of Query5 : " + "Keys within given time range are :\n" + sb;
                    }
                }
                else
                {
                    content = "\n  Result of Query5 : " + "Keys are not found in given time range are :\n";
                }
            }
            return(content);
        }
예제 #5
0
        //----< process query2 message and parse xdocument and take action.>-----
        public string processQuery2Message(XDocument xdoc)
        {
            string content               = "";
            IEnumerable <string> keys    = db.Keys();
            List <string>        keyList = keys.ToList();
            string keyToSearch           = keyList.First();

            if (!keyList.Contains(keyToSearch))
            {
                Console.WriteLine("Key {0} is not present in the DB", keyToSearch);
                content = "Key " + keyToSearch + " is not present in the DB";
            }
            else
            {
                int type = getKeyValueType(xdoc);
                if (type == 1)
                {
                    List <string> childrens;
                    QueryProcessEngine <string, List <string> > queryEngine = new QueryProcessEngine <string, List <string> >(db);
                    if (queryEngine.processChildrenQuery(keyToSearch, out childrens))
                    {
                        if (childrens.Count() > 0)
                        {
                            StringBuilder sb = new StringBuilder();
                            foreach (string str in childrens)
                            {
                                sb.Append(str);
                                sb.Append("\n");
                            }
                            content = "\n  Result of Query : " + "Children of " + keyToSearch + " is :\n" + sb;
                        }
                        else
                        {
                            content = "\n  Children of " + keyToSearch + " not found";
                        }
                    }
                    else
                    {
                        content = "\n  Children of " + keyToSearch + " not found";
                    }
                }
            }
            return(content);
        }
예제 #6
0
        static void Main(string[] args)
        {
            "Testing QueryProcessing Package".title('=');
            WriteLine();

            DBEngine <int, DBElement <int, ListOfStrings> > db1 = new DBEngine <int, DBElement <int, ListOfStrings> >();
            DBElement <int, ListOfStrings> elem1 = new DBElement <int, ListOfStrings>();

            elem1.name      = "1st Key/Value = Int/ListOfStrings";
            elem1.descr     = "This is first element of Int/ListOfStrings key value pair.";
            elem1.timeStamp = DateTime.Now;
            elem1.children.AddRange(new List <int> {
                100, 101, 102, 103, 104, 105
            });
            elem1.payload = new ListOfStrings();
            elem1.payload.theWrappedData = new List <string> {
                "CSE681", "SMA", "C#.net", "AI"
            };
            db1.insert(1, elem1);

            DBElement <int, ListOfStrings> elem2 = new DBElement <int, ListOfStrings>();

            elem2.name      = "element int-ListOfString 2";
            elem2.descr     = "test element int-ListOfString 2";
            elem2.timeStamp = DateTime.Now;
            elem2.children.AddRange(new List <int> {
                10, 22, 23, 24, 25, 26
            });
            elem2.payload = new ListOfStrings();
            elem2.payload.theWrappedData = new List <string> {
                "CSE6812", "SMA2", "C#.net2", "AI2"
            };
            db1.insert(2, elem2);

            WriteLine("  Query : value of key = 2");
            QueryProcessEngine <int, ListOfStrings> queryEngine = new QueryProcessEngine <int, ListOfStrings>(db1);
            DBElement <int, ListOfStrings>          result;

            queryEngine.processValueQuery(14, out result);
            result.showElement();

            WriteLine("  Query : Children of key = 1");
            List <int> childrens;

            queryEngine.processChildrenQuery(1, out childrens);
            foreach (var item in childrens)
            {
                WriteLine(item);
            }
            WriteLine();

            "The set of all keys matching a specified pattern which defaults to all keys.".title('-');
            Dictionary <int, DBElement <int, ListOfStrings> > results;

            //queryEngine.processPatternMatchInKeysQuery(queryEngine.defineQueryKeyPatternSearch("1"), out results);
            //DBFactory<int, DBElement<int, ListOfStrings>> dbFactory = new DBFactory<int, DBElement<int, ListOfStrings>>(results);
            //dbFactory.showDBFactory();

            WriteLine();
            "All keys that contain a specified string in their metadata section.".title('-');
            //results.Clear();
            //queryEngine.processPatternMatchInMetaDataQuery(queryEngine.defineQueryValuePatternSearch("Scheduler"), out results);
            //dbFactory = new DBFactory<int, DBElement<int, ListOfStrings>>(results);
            //dbFactory.showDBFactory();

            WriteLine();
            "All keys that contain values written within a specified time-date interval".title('-');
            DateTime dt1 = new DateTime(1990, 6, 14, 0, 0, 0);
            DateTime dt2 = new DateTime(1990, 6, 17, 0, 0, 0);
            //results.Clear();
            //queryEngine.processTimeIntervalQuery(queryEngine.defineTimeStampQuery(dt1, dt2), out results);
            //dbFactory.showDBFactory();
        }