Пример #1
0
        static void Main(string[] args)
        {
            "Testing DBElement Package".title('=');
            WriteLine();

            Write("\n --- Test DBElement<int,string> ---");
            WriteLine();

            DBElement <int, string> elem1 = new DBElement <int, string>();

            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 = new List <int> {
                1, 2, 7
            };
            elem3.payload = "X-Wing fighter in swamp - Oh oh!";
            Write(elem3.showElement <int, string>());
            WriteLine();

            Write("\n --- Test DBElement<string,List<string>> ---");
            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"
            };
            Write(newelem1.showElement <string, List <string>, string>());
            WriteLine();

            DBElement <string, List <string> > newerelem1 = new DBElement <string, List <string> >();

            newerelem1.name  = "newerelem1";
            newerelem1.descr = "same stuff";
            newerelem1.children.Add("first_key");
            newerelem1.children.Add("second_key");
            newerelem1.payload = new List <string> {
                "alpha", "beta", "gamma"
            };
            newerelem1.payload.AddRange(new[] { "delta", "epsilon" });
            Write(newerelem1.showElement <string, List <string>, string>());
            WriteLine();

            Write("\n\n");
        }
Пример #2
0
 public static void show <Key, Value, Data>(this DBFactory <Key, Value> db)
 {
     foreach (Key key in db.Keys())
     {
         Value value;
         db.getValue(key, out value);
         DBElement <Key, Data> elem = value as DBElement <Key, Data>;
         Write("\n\n  -- key = {0} --", key);
         Write(elem.showElement());
     }
 }
Пример #3
0
 //----< write enumerable db elements out to Console >--------------
 public static void show <Key, Value, Data, T>(this DBEngine <Key, Value> db)
     where Data : IEnumerable <T>
 {
     foreach (Key key in db.Keys())
     {
         Value value;
         db.getValue(key, out value);
         DBElement <Key, Data> elem = value as DBElement <Key, Data>;
         Write("\n\n  -- key = {0} --", key);
         Write(elem.showElement <Key, Data, T>());
     }
 }
Пример #4
0
        static void Main(string[] args)
        {
            /*
             * Create and edit a DBEngine first.
             * Then create a DBFactory using the DBEngine.
             */

            "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();

            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);

            Write("\n --- Create DBFactory<int, DBElement<int, string>> from DBEngine<int,DBElement<int, string>> ---");

            DBFactory <int, DBElement <int, string> > dbFactory = new DBFactory <int, DBElement <int, string> >(db);

            foreach (int dbKey in dbFactory.Keys())
            {
                DBElement <int, string> value;
                dbFactory.getValue(dbKey, out value);
                value.showElement();
            }
            dbFactory.showDB();
            Write("\n\n");
        }
Пример #5
0
        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");
        }
Пример #6
0
        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");
        }
Пример #7
0
 public static void showEnumerableElement(this DBElement <string, List <string> > enumElement)
 {
     Console.Write(enumElement.showElement <string, List <string>, string>());
     WriteLine();
 }
Пример #8
0
 public static void showElement(this DBElement <int, string> element)
 {
     Console.Write(element.showElement <int, string>());
     WriteLine();
 }
Пример #9
0
        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");
        }
Пример #10
0
        static void Main(string[] args)
        {
            QueyEngineTest test    = new QueyEngineTest();
            QueryEngine    qEngine = new QueryEngine();

            "Creating & Populating DB".title2();
            test.TestCreate();
            test.TestAdd(1);
            test.TestAdd(2);
            test.TestAdd(4);
            test.TestAdd(3);
            test.TestAdd(5);
            test.TestAdd(15);
            test.TestRemove(6);
            test.TestRemove(4);
            WriteLine();

            "Query by Key for value".title2();
            DBElement <int, string> value = QueryEngine.queryValue <int, DBElement <int, string>, string>(2, test.db);

            "Querying for value of Key = 2".body();
            string status = "Result of query: ";

            status.success();
            value.showElement();
            WriteLine();

            "Query by Key for children".title2();
            "Querying for children of Key = 1".body();
            QueryEngine queryEngine = new QueryEngine();
            DBFactory <int, DBElement <int, string> > newDB;
            // build query
            Func <int, bool> query = queryEngine.queryChildren <int, DBElement <int, string>, string>(test.db);
            // process query
            List <int> keyCollection;
            bool       result = queryEngine.processChildrenQuery <int, DBElement <int, string>, string>(query, out keyCollection, 1, test.db);

            newDB = queryEngine.queryResults <int, DBElement <int, string>, string>(result, keyCollection, test.db);
            newDB.showDB();
            WriteLine();

            "Query by KeyPattern for matching Keys".title2();
            "Querying for pattern \"1.*\" ".body();
            DBFactory <int, DBElement <int, string> > newDB2;
            // build query
            string regEx = "1.*";

            query = queryEngine.queryRegEx <int, DBElement <int, string>, string>(test.db, regEx);
            // process query
            result = queryEngine.processQuery <int, DBElement <int, string> >(query, out keyCollection, test.db);
            newDB2 = queryEngine.queryResults <int, DBElement <int, string>, string>(result, keyCollection, test.db);
            newDB2.showDB();
            WriteLine();

            // build query
            "Querying without suplying a pattern ( will be treated as \".*\") ".body();
            query = queryEngine.queryRegEx <int, DBElement <int, string>, string>(test.db);
            // process query
            result = queryEngine.processQuery <int, DBElement <int, string> >(query, out keyCollection, test.db);
            newDB  = queryEngine.queryResults <int, DBElement <int, string>, string>(result, keyCollection, test.db);
            newDB.showDB();
            WriteLine();

            "Query by metadata for Keys".title2();
            "Querying for metadata substring \"of 2\" ".body();
            DBFactory <int, DBElement <int, string> > newDB3;
            // build query
            string search = "of 2";

            query = queryEngine.queryMetadata <int, DBElement <int, string>, string>(search, test.db);
            // process query
            result = queryEngine.processQuery <int, DBElement <int, string> >(query, out keyCollection, test.db);
            newDB3 = queryEngine.queryResults <int, DBElement <int, string>, string>(result, keyCollection, test.db);
            newDB3.showDB();
            WriteLine();
            "Querying for metadata substring \"of \" ".body();
            DBFactory <int, DBElement <int, string> > newDB4;

            // build query
            search = "of ";
            query  = queryEngine.queryMetadata <int, DBElement <int, string>, string>(search, test.db);
            // process query
            result = queryEngine.processQuery <int, DBElement <int, string> >(query, out keyCollection, test.db);
            newDB4 = queryEngine.queryResults <int, DBElement <int, string>, string>(result, keyCollection, test.db);
            newDB4.showDB();


            "Query by timestamp for Keys".title2();
            DBFactory <int, DBElement <int, string> > newDB5;
            TimeSpan tspan   = new TimeSpan(0, 0, 0, 0, 300);
            DateTime initial = DateTime.Now.Subtract(tspan);
            string   message = "Querying for Keys added between " + initial.ToLongTimeString() + " and now";

            message += "\n\t(A timespan of " + tspan.TotalMilliseconds + " milliseconds)";
            WriteLine();
            message.body();
            WriteLine();
            // build query
            message = "\n\tsecond value of range not specified, current time assumed";
            WriteLine();
            message.body();
            query = queryEngine.queryTimestamp <int, DBElement <int, string>, string>(test.db, initial);
            // process query
            result = queryEngine.processQuery <int, DBElement <int, string> >(query, out keyCollection, test.db);
            newDB5 = queryEngine.queryResults <int, DBElement <int, string>, string>(result, keyCollection, test.db);
            newDB5.showDB();
            WriteLine();
        }