private void test2()
        {
            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);
            };
            int        key    = 0;
            Func <int> keyGen = () => { ++key; return(key); };
            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();
        }
        private void test1()
        {
            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();
        }
        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";
            elem1.children = new List <int> {
                1, 2, 3, 4
            };
            Write(elem1.showMetaData <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");
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            "Testing DBEngine Package".title('=');
            WriteLine();

            Program p1 = new Program();

            p1.testDBlement();
            p1.testDBElementenurmableData();
            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");
        }
Esempio n. 5
0
 public static void showEnumerableDB(this DBEngine <string, DBElement <string, List <string> > > db)
 {
     db.show <string, DBElement <string, List <string> >, List <string>, string>();
 }
Esempio n. 6
0
 public static void showDB(this DBEngine <int, DBElement <int, string> > db)
 {
     db.show <int, DBElement <int, string>, string>();
 }
        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");
        }
Esempio n. 8
0
 // show DB which has key as string and value as ListOfStrings.
 public static void showDB(this DBEngine <string, DBElement <string, ListOfStrings> > db)
 {
     db.show <string, DBElement <string, ListOfStrings>, ListOfStrings>();
 }
 public static string showEnumerableDB(this DBEngine <string, DBElement <string, List <string> > > db)
 {
     return(db.show <string, DBElement <string, List <string> >, List <string>, string>());
 }
Esempio n. 10
0
        public XElement process_msg <Key, Value, Data>(string msg, DBEngine <Key, DBElement <Key, Data> > db)
        {
            XElement request_msg = XElement.Parse(msg);
            XElement response    = new XElement("Result", "Request type {0} not found.", request_msg.Element("Request_Type").Value);
            //Determine which methods needs to be called. (Based on the Request_Type tag)

            string method = request_msg.Element("Request_Type").Value;

            if (method == "Insert")
            {
                response = insert_elem <Key, Data>(request_msg, db);
            }

            if (method == "Delete")
            {
                response = delete_elem <Key, Data>(request_msg, db);
            }

            if (method == "Edit Name")
            {
                response = edit_name <Key, Data>(request_msg, db);
            }

            if (method == "Edit Description")
            {
                response = edit_description <Key, Data>(request_msg, db);
            }

            if (method == "Add Children")
            {
                response = add_children <Key, Data>(request_msg, db);
            }

            if (method == "Show DB")
            {
                Console.Write("\n  Request to display database contents:");
                db.show <Key, DBElement <Key, Data>, Data>();
                response = new XElement("Result", "Database displayed successfuly");
                Console.WriteLine();
            }
            if (method == "Get Value")
            {
                response = get_value <Key, Data>(request_msg, db);
            }
            if (method == "Get Children")
            {
                response = get_children <Key, Data>(request_msg, db);
            }
            if (method == "Get Keys metadata")
            {
                response = keys_metada <Key, Data>(request_msg, db);
            }
            if (method == "Persist Database")
            {
                response = persist_database <Key, Data>(request_msg, db);
            }
            if (method == "Load Database")
            {
                response = load_database <Key, Data>(request_msg, db);
            }

            return(response);
        }