static void Main(string[] args) { Write("\n --- Test specific key query ---"); Write("\n ---Database contents"); DBElement <int, string> elem1 = new DBElement <int, string>(); elem1.descr = "payload desxription"; elem1.name = "element 1"; elem1.timeStamp = DateTime.Now; elem1.payload = "a payload"; WriteLine(); DBElement <int, string> elem2 = new DBElement <int, string>("Darth Vader", "Evil Overlord"); elem2.descr = "star war 2"; elem2.name = "element 2"; elem2.timeStamp = new DateTime(2015, 9, 10, 12, 30, 1); elem2.payload = "The Empire strikes back!"; WriteLine(); var elem3 = new DBElement <int, string>("Luke Skywalker", "Young HotShot"); elem3.name = "fight"; elem3.descr = "star war 3"; elem3.timeStamp = new DateTime(2015, 10, 2, 8, 0, 0); elem3.children = new List <int> { 1, 2, 3 }; elem3.payload = "X-Wing fighter in swamp - Oh oh!"; WriteLine(); int key = 0; Func <int> keyGen = () => { ++key; return(key); }; // anonymous function to generate keys DBEngine <int, DBElement <int, string> > db = new DBEngine <int, DBElement <int, string> >(); bool p1 = db.insert(keyGen(), elem1); bool p2 = db.insert(keyGen(), elem2); bool p3 = db.insert(keyGen(), elem3); db.show <int, DBElement <int, string>, string>(); WriteLine(); Write("\n --- Test creation of immutable database ---"); Write("\n --- create database for elements which contain \"element\" in metadata ---"); QueryEngine <int, string> query = new QueryEngine <int, string>(db); Func <int, bool> defineQuery = query.defineStringQuery("element"); List <int> keyCollection; bool result = query.processQuery(defineQuery, out keyCollection); immutableDB <int, DBElement <int, string> > imdb = new immutableDB <int, DBElement <int, string> >(db, keyCollection); imdb.ImmutableDB.showDB(); WriteLine(); }
void TestR8() { "Demonstrating Requirement #8".title(); Write("\n Create a new immutable database"); List <int> result; QueryEngine <int, string> query = new QueryEngine <int, string>(dbInt); Func <int, bool> defineQuery = query.defineStringQuery("element"); query.processQuery(defineQuery, out result); Write("\n Query for \"element\" in metadata first, return a list of key"); Write("\n Use the list of key to build immutable database"); immutableDB <int, DBElement <int, string> > immdb = new immutableDB <int, DBElement <int, string> >(dbInt, result); Write("\n Show the immutable database"); immdb.ImmutableDB.showDB(); WriteLine(); }