//helper function for showDBbyCategory public void queryByCategory(int category, DBEngine1 <DBElement1 <int, string> > db) { List <int> foundKeys = new List <int>(); IEnumerable <int> keys = db.Keys(); foreach (int key in keys) { DBElement1 <int, string> elem = new DBElement1 <int, string>(); db.getValue(key, out elem); if (elem.category.Contains(category)) { foundKeys.Add(key); } } foreach (int key1 in foundKeys) { Console.WriteLine("Key={0}", key1); DBElement1 <int, string> elem = new DBElement1 <int, string>(); db.getValue(key1, out elem); Console.WriteLine("Name: {0}", elem.name); // Printing DB contents grouped by category Console.WriteLine("Description ={0}", elem.descr); Console.WriteLine("timeStamp : {0}", elem.timeStamp); Console.Write("Children:"); foreach (int child in elem.children) { Console.Write("{0} ", child); } //WriteLine(); Console.WriteLine("Payload : {0}", elem.payload); WriteLine(); } }
public void showDBbyCategory(DBEngine1 <DBElement1 <int, string> > db) { List <int> cats = new List <int>(); List <int> foundKeys = new List <int>(); IEnumerable <int> keys = db.Keys(); foreach (int key in keys) { DBElement1 <int, string> elem = new DBElement1 <int, string>(); db.getValue(key, out elem); foreach (int cat in elem.category) { if (cats.Contains(cat)) // Skip for repeated categories { continue; } WriteLine("\nCategory = {0}", cat); WriteLine("- - - - - - "); queryByCategory(cat, db); // Querying DB by category cats.Add(cat); } } }
public void show(DBEngine1 <Value> db) { foreach (int key in db.Keys()) { Value value; db.getValue(key, out value); DBElement1 <int, string> elem = value as DBElement1 <int, string>; Write("\n\n -- key = {0} --", key); Write(showElement(elem)); } }