/* Defining a query using lambda function to search specific key 
 */
 public void key_value_search(DBEngine<int, DBElement<int, string>> db, IQuery<int, DBElement<int, string>> i_query, QueryEngine<int, DBElement<int, string>> qe )
 {
     "Query for value with specified key (key = 2):".title();
     WriteLine();
     int key_to_search = 2;
     Func<int, string, bool> keyValueSearch = (int key, string search) => //lambda function
     {
         if (!db.Keys().Contains(key))
             return false;
         else
         {
             if (key == int.Parse(search))
             {
                 DBElement<int, string> ele = new DBElement<int, string>();
                 db.getValue(key, out ele);
                 return true;
             }
             else { return false; }
         }
     };
     // pass query to query engine and call simpleQuery to make query on DBEngine
     qe.simpleQuery(keyValueSearch, key_to_search.ToString(), out i_query);
     WriteLine();
     foreach (var key in i_query.Keys())
     {
         DBElement<int, string> temp = new DBElement<int, string>();
         i_query.getValue(key, out temp);
         WriteLine("key : {0}", key);
         temp.showElement();
         WriteLine();
     }
 }
예제 #2
0
        static void Main(string[] args)
        {
            WriteLine("Testing DBExtensions Package\n");
            WriteLine();

            //Insert first element
            Write("\n --- Test DBElement<int,string> ---");
            DBElement<int, string> elem1 = new DBElement<int, string>();
            elem1.payload = "a payload";
            Write(elem1.showElement<int, string>());

            //Insert first element into DB
            DBEngine<int, DBElement<int, string>> dbs = new DBEngine<int, DBElement<int, string>>();
            dbs.insert(1, elem1);
            dbs.show<int, DBElement<int, string>, string>();
            WriteLine();

            //Insert first element into String Key/Value DB
            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");
        }
예제 #3
0
        public void testDBlement()
        {
            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();
        }
    public void TestR2()
    {
      "Demonstrating Requirement #2".title('=');
      "Database with string as payload".title();
      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(1, elem);
      db.showDB();
      WriteLine();
      "database with list of strings as payload".title();
      DBElement<string, List<string>> element = new DBElement<string, List<string>>();
      element.name = "element2";
      element.descr = "test element for list of strings as value";
      element.timeStamp = DateTime.Now;
      element.children.AddRange(new List<string> { "one","two"});
      element.payload = new List<string> { "element's payload", "2nd payload" };
      element.showEnumerableElement();
      enum_db.insert("enum_one", element);
      enum_db.showEnumerableDB();
      WriteLine();

    }
예제 #5
0
    void TestR3()//addition and deletion of key/value pairs
    {
      "Demonstrating Requirement #3".title();
	  WriteLine();
	  
	  Write("\n --- Test addition of key/value pairs Start---");
	  WriteLine();
	  DBElement<int, string> elem1 = new DBElement<int, string>();
      elem1.name = "element#1";//add a new key/value pairs
      elem1.descr = "test element#1";
      elem1.timeStamp = DateTime.Now;
      elem1.children.AddRange(new List<int>{ 6, 8 });
      elem1.payload = "elem#1's payload";
      elem1.showElement();
      db.insert(2, elem1);
	  Write("\n\n Show key/value pairs in data base:\n");
      db.showDB();
      WriteLine();
	  Write("\n --- Test addition of key/value pairs End---");
	  WriteLine();
	  
	  Write("\n --- Test deletion of key/value pairs Start---");
	  WriteLine();
	  db.delete(1);//delete an existing key/value pairs
	  Write("\n\n Show key/value pairs in data base:\n");
      db.showDB();
      WriteLine();
      db.delete(100);//try to delete a key/value pairs that doesn't exist
	  Write("\n --- Test deletion of key/value pairs End---");
      WriteLine();
    }
        void TestR2()
        {
            "Demonstrating Requirement #2".title();
            //creating new element of type int and string
            DBElement<int, string> element = new DBElement<int, string>();
            element.name = "first element of db";
            element.descr = "int and string type";
            element.timeStamp = DateTime.Now;
            element.children.AddRange(new List<int> { 0, 2, 4, 8 });
            element.payload = "first element's payload";
            element.showElement();
            db.insert(1, element);
            db.showDB();
            WriteLine();
            //creating new element of type string and list of strings
            DBElement<string, List<string>> element2 = new DBElement<string, List<string>>();
            element2.name = "second element of db";
            element2.descr = "strings and strings of string types";
            element2.timeStamp = DateTime.Now;
            element2.children.AddRange(new List<string> { "SMA", "OOD", "Project2" });
            element2.payload = new List<string> { "second", "SMA", "project" };
            element2.showEnumerableElement();
            db2.insert("2", element2);
            db2.showEnumerableDB();
            WriteLine();

        }
