//----< Demonstrating req 5 - Demonstrating persisting, unpersisting and restoring db>------------------- public void TestR5(DBEngine <int, DBElement <int, string> > dbType1, DBEngine <string, DBElement <string, List <string> > > dbType2) { string dir = "..\\..\\..\\..\\input_xml\\"; string xmlFile1 = "nosqdldb_primitive.xml"; "\n\nDemonstrating Requirement #5 Primitive DB".title(); dbType1.persist_db <int, DBElement <int, string>, string>(dir + xmlFile1); WriteLine("\nSuccesfully persisted dbengine contents to xml file :" + xmlFile1); string xmlFile2 = "nosqdldb.xml"; "\n\nDemonstrating Requirement #5 - Collection DB".title(); dbType2.persist_db <string, DBElement <string, List <string> >, List <string>, string>(dir + xmlFile2); WriteLine("\nSuccesfully persisted dbengine contents to xml file : " + xmlFile2); string xmlFile3 = "read_nosqldb_primitive.xml"; "\n\nDemonstrating Requirement #5 - Augumenting DB - Primitive DB".title(); WriteLine("\n\n Before Augumenting DB from xml file : " + xmlFile3); dbType1.showDB(); dbType1.augument_db <int, DBElement <int, string>, string>(dir + xmlFile3); WriteLine("\n\n After Augumenting DB from xml file : " + xmlFile3); dbType1.showDB(); string xmlFile4 = "read_nosqdldb.xml"; "\n\nDemonstrating Requirement #5 - Augumenting DB - Collection DB".title(); WriteLine("\n\n Before Augumenting DB from xml file : " + xmlFile4); dbType2.showEnumerableDB(); dbType2.augument_db <string, DBElement <string, List <string> >, List <string>, string>(dir + xmlFile4); WriteLine("\n\n After Augumenting DB from xml file : " + xmlFile4); dbType2.showEnumerableDB(); DBEngine <int, DBElement <int, string> > dbType1New = new DBEngine <int, DBElement <int, string> >(); DBEngine <string, DBElement <string, List <string> > > dbType2New = new DBEngine <string, DBElement <string, List <string> > >(); string xmlFile5 = "read_nosqldb_primitive.xml"; "\n\nDemonstrating Requirement #5 - Restoring DB - Primitive DB".title(); WriteLine("\n\n Before Restoring DB from xml file : " + xmlFile5); dbType1New.showDB(); dbType1New.augument_db <int, DBElement <int, string>, string>(dir + xmlFile5); WriteLine("\n\n After Restoring DB from xml file : " + xmlFile5); dbType1New.showDB(); string xmlFile6 = "read_nosqdldb.xml"; "\n\nDemonstrating Requirement #5 - Restoring DB - Collection DB".title(); WriteLine("\n\n Before Restoring DB from xml file : " + xmlFile6); dbType2New.showEnumerableDB(); dbType2New.augument_db <string, DBElement <string, List <string> >, List <string>, string>(dir + xmlFile6); WriteLine("\n\n After Restoring DB from xml file : " + xmlFile6); dbType2New.showEnumerableDB(); }
//----<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"); }
static void Main(string[] args) { "Demonstrating Persist Engine".title('='); 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> > >(); //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"; dbType1.insert(DBElementExtensions.generate_int_key(), elem1); 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."; dbType1.insert(DBElementExtensions.generate_int_key(), elem2); dbType1.showDB(); //Demostrating IEnumberable Type DBElement <string, List <string> > newerelem1 = new DBElement <string, List <string> >(); newerelem1.name = "Movie Name - The Good the Bad and the Ugly"; newerelem1.descr = "A bounty hunting scam joins two men in an uneasy alliance "; newerelem1.payload = new List <string> { "Clint Eastwood", " Eli Wallach", "Lee Van Cleef" }; String key = "The Good, the Bad and the Ugly"; dbType2.insert(key, newerelem1); DBElement <string, List <string> > newerelem2 = new DBElement <string, List <string> >(); newerelem2.name = "Movie Name - Django Unchained"; newerelem2.descr = "With the help of a German hunter, a freed slave sets to rescue"; newerelem2.children.AddRange(new[] { key, "Life Is Beautiful" }); newerelem2.payload = new List <string> { "Jamie Foxx", "Christoph Waltz", "Leonardo DiCaprio" }; newerelem2.payload.Add("Quentin Tarantino"); String key1 = "Django Unchained"; dbType2.insert(key1, newerelem2); dbType2.showEnumerableDB(); string xmlFile1 = "nosqdldb_primitive.xml"; dbType1.persist_db <int, DBElement <int, string>, string>(xmlFile1); WriteLine("\nSuccesfully persisted dbengine contents to xml file :" + xmlFile1); string xmlFile2 = "nosqdldb.xml"; dbType2.persist_db <string, DBElement <string, List <string> >, List <string>, string>(xmlFile2); WriteLine("\nSuccesfully persisted dbengine contents to xml file : " + xmlFile2); string xmlFile3 = "read_nosqldb_primitive.xml"; WriteLine("\n\n Before Augumenting DB from xml file : " + xmlFile3); dbType1.showDB(); dbType1.augument_db <int, DBElement <int, string>, string>(xmlFile3); WriteLine("\n\n After Augumenting DB from xml file : " + xmlFile3); dbType1.showDB(); string xmlFile4 = "read_nosqdldb.xml"; WriteLine("\n\n Before Augumenting DB from xml file : " + xmlFile4); dbType2.showEnumerableDB(); dbType2.augument_db <string, DBElement <string, List <string> >, List <string>, string>(xmlFile4); WriteLine("\n\n After Augumenting DB from xml file : " + xmlFile4); dbType2.showEnumerableDB(); DBEngine <int, DBElement <int, string> > dbType1New = new DBEngine <int, DBElement <int, string> >(); DBEngine <string, DBElement <string, List <string> > > dbType2New = new DBEngine <string, DBElement <string, List <string> > >(); string xmlFile5 = "read_nosqldb_primitive.xml"; WriteLine("\n\n Before Restoring DB from xml file : " + xmlFile5); dbType1New.showDB(); dbType1New.augument_db <int, DBElement <int, string>, string>(xmlFile5); WriteLine("\n\n After Restoring DB from xml file : " + xmlFile5); dbType1New.showDB(); string xmlFile6 = "read_nosqdldb.xml"; WriteLine("\n\n Before Restoring DB from xml file : " + xmlFile6); dbType2New.showEnumerableDB(); dbType2New.augument_db <string, DBElement <string, List <string> >, List <string>, string>(xmlFile6); WriteLine("\n\n After Restoring DB from xml file : " + xmlFile6); dbType2New.showEnumerableDB(); }