private void test() { DBEngine <int, DBElement <int, string> > db = new DBEngine <int, DBElement <int, string> >(); ItemFactory <int, string> itemFactory = new ItemFactory <int, string>(); int key = 0; //-----------Modify Metadata-------------------------- "Modify metadata".title('.'); WriteLine("\n Elements in DB :"); db.showDB(); key = 2; string name = "Nitish"; string description = "MS in CE"; WriteLine("\n\n\n New Details for metadata of key {0} :", key); WriteLine("\n Name : {0}", name); WriteLine("\n Description : {0}", description); WriteLine(); db.modifyMetadata(key, name, description); WriteLine("\n\n DB after the change :"); db.showDB(); WriteLine(); "".demarcation(); //-----------Modify Metadata-------------------------- //-------------------Replace Value instance----------------------- "Replace value instance".title('.'); WriteLine("\n\n Elements in DB :"); DBElement <int, string> elem = itemFactory.Create(); db.showDB(); key = 2; //DBElement<int, string> elem = new DBElement<int, string>(); elem.name = "new element"; elem.descr = "new test element"; elem.timeStamp = DateTime.Now; elem.children.AddRange(new List <int> { 7, 8, 9 }); elem.payload = "new elem's payload"; WriteLine("\n\n New instance for replacement for key {0}:\n", key); elem.showElement(); WriteLine("\n\n Replace instance of a key :"); db.replaceKeyInstance(key, elem); WriteLine("\n\n DB after the change :"); db.showDB(); WriteLine(); "".demarcation(); //-------------------Replace Value instance----------------------- }
/// <summary> /// Queries the database. /// </summary> /// <param name="input">The input.</param> /// <returns></returns> public String QueryDatabase(String input) { String result = String.Empty; var dbElement = ParseXml(input); switch (dbElement.dbOperation) { case "Add": db.insert(dbElement.key, dbElement); result = "Key " + dbElement.key + " inserted successfully!"; break; case "Edit": db.replaceKeyInstance(dbElement.key, dbElement); result = "Key " + dbElement.key + "'s value modified successfully!"; break; case "Delete": if (db.delete(dbElement.key)) { result = "Key " + dbElement.key + " deleted successfully!"; } else { result = "Key " + dbElement.key + " not found!!"; } break; case "SearchChild": var children = db.searchChildren(dbElement.key); result = "Children are " + string.Join(", ", children.ToArray()); break; case "Search": var value = db.searchValue(dbElement.key); if (value != null) { result = "Key " + dbElement.key + " found!!!!!\n\n"; result += value.showEnumerableElement(); } else { result = "Key " + dbElement.key + " not found!!"; } break; case "Persist": db.toXml(); result = "Database persisted successfully"; break; case "Restore": db.restoreDatabase(); result = "Database successfully restored!!"; break; default: break; } string dbView = db.showEnumerableDB(); "\nDB Contents:\n".title(); result += dbView; return(result); }