예제 #7
0
        //-----------< Fish out the type of query and criteria from the request string >-------------
        public bool parseRequest(DBEngine <string, DBElement <string, List <string> > > db, string msg, out string reply)
        {
            elem = new DBElement <string, List <string> >();
            int IndexOfComma = msg.IndexOf(",");

            message = msg.Substring(IndexOfComma + 1);
            content = message.Split(',');
            type    = content[0];
            query   = content[1];

            //-----------< make function call and convert response into suitable string >----------
            if (call(db, type))
            {
                if (type == "value")
                {
                    reply = "\n  Value of key " + query + ": " + elem.showElement <string, List <string>, string>();
                }
                else if (type == "children")
                {
                    reply = "\n  Children of key " + query + ": " + Utilities.ToString(replyList);
                }
                else if (type == "pattern")
                {
                    reply = "\n  List of keys starting with \"" + query + "\": " + Utilities.ToString(replyList);
                }
                else if (type == "string")
                {
                    reply = "\n  List of keys containing \"" + query + "\" in their metadata: " + Utilities.ToString(replyList);
                }
                else
                {
                    reply = "\n  List of keys entered from " + query + " to present: " + Utilities.ToString(replyList);
                }
                return(true);
            }
            if (type == "value")
            {
                reply = "\n  Value of key " + query + " not found";
            }
            else if (type == "children")
            {
                reply = "\n  Children of key " + query + " not found";
            }
            else if (type == "pattern")
            {
                reply = "\n  List of keys starting with \"" + query + "\" not found";
            }
            else if (type == "string")
            {
                reply = "\n  List of keys containing \"" + query + "\" in their metadata not found";
            }
            else
            {
                reply = "\n  List of keys entered from " + query + " to present not found";
            }
            return(false);
        }
예제 #8
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");
        }
예제 #9
0
 //----< write simple db elements out to Console >------------------
 public static void show <Key, Value, Data>(this DBEngine <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());
     }
 }
예제 #10
0
        void TestR2()
    {
      "Demonstrating Requirement #2".title();
      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(1, elem);
	  Write("\n\n Show key/value pairs in data base:\n");
      db.showDB();
      WriteLine();
    }
예제 #11
0
    void TestR3()
    {
      WriteLine();
      "Demonstrating Requirement #3".title('=');
      WriteLine();
      "Adding Key-Value pair to database".title();
      DBElement<int, string> element = new DBElement<int, string>();
      element.addElementData("element3", "test element for adding key-value pair to databse with value as string", DateTime.Now, new List<int> { 1, 2 }, "test elemet3's payload");
      "element to be added to database".title();
      element.showElement();
      db.insert(2, element);
      db.showDB();                        
      WriteLine();

      "Adding Key-Value pair to enumerable database".title();
      DBElement<string, List<string>> listelement = new DBElement<string, List<string>>();
      listelement.addElementData("element4", "test element for adding key-value pair to databse with value as list of string", DateTime.Now, new List<string> { "1", "two" }, new List<string> { "test elemet4's payload" });
      "element to be added to database".title();
      listelement.showEnumerableElement();
      enum_db.insert("enum_two", listelement);
      enum_db.showEnumerableDB();  
      WriteLine();
       
      "Deleting Key-Value pair from database".title();
      "Element with key=1 will be deleted from database".title();
      "Element with key=1:".title();
      DBElement<int, string> remove_element = new DBElement<int, string>();
      db.getValue(1, out remove_element);
      remove_element.showElement();
      db.remove(1);
      WriteLine();
      "Modified Database: ".title();
      db.showDB();
      WriteLine();

      "Deleting Key-Value pair from enumerable database".title();
      "Element with key=enum_one will be deleted from database".title();
      "Element with key=enum_one:".title();
      DBElement<string, List<string>> remove_enum_element = new DBElement<string, List<string>>();
      enum_db.getValue("enum_one", out remove_enum_element);
      remove_enum_element.showEnumerableElement();
      enum_db.remove("enum_one");
      WriteLine();
      "Modified enumerable Database: ".title();
      enum_db.showEnumerableDB();
      WriteLine();
      
    }
예제 #12
0
        // Main Method to test the implementation of DBElement Package
        static void Main(string[] args)
        {
            "Testing DBElement Package".title('=');
            WriteLine();

            Write("\n --- Test DBElement<int,string> ---");
            WriteLine();
            // new elements for  int and string database
            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();

            //new elements for  string and list of strings database
            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");
        }
