void TestR2() { "Demonstrating Requirement #2".title(); //creating new element of type int and string DBElement <int, string> element = new DBElement <int, string>(); element.name = "first element of db"; element.descr = "int and string type"; element.timeStamp = DateTime.Now; element.children.AddRange(new List <int> { 0, 2, 4, 8 }); element.payload = "first element's payload"; element.showElement(); db.insert(1, element); db.showDB(); WriteLine(); //creating new element of type string and list of strings DBElement <string, List <string> > element2 = new DBElement <string, List <string> >(); element2.name = "second element of db"; element2.descr = "strings and strings of string types"; element2.timeStamp = DateTime.Now; element2.children.AddRange(new List <string> { "SMA", "OOD", "Project2" }); element2.payload = new List <string> { "second", "SMA", "project" }; element2.showEnumerableElement(); db2.insert("2", element2); db2.showEnumerableDB(); WriteLine(); }
public void persistdb <Key, Value, Data>(DBEngine <Key, Value> db) { XDocument xml = new XDocument(); xml.Declaration = new XDeclaration("1.0", "utf-8", "yes"); XComment comment = new XComment("NoSQL Database"); //title for XML xml.Add(comment); XElement NoSQLelem = new XElement("NoSQLDB_ELEMENTS"); XElement type = new XElement("numbers", typeof(Key)); XElement payload = new XElement("name", typeof(Data)); xml.Add(NoSQLelem); NoSQLelem.Add(type); NoSQLelem.Add(payload); foreach (Key k1 in db.Keys()) { XElement tags = new XElement("open_close"); XElement key = new XElement("new_Key", k1); //tag for new keys generated tags.Add(key); Value value1; db.getValue(k1, out value1); DBElement <Key, Data> element = value1 as DBElement <Key, Data>; WriteLine(element.showElement()); XElement dbelement = persistdbelement <Key, Data>(element); tags.Add(dbelement); NoSQLelem.Add(tags); xml.Save("XML_FILE.xml"); //XML file name } }
// Main Method to test the implementation of DBElement Package static void Main(string[] args) { "Testing DBElement Package".title('='); WriteLine(); Write("\n --- Test DBElement<int,string> ---"); WriteLine(); // new elements for int and string database DBElement <int, string> elem1 = new DBElement <int, string>(); Write(elem1.showElement <int, string>()); WriteLine(); DBElement <int, string> elem2 = new DBElement <int, string>("Darth Vader", "Evil Overlord"); elem2.payload = "The Empire strikes back!"; Write(elem2.showElement <int, string>()); WriteLine(); var elem3 = new DBElement <int, string>("Luke Skywalker", "Young HotShot"); elem3.children = new List <int> { 1, 2, 7 }; elem3.payload = "X-Wing fighter in swamp - Oh oh!"; Write(elem3.showElement <int, string>()); WriteLine(); Write("\n --- Test DBElement<string,List<string>> ---"); WriteLine(); //new elements for string and list of strings database DBElement <string, List <string> > newelem1 = new DBElement <string, List <string> >(); newelem1.name = "newelem1"; newelem1.descr = "test new type"; newelem1.payload = new List <string> { "one", "two", "three" }; Write(newelem1.showElement <string, List <string>, string>()); WriteLine(); DBElement <string, List <string> > newerelem1 = new DBElement <string, List <string> >(); newerelem1.name = "newerelem1"; newerelem1.descr = "same stuff"; newerelem1.children.Add("first_key"); newerelem1.children.Add("second_key"); newerelem1.payload = new List <string> { "alpha", "beta", "gamma" }; newerelem1.payload.AddRange(new[] { "delta", "epsilon" }); Write(newerelem1.showElement <string, List <string>, string>()); WriteLine(); Write("\n\n"); }
//----< write simple db elements out to Console >------------------ public static void show <Key, Value, Data>(this DBEngine <Key, Value> db) { foreach (Key key in db.Keys()) { Value value; db.getValue(key, out value); DBElement <Key, Data> elem = value as DBElement <Key, Data>; Write("\n\n -- key = {0} --", key); Write(elem.showElement()); } }
// main method to test DBExtensions package static void Main(string[] args) { "Testing DBExtensions Package".title('='); WriteLine(); // creation of new element Write("\n --- Test DBElement<int,string> ---"); DBElement <int, string> elem1 = new DBElement <int, string>(); elem1.payload = "a payload"; Write(elem1.showElement <int, string>()); // creation of new database DBEngine <int, DBElement <int, string> > dbs = new DBEngine <int, DBElement <int, string> >(); dbs.insert(1, elem1); dbs.show <int, DBElement <int, string>, string>(); WriteLine(); Write("\n --- Test DBElement<string,List<string>> ---"); // creation of new element DBElement <string, List <string> > newelem1 = new DBElement <string, List <string> >(); newelem1.name = "newelem1"; newelem1.descr = "test new type"; newelem1.children = new List <string> { "Key1", "Key2" }; newelem1.payload = new List <string> { "one", "two", "three" }; Write(newelem1.showElement <string, List <string>, string>()); DBEngine <string, DBElement <string, List <string> > > dbe = new DBEngine <string, DBElement <string, List <string> > >(); dbe.insert("key1", newelem1); dbe.show <string, DBElement <string, List <string> >, List <string>, string>(); Write("\n\n"); }
void TestR7() { //Demonstrating queries "Demonstrating Requirement #7".title(); WriteLine(); QueryEngine queryv = new QueryEngine(); DBElement <int, string> displayresc = new DBElement <int, string>(); DBElement <int, string> displayres = new DBElement <int, string>(); //demonstrating query 1 Console.WriteLine("\n \n getting value for key 1"); displayres = queryv.queryvalue <int, DBElement <int, string>, string>(db, 1); if (displayres != null) { displayres.showElement(); } DBElement <string, List <string> > valuestring = new DBElement <string, List <string> >(); Console.WriteLine("\n \n getting value for key 2"); valuestring = queryv.queryvalue <string, DBElement <string, List <string> >, string>(db2, "2"); if (valuestring != null) { valuestring.showEnumerableElement(); } // demonstrating query 2 Console.WriteLine("\n \n getting children for key 1"); List <int> tchildlist = new List <int>(); tchildlist = queryv.querychildren <int, DBElement <int, string>, string>(db, 1); if (tchildlist != null) { foreach (int i in tchildlist) { Console.WriteLine(i); } } }
static void Main(string[] args) { "Testing DBEngine Package".title('=');; WriteLine(); "Test db of scalar elements".title(); WriteLine(); //creation of new elements DBElement <int, string> elem1 = new DBElement <int, string>(); elem1.payload = "a payload"; DBElement <int, string> elem2 = new DBElement <int, string>("Darth Vader", "Evil Overlord"); elem2.payload = "The Empire strikes back!"; var elem3 = new DBElement <int, string>("Luke Skywalker", "Young HotShot"); elem3.payload = "X-Wing fighter in swamp - Oh oh!"; if (verbose) { Write("\n --- Test DBElement<int,string> ---"); WriteLine(); elem1.showElement(); WriteLine(); elem2.showElement(); WriteLine(); elem3.showElement(); WriteLine(); } Write("\n --- Test DBEngine<int,DBElement<int,string>> ---"); WriteLine(); int key = 0; Func <int> keyGen = () => { ++key; return(key); }; // function to generate keys // new database created 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); if (p1 && p2 && p3) { Write("\n all inserts succeeded"); } else { Write("\n at least one insert failed"); } db.showDB(); WriteLine(); "Test db of enumerable elements".title(); WriteLine(); //new element created DBElement <string, List <string> > newelem1 = new DBElement <string, List <string> >(); newelem1.name = "newelem1"; newelem1.descr = "test new type"; newelem1.payload = new List <string> { "one", "two", "three" }; //new element created DBElement <string, List <string> > newerelem1 = new DBElement <string, List <string> >(); newerelem1.name = "newerelem1"; newerelem1.descr = "better formatting"; newerelem1.payload = new List <string> { "alpha", "beta", "gamma" }; newerelem1.payload.Add("delta"); newerelem1.payload.Add("epsilon"); //new element created DBElement <string, List <string> > newerelem2 = new DBElement <string, List <string> >(); newerelem2.name = "newerelem2"; newerelem2.descr = "better formatting"; newerelem2.children.AddRange(new List <string> { "first", "second" }); newerelem2.payload = new List <string> { "a", "b", "c" }; newerelem2.payload.Add("d"); newerelem2.payload.Add("e"); if (verbose) { Write("\n --- Test DBElement<string,List<string>> ---"); WriteLine(); newelem1.showEnumerableElement(); WriteLine(); newerelem1.showEnumerableElement(); WriteLine(); newerelem2.showEnumerableElement(); WriteLine(); } Write("\n --- Test DBEngine<string,DBElement<string,List<string>>> ---"); int seed = 0; string skey = seed.ToString(); Func <string> skeyGen = () => { ++seed; skey = "string" + seed.ToString(); skey = skey.GetHashCode().ToString(); return(skey); }; DBEngine <string, DBElement <string, List <string> > > newdb = new DBEngine <string, DBElement <string, List <string> > >(); newdb.insert(skeyGen(), newelem1); newdb.insert(skeyGen(), newerelem1); newdb.insert(skeyGen(), newerelem2); newdb.showEnumerableDB(); Write("\n\n"); }
//calling function to show elements of type strings and list of strings public static void showEnumerableElement(this DBElement <string, List <string> > enumElement) { Console.Write(enumElement.showElement <string, List <string>, string>()); }
{ // calling function to show elements of type int and strings public static void showElement(this DBElement <int, string> element) { Console.Write(element.showElement <int, string>()); }
static void Main(string[] args) { "Testing Payload Wrapper".title('='); WriteLine(); ListOfStrings los = new ListOfStrings(); los.theWrappedData.AddRange(new List <string> { "one", "two", "three" }); "showing List of strings:".title(); foreach (string item in los.theWrappedData) { Write("\n {0}", item); } WriteLine(); "Output from PayloadWrapper.ToString()".title(); Write("\n{0}", los.ToString()); //WriteLine(); "output from PayloadWrapper.ToXml()".title(); Write("\n{0}", los.ToXml()); WriteLine(); "output from elem.showElement<string, ListOfStrings>()".title(); DBElement <string, ListOfStrings> elem = new DBElement <string, ListOfStrings>(); elem.name = "test element"; elem.descr = "created to test PayloadWrapper"; elem.payload = new ListOfStrings(); elem.payload.theWrappedData = new List <string> { "alpha", "beta", "gamma", "delta", "epsilon" }; Write(elem.showElement <string, ListOfStrings>()); // The sequence of statements below should be turned into an // extension method: static public void clone(this List<string>) "test cloning elem".title('='); WriteLine(); DBElement <string, ListOfStrings> cloned = new DBElement <string, ListOfStrings>(); cloned.name = String.Copy(elem.name); cloned.descr = String.Copy(elem.descr); cloned.timeStamp = DateTime.Parse(elem.timeStamp.ToString()); cloned.children = new List <string>(); cloned.children.AddRange(elem.children); cloned.payload = elem.payload.clone() as ListOfStrings; "output from elem.showElement<string, ListOfStrings>()".title(); Write(elem.showElement <string, ListOfStrings>()); "output from cloned.showElement<string, ListOfStrings>()".title(); Write(cloned.showElement <string, ListOfStrings>()); //"Hashcodes are not reliable object identifiers".title(); //Write(string.Format("\n hashcode of elem = {0}", elem.GetHashCode())); //Write(string.Format("\n hashcode of elem.name = {0}", elem.name.GetHashCode())); //Write(string.Format("\n hashcode of elem.descr = {0}", elem.descr.GetHashCode())); //Write(string.Format("\n hashcode of elem.payload = {0}", elem.payload.GetHashCode())); //WriteLine(); //Write(string.Format("\n hashcode of cloned = {0}", cloned.GetHashCode())); //Write(string.Format("\n hashcode of cloned.name = {0}", cloned.name.GetHashCode())); //Write(string.Format("\n hashcode of cloned.descr = {0}", cloned.descr.GetHashCode())); //Write(string.Format("\n hashcode of cloned.payload = {0}", cloned.payload.GetHashCode())); //WriteLine(); "testing for equality immediately after cloning".title(); showEquality(cloned.name, elem.name, "cloned.name vs. elem.name"); showEquality(cloned.descr, elem.descr, "cloned.descr vs. elem.descr"); showDateTimeEquality(cloned.timeStamp, elem.timeStamp, "cloned.timeStamp vs. elem.timeStamp"); showListEquality(cloned.children, elem.children, "cloned.children vs. elem.children"); showListEquality <string>(cloned.payload.theWrappedData, elem.payload.theWrappedData, "cloned.payload vs. elem.payload"); WriteLine(); "modifying clone's properties".title(); WriteLine(); cloned.name = cloned.name + " modified"; cloned.descr = cloned.descr + " modified"; cloned.timeStamp = DateTime.Today; cloned.children.AddRange(new List <string> { "key11", "key13" }); cloned.payload.theWrappedData.AddRange(new List <string> { "zeta", "eta" }); "output from elem.showElement<string, ListOfStrings>()".title(); Write(elem.showElement <string, ListOfStrings>()); "output from cloned.showElement<string, ListOfStrings>()".title(); Write(cloned.showElement <string, ListOfStrings>()); "Testing equality after modifying clone's values".title(); showEquality(cloned.name, elem.name, "cloned.name vs. elem.name"); showEquality(cloned.descr, elem.descr, "cloned.descr vs. elem.descr"); showDateTimeEquality(cloned.timeStamp, elem.timeStamp, "cloned.timeStamp vs. elem.timeStamp"); showListEquality(cloned.children, elem.children, "cloned.children vs. elem.children"); showListEquality <string>(cloned.payload.theWrappedData, elem.payload.theWrappedData, "cloned.payload vs. elem.payload"); Write("\n\n"); }
//Main method public static void Main() { "Testing QueryEngine Package".title('='); Console.WriteLine(); QueryEngine queryv = new QueryEngine(); // new database created for different types DBEngine<int, DBElement<int, string>> newdbq = new DBEngine<int, DBElement<int, string>>(); DBEngine<string, DBElement<string, List<string>>> newdbqs = new DBEngine<string, DBElement<string, List<string>>>(); //new elements created for int ,string database DBElement<int, string> newqelem1 = new DBElement<int, string>(); DBElement<int, string> newqelem2 = new DBElement<int, string>(); DBElement<int, string> newqelem3 = new DBElement<int, string>(); newqelem1.name = "query elemnt 1"; newqelem1.descr = "testing qurey get value for 1"; newqelem1.payload = "new query element payload 1"; newqelem1.children.AddRange(new List<int> { 1, 22, 333 }); newqelem2.name = "query elemnt 2"; newqelem2.descr = "testing query get value for 2"; newqelem2.payload = "new query element payload 2"; newqelem2.children.AddRange(new List<int> { 010, 020, 030 }); newqelem3.name = "query elemnt 3"; newqelem3.descr = "testing quey get value for 3"; newqelem3.payload = "new query element payload 3"; newqelem3.children.AddRange(new List<int> { 777, 222, 333 }); newdbq.insert(1, newqelem1); newdbq.insert(2, newqelem2); newdbq.insert(3, newqelem3); newdbq.showDB(); // testing query 1 DBElement<int, string> displayres = new DBElement<int, string>(); Console.WriteLine("\n \n getting value for key 2"); displayres = queryv.queryvalue<int, DBElement<int, string>, string>(newdbq, 2); if (displayres != null) displayres.showElement(); //testing query 2 Console.WriteLine("\n \n getting children for key 3"); List<int> childlist = new List<int>(); childlist = queryv.querychildren<int, DBElement<int, string>, string>(newdbq, 3); if (childlist != null) { foreach (int i in childlist) Console.WriteLine(i); } //new elements created for string,list of string database DBElement<string, List<string>> newelem1q = new DBElement<string, List<string>>(" element 1", "1 is first"); DBElement<string, List<string>> newelem2q = new DBElement<string, List<string>>(" element 2", "2 is second"); DBElement<string, List<string>> newelem3q = new DBElement<string, List<string>>(" element 3", " 3 is third"); newelem1q.children.AddRange(new List<string> { " one", "one", "one" }); newelem1q.payload = new List<string> { "h", "e", "l", "l", "o" }; newelem2q.children.AddRange(new List<string> { " two", "two", "two" }); newelem2q.payload = new List<string> { "h", "d", "w", "f", "b" }; newelem3q.children.AddRange(new List<string> { " three", "three", "three" }); newelem3q.payload = new List<string> { "a", "e", "i", "o", "u" }; newdbqs.insert("one", newelem1q); newdbqs.insert("two", newelem2q); newdbqs.insert("three", newelem3q); newdbqs.showEnumerableDB(); // testing query one DBElement<string, List<string>> valuestring = new DBElement<string, List<string>>(); Console.WriteLine("\n \n getting value for key 2"); valuestring = queryv.queryvalue<string, DBElement<string, List<string>>, string>(newdbqs, "two"); if (valuestring != null) valuestring.showEnumerableElement(); //testing query two DBElement<string, List<string>> valuestrings = new DBElement<string, List<string>>(); Console.WriteLine("\n \n getting children for key five"); List<string> childlists = new List<string>(); childlists = queryv.querychildren<string, DBElement<string, List<string>>, string>(newdbqs, "five"); if (childlists != null) { foreach (string cstring in childlists) Console.WriteLine(cstring); } }
static void Main(string[] args) { "Testing DBEngine Package".title('='); WriteLine(); // New element being created Write("\n --- Test DBElement<int,string> ---"); DBElement <int, string> elem1 = new DBElement <int, string>(); elem1.payload = "a payload"; Write(elem1.showElement <int, string>()); WriteLine(); // New element being created DBElement <int, string> elem2 = new DBElement <int, string>("Darth Vader", "Evil Overlord"); elem2.payload = "The Empire strikes back!"; Write(elem2.showElement <int, string>()); WriteLine(); // New element being created var elem3 = new DBElement <int, string>("Luke Skywalker", "Young HotShot"); elem3.children.AddRange(new List <int> { 1, 5, 23 }); elem3.payload = "X-Wing fighter in swamp - Oh oh!"; Write(elem3.showElement <int, string>()); WriteLine(); Write("\n --- Test DBEngine<int,DBElement<int,string>> ---"); 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); if (p1 && p2 && p3) { Write("\n all inserts succeeded"); } else { Write("\n at least one insert failed"); } db.show <int, DBElement <int, string>, string>(); WriteLine(); WriteLine("\n\n removing element of key 2"); bool p4 = db.remove(2); db.show <int, DBElement <int, string>, string>(); Write("\n --- Test DBElement<string,List<string>> ---"); // New element being created of type string and list of strings DBElement <string, List <string> > newelem1 = new DBElement <string, List <string> >(); newelem1.name = "newelem1"; newelem1.descr = "test new type"; newelem1.payload = new List <string> { "one", "two", "three" }; Write(newelem1.showElement <string, List <string> >()); WriteLine(); Write("\n --- Test DBElement<string,List<string>> ---"); DBElement <string, List <string> > newerelem1 = new DBElement <string, List <string> >(); newerelem1.name = "newerelem1"; newerelem1.descr = "better formatting"; newerelem1.payload = new List <string> { "alpha", "beta", "gamma" }; newerelem1.payload.Add("delta"); newerelem1.payload.Add("epsilon"); Write(newerelem1.showElement <string, List <string>, string>()); WriteLine(); //new elements being created DBElement <string, List <string> > newerelem2 = new DBElement <string, List <string> >(); newerelem2.name = "newerelem2"; newerelem2.descr = "better formatting"; newerelem1.children.AddRange(new[] { "first", "second" }); newerelem2.payload = new List <string> { "a", "b", "c" }; newerelem2.payload.Add("d"); newerelem2.payload.Add("e"); Write(newerelem2.showElement <string, List <string>, string>()); WriteLine(); Write("\n --- Test DBEngine<string,DBElement<string,List<string>>> ---"); int seed = 0; string skey = seed.ToString(); Func <string> skeyGen = () => { ++seed; skey = "string" + seed.ToString(); skey = skey.GetHashCode().ToString(); return(skey); }; // create a new database of string and list of string type DBEngine <string, DBElement <string, List <string> > > newdb = new DBEngine <string, DBElement <string, List <string> > >(); newdb.insert(skeyGen(), newerelem1); newdb.insert(skeyGen(), newerelem2); newdb.show <string, DBElement <string, List <string> >, List <string>, string>(); WriteLine(); // removing element WriteLine("removing element "); newdb.remove("newerelem2"); newdb.show <string, DBElement <string, List <string> >, List <string>, string>(); // testing editing of metadata text "testing edits".title(); db.show <int, DBElement <int, string>, string>(); DBElement <int, string> editElement = new DBElement <int, string>(); db.getValue(1, out editElement); editElement.showElement <int, string>(); editElement.name = "editedName"; editElement.descr = "editedDescription"; db.show <int, DBElement <int, string>, string>(); Write("\n\n"); }