static void Main(string[] args) { "Testing ItemEditor Package".title('='); Console.WriteLine(); DBEngine <int, DBElement <int, ListOfStrings> > db1 = new DBEngine <int, DBElement <int, ListOfStrings> >(); ItemEditor <int, string> itemEditor = new ItemEditor <int, string>(); "For key = 1, metadata before editing is: ".title('-'); DBElement <int, ListOfStrings> elem1 = new DBElement <int, ListOfStrings>(); elem1.name = "1st Key/Value = Int/ListOfStrings"; elem1.descr = "This is first element of Int/ListOfStrings key value pair."; elem1.timeStamp = DateTime.Now; elem1.children.AddRange(new List <int> { 100, 101, 102, 103, 104, 105 }); elem1.payload = new ListOfStrings(); elem1.payload.theWrappedData = new List <string> { "CSE681", "SMA", "C#.net", "AI" }; db1.insert(1, elem1); db1.showDB(); Console.WriteLine("\n\n"); "For key = 1, metadata after editing is: ".title('-'); itemEditor.editByName(ref db1, 1, "NewX"); itemEditor.editByDescr(ref db1, 1, "NewDescription"); db1.showDB(); Console.WriteLine("\n\n"); }
void TestR2() { "Demonstrating Requirement #2".title(); WriteLine("\nKey/Value database with key of type 'int' and data of type 'string'"); db.showDB(); WriteLine("\n\nKey/Value database with key of type 'int' and data of type 'list of string'"); dbPay.showEnumerableDB(); WriteLine("\n\nKey/Value database with key of type 'string' and data of type 'list of string'"); dbString.showEnumerableDB(); WriteLine(); }
//private DBEngine<int, DBElement<int, string>> db2 = new DBEngine<int, DBElement<int, string>>(); void TestR2() { "Demonstrating Requirement #2".title(); DBElement <int, string> elem = new DBElement <int, string>(); elem.name = "element"; elem.descr = "test element"; elem.timeStamp = DateTime.Now; elem.children.AddRange(new List <int> { 1, 2, 3 }); elem.payload = "elem's payload"; elem.showElement(); db.insert(1, elem); Write("\n\n Show key/value pairs in data base:\n"); db.showDB(); WriteLine(); }
void TestR5() { PersistData <int, ListOfStrings> persistEngine1 = new PersistData <int, ListOfStrings>(); "Demonstrating Requirement #5".title(); "Write in-memory database in XML file to persist data, please check Data1.xml file.".title('-'); persistEngine1.loadXmlFile("Data1.xml", typeof(int).Name, typeof(ListOfStrings).Name); if (!persistEngine1.addRecord(1, db1.Dictionary[1])) { WriteLine("\nKey 1 is already in xml file."); } else { WriteLine("Key 1 is inserted in xml file."); } if (!persistEngine1.addRecord(2, db1.Dictionary[2])) { WriteLine("Key 2 is already in xml file."); } else { WriteLine("Key 2 is inserted in xml file."); } if (!persistEngine1.addRecord(4, db1.Dictionary[4])) { WriteLine("Key 4 is already in xml file."); } else { WriteLine("Key 4 is inserted in xml file."); } if (!persistEngine1.addRecord(2, db1.Dictionary[4])) { WriteLine("Key 4 is already in xml file."); } else { WriteLine("Key 4 is inserted in xml file."); } "Persist XML file looks like this ".title('-'); XDocument document = persistEngine1.loadXmlFile("Data1.xml"); WriteLine(document.ToString()); "Database restored or augmented from an existing XML (Data1.xml) file".title('-'); DBEngine <int, DBElement <int, ListOfStrings> > augmentData = new DBEngine <int, DBElement <int, ListOfStrings> >(); persistEngine1.retrieveDataFromXML(augmentData, "Data1.xml"); augmentData.showDB(); WriteLine(); }
static void Main(string[] args) { "Testing Persist Engine Package".title('='); DBEngine <int, DBElement <int, ListOfStrings> > db1 = new DBEngine <int, DBElement <int, ListOfStrings> >(); PersistData <int, ListOfStrings> persistEngine1 = new PersistData <int, ListOfStrings>(); "Write in-memory database in XML file, please check DataPersistTest.xml file.".title('-'); persistEngine1.loadXmlFile("DataPersistTest.xml", typeof(int).Name, typeof(ListOfStrings).Name); if (!persistEngine1.addRecord(1, db1.Dictionary[1])) { WriteLine("Key 1 is already in xml file."); } else { WriteLine("Key 1 is inserted in xml file."); } if (!persistEngine1.addRecord(2, db1.Dictionary[2])) { WriteLine("Key 2 is already in xml file."); } else { WriteLine("Key 2 is inserted in xml file."); } if (!persistEngine1.addRecord(4, db1.Dictionary[4])) { WriteLine("Key 4 is already in xml file."); } else { WriteLine("Key 4 is inserted in xml file."); } if (!persistEngine1.addRecord(2, db1.Dictionary[4])) { WriteLine("Key 4 is already in xml file."); } else { WriteLine("Key 4 is inserted in xml file."); } "Database restored or augmented from an existing XML (Data1.xml) file".title('-'); DBEngine <int, DBElement <int, ListOfStrings> > augmentData = new DBEngine <int, DBElement <int, ListOfStrings> >(); persistEngine1.retrieveDataFromXML(augmentData, "DataPersistTest.xml"); augmentData.showDB(); WriteLine(); }
void testR2() { "Demonstrating Requirement #2".title(); DBElement <int, String> elem = new DBElement <int, string>(); elem.name = "text element"; elem.descr = "descr"; elem.timeStamp = DateTime.Now; elem.payload = "elem's payload"; elem.children.AddRange(new [] { 1, 2, 3 }); elem.showElement(); db.insert(1, elem); db.showDB(); WriteLine(); }
static void Main(string[] args) { "Testing DBEngine Package".title('=');; WriteLine(); "Test db of scalar elements".title(); WriteLine(); 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(); /* ElementFormatter is not ready for prime time yet */ //Write(ElementFormatter.formatElement(elem1.showElement<int, string>(), false)); } Write("\n --- Test DBEngine<int,DBElement<int,string>> ---"); WriteLine(); int key = 0; Func <int> keyGen = () => { ++key; return(key); }; 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(); 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" }; 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"); 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"); }
static void Main(string[] args) { "Testing PersistEngine Package".title('='); WriteLine(); DBEngine <int, DBElement <int, string> > db = new DBEngine <int, DBElement <int, string> >(); "\nSave to an XML file".title(); DBElement <int, string> elem1 = new DBElement <int, string>(); elem1.name = "Usain Bolt"; elem1.descr = "Athelte"; elem1.timeStamp = DateTime.Now; elem1.children.AddRange(new List <int> { 2 }); elem1.payload = "Fastest in the world"; db.insert(1, elem1); DBElement <int, string> elem2 = new DBElement <int, string>(); elem2.name = "Saina Nehwal"; elem2.descr = "Badminton Player"; elem2.timeStamp = DateTime.Now; elem2.children.AddRange(new List <int> { 1 }); elem2.payload = "Famous badminton player"; db.insert(2, elem2); db.showDB(); WriteLine(); dynamic allKeys = db.Keys(); PersistEngine <int, DBElement <int, string> > pEngine = new PersistEngine <int, DBElement <int, string> >(db); pEngine.persistToXML(allKeys); WriteLine("\n\nAbove database is stored as XML file in local machine"); WriteLine(); WriteLine("\nThe persisted XML file along with new key/value pairs are augmented to the database.\n"); WriteLine("Below shown key/value pairs are augmented to the database.\n"); pEngine.augmentDatabaseFromXML(db); //Augment the persisted database along with new values to the main database pEngine.persistToXML(allKeys); db.showDB(); WriteLine(); WriteLine(); "\nPersist database every 5 seconds until its cancelled".title(); WriteLine(); pEngine.scheduledSaveDatabase(); WriteLine(); WriteLine(); "\nProject dependancy and realtionships".title(); WriteLine(); DBEngine <string, DBElement <string, List <string> > > dependancyDb = new DBEngine <string, DBElement <string, List <string> > >(); PersistEngine <string, DBElement <string, List <string> > > pEngineString = new PersistEngine <string, DBElement <string, List <string> > >(dependancyDb); try { Console.WriteLine("\nBelow details provide information on dependancy of every package in the project\n"); pEngine.displayDependancy(); dependancyDb.showEnumerableDB(); WriteLine(); } catch (Exception e) { WriteLine("\n" + e.Message + "\n"); } }
void TestR2() { DBElement <int, string> elem = new DBElement <int, string>(); elem.name = "India"; elem.descr = "Country"; elem.timeStamp = DateTime.Now; elem.children.AddRange(new List <int> { 2, 3 }); elem.payload = "Famous cricket player"; WriteLine(); "1) The element is as shown below".title(); elem.showElement(); db.insert(1, elem); WriteLine(); "2) The key Value pair is shown below".title(); db.showDB(); WriteLine(); }
static void Main(string[] args) { "Testing ItemEditor Package".title('='); WriteLine(); DBEngine <int, DBElement <int, string> > db = new DBEngine <int, DBElement <int, string> >(); DBElement <int, string> elem1 = new DBElement <int, string>(); elem1.name = "Usain Bolt"; elem1.descr = "Athelte"; elem1.timeStamp = DateTime.Now; elem1.children.AddRange(new List <int> { 2 }); elem1.payload = "Fastest in the world"; db.insert(1, elem1); DBElement <int, string> elem2 = new DBElement <int, string>(); elem2.name = "Saina Nehwal"; elem2.descr = "Badminton Player"; elem2.timeStamp = DateTime.Now; elem2.children.AddRange(new List <int> { 1 }); elem2.payload = "Famous badminton player"; db.insert(2, elem2); db.showDB(); WriteLine(); ItemEditor <int, DBElement <int, string> > iEditor = new ItemEditor <int, DBElement <int, string> >(db); "\n1) Editing metadata".title(); "\nBefore editing metadata for key 1".title(); db.showDB(); WriteLine(); "\nAfter editing metadata for key 1".title(); iEditor = new ItemEditor <int, DBElement <int, string> >(db); iEditor.editMetaData(1, "Sachin Tendulkar", "Cricket player"); //send the values to be edited to the editMetaData() function db.showDB(); WriteLine(); WriteLine(); "\n2) Adding children".title(); "\nBefore adding relationship(children) for key 1".title(); db.showDB(); WriteLine(); "\nAfter adding relationship(children) for Key 1".title(); iEditor.addrelationships(1, new List <int> { 3 }); //send a new list with children to be added to a key db.showDB(); WriteLine(); WriteLine(); "\n3) Deleting children".title(); "\nBefore deleting relationship(children) for key 1".title(); db.showDB(); WriteLine(); "\nAfter deleting relationship(children) to Key 1".title(); //send a new list with children to be deleted from a key iEditor.deleteRelationships(1, new List <int> { 3 }); db.showDB(); WriteLine(); WriteLine(); "\n4) Replacing value instance".title(); DBElement <int, string> elem = new DBElement <int, string>(); //create a new element for replacing value elem.name = "Messi"; elem.payload = "Plays for Argentina"; elem.descr = "Football player"; elem.children.AddRange(new List <int> { 2 }); elem.timeStamp = DateTime.Now; "\nBefore replacing the value instance for key 2".title(); db.showDB(); WriteLine(); "\nAfter replacing the value instance for key 2".title(); iEditor.replaceValueInstance(2, elem); //send value to be replaced for a key db.showDB(); WriteLine(); }
void TestR2() { "Demonstrating Requirement #2".title('='); // First type of database. " First Type of database.".title('-'); DBElement <int, string> elem = new DBElement <int, string>(); elem.name = "1st Key/Value = Int/String"; elem.descr = "This is the first element which is int/string key value pair."; elem.timeStamp = DateTime.Now; elem.children.AddRange(new List <int> { 10, 11, 12 }); elem.payload = "Payload : Key/Value = Int/String"; db2.insert(1, elem); DBElement <int, string> elem21 = new DBElement <int, string>(); elem21.name = "2nd Key/Value = Int/String"; elem21.descr = "This is the second element which is int/string key value pair."; elem21.timeStamp = DateTime.Now; elem21.children.AddRange(new List <int> { 20, 21, 22 }); elem21.payload = "Payload 2 : Key/Value = Int/String"; db2.insert(1, elem21); WriteLine(" This shows Int/String key/value paris data in-memory database."); db2.showDB(); WriteLine(); // second type of database. WriteLine(); " Second Type of database.".title('-'); WriteLine(); DBElement <int, ListOfStrings> elem1 = new DBElement <int, ListOfStrings>(); elem1.name = "1st Key/Value = Int/ListOfStrings"; elem1.descr = "This is first element of Int/ListOfStrings key value pair."; elem1.timeStamp = DateTime.Now; elem1.children.AddRange(new List <int> { 100, 101, 102, 103, 104, 105 }); elem1.payload = new ListOfStrings(); elem1.payload.theWrappedData = new List <string> { "CSE681", "SMA", "C#.net", "AI" }; db1.insert(1, elem1); DBElement <int, ListOfStrings> elem2 = new DBElement <int, ListOfStrings>(); elem2.name = "element int-ListOfString 2"; elem2.descr = "test element int-ListOfString 2"; elem2.timeStamp = DateTime.Now; elem2.children.AddRange(new List <int> { 10, 22, 23, 24, 25, 26 }); elem2.payload = new ListOfStrings(); elem2.payload.theWrappedData = new List <string> { "CSE6812", "SMA2", "C#.net2", "AI2" }; db1.insert(2, elem2); WriteLine(" This shows Int/ListOfString key/value paris data in-memory database."); db1.showDB(); WriteLine(); }
static void Main(string[] args) { "Testing DBFactory Package".title('='); WriteLine(); "\nCreation of immutable database".title(); WriteLine(); "\nOriginal database".title(); DBEngine <int, DBElement <int, string> > db = new DBEngine <int, DBElement <int, string> >(); DBElement <int, string> elem1 = new DBElement <int, string>(); elem1.name = "India"; elem1.descr = "Country"; elem1.timeStamp = DateTime.Now; elem1.children.AddRange(new List <int> { 2, 3 }); elem1.payload = "Famous cricket player"; db.insert(1, elem1); DBElement <int, string> elem2 = new DBElement <int, string>(); elem2.name = "Roger federer"; elem2.descr = "Tennis player"; elem2.timeStamp = DateTime.Now.AddDays(-15); elem2.children.AddRange(new List <int> { 3 }); elem2.payload = "Famous tennis player"; db.insert(2, elem2); DBElement <int, string> elem3 = new DBElement <int, string>(); elem3.name = "Usain Bolt"; elem3.descr = "Athelte"; elem3.timeStamp = DateTime.Now; elem3.children.AddRange(new List <int> { 1 }); elem3.payload = "Fastest in the world"; db.insert(3, elem3); DBElement <int, string> elem4 = new DBElement <int, string>(); elem4.name = "Saina Nehwal"; elem4.descr = "Badminton Player"; elem4.timeStamp = DateTime.Now; elem4.children.AddRange(new List <int> { 2 }); elem4.payload = "Famous badminton player"; db.insert(4, elem4); db.showDB(); WriteLine(); "\n Fetch all the keys which are even from the above database".title(); try { QueryEngine <int, DBElement <int, string> > qEngine = new QueryEngine <int, DBElement <int, string> >(db); Dictionary <int, DBElement <int, string> > dictFactory = new Dictionary <int, DBElement <int, string> >(); DBFactory <int, DBElement <int, string> > dbFactory; var keys = qEngine.getListKeyPattern(); if (keys != null) { foreach (var key in keys) { var val = db.getValueOfKey(key); dictFactory.Add(key, val); //add keys and values to the dictionary } dbFactory = new DBFactory <int, DBElement <int, string> >(dictFactory); //store the dictionary in the WriteLine("\nThe below key/value pairs with even keys pattern are saved as an immutable database\n"); dbFactory.showDB(); //display the immutable database WriteLine(); WriteLine(); } else { WriteLine("\nNo keys are obtained from a query for creation of immutable database\n"); } WriteLine(); WriteLine(); } catch (Exception e) { Console.WriteLine("\n" + e.Message + "\n"); } }
static void Main(string[] args) { "Testing ItemEditor Package".title('='); Console.WriteLine(); DBEngine <int, DBElement <int, string> > db = new DBEngine <int, DBElement <int, string> >(); DBElement <int, string> elem1 = new DBElement <int, string>(); elem1.name = "India"; elem1.descr = "Country"; elem1.timeStamp = DateTime.Now; elem1.children.AddRange(new List <int> { 2, 3 }); elem1.payload = "Famous cricket player"; db.insert(1, elem1); DBElement <int, string> elem2 = new DBElement <int, string>(); //Add new key/value pairs to the database elem2.name = "Roger federer"; elem2.descr = "Tennis player"; elem2.timeStamp = DateTime.Now.AddDays(-15); elem2.children.AddRange(new List <int> { 3 }); elem2.payload = "Famous tennis player"; db.insert(2, elem2); DBElement <int, string> elem3 = new DBElement <int, string>(); elem3.name = "Usain Bolt"; elem3.descr = "Athelte"; elem3.timeStamp = DateTime.Now; elem3.children.AddRange(new List <int> { 1 }); elem3.payload = "Fastest in the world"; db.insert(3, elem3); Console.WriteLine(); db.showDB(); "\n1) Fetch Value for key 3".title(); var val = db.getValueOfKey(3); val.showElement(); Console.WriteLine(); QueryEngine <int, DBElement <int, string> > qEngine = new QueryEngine <int, DBElement <int, string> >(db); "\n2) Fetch the children of key 1".title(); var children = qEngine.getChildrenOfKey(1); displayChildren(children); DBEngine <string, DBElement <string, List <string> > > db2 = new DBEngine <string, DBElement <string, List <string> > >(); "\n 3) Fetch the keys which starts with r in the below database with key/value pairs".title(); //Taking new database with string keys DBElement <string, List <string> > elem4 = new DBElement <string, List <string> >(); elem4.name = "Christ college"; elem4.descr = "College where the person studied"; elem4.timeStamp = DateTime.Now; elem4.children.AddRange(new List <string> { "rakesh" }); elem4.payload = new List <string> { "One", "Two", "Three", "Four" }; db2.insert("saahith", elem4); DBElement <string, List <string> > elem5 = new DBElement <string, List <string> >(); elem5.name = "PESIT college"; elem5.descr = "College where the person pursued undergraduation"; elem5.timeStamp = DateTime.Now.AddDays(-2); elem5.children.AddRange(new List <string> { "saahith" }); elem5.payload = new List <string> { "Five", "Six", "Seven", "Eight" }; db2.insert("rakesh", elem5); db2.showEnumerableDB(); WriteLine(); QueryEngine <string, DBElement <string, List <string> > > qEngine2 = new QueryEngine <string, DBElement <string, List <string> > >(db2); string pattern1 = @"(^r)"; var spKeys = qEngine2.getListStringKeyPattern(pattern1); displayStringKeys(spKeys); "\n4) Fetch keys with metadata pattern 'Country'".title(); string pattern = "Country"; var mdKeys = qEngine.getListMetaDataPattern(pattern); displayKeys(mdKeys); "\n5) Fetch keys which are created between two dates 29th sept 2015 and 15th oct 2015".title(); DateTime time1 = new DateTime(2015, 9, 29); DateTime time2 = new DateTime(2015, 10, 15); var tpKeys = qEngine.getListTimePattern(time1, time2); displayKeys(tpKeys); }