예제 #13
0
    //private DBEngine<int, DBElement<int, List<int>>> keysFromQuery = new DBEngine<int, DBElement<int, List<int>>>();

        
	public string query(XDocument message)	{//method used to handle queries
		string reply;
		List<int> children = new List<int>();
		XElement element = message.Element("Message").Element("QueryType");
		Query<int, int, string> query1 = new Query<int, int, string>(db);
		switch(element.Value){
				case "the value of specified key":
					element = message.Element("Message").Element("Key");
				    DBElement<int, string> elem = new DBElement<int, string>();
				    query1.checkValueByKey(Int32.Parse(element.Value), out elem);
					reply = ("The value of specified key " + element.Value + " is\n" + elem.showElement<int, string>());
					break;
				case "the children of specified key":
					element = message.Element("Message").Element("Key");
					children = query1.childrenByKey(Int32.Parse(element.Value));
					reply = ("The children of specified key " + element.Value + " is\n");
					reply = this.addChildToStr(children, reply);
					break;
				case "the keys share a same pattern":
					element = message.Element("Message").Element("Pattern");
					Query<string, int, string> queryString = new Query<string, int, string>(dbString);
					List<string> keyString = new List<string>();
					keyString = queryString.keysWithPattern(dbString,element.Value);
					reply = ("The keys share a same pattern \"" + element.Value + "\" is\n");
					foreach(var key in keyString)
						reply += (String.Format("{0}\n", key.ToString()));
					break;
				case "the keys share same pattern in their metadata":
					element = message.Element("Message").Element("Pattern");
					children = query1.keysSameMdataPattern(element.Value);
					reply = ("The keys share same pattern " + element.Value + " is\n");
					reply = this.addChildToStr(children, reply);
					break;
				case "the keys of value created in the same time interval":
					List<DateTime> dts = new List<DateTime>();
					dts = this.getDTS(message);
					children = query1.keysSameTinterval(dts[0], dts[1]);
					reply = ("The keys of value created in the same time interval between " + dts[0].ToString() + " and " + dts[1]).ToString()+"\n";
					reply = this.addChildToStr(children, reply);
					break;
				default:
                    reply = ("Invalid editing type.");
					break;
			}
		return reply;
	}
예제 #14
0
        void TestR2()
        {
            DBElement<int, string> elem = new DBElement<int, string>();
            elem.name = "India";
            elem.descr = "Country";
            elem.timeStamp = DateTime.Now;
            elem.children.AddRange(new List<int> { 2, 3 });
            elem.payload = "Famous cricket player";
            WriteLine();

            "1) The element is as shown below".title();
            elem.showElement();
            db.insert(1, elem);
            WriteLine();

            "2) The key Value pair is shown below".title();
            db.showDB();
            WriteLine();
        }
예제 #15
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");
        }
예제 #16
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");
        }
예제 #17
0
 static void Main(string[] args)
 {
     DBEngine<int, DBElement<int, string>> db = Test1();
     //Insert the Second element
     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();
     //Insert the Third element
     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>>> ---");
     //Anonymous functionality for generating string key
     int seed = 0;
     string skey = seed.ToString();
     Func<string> skeyGen = () =>
     {
         ++seed;
         skey = "string" + seed.ToString();
         skey = skey.GetHashCode().ToString();
         return skey;
     };
     Test2(db, newerelem1, newerelem2, skeyGen);
 }
예제 #18
0
    void TestR4(){//support editing of value including the addition and/or deletion of relationships, 
                  //editing text metadata and replacing an existing value's instance with a new instance

            "Demonstrating Requirement #4".title();

        DBElement<int, string> temp = new DBElement<int, string>();
        ItemEditor<int, string> editItem;
		
        if (db.containsKey(2)){
            db.getValue(2, out temp);
			Write("\n\n --- value before modified---\n");
			temp.showElement();
            editItem = new ItemEditor<int, string>(temp);
			editItem.nameEdit("newName!!");//edit the name of the value with key 2
			editItem.descrEdit("new description!!");//edit description
			editItem.dateTimeEdit();//update timeStamp
			editItem.addRelationship(18);//add relationship
			editItem.deleteRelationship(6);//delete relationship
			editItem.payloadEdit("new payload!!");//modify payload
			
			DBElement<int, string> elemNew = new DBElement<int, string>();
			editItem.replaceWithInstance(out elemNew);// replace an existing value's instance with a new instance
			temp = null;
			Write("\n\n --- value after modified---\n");
			elemNew.showElement();
            editItem = null;
        }

        else
			Write("Value not found!");
		
      //Write("\n\n Show key/value pairs in data base:\n");
	  //db.showDB();
      WriteLine();
      WriteLine();
    }
예제 #19
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");
        }
        static void Main(string[] args)
        {
            "Demonstrate Timer - needed for scheduled persistance in Project #2".title('=');
            Console.Write("\n\n  press any key to exit\n");
            DBEngine<int, DBElement<int, string>> db = new DBEngine<int, DBElement<int, 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();
            Schedular td = new Schedular(db);
            td.schedular.Enabled = true;
            Console.ReadKey();
            Console.Write("\n\n");
        }
 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();
     
 }
예제 #22
0
 /// <summary>
 /// Get by GetByKey results are handled here and query constructed
 /// </summary>
 /// <param name="status"></param>
 /// <param name="doc"></param>
 /// <param name="key"></param>
 /// <param name="elem"></param>
 private void GetByKey(out bool status, ref XDocument doc, out int key, out DBElement<int, string> elem)
 {
     sb = new StringBuilder();
     key = int.Parse(doc.Descendants("Key").Select(i => i).Single().Value);
     WriteLine("\n..Getting the value for key {0} ..\n", key);
     elem = new DBElement<int, string>();
     status = query.getKey(db, key, out elem);
     sb.Append(String.Format(" Key:" + key));
     sb.AppendLine();
     sb.Append(String.Format(" Value:"));
     sb.AppendLine();
     WriteLine(sb.ToString());
     sb.Append(elem.showElement());
     doc.Descendants("Response").Select(i => i).Single().Value = sb.ToString();
 }
예제 #23
0
 public static void showEnumerableElement(this DBElement <string, List <string> > enumElement)
 {
     Console.Write(enumElement.showElement <string, List <string>, string>());
 }
예제 #24
0
    void TestR7()
    {
      "Demonstrating Requirement #7".title();
	  
	  Write("\n\n --- Query the value of specified key Start---\n");
	  Query<int, int, string> query = new Query<int, int, string>(db);
	  DBElement<int, string> elemR7 = new DBElement<int, string>();
	  query.checkValueByKey(2, out elemR7);
	  elemR7.showElement();
	  Write("\n\n --- Query the value of specified key End---\n");
      WriteLine();
	  /*****************************************************************/
	  Write("\n\n --- Query the children of specified key Start---\n");
	  Write("Children of value with key #2");
	  List<int> children = new List<int>();
	  children = query.childrenByKey(2);
	  foreach(var child in children)
	  Write("\n"+child);
	  Write("\n\n --- Query the children of specified key End---\n");
	  /*****************************************************************/
	  Write("\n\n --- Query the keys share a same pattern Start---\n");
	  DBElement<int, string> elemR701 = new DBElement<int, string>();
      elemR701.name = "r701";
      elemR701.descr = "su cs";
      elemR701.timeStamp = DateTime.Now;
      elemR701.children.AddRange(new List<int>{ 1, 2, 3 });
      elemR701.payload = "cs";
      dbString.insert("SU cs dep", elemR701);
	  DBElement<int, string> elemR702 = new DBElement<int, string>();
      elemR702.name = "r702";
      elemR702.descr = "su math";
      elemR702.timeStamp = DateTime.Now;
      elemR702.children.AddRange(new List<int>{ 4, 5, 2 });
      elemR702.payload = "math";
      dbString.insert("SU math dep", elemR702);
	  DBElement<int, string> elemR703 = new DBElement<int, string>();
      elemR703.name = "r703";
      elemR703.descr = "cornell math";
      elemR703.timeStamp = DateTime.Now;
      elemR703.children.AddRange(new List<int>{ 4, 5, 2 });
      elemR703.payload = "music";
      dbString.insert("CORNELL music dep", elemR703);
	  IEnumerable<string> keys = dbString.Keys();
	  Write("All keys in this database:");
	  foreach(var key in keys)
		Write("\n"+key);
	  Query<string, int, string> queryString = new Query<string, int, string>(dbString);
	  List<string> keyString = new List<string>();
	  keyString = queryString.keysWithPattern(dbString,"SU");
	  Write("\n\nKeys with pattern SU:");
	  foreach(var key in keyString)
	  	 Write("\n"+key);
	  Write("\n\n --- Query the keys share a same pattern End---\n");
	  /*****************************************************************/
	  Write("\n\n --- Query the keys share a same pattern Start---\n");
	  db.showDB();
	  Write("\n\nKeys with pattern ‘description’ in there metadata(name & descr):");
	  List<int> keyslist = new List<int>();
	  keyslist = query.keysSameMdataPattern("description");
	  foreach(var key in keyslist)
	  	 Write("\n"+key);
	  Write("\n\n --- Query the keys share a same pattern End---\n");
	  /*****************************************************************/
	  Write("\n\n --- Query the keys of value created in the same time interval Start---\n");
	  DBElement<int, string> temp = new DBElement<int, string>();
	  db.getValue(7, out temp);
	  temp.timeStamp = new DateTime(1991, 4, 15, 8, 9, 05);
	  db.getValue(82, out temp);
	  temp.timeStamp = new DateTime(1994, 9, 7, 10, 8, 55);
	  db.showDB();
	  DateTime dt1 = new DateTime(1990, 4, 15, 5, 9, 05);
	  DateTime dt2 = new DateTime(1995, 9, 7, 5, 8, 05);
	  Write("\n\nkeys of value created after 1990/4/15 05:09:05 but before 1995/9/7 05:08:05:");
	  keyslist = query.keysSameTinterval(dt1, dt2);
	  foreach(var key in keyslist)
	  	 Write("\n"+key);
	  Write("\n\n --- Query the keys of value created in the same time interval Start---\n");
    }
        static void Main(string[] args)
        {
            "Testing DBEngine Package".title('='); ;
            WriteLine();

            "Test db of scalar elements".title();
            WriteLine();
             //creation of new elements
            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();
            }

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

            int key = 0;
            Func<int> keyGen = () => { ++key; return key; };  // function to generate keys

                              // new database created
            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();
                       //new element created
            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" };
                       //new element created
            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");
                          //new element created
            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");
        }
예제 #26
0
        static void Main(string[] args)
        {
            "Testing Payload Wrapper".title('=');
            WriteLine();

            ListOfStrings los = new ListOfStrings();

            los.theWrappedData.AddRange(new List <string> {
                "one", "two", "three"
            });

            "showing List of strings:".title();
            foreach (string item in los.theWrappedData)
            {
                Write("\n  {0}", item);
            }
            WriteLine();

            "Output from PayloadWrapper.ToString()".title();
            Write("\n{0}", los.ToString());
            //WriteLine();

            "output from PayloadWrapper.ToXml()".title();
            Write("\n{0}", los.ToXml());
            WriteLine();

            "output from elem.showElement<string, ListOfStrings>()".title();
            DBElement <string, ListOfStrings> elem = new DBElement <string, ListOfStrings>();

            elem.name    = "test element";
            elem.descr   = "created to test PayloadWrapper";
            elem.payload = new ListOfStrings();
            elem.payload.theWrappedData = new List <string> {
                "alpha", "beta", "gamma", "delta", "epsilon"
            };
            Write(elem.showElement <string, ListOfStrings>());

            /////////////////////////////////////////////////////////////////////
            // The sequence of statements below should be turned into an
            // extension method: static public void clone(this List<string>)
            //
            "test cloning elem".title('=');
            WriteLine();
            DBElement <string, ListOfStrings> cloned = new DBElement <string, ListOfStrings>();

            cloned.name      = String.Copy(elem.name);
            cloned.descr     = String.Copy(elem.descr);
            cloned.timeStamp = DateTime.Parse(elem.timeStamp.ToString());
            cloned.children  = new List <string>();
            cloned.children.AddRange(elem.children);
            cloned.payload = elem.payload.clone() as ListOfStrings;
            "output from elem.showElement<string, ListOfStrings>()".title();
            Write(elem.showElement <string, ListOfStrings>());
            "output from cloned.showElement<string, ListOfStrings>()".title();
            Write(cloned.showElement <string, ListOfStrings>());

            //"Hashcodes are not reliable object identifiers".title();
            //Write(string.Format("\n  hashcode of elem           = {0}", elem.GetHashCode()));
            //Write(string.Format("\n  hashcode of elem.name      = {0}", elem.name.GetHashCode()));
            //Write(string.Format("\n  hashcode of elem.descr     = {0}", elem.descr.GetHashCode()));
            //Write(string.Format("\n  hashcode of elem.payload   = {0}", elem.payload.GetHashCode()));
            //WriteLine();

            //Write(string.Format("\n  hashcode of cloned         = {0}", cloned.GetHashCode()));
            //Write(string.Format("\n  hashcode of cloned.name    = {0}", cloned.name.GetHashCode()));
            //Write(string.Format("\n  hashcode of cloned.descr   = {0}", cloned.descr.GetHashCode()));
            //Write(string.Format("\n  hashcode of cloned.payload = {0}", cloned.payload.GetHashCode()));
            //WriteLine();

            "testing for equality immediately after cloning".title();
            showEquality(cloned.name, elem.name, "cloned.name vs. elem.name");
            showEquality(cloned.descr, elem.descr, "cloned.descr vs. elem.descr");
            showDateTimeEquality(cloned.timeStamp, elem.timeStamp, "cloned.timeStamp vs. elem.timeStamp");
            showListEquality(cloned.children, elem.children, "cloned.children vs. elem.children");
            showListEquality <string>(cloned.payload.theWrappedData, elem.payload.theWrappedData, "cloned.payload vs. elem.payload");
            WriteLine();

            "modifying clone's properties".title();
            WriteLine();
            cloned.name      = cloned.name + " modified";
            cloned.descr     = cloned.descr + " modified";
            cloned.timeStamp = DateTime.Today;
            cloned.children.AddRange(new List <string> {
                "key11", "key13"
            });
            cloned.payload.theWrappedData.AddRange(new List <string> {
                "zeta", "eta"
            });
            "output from elem.showElement<string, ListOfStrings>()".title();
            Write(elem.showElement <string, ListOfStrings>());
            "output from cloned.showElement<string, ListOfStrings>()".title();
            Write(cloned.showElement <string, ListOfStrings>());

            "Testing equality after modifying clone's values".title();
            showEquality(cloned.name, elem.name, "cloned.name vs. elem.name");
            showEquality(cloned.descr, elem.descr, "cloned.descr vs. elem.descr");
            showDateTimeEquality(cloned.timeStamp, elem.timeStamp, "cloned.timeStamp vs. elem.timeStamp");
            showListEquality(cloned.children, elem.children, "cloned.children vs. elem.children");
            showListEquality <string>(cloned.payload.theWrappedData, elem.payload.theWrappedData, "cloned.payload vs. elem.payload");

            Write("\n\n");
        }
예제 #27
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");
        }
예제 #28
0
	public string returnDBAsString(string type){
		string str = "";
		DBElement<int, string> elem = new DBElement<int, string>();
		if(type=="int"){
			foreach(int key in db.Keys()){	
				db.getValue(key, out elem);	  
				str += ("\n\n  -- key = "+key+" --");
				str += (elem.showElement<int, string>() + "\n\n");
			}
		}
		else{
			foreach(string key in dbString.Keys()){	
				dbString.getValue(key, out elem);	  
				str += ("\n\n  -- key = "+key+" --");
				str += (elem.showElement<int, string>() + "\n\n");
			}
		}
		return str;
	}
예제 #29
0
 void TestR7()
 {
   "Demonstrating Requirement #7".title('=');
   WriteLine();
   "Adding elements to db".title();
   WriteLine();
   for (int i = 0; i < 3; i++)
   {
       DBElement<int, string> elem = new DBElement<int, string>();
       elem.name = "element";
       elem.descr = "test element";
       elem.timeStamp = new DateTime(2015,10,(2+i));
       elem.children.AddRange(new List<int> { 1, 2, 3 });
       elem.payload = "elem's payload";
       elem.showElement();
       WriteLine();
       db.insert(12345+i, elem);
   }     
   "current DB status:".title();
   db.showDB();
   IQuery<int, DBElement<int, string>> i_query = new DBEngine<int, DBElement<int, string>>();
   QueryEngine<int, DBElement<int, string>> qe = new QueryEngine<int, DBElement<int, string>>(db);
   QueryPredicate qp = new QueryPredicate();
   qp.key_value_search(db, i_query, qe);
   WriteLine();
   qp.key_children_search(db, i_query, qe);
   WriteLine();
   qp.pattern_matching(db, i_query, qe);
   WriteLine();
   qp.default_pattern_matching(db, i_query, qe);
   WriteLine();
   qp.metadata_string(db, i_query, qe);
   WriteLine();
   qp.date_time_specific(db, i_query, qe);
   WriteLine();
   qp.default_date_time_specific(db,i_query, qe);
   WriteLine();
 }
예제 #30
0
    void TestR4()
    {
      DBElement<int, string> element = new DBElement<int, string>();
      element.addElementData("element1", "test element for editing key-value pair to databse with value as string", DateTime.Now, new List<int> { 1, 2 }, "test element1's payload");
      db.insert(1, element);
      "Demonstrating Requirement #4".title();
      DBElement<int, string> edit_element = new DBElement<int, string>();
      db.getValue(1, out edit_element);
      "Element to be edited".title();
      edit_element.showElement();
      WriteLine();

      "Databaser before editing".title();
      db.showDB();
      WriteLine();

      "Editing metadata of element:".title();
      "adding relationship in metadata".title();
      edit_element.name="name after editing";
      edit_element.descr="descr after editing";
      edit_element.timeStamp=DateTime.Now;
      edit_element.children.Add(3);
      edit_element.showElement();
      db.showDB();
      WriteLine();

      "removing relationship from metadata".title();
      edit_element.children.Remove(3);
      db.showDB();
      WriteLine();

      "editing value's instance".title();
      edit_element.payload = "payload after editing";
      db.showDB();
      WriteLine();
    }
예제 #31
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");
        }
예제 #32
0
 private static void Test2(DBEngine<int, DBElement<int, string>> db, DBElement<string, List<string>> newerelem1, DBElement<string, List<string>> newerelem2, Func<string> skeyGen)
 {
     //Insert entries into DB
     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 the Edit functionality
     WriteLine("Testing edits\n");
     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");
 }
예제 #33
0
        public void testDBElementenurmableData()
        {
            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();  
        }
예제 #34
0
 private static DBEngine<int, DBElement<int, string>> Test1()
 {
     WriteLine("Testing DBEngine Package\n");
     WriteLine();
     Write("\n --- Test DBElement<int,string> ---");
     //Int&String Key/Value DB
     //Insert the First element
     DBElement<int, string> elem1 = new DBElement<int, string>();
     elem1.payload = "a payload";
     Write(elem1.showElement<int, string>());
     WriteLine();
     //Insert the Second element
     DBElement<int, string> elem2 = new DBElement<int, string>("Darth Vader", "Evil Overlord");
     elem2.payload = "The Empire strikes back!";
     Write(elem2.showElement<int, string>());
     WriteLine();
     //Insert the Third element
     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;
     // anonymous function to generate keys
     Func<int> keyGen = () => { ++key; return key; };
     //Insert all the elements into the Database
     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");
     //Show the DB 
     db.show<int, DBElement<int, string>, string>();
     WriteLine();
     //String & String Key/Value DB
     //Insert the First element
     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();
     return db;
 }
예제 #35
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");
    }
        void TestR7()
        {
            //Demonstrating queries
            "Demonstrating Requirement #7".title();
            WriteLine();
            QueryEngine queryv = new QueryEngine();
            DBElement<int, string> displayresc = new DBElement<int, string>();
            DBElement<int, string> displayres = new DBElement<int, string>();

            //demonstrating query 1
            Console.WriteLine("\n \n getting value for key 1");
            displayres = queryv.queryvalue<int, DBElement<int, string>, string>(db, 1);
            if (displayres != null)
                displayres.showElement();

            DBElement<string, List<string>> valuestring = new DBElement<string, List<string>>();
            Console.WriteLine("\n \n getting value for key 2");
            valuestring = queryv.queryvalue<string, DBElement<string, List<string>>, string>(db2, "2");
            if (valuestring != null)
                valuestring.showEnumerableElement();

            // demonstrating query 2
            Console.WriteLine("\n \n getting children for key 1");
            List<int> tchildlist = new List<int>();
            tchildlist = queryv.querychildren<int, DBElement<int, string>, string>(db, 1);
            if (tchildlist != null)
            {
                foreach (int i in tchildlist)
                    Console.WriteLine(i);
            }


        }
예제 #37
0
 /// <summary>
 /// Get by GetByMetaData results are handled here and query constructed
 /// </summary>
 /// <param name="doc"></param>
 /// <returns></returns>
 private string GetByMetaData(ref XDocument doc)
 {
     sb = new StringBuilder();
     string pattern = doc.Descendants("Criteria").Select(i => i).Single().Value;
     List<int> dbKeys = new List<int>();
     WriteLine("\n..Getting the set of all keys that contain a specified string '{0}' in metadata {0}..\n", pattern);
     List<int> keyMet = new List<int>();
     query.getMetadataCriteria(db, pattern, out keyMet);   //Get the metadata criteria
     WriteLine("\n ..Keys that has metadata with {0} in it are : \n", pattern);
     foreach (var i in keyMet)
     {
         DBElement<int, string> strElem = new DBElement<int, string>();
         query.getKey(db, i, out strElem);
         sb.Append(" Key: " + i);
         //WriteLine("Key: " + i);
         sb.AppendLine();
         sb.Append(strElem.showElement());
         //WriteLine("\n");
     }
     doc.Descendants("Response").Select(i => i).Single().Value = sb.ToString();
     Console.WriteLine(sb.ToString());
     return pattern;
 }
예제 #38
0
 public static void showElement(this DBElement <int, string> element)
 {
     Console.Write(element.showElement <int, string>());
 }
예제 #39
0
 /// <summary>
 /// Get by timestamp results are handled here and query constructed
 /// </summary>
 /// <param name="doc"></param>
 /// <param name="keyMet"></param>
 /// <param name="FromDate"></param>
 /// <param name="ToDate"></param>
 private void GetByTimeStampCriteria(ref XDocument doc, out List<int> keyMet, DateTime FromDate, out DateTime ToDate)
 {
     
     if (!doc.Descendants("ToDate").Any() || doc.Descendants("ToDate").Select(i => i).Single().Value == "")
     {
         ToDate = DateTime.Now;
     }
     else
         ToDate = DateTime.Parse(doc.Descendants("ToDate").Select(i => i).Single().Value);
     WriteLine("\nGetting the set of all keys that contain value within a specified time-date interval '{0}' to '{1}'..\n", FromDate, ToDate);
     query.getTimeStampCriteria(db, FromDate, ToDate, out keyMet);   //get the criteria based on the date range
     WriteLine("\nKeys that has Date Range between {0} and {1} are : \n", FromDate, ToDate);
     foreach (var i in keyMet)
     {
         DBElement<int, string> strElem = new DBElement<int, string>();
         query.getKey(db, i, out strElem); //get the value based on key              
         sb.Append("Key:" + i);
         sb.AppendLine();
         //WriteLine("Key: " + i);
         sb.Append(strElem.showElement()+"\n");      //show the db
         //WriteLine("\n");
     }
     doc.Descendants("Response").Select(i => i).Single().Value = sb.ToString();
     Console.WriteLine(sb.ToString());
 }
    public static void Main()
    {
        "Testing QueryEngine Package".title('=');
        Console.WriteLine();
        QueryEngine queryv = new QueryEngine();
        DBEngine <int, DBElement <int, string> > newdbq = new DBEngine <int, DBElement <int, string> >();
        DBEngine <string, DBElement <string, List <string> > > newdbqs = new DBEngine <string, DBElement <string, List <string> > >();
        DBElement <int, string> newqelem1 = new DBElement <int, string>();
        DBElement <int, string> newqelem2 = new DBElement <int, string>();
        DBElement <int, string> newqelem3 = new DBElement <int, string>();

        newqelem1.name    = "query elemnt 1";
        newqelem1.descr   = "testing qurey get value for 1";
        newqelem1.payload = "new query element payload 1";
        newqelem1.children.AddRange(new List <int> {
            1, 22, 333
        });
        newqelem2.name    = "query elemnt 2";
        newqelem2.descr   = "testing query get value for 2";
        newqelem2.payload = "new query element payload 2";
        newqelem2.children.AddRange(new List <int> {
            010, 020, 030
        });
        newqelem3.name    = "query elemnt 3";
        newqelem3.descr   = "testing quey get value for 3";
        newqelem3.payload = "new query element payload  3";
        newqelem3.children.AddRange(new List <int> {
            777, 222, 333
        });
        newdbq.insert(1, newqelem1);
        newdbq.insert(2, newqelem2);
        newdbq.insert(3, newqelem3);
        newdbq.showDB();
        DBElement <int, string> displayres = new DBElement <int, string>();

        Console.WriteLine("\n \n getting value for key 2");
        displayres = queryv.queryvalue <int, DBElement <int, string>, string>(newdbq, 2);
        if (displayres != null)
        {
            displayres.showElement();
        }
        Console.WriteLine("\n \n getting children for key 3");
        List <int> childlist = new List <int>();

        childlist = queryv.querychildren <int, DBElement <int, string>, string>(newdbq, 3);
        if (childlist != null)
        {
            foreach (int i in childlist)
            {
                Console.WriteLine(i);
            }
        }
        DBElement <string, List <string> > newelem1q = new DBElement <string, List <string> >(" element 1", "1 is first");
        DBElement <string, List <string> > newelem2q = new DBElement <string, List <string> >(" element 2", "2 is second");
        DBElement <string, List <string> > newelem3q = new DBElement <string, List <string> >(" element 3", " 3 is third");

        newelem1q.children.AddRange(new List <string> {
            " one", "one", "one"
        });
        newelem1q.payload = new List <string> {
            "h", "e", "l", "l", "o"
        };
        newelem2q.children.AddRange(new List <string> {
            " two", "two", "two"
        });
        newelem2q.payload = new List <string> {
            "h", "d", "w", "f", "b"
        };
        newelem3q.children.AddRange(new List <string> {
            " three", "three", "three"
        });
        newelem3q.payload = new List <string> {
            "a", "e", "i", "o", "u"
        };
        newdbqs.insert("one", newelem1q);
        newdbqs.insert("two", newelem2q);
        newdbqs.insert("three", newelem3q);
        newdbqs.showEnumerableDB();
        DBElement <string, List <string> > valuestring = new DBElement <string, List <string> >();

        Console.WriteLine("\n \n getting value for key 2");
        valuestring = queryv.queryvalue <string, DBElement <string, List <string> >, string>(newdbqs, "two");
        if (valuestring != null)
        {
            valuestring.showEnumerableElement();
        }
        DBElement <string, List <string> > valuestrings = new DBElement <string, List <string> >();

        Console.WriteLine("\n \n getting children for key five");
        List <string> childlists = new List <string>();

        childlists = queryv.querychildren <string, DBElement <string, List <string> >, string>(newdbqs, "five");
        if (childlists != null)
        {
            foreach (string cstring in childlists)
            {
                Console.WriteLine(cstring);
            }
        }
    }