//----< Augument xml file db contents to existing primtive type db>------------------- public static void augument_db <Key, Value, Data>(this DBEngine <Key, Value> db, string fileName) { XDocument newDoc = null; try { newDoc = XDocument.Load(fileName); WriteLine("\n\nInput XML\n"); WriteLine(newDoc.ToString()); XElement keyElement = newDoc.Root.Element("keytype"); XElement payloadElement = newDoc.Root.Element("payloadtype"); String keyType = keyElement.Value; String payLoad = payloadElement.Value; // check the key-type if (typeof(Key).ToString() == keyType && typeof(Data).ToString() == payLoad) { IEnumerable <XElement> elements = newDoc.Root.Elements("record"); foreach (XElement item in elements) // Extract each record { string KeyStringval = item.Element("key").Value; Key key = (Key)Convert.ChangeType(KeyStringval, typeof(Key)); DBElement <Key, Data> dbElement = new DBElement <Key, Data>(); XElement myelement = item.Element("element"); dbElement.name = myelement.Element("name").Value; dbElement.descr = myelement.Element("descr").Value; dbElement.timeStamp = DateTime.Now; IEnumerable <XElement> childrensElements = myelement.Elements("children").Elements("key"); foreach (XElement child in childrensElements) { Key childKey = (Key)Convert.ChangeType(child.Value, typeof(Key)); dbElement.children.AddRange(new[] { childKey }); } Data payLoadData = (Data)Convert.ChangeType(myelement.Element("payload").Value, typeof(Data)); dbElement.payload = payLoadData; Value valueType = (Value)Convert.ChangeType(dbElement, typeof(Value)); db.insert(key, valueType); } } else { Console.WriteLine("Not matching db"); } } catch (Exception) { Console.WriteLine("File Not Found to Read"); } }
//----< add key value pair info for primitive type db >------------------------------------- public bool addKeyValyePair <Key, Data>(DBEngine <Key, DBElement <Key, Data> > dbType2, DBElement <Key, Data> dbElem, Key keyVal) { bool res = dbType2.insert(keyVal, dbElem); if (res) { dbType2.numberOfWrties++; if (dbType2.numberOfWrties >= dbType2.max_writes) { dbType2.numberOfWrties = 0; trigger_primitive_storage <Key, Data>(dbType2); } } return(res); }
//----< update payload info for collection type db >------------------------------------- public bool updatePayloadInfo <Key, Data, T>(DBEngine <Key, DBElement <Key, Data> > dbType, DBElement <Key, Data> dbElem, Key keyVal) where Data : IEnumerable <T> { bool res = dbType.update(keyVal, dbElem); { dbType.numberOfWrties++; if (dbType.numberOfWrties >= dbType.max_writes) { dbType.numberOfWrties = 0; trigger_collection_storage <Key, Data, T>(dbType); } } return(res); }
//----< remove key value pair info for collection type db >------------------------------------- public bool removeKey <Key, Data, T>(DBEngine <Key, DBElement <Key, Data> > dbType2, Key key) where Data : IEnumerable <T> { bool res = dbType2.delete(key); { dbType2.numberOfWrties++; if (dbType2.numberOfWrties >= dbType2.max_writes) { dbType2.numberOfWrties = 0; trigger_collection_storage <Key, Data, T>(dbType2); } } return(res); }
//----< add key value pair info for collection type db >------------------------------------- public bool addKeyValyePair <Key, Data, T>(DBEngine <Key, DBElement <Key, Data> > dbType2, DBElement <Key, Data> dbElem, Key keyVal) where Data : IEnumerable <T> { bool res = dbType2.insert(keyVal, dbElem); if (res) { dbType2.numberOfWrties++; if (dbType2.numberOfWrties >= dbType2.max_writes) { dbType2.numberOfWrties = 0; trigger_collection_storage <Key, Data, T>(dbType2); } } return(res); }
//----< add children for primitive type db >------------------------------------- public bool addChildren <Key, Data>(DBEngine <Key, DBElement <Key, Data> > dbType2, Key keyVal, Key newChild) { DBElement <Key, Data> dbElem; dbType2.getValue(keyVal, out dbElem); dbElem.children.Add(newChild); { dbType2.numberOfWrties++; if (dbType2.numberOfWrties >= dbType2.max_writes) { dbType2.numberOfWrties = 0; trigger_primitive_storage <Key, Data>(dbType2); } } return(true); }
//----< 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(); }
//----< add children for collection type db >------------------------------------- public bool addChildren <Key, Data, T>(DBEngine <Key, DBElement <Key, Data> > dbType2, Key keyVal, Key newChild) where Data : IEnumerable <T> { DBElement <Key, Data> dbElem; dbType2.getValue(keyVal, out dbElem); dbElem.children.Add(newChild); { dbType2.numberOfWrties++; if (dbType2.numberOfWrties >= dbType2.max_writes) { dbType2.numberOfWrties = 0; trigger_collection_storage <Key, Data, T>(dbType2); } } return(true); }
//----< 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(); }
//----<Demonstrating queries :keys matching a pattern - primitive >------------------- public void testR7c(DBEngine <int, DBElement <int, string> > dbType1, DBEngine <string, DBElement <string, List <string> > > dbType2) { "\nDemonstrating Requirement #7C - The set of all keys matching a specified pattern - Primitive DB".title(); QueryEngine <int, string> queryEngine = new QueryEngine <int, string>(dbType1); QueryEngine <string, List <string> > queryEngineType2 = new QueryEngine <string, List <string> >(dbType2); string inputString = "11"; Write("\n\n Input Search String :" + inputString); List <int> resultList = queryEngine.searchKeyPattern(inputString); foreach (int key in resultList) { Write("\n found \"{0}\" in key \"{1}\"", inputString, key); } testR7c2(dbType2, queryEngineType2); testR7d(dbType2, queryEngineType2); testR7d_primitive(dbType1, queryEngine); testR7e_primitiveType(dbType1, queryEngine); testR7e(dbType2, queryEngineType2); }
//----<Demonstrating categories >------------------- public void testR12() { DBEngine <string, DBElement <string, List <string> > > dbType2New = new DBEngine <string, DBElement <string, List <string> > >(); string dir = "..\\..\\..\\..\\input_xml\\"; string xmlFile6 = "categories.xml"; "\n\nDemonstrating Requirement #12 - Categories DB".title(); WriteLine("\n\n Creating Categories DB from xml file : " + xmlFile6); dbType2New.augument_db <string, DBElement <string, List <string> >, List <string>, string>(dir + xmlFile6); dbType2New.showEnumerableDB(); "\n\nQueries on Categories DB".title(); String inputKey = "Food Products"; QueryEngine <string, List <string> > queryEngine = new QueryEngine <string, List <string> >(dbType2New); DBElement <string, List <string> > queryElement; IEnumerable <string> keys = dbType2New.Keys(); String first = keys.First(); queryEngine.getValueForKey(first, out queryElement); List <String> values = queryElement.payload; Write("\nList of keys for the db items in category \"" + inputKey + "\" are "); foreach (String key in values) { Write(" {0}, ", key); } List <String> children; String child = values[values.Count - 2]; queryEngine.getChildren(child, out children); Write("\nList of categories to which \"" + values[values.Count - 2] + "\" belong are "); foreach (String key1 in children) { Write(" {0}, ", key1); } WriteLine("\n"); }
static void Main(string[] args) { "Demonstrating Project Requirements".title('='); ReqDemos demos = new ReqDemos(); DBEngine <int, DBElement <int, string> > dbType = new DBEngine <int, DBElement <int, string> >(); DBEngine <string, DBElement <string, List <string> > > dbCollectionType = new DBEngine <string, DBElement <string, List <string> > >(); DBItemEditor editor = new DBItemEditor(); demos.TestR2(dbType, dbCollectionType, editor); demos.TestR3(dbType, dbCollectionType, editor); demos.TestR3_NonPrimitive(dbType, dbCollectionType, editor); demos.TestR4(dbType, dbCollectionType, editor); demos.TestR4_NonPrimitive(dbType, dbCollectionType, editor); demos.TestR4_NonPrimitive(dbType, dbCollectionType, editor); demos.TestR7(dbType, dbCollectionType); demos.TestR5(dbType, dbCollectionType); demos.testR7c(dbType, dbCollectionType); demos.TestR6(dbType, dbCollectionType); demos.TestR8(); demos.testR9(); demos.testR12(); }
static void Main(string[] args) { DBEngine <int, DBElement <int, string> > dbType = new DBEngine <int, DBElement <int, string> >(); DBEngine <string, DBElement <string, List <string> > > dbCollectionType = new DBEngine <string, DBElement <string, List <string> > >(); DBItemEditor editor = new DBItemEditor(); ReqDemos demos = new ReqDemos(); demos.TestR2(dbType, dbCollectionType, editor); demos.TestR3(dbType, dbCollectionType, editor); demos.TestR3_NonPrimitive(dbType, dbCollectionType, editor); demos.TestR4(dbType, dbCollectionType, editor); demos.TestR4_NonPrimitive(dbType, dbCollectionType, editor); demos.TestR5(dbType, dbCollectionType); demos.TestR7(dbType, dbCollectionType); demos.testR7c(dbType, dbCollectionType); demos.TestR8(); demos.testR9(); demos.testR12(); demos.TestR6(dbType, dbCollectionType); Console.ReadKey(); }
static void Main(string[] args) { "Testing DBExtensions Package".title('='); WriteLine(); Write("\n --- Test DBElement<int,string> ---"); DBElement <int, string> elem1 = new DBElement <int, string>(); elem1.payload = "a payload"; Write(elem1.showElement <int, string>()); 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>> ---"); 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"); }
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"); }
public static void showEnumerableDB(this DBEngine <string, DBElement <string, List <string> > > db) { db.show <string, DBElement <string, List <string> >, List <string>, string>(); }
public static void showDB(this DBEngine <int, DBElement <int, string> > db) { db.show <int, DBElement <int, string>, string>(); }
static void Main(string[] args) { "Demonstrating Persist Engine".title('='); 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> > >(); //Demonstrating primitive type 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"; dbType1.insert(DBElementExtensions.generate_int_key(), elem1); 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."; dbType1.insert(DBElementExtensions.generate_int_key(), elem2); dbType1.showDB(); //Demostrating IEnumberable Type DBElement <string, List <string> > newerelem1 = new DBElement <string, List <string> >(); newerelem1.name = "Movie Name - The Good the Bad and the Ugly"; newerelem1.descr = "A bounty hunting scam joins two men in an uneasy alliance "; newerelem1.payload = new List <string> { "Clint Eastwood", " Eli Wallach", "Lee Van Cleef" }; String key = "The Good, the Bad and the Ugly"; dbType2.insert(key, newerelem1); DBElement <string, List <string> > newerelem2 = new DBElement <string, List <string> >(); newerelem2.name = "Movie Name - Django Unchained"; newerelem2.descr = "With the help of a German hunter, a freed slave sets to rescue"; newerelem2.children.AddRange(new[] { key, "Life Is Beautiful" }); newerelem2.payload = new List <string> { "Jamie Foxx", "Christoph Waltz", "Leonardo DiCaprio" }; newerelem2.payload.Add("Quentin Tarantino"); String key1 = "Django Unchained"; dbType2.insert(key1, newerelem2); dbType2.showEnumerableDB(); string xmlFile1 = "nosqdldb_primitive.xml"; dbType1.persist_db <int, DBElement <int, string>, string>(xmlFile1); WriteLine("\nSuccesfully persisted dbengine contents to xml file :" + xmlFile1); string xmlFile2 = "nosqdldb.xml"; dbType2.persist_db <string, DBElement <string, List <string> >, List <string>, string>(xmlFile2); WriteLine("\nSuccesfully persisted dbengine contents to xml file : " + xmlFile2); string xmlFile3 = "read_nosqldb_primitive.xml"; WriteLine("\n\n Before Augumenting DB from xml file : " + xmlFile3); dbType1.showDB(); dbType1.augument_db <int, DBElement <int, string>, string>(xmlFile3); WriteLine("\n\n After Augumenting DB from xml file : " + xmlFile3); dbType1.showDB(); string xmlFile4 = "read_nosqdldb.xml"; WriteLine("\n\n Before Augumenting DB from xml file : " + xmlFile4); dbType2.showEnumerableDB(); dbType2.augument_db <string, DBElement <string, List <string> >, List <string>, string>(xmlFile4); WriteLine("\n\n After Augumenting DB from xml file : " + xmlFile4); dbType2.showEnumerableDB(); DBEngine <int, DBElement <int, string> > dbType1New = new DBEngine <int, DBElement <int, string> >(); DBEngine <string, DBElement <string, List <string> > > dbType2New = new DBEngine <string, DBElement <string, List <string> > >(); string xmlFile5 = "read_nosqldb_primitive.xml"; WriteLine("\n\n Before Restoring DB from xml file : " + xmlFile5); dbType1New.showDB(); dbType1New.augument_db <int, DBElement <int, string>, string>(xmlFile5); WriteLine("\n\n After Restoring DB from xml file : " + xmlFile5); dbType1New.showDB(); string xmlFile6 = "read_nosqdldb.xml"; WriteLine("\n\n Before Restoring DB from xml file : " + xmlFile6); dbType2New.showEnumerableDB(); dbType2New.augument_db <string, DBElement <string, List <string> >, List <string>, string>(xmlFile6); WriteLine("\n\n After Restoring DB from xml file : " + xmlFile6); dbType2New.showEnumerableDB(); }
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(); }
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 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(); QueryEngine <int, string> queryEnginePrimitive = new QueryEngine <int, string>(dbType1); DBElement <int, string> queryElementPrimitive; IEnumerable <int> dbType1keys = dbType1.Keys(); int lastKeyDB1 = dbType1keys.Last(); Write("\n\n\n Input Key :" + lastKeyDB1); queryEnginePrimitive.getValueForKey(lastKeyDB1, out queryElementPrimitive); queryElementPrimitive.showElement(); List <int> childrenDB1 = new List <int>(); IEnumerable <int> keys1 = dbType1.Keys(); int lastKey1 = keys1.Last(); Write("\n\n\n Input Key :" + lastKey1); StringBuilder accum = new StringBuilder(); accum.Append(String.Format(" children of key: {0}", lastKey1.ToString())); queryEnginePrimitive.getChildren(lastKey1, out childrenDB1); childrenDB1.showkeys(); Write("\n\n\n "); string inputString = "11"; Write("\n\n \n Input Search String :" + inputString); List <int> resultList = queryEnginePrimitive.searchKeyPattern(inputString); foreach (int key in resultList) { Write("\n found \"{0}\" in key \"{1}\"", inputString, key); } string inputString2 = "Movie"; Write("\n\n Input Search String :" + inputString); List <int> resultList2 = queryEnginePrimitive.searchMetadataPattern(inputString2); foreach (int key in resultList2) { Write("\n found \"{0}\" in \"{1}\"", inputString, key); } DateTime startDate = new DateTime(2014, DateTime.Today.Month, DateTime.Today.Day, 00, 00, 01); DateTime endDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 23, 59, 59); List <int> resultList3 = queryEnginePrimitive.searchTimeStamp(startDate); foreach (int key in resultList3) { Write("\n found key within \"{0}\" within range \"{1}\" {2}", key, startDate, endDate); } }
//----< Constructor>------------------- public DBFactory(DBEngine <Key, DBElement <Key, Data> > dbEngine) { db = dbEngine; }
static void Main(string[] args) { "Testing DBEngine Package".title('='); WriteLine(); Write("\n --- Test DBElement<int,string> ---"); DBElement <int, string> elem1 = new DBElement <int, string>(); elem1.payload = "a payload"; 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.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(); Write("\n --- Test DBElement<string,List<string>> ---"); 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(); 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); }; 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(); "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"); }
//----<Constructor>------------------- public QueryEngine(DBEngine <Key, DBElement <Key, Data> > dbEngine) { db = dbEngine; }
//----< Demonstrating req 3 - addition/deletion of key/value database for collection type db>------------------- public void TestR3_NonPrimitive(DBEngine <int, DBElement <int, string> > dbType1, DBEngine <string, DBElement <string, List <string> > > dbType2, DBItemEditor editor) { "\nDemonstrating Requirement #3 Collection Type".title(); WriteLine("\n\n Addition of Key/value pair"); String movie_name = "3 Idiots"; WriteLine(" Before Adding Key : " + movie_name); dbType2.showEnumerableDB(); DBElement <string, List <string> > newerelem3 = new DBElement <string, List <string> >(); newerelem3.name = "Movie Name: 3 Idiots"; newerelem3.descr = "3 Friends revist the college days and recall memories"; newerelem3.children.AddRange(new[] { "The Good, the Bad and the Ugly", "Django Unchained" }); newerelem3.payload = new List <string> { "Aamir Khan", "Madhavan", "Mona Singh" }; editor.addKeyValyePair <string, List <String>, string>(dbType2, newerelem3, movie_name); WriteLine("\n\n After adding key :" + movie_name); dbType2.showEnumerableDB(); IEnumerable <string> keys = dbType2.Keys(); String first = keys.First(); WriteLine("\n\n Removal of Key/value pair"); WriteLine(" Before removing key :" + first); dbType2.showEnumerableDB(); editor.removeKey <string, List <string>, string>(dbType2, first); WriteLine("\n\n After removing key :" + first); dbType2.showEnumerableDB(); }