コード例 #1
0
 static void Main(string[] args)
 {
     
     //<------Create test DB----->
     "Testing for PersistEngine package".title();
     DBEngine<int, DBElement<int, string>> db = new DBEngine<int, DBElement<int, string>>();
     DBEngine<string, DBElement<string, List<string>>> enum_db = new DBEngine<string, DBElement<string, List<string>>>();
     
     for (int i = 0; i < 3; i++)
     {
         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(i, elem);
     }
     db.showDB();
     WriteLine();
     //<-------Save DB data to XML file--------->
     "Demonstrating XDocument class".title('=');
     WriteLine();
     "Creating XML string using XDocument".title();
     WriteLine();
     db.create_xml_from_db(false);
     //<---Empty DBEngine<int, DBElement<int, string>>--->
     "Removing entries from Db if any".title();
     if (db != null)
     {
         db.removeAll();
     }
     "Current DB state".title();
     db.showDB();
     WriteLine();
     db.create_db_from_xml();
     WriteLine();
     //<---------Create test enum DB-------->
     for (int i = 0; i < 3; i++)
     {
         DBElement<string, List<string>> elem = new DBElement<string, List<string>>();
         elem.name = "element";
         elem.descr = "test element";
         elem.timeStamp = DateTime.Now;
         elem.children.AddRange(new List<string> { "child1", "child2" });
         elem.payload = new List<string> { "payload 1", "payload 2" };
         elem.showEnumerableElement();
         enum_db.insert(i.ToString(), elem);
     }
     enum_db.showEnumerableDB();
     WriteLine();
     //<-------Save enum_DB data to XML file--------->
     "Creating XML string using XDocument".title();
     enum_db.create_xml_from_enum_db(false);
     WriteLine();
     
     if (enum_db != null)
     {
         enum_db.removeAll();
     }
     //<----Empty DBEngine<string, DBElement<string, List<string>>----->
     "Removing entries from enum Db if any".title();
     if (enum_db != null)
     {
         string[] key_array = enum_db.Keys().ToArray();
         foreach (string key in key_array)
         {
             enum_db.remove(key);
         }
     }            
     "Cureent enum DB state".title();
     enum_db.showEnumerableDB();
     WriteLine();
     enum_db.create_enum_db_from_xml();
     WriteLine();
     WriteLine();
     
 }
コード例 #2
0
 private void restore_database(out string str, ref IEnumerator<string> msg_enumerator, DBEngine<int, DBElement<int, string>> db)
 {
     str = "";
       "Database before restoring".title();
       db.showDB();
       Console.WriteLine();
       while (msg_enumerator.MoveNext())
       {
     if (msg_enumerator.Current == "Source")
     {
       msg_enumerator.MoveNext();
       Console.WriteLine(msg_enumerator.Current);
       int count = db.Keys().ToArray().Length;
       db.create_db_from_xml(msg_enumerator.Current);
       if(db.Keys().ToArray().Length > count)
       {
     str += "Database Restored from " + msg_enumerator.Current + " file.";
       } else
       {
     str += "Database not able to restore from " + msg_enumerator.Current + "file";
       }
       return;
     }
       }
       str += "Database persistence failed.";
 }