Exemplo n.º 1
0
        void TestR5()
        {
            //-----------< Demonstrating writing to XML files and
            //-----------< augmenting from some other files >-----------
            "Demonstrating Requirement #5".title();
            WriteLine();
            "Persisting the data".title('-');
            PersistEngine pe = new PersistEngine();

            pe.XMLWrite(db, out pathname);                      // File created as xmlDoc.xml
            pe.XMLWriteLOS(dbLOS, out pathnameLOS);             // File created as xmlDocLOS.xml
            WriteLine();
            "File generated for <int, string>".title();
            WriteLine("\n{0}", XDocument.Load(pathname).Declaration);
            WriteLine("{0}", XDocument.Load(pathname).ToString());
            WriteLine();
            "File generated for <string, List<string>>".title();
            WriteLine("\n{0}", XDocument.Load(pathnameLOS).Declaration);
            WriteLine("{0}", XDocument.Load(pathnameLOS).ToString());
            WriteLine();
            "Restoring (or Augmenting) from XML into database".title('-');
            try
            {
                pe.XMLRestore(@"XMLRestore.xml", db);
                pe.XMLRestoreLOS(@"xmlRestoreLOS.xml", dbLOS);
            }
            catch
            {
                Console.WriteLine("\nAt least one file failed to load, please check the paths in code\n");
            }

            db.show <int, DBElement <int, string>, string>();
            dbLOS.show <string, DBElement <string, List <string> >, List <string>, string>();
            WriteLine();
        }
Exemplo n.º 2
0
 void TestR6()
 {
     //------< Write to XML files (same as above) after every 1 second. Press any key to stop persisting >--------
     "Demonstrating Requirement #6".title();
     "Press any key to stop".title();
     WriteLine();
     Scheduler sc = new Scheduler(1000);
     sc.schedular.Enabled = true;
     PersistEngine pe = new PersistEngine();
     pe.XMLWrite(db, out pathname);
     pe.XMLWriteLOS(dbLOS, out pathnameLOS);
     Console.ReadKey();
     sc.schedular.Enabled = false; // Setting this will prevent the scheduler to stop executing
     WriteLine();
 }
Exemplo n.º 3
0
        private string pathnameLOS = "";    // they can be reused later.
        static void Main(string[] args)
        {
            PersistEngine      pe  = new PersistEngine();
            TEST_PERSISTENGINE pet = new TEST_PERSISTENGINE();
            DBEngine <int, DBElement <int, string> > db = new DBEngine <int, DBElement <int, string> >();
            DBEngine <string, DBElement <string, List <string> > > dbLOS = new DBEngine <string, DBElement <string, List <string> > >();
            DBElement <int, string>            elem    = new DBElement <int, string>();
            DBElement <string, List <string> > elemLOS = new DBElement <string, List <string> >();

            //Adding DBElement<int, string>
            elem.name      = "name";
            elem.descr     = "descr";
            elem.timeStamp = DateTime.Now;
            elem.children.AddRange(new List <int>()
            {
                1, 2, 3
            });
            elem.payload = "hello";
            db.insert(0, elem);
            DBElement <int, string> elem1 = new DBElement <int, string>();

            elem1.name  = "name1";
            elem1.descr = "descr1";
            elem1.children.AddRange(new List <int>()
            {
                1, 2, 3
            });
            elem1.timeStamp = DateTime.Now;
            elem1.payload   = "hello1";
            db.insert(1, elem1);
            //Adding DBElement<string, List<string>>
            elemLOS.name    = "name2";
            elemLOS.descr   = "descr2";
            elem.timeStamp  = DateTime.Now;
            elemLOS.payload = new List <string>()
            {
                "hello", "world"
            };
            dbLOS.insert("Two", elemLOS);
            elemLOS           = new DBElement <string, List <string> >();
            elemLOS.name      = "name3";
            elemLOS.descr     = "descr3";
            elemLOS.timeStamp = DateTime.Now;
            elemLOS.children.AddRange(new List <string>()
            {
                "One", "Two", "Three"
            });
            elemLOS.payload = new List <string>()
            {
                "fee", "foo", "bar"
            };
            dbLOS.insert("Three", elemLOS);
            pe.XMLWrite(db, out pet.pathname);
            pe.XMLWriteLOS(dbLOS, out pet.pathnameLOS);
            WriteLine("\n{0}", XDocument.Load(pet.pathname).ToString());
            WriteLine("\n{0}", XDocument.Load(pet.pathnameLOS).ToString());
            pe.XMLRestore("../../xmlRestore.xml", db);
            db.show <int, DBElement <int, string>, string>();
            pe.XMLRestoreLOS("../../xmlRestoreLOS.xml", dbLOS);
            dbLOS.show <string, DBElement <string, List <string> >, List <string>, string>();
        }
Exemplo n.º 4
0
 private string pathnameLOS = "";    // they can be reused later.
 static void Main(string[] args)
 {
     PersistEngine pe = new PersistEngine();
     TEST_PERSISTENGINE pet = new TEST_PERSISTENGINE();
     DBEngine<int, DBElement<int, string>> db = new DBEngine<int, DBElement<int, string>>();
     DBEngine<string, DBElement<string, List<string>>> dbLOS = new DBEngine<string, DBElement<string, List<string>>>();
     DBElement<int, string> elem = new DBElement<int, string>();
     DBElement<string, List<string>> elemLOS = new DBElement<string, List<string>>();
     //Adding DBElement<int, string>
     elem.name = "name";
     elem.descr = "descr";
     elem.timeStamp = DateTime.Now;
     elem.children.AddRange(new List<int>() { 1, 2, 3 });
     elem.payload = "hello";
     db.insert(0, elem);
     DBElement<int, string> elem1 = new DBElement<int, string>();
     elem1.name = "name1";
     elem1.descr = "descr1";
     elem1.children.AddRange(new List<int>() { 1, 2, 3 });
     elem1.timeStamp = DateTime.Now;
     elem1.payload = "hello1";
     db.insert(1, elem1);
     //Adding DBElement<string, List<string>>
     elemLOS.name = "name2";
     elemLOS.descr = "descr2";
     elem.timeStamp = DateTime.Now;
     elemLOS.payload = new List<string>() { "hello", "world" };
     dbLOS.insert("Two", elemLOS);
     elemLOS = new DBElement<string, List<string>>();
     elemLOS.name = "name3";
     elemLOS.descr = "descr3";
     elemLOS.timeStamp = DateTime.Now;
     elemLOS.children.AddRange(new List<string>() { "One", "Two", "Three" });
     elemLOS.payload = new List<string>() { "fee", "foo", "bar" };
     dbLOS.insert("Three", elemLOS);
     pe.XMLWrite(db, out pet.pathname);
     pe.XMLWriteLOS(dbLOS, out pet.pathnameLOS);
     WriteLine("\n{0}", XDocument.Load(pet.pathname).ToString());
     WriteLine("\n{0}", XDocument.Load(pet.pathnameLOS).ToString());
     pe.XMLRestore("../../xmlRestore.xml", db);
     db.show<int, DBElement<int, string>, string>();
     pe.XMLRestoreLOS("../../xmlRestoreLOS.xml", dbLOS);
     dbLOS.show<string, DBElement<string, List<string>>, List<string>, string>();
 }