//----< Demonstrating req 4 - editing metadata,value instance of key/value collection primitive type>------------------- public void TestR4_NonPrimitive(DBEngine <int, DBElement <int, string> > dbType1, DBEngine <string, DBElement <string, List <string> > > dbType2, DBItemEditor editor) { "\nDemonstrating Requirement #4 Updating Metadata - Collection Type DB".title(); IEnumerable <string> db2Keys = dbType2.Keys(); String firstDB2Key = db2Keys.ElementAt(0); String secondDB2Key = db2Keys.ElementAt(1); WriteLine("\n\n Before updating Metadata for key : " + firstDB2Key); dbType2.showEnumerableDB(); WriteLine("\n\n After updating Metadata for key : " + firstDB2Key); editor.updateMetadataInfo <string, List <string>, string>(dbType2, firstDB2Key, "Django Unchained Reborn", " German Hunter helps to resuce a slave wife"); dbType2.showEnumerableDB(); "\nDemonstrating Requirement #4 Editing Value Instance Info - Collection Type DB".title(); WriteLine("\n\n Before updating Value Instance for key : " + secondDB2Key); dbType2.showEnumerableDB(); WriteLine("\n\n After updating Value Instance for key : " + secondDB2Key); DBElement <string, List <string> > newerelem3 = new DBElement <string, List <string> >(); newerelem3.name = "3 Idiots Remade"; newerelem3.descr = " They think differently, even as the rest of the world called them idiots"; newerelem3.children.AddRange(new[] { "Django Unchained Remake" }); newerelem3.payload = new List <string> { "Rajkumar Hirani", "Amir Khan", "Abhijat Joshi" }; editor.updatePayloadInfo <string, List <string>, string>(dbType2, newerelem3, secondDB2Key); dbType2.showEnumerableDB(); "\nDemonstrating Requirement #4 Addition of child instances - Collection DB".title(); WriteLine("\n\n Before adding child Instance :" + secondDB2Key + " to key : " + firstDB2Key); dbType2.showEnumerableDB(); editor.addChildren <string, List <string>, string>(dbType2, firstDB2Key, secondDB2Key); WriteLine("\n\n After adding child Instance :" + secondDB2Key + " to key :" + firstDB2Key); dbType2.showEnumerableDB(); "\nDemonstrating Requirement #4 Removal of child instances - Collection DB".title(); string keyChild = "Django Unchained Remake"; WriteLine("\n\n Before removing child Instance :" + keyChild + " from key :" + secondDB2Key); dbType2.showEnumerableDB(); editor.removeChildren <string, List <string>, string>(dbType2, secondDB2Key, "Django Unchained Remake"); WriteLine("\n\n After removing child Instance :" + keyChild + " from key :" + secondDB2Key); dbType2.showEnumerableDB(); }
//----< Demonstrating req 4 - editing metadata,value instance of key/value database primitive type>------------------- public void TestR4(DBEngine <int, DBElement <int, string> > dbType1, DBEngine <string, DBElement <string, List <string> > > dbType2, DBItemEditor editor) { "\n\nDemonstrating Requirement #4 Updating Metadata - Primitive Type DB".title(); IEnumerable <int> keys = dbType1.Keys(); int firstDB1Key = keys.ElementAt(0); int secondDB1Key = keys.ElementAt(1); WriteLine("\n\n Before updating Metadata for key : " + firstDB1Key); dbType1.showDB(); WriteLine("\n\n After updating Metadata for key : " + firstDB1Key); editor.updateMetadataInfo <int, String>(dbType1, firstDB1Key, "Reborn -Cast Away", "The guy who survived in deserted insland"); dbType1.showDB(); "\nDemonstrating Requirement #4 Editing Value Instance Info - Primitive Type DB".title(); WriteLine("\n\n Before updating Value Instance for key : " + secondDB1Key); dbType1.showDB(); WriteLine("\n\n After updating Value Instance for key : " + secondDB1Key); DBElement <int, string> elem2 = new DBElement <int, string>(); elem2.name = "Titanic Reborn"; elem2.descr = "A new movie directed in 2015 with the same plot line"; elem2.timeStamp = DateTime.Now; elem2.children.AddRange(new List <int> { 114 }); elem2.payload = "The movie will feature same actors but director changes"; editor.updatePayloadInfo <int, String>(dbType1, elem2, secondDB1Key); dbType1.showDB(); "\nDemonstrating Requirement #4 Addition of child instances - Primitive Type DB ".title(); WriteLine("\n\n Before adding child Instance " + secondDB1Key + " to key " + firstDB1Key); dbType1.showDB(); editor.addChildren <int, string>(dbType1, firstDB1Key, secondDB1Key); WriteLine("\n\n After adding child Instance : " + secondDB1Key + " to key " + firstDB1Key); dbType1.showDB(); "\nDemonstrating Requirement #4 Removal of child instances - Primitive DB ".title(); WriteLine("\n\n Before removing child Instance key " + 113 + " from key " + firstDB1Key); dbType1.showDB(); editor.removeChildren <int, string>(dbType1, firstDB1Key, 113); WriteLine("\n\n After removing child Instance key " + 113 + " from key " + firstDB1Key); dbType1.showDB(); }
static void Main(string[] args) { DBEngine <int, DBElement <int, string> > dbType1 = new DBEngine <int, DBElement <int, string> >(); DBEngine <string, DBElement <string, List <string> > > dbType2 = new DBEngine <string, DBElement <string, List <string> > >(); DBItemEditor editor = new DBItemEditor(); //Demonstrating primitive type "\nDemonstrating Requirement #2 - Primitive Type DB".title(); DBElement <int, string> elem1 = new DBElement <int, string>(); elem1.name = "Jurassic World"; elem1.descr = "Story on escape from giant creatures"; elem1.timeStamp = DateTime.Now; elem1.payload = "A giant creature attacks the park and becomes a killing machine"; editor.addKeyValyePair <int, String>(dbType1, elem1, DBElementExtensions.generate_int_key()); DBElement <int, string> elem2 = new DBElement <int, string>(); elem2.name = "Cast Away"; elem2.descr = "Story of surviving a crash landing on a deserted island."; elem2.timeStamp = DateTime.Now; elem2.children.AddRange(new List <int> { 4, 5 }); elem2.payload = "Directed by Robert Zemeckis and written by Willian Broyles Jr."; editor.addKeyValyePair <int, String>(dbType1, elem2, DBElementExtensions.generate_int_key()); dbType1.showDB(); Console.WriteLine("\n\n Before updating metadata"); IEnumerable <int> keys1 = dbType1.Keys(); int first = keys1.First(); dbType1.showDB(); Console.WriteLine("\n\n After updating metadata"); editor.updateMetadataInfo <int, String>(dbType1, first, "Reborn -Cast Away", "The guy who survived in deserted insland"); dbType1.showDB(); IEnumerable <int> keys = dbType1.Keys(); int firstDB1Key = keys.ElementAt(0); int secondDB1Key = keys.ElementAt(1); DBElement <int, string> elem22 = new DBElement <int, string>(); elem22.name = "Titanic Reborn"; elem22.descr = "A new movie directed in 2015 with the same plot line"; elem22.timeStamp = DateTime.Now; elem22.children.AddRange(new List <int> { 1 }); elem22.payload = "The movie will feature same actors but director changes"; editor.updatePayloadInfo <int, String>(dbType1, elem22, secondDB1Key); Console.WriteLine("\n\n Before adding child Instance " + secondDB1Key + " from key " + firstDB1Key); dbType1.showDB(); editor.addChildren <int, string>(dbType1, firstDB1Key, secondDB1Key); Console.WriteLine("\n\n After adding child Instance : " + secondDB1Key + " from key " + firstDB1Key); dbType1.showDB(); Console.WriteLine("\n\n Before removing child Instance key " + 114 + " from key " + firstDB1Key); dbType1.showDB(); editor.removeChildren <int, string>(dbType1, firstDB1Key, 114); Console.WriteLine("\n\n After removing child Instance key " + 114 + " from key " + firstDB1Key); dbType1.showDB(); }