private int writeCountDB1 = 0; // counter to run scheduler runs 3 times //----< Constructor>------------------- public Scheduler(DBEngine <Key, Value> dbEngine, int interval) { db = dbEngine; timeInterval = interval; schedular.Interval = timeInterval; schedular.AutoReset = true; schedular.Enabled = true; schedular.Elapsed += (object source, ElapsedEventArgs e) => { if (writeCountDB1 <= 2) // Run scheduler for 3 times { string xmlFile1 = "nosqdldb_primitive.xml"; string xmlFile2 = "nosqdldb.xml"; writeCountDB1++; if (typeof(DBElement <Key, T>).ToString() == typeof(Value).ToString()) { Console.Write("\n Scheduled save of NOSQL key/Value database to persistent storage file {0} at time {1} ", xmlFile1, e.SignalTime); db.persist_db <Key, Value, T>(xmlFile1); } else { Console.Write("\n Scheduled save of NOSQL key/Value database to persistent storage file {0} at time {1} ", xmlFile2, e.SignalTime); db.persist_db <Key, Value, Data, T>(xmlFile2); } } else { //Disable scheduler after 3 saves schedular.Enabled = false; } }; }
//----< trigger primitive storage persisting >------------------------------------- private void trigger_primitive_storage <Key, Data>(DBEngine <Key, DBElement <Key, Data> > dbType) { string dir = "..\\..\\..\\..\\input_xml\\"; string xmlFile3 = "nosqldb_primitive.xml"; String maxWrites = "\n\n Save call triggered after exceeding maximum " + dbType.max_writes + " writes to DB"; maxWrites.title(); dbType.persist_db <Key, DBElement <Key, Data>, Data>(dir + xmlFile3); }
//----< trigger collection persisting >------------------------------------- private void trigger_collection_storage <Key, Data, T>(DBEngine <Key, DBElement <Key, Data> > dbType2) { string dir = "..\\..\\..\\..\\input_xml\\"; String maxWrites = "\n\n Save call triggered after exceeding maximum " + dbType2.max_writes + " writes to DB"; maxWrites.title(); string xmlFile2 = "nosqdldb.xml"; dbType2.persist_db <Key, DBElement <Key, Data>, List <T>, T>(dir + xmlFile2); }
//----< Demonstrating req 5 - Demonstrating persisting, unpersisting and restoring db>------------------- public void TestR5(DBEngine <int, DBElement <int, string> > dbType1, DBEngine <string, DBElement <string, List <string> > > dbType2) { string dir = "..\\..\\..\\..\\input_xml\\"; string xmlFile1 = "nosqdldb_primitive.xml"; "\n\nDemonstrating Requirement #5 Primitive DB".title(); dbType1.persist_db <int, DBElement <int, string>, string>(dir + xmlFile1); WriteLine("\nSuccesfully persisted dbengine contents to xml file :" + xmlFile1); string xmlFile2 = "nosqdldb.xml"; "\n\nDemonstrating Requirement #5 - Collection DB".title(); dbType2.persist_db <string, DBElement <string, List <string> >, List <string>, string>(dir + xmlFile2); WriteLine("\nSuccesfully persisted dbengine contents to xml file : " + xmlFile2); string xmlFile3 = "read_nosqldb_primitive.xml"; "\n\nDemonstrating Requirement #5 - Augumenting DB - Primitive DB".title(); WriteLine("\n\n Before Augumenting DB from xml file : " + xmlFile3); dbType1.showDB(); dbType1.augument_db <int, DBElement <int, string>, string>(dir + xmlFile3); WriteLine("\n\n After Augumenting DB from xml file : " + xmlFile3); dbType1.showDB(); string xmlFile4 = "read_nosqdldb.xml"; "\n\nDemonstrating Requirement #5 - Augumenting DB - Collection DB".title(); WriteLine("\n\n Before Augumenting DB from xml file : " + xmlFile4); dbType2.showEnumerableDB(); dbType2.augument_db <string, DBElement <string, List <string> >, List <string>, string>(dir + 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"; "\n\nDemonstrating Requirement #5 - Restoring DB - Primitive DB".title(); WriteLine("\n\n Before Restoring DB from xml file : " + xmlFile5); dbType1New.showDB(); dbType1New.augument_db <int, DBElement <int, string>, string>(dir + xmlFile5); WriteLine("\n\n After Restoring DB from xml file : " + xmlFile5); dbType1New.showDB(); string xmlFile6 = "read_nosqdldb.xml"; "\n\nDemonstrating Requirement #5 - Restoring DB - Collection DB".title(); WriteLine("\n\n Before Restoring DB from xml file : " + xmlFile6); dbType2New.showEnumerableDB(); dbType2New.augument_db <string, DBElement <string, List <string> >, List <string>, string>(dir + xmlFile6); WriteLine("\n\n After Restoring DB from xml file : " + xmlFile6); dbType2New.showEnumerableDB(); }
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(); }