Esempio n. 1
0
        //----< Demonstrating req 7 - Queries - Value, children of a key>-------------------
        public void TestR7(DBEngine <int, DBElement <int, string> > dbType1, DBEngine <string, DBElement <string, List <string> > > dbType2)
        {
            "\n Demonstrating Requirement #7 - Queries - Primitive DB Contents".title();
            dbType1.showDB();
            "\n Demonstrating Requirement #7 - Queries - Collection DB Contents".title();
            dbType2.showEnumerableDB();
            QueryEngine <int, string> queryEnginePrimitive = new QueryEngine <int, string>(dbType1);

            "\n Demonstrating Requirement #7A - The value of a specified key - Primitive DB".title();
            DBElement <int, string> queryElementPrimitive;
            IEnumerable <int>       dbType1keys = dbType1.Keys();
            int lastKeyDB1 = dbType1keys.Last();

            Write("\n Input Key :" + lastKeyDB1);
            Write("\n Value of Key \n");
            queryEnginePrimitive.getValueForKey(lastKeyDB1, out queryElementPrimitive);
            queryElementPrimitive.showElement();
            QueryEngine <string, List <string> > queryEngine = new QueryEngine <string, List <string> >(dbType2);

            "\n Demonstrating Requirement #7A - The value of a specified key - Collection DB".title();
            DBElement <string, List <string> > queryElement;
            IEnumerable <string> keys = dbType2.Keys();
            String lastKey            = keys.Last();

            Write("\n  Input Key :" + lastKey);
            Write("\n Value of Key \n");
            queryEngine.getValueForKey(lastKey, out queryElement);
            queryElement.showEnumerableElement();
            "\n Demonstrating Requirement #7B - The children of a specified key - Primitive DB".title();
            List <int>        childrenDB1 = new List <int>();
            IEnumerable <int> keys1       = dbType1.Keys();
            int firstKey1 = keys1.First();

            Write("\n  Input Key :" + firstKey1);
            StringBuilder accum = new StringBuilder();

            accum.Append(String.Format(" children of key: {0}", firstKey1.ToString()));
            queryEnginePrimitive.getChildren(firstKey1, out childrenDB1);
            childrenDB1.showkeys();
            "\n Demonstrating Requirement #7B- The children of a specified key - Collection DB".title();
            List <String>        children;
            IEnumerable <string> keys2 = dbType2.Keys();
            String firstKey2           = keys2.First();

            Write("\n  Input Key :" + firstKey2);
            StringBuilder accum2 = new StringBuilder();

            accum2.Append(String.Format(" children of key: {0}", firstKey2));
            queryEngine.getChildren(firstKey2, out children);
            children.showkeys();
            String lastKey2 = keys2.Last();

            Write("\n\n  Input Key :" + lastKey2);
            StringBuilder accum3 = new StringBuilder();

            accum3.Append(String.Format(" children of key: {0}", lastKey2));
            queryEngine.getChildren(lastKey2, out children);
            children.showkeys();
        }
Esempio n. 2
0
        //----<Demonstrating categories >-------------------
        public void testR12()
        {
            DBEngine <string, DBElement <string, List <string> > > dbType2New = new DBEngine <string, DBElement <string, List <string> > >();
            string dir      = "..\\..\\..\\..\\input_xml\\";
            string xmlFile6 = "categories.xml";

            "\n\nDemonstrating Requirement #12 - Categories DB".title();
            WriteLine("\n\n Creating Categories DB from xml file : " + xmlFile6);
            dbType2New.augument_db <string, DBElement <string, List <string> >, List <string>, string>(dir + xmlFile6);
            dbType2New.showEnumerableDB();
            "\n\nQueries on Categories DB".title();

            String inputKey = "Food Products";
            QueryEngine <string, List <string> > queryEngine = new QueryEngine <string, List <string> >(dbType2New);

            DBElement <string, List <string> > queryElement;
            IEnumerable <string> keys = dbType2New.Keys();
            String first = keys.First();

            queryEngine.getValueForKey(first, out queryElement);
            List <String> values = queryElement.payload;

            Write("\nList of keys for the db items in category \"" + inputKey + "\" are ");
            foreach (String key in values)
            {
                Write(" {0}, ", key);
            }

            List <String> children;
            String        child = values[values.Count - 2];

            queryEngine.getChildren(child, out children);
            Write("\nList of categories to which \"" + values[values.Count - 2] + "\" belong are ");
            foreach (String key1 in children)
            {
                Write(" {0}, ", key1);
            }
            WriteLine("\n");
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            DBEngine <int, DBElement <int, string> > dbType1 = new DBEngine <int, DBElement <int, string> >();
            DBEngine <string, DBElement <string, List <string> > > dbType2 = new DBEngine <string, DBElement <string, List <string> > >();
            DBItemEditor editor = new DBItemEditor();

            //Demonstrating primitive type
            DBElement <int, string> elem1 = new DBElement <int, string>();

            elem1.name      = "Jurassic World";
            elem1.descr     = "Story on escape from giant creatures";
            elem1.timeStamp = DateTime.Now;
            elem1.payload   = "A giant creature attacks the park and becomes a killing machine";
            editor.addKeyValyePair <int, String>(dbType1, elem1, DBElementExtensions.generate_int_key());

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

            elem2.name      = "Cast Away";
            elem2.descr     = "Story of surviving a crash landing on a deserted island.";
            elem2.timeStamp = DateTime.Now;
            elem2.children.AddRange(new List <int> {
                4, 5
            });
            elem2.payload = "Directed by Robert Zemeckis and written by Willian Broyles Jr.";
            editor.addKeyValyePair <int, String>(dbType1, elem2, DBElementExtensions.generate_int_key());
            dbType1.showDB();

            QueryEngine <int, string> queryEnginePrimitive = new QueryEngine <int, string>(dbType1);
            DBElement <int, string>   queryElementPrimitive;
            IEnumerable <int>         dbType1keys = dbType1.Keys();
            int lastKeyDB1 = dbType1keys.Last();

            Write("\n\n\n Input Key :" + lastKeyDB1);
            queryEnginePrimitive.getValueForKey(lastKeyDB1, out queryElementPrimitive);
            queryElementPrimitive.showElement();

            List <int>        childrenDB1 = new List <int>();
            IEnumerable <int> keys1       = dbType1.Keys();
            int lastKey1 = keys1.Last();

            Write("\n\n\n  Input Key :" + lastKey1);
            StringBuilder accum = new StringBuilder();

            accum.Append(String.Format(" children of key: {0}", lastKey1.ToString()));
            queryEnginePrimitive.getChildren(lastKey1, out childrenDB1);
            childrenDB1.showkeys();
            Write("\n\n\n ");

            string inputString = "11";

            Write("\n\n \n Input Search String :" + inputString);
            List <int> resultList = queryEnginePrimitive.searchKeyPattern(inputString);

            foreach (int key in resultList)
            {
                Write("\n  found \"{0}\" in key \"{1}\"", inputString, key);
            }

            string inputString2 = "Movie";

            Write("\n\n  Input Search String :" + inputString);
            List <int> resultList2 = queryEnginePrimitive.searchMetadataPattern(inputString2);

            foreach (int key in resultList2)
            {
                Write("\n  found \"{0}\" in \"{1}\"", inputString, key);
            }

            DateTime startDate = new DateTime(2014, DateTime.Today.Month, DateTime.Today.Day, 00, 00, 01);
            DateTime endDate   = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 23, 59, 59);

            List <int> resultList3 = queryEnginePrimitive.searchTimeStamp(startDate);

            foreach (int key in resultList3)
            {
                Write("\n  found key within \"{0}\" within range \"{1}\" {2}", key, startDate, endDate);
            }
        }