static void Main(string[] args)
        {
            "Testing Persist Engine Package".title('=');
            DBEngine <int, DBElement <int, ListOfStrings> > db1 = new DBEngine <int, DBElement <int, ListOfStrings> >();
            PersistData <int, ListOfStrings> persistEngine1     = new PersistData <int, ListOfStrings>();

            "Write in-memory database in XML file, please check DataPersistTest.xml file.".title('-');
            persistEngine1.loadXmlFile("DataPersistTest.xml", typeof(int).Name, typeof(ListOfStrings).Name);
            if (!persistEngine1.addRecord(1, db1.Dictionary[1]))
            {
                WriteLine("Key 1 is already in xml file.");
            }
            else
            {
                WriteLine("Key 1 is inserted in xml file.");
            }
            if (!persistEngine1.addRecord(2, db1.Dictionary[2]))
            {
                WriteLine("Key 2 is already in xml file.");
            }
            else
            {
                WriteLine("Key 2 is inserted in xml file.");
            }
            if (!persistEngine1.addRecord(4, db1.Dictionary[4]))
            {
                WriteLine("Key 4 is already in xml file.");
            }
            else
            {
                WriteLine("Key 4 is inserted in xml file.");
            }
            if (!persistEngine1.addRecord(2, db1.Dictionary[4]))
            {
                WriteLine("Key 4 is already in xml file.");
            }
            else
            {
                WriteLine("Key 4 is inserted in xml file.");
            }

            "Database restored or augmented from an existing XML (Data1.xml) file".title('-');

            DBEngine <int, DBElement <int, ListOfStrings> > augmentData = new DBEngine <int, DBElement <int, ListOfStrings> >();

            persistEngine1.retrieveDataFromXML(augmentData, "DataPersistTest.xml");
            augmentData.showDB();

            WriteLine();
        }
 // This function will edit payload details in metadata of item.
 public bool editPayloadByListOfString(ref DBEngine <Key, DBElement <Key, ListOfStrings> > dbEngine, Key key, List <string> payload)
 {
     if (dbEngine.Dictionary.Keys.Contains(key))
     {
         dbElement = dbEngine.Dictionary[key];
         clone();
         dbElementCloned.payload.theWrappedData = payload;
         editDictionary(ref dbEngine, key);
         return(true);
     }
     else
     {
         return(false);
     }
 }
 // This function will edit children details in item's metadata. New description will be provide in function argument.
 public bool editByChild(ref DBEngine <Key, DBElement <Key, ListOfStrings> > dbEngine, Key key, List <Key> children)
 {
     if (dbEngine.Dictionary.Keys.Contains(key))
     {
         dbElement = dbEngine.Dictionary[key];
         clone();
         dbElementCloned.children = children;
         editDictionary(ref dbEngine, key);
         return(true);
     }
     else
     {
         return(false);
     }
 }
 // This function will edit time in item's metadata. New time will be provide in function argument.
 public bool editByTime(ref DBEngine <Key, DBElement <Key, ListOfStrings> > dbEngine, Key key, DateTime newTime)
 {
     if (dbEngine.Dictionary.Keys.Contains(key))
     {
         dbElement = dbEngine.Dictionary[key];
         clone();
         dbElementCloned.timeStamp = newTime;
         editDictionary(ref dbEngine, key);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #5
0
        static void Main(string[] args)
        {
            DBEngine <string, DBElement <string, List <string> > > dbRead = new DBEngine <string, DBElement <string, List <string> > >();
            ReadXml <string> test = new ReadXml <string>();
            DBEngine <string, DBElement <string, List <string> > > dbPay = new DBEngine <string, DBElement <string, List <string> > >();
            DBEngine <int, DBElement <int, List <string> > >       db    = new DBEngine <int, DBElement <int, List <string> > >();
            ReadXml <string> test2 = new ReadXml <string>();
            ReadXml <int>    test1 = new ReadXml <int>();

            test1.readXml(db);
            Console.WriteLine(); Console.WriteLine();
            db.showEnumerableDB();
            dbPay.showEnumerableDB();
            WriteLine();
        }
 // This function will edit description in item's metadata. New description will be provide in function argument.
 public bool editByDescr(ref DBEngine <Key, DBElement <Key, ListOfStrings> > dbEngine, Key key, String descr)
 {
     if (dbEngine.Dictionary.Keys.Contains(key))
     {
         dbElement = dbEngine.Dictionary[key];
         clone();
         dbElementCloned.descr = descr;
         editDictionary(ref dbEngine, key);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #7
0
        public bool editChildern(Key key, string attribute, List <Key> newValue, DBEngine <Key, DBElement <Key, string> > db)
        {
            bool test = db.getValue(key, out elem);

            if (!test)
            {
                return(false);
            }

            else
            {
                elem.children = newValue;
                db.insert(key, elem);
            }
            return(true);
        }
Beispiel #8
0
        public bool editPayload(Key key, string attribute, List <string> newValue, DBEngine <Key, DBElement <Key, List <string> > > db)
        {
            bool test = db.getValue(key, out elemPay);

            if (!test)
            {
                return(false);
            }

            else
            {
                elemPay.payload = newValue;
                db.insert(key, elemPay);
            }
            return(true);
        }
        /*
         * Retrive data from xml file. augmented in DBEngine.
         */
        public void retrieveDataFromXML(DBEngine <int, DBElement <int, ListOfStrings> > dbEngine, String inputFile)
        {
            fileName = inputFile;
            var elem = from c in document.Descendants("elements") select c;

            for (int i = 0; i < elem.Elements().Count(); i++)
            {
                DBElement <int, ListOfStrings> dbElement = new DBElement <int, ListOfStrings>();
                int key = Int32.Parse(elem.Elements().Attributes().ElementAt(i).Value);

                for (int count = 0; count < elem.Elements().Attributes().ElementAt(i).Parent.Descendants().Count(); count++)
                {
                    XElement elementRecord = elem.Elements().Attributes().ElementAt(i).Parent.Descendants().ElementAt(count);
                    if (elementRecord.Name.ToString().Equals("name"))
                    {
                        dbElement.name = elementRecord.Value;
                    }
                    else if (elementRecord.Name.ToString().Equals("desc"))
                    {
                        dbElement.descr = elementRecord.Value;
                    }
                    else if (elementRecord.Name.ToString().Equals("time"))
                    {
                        dbElement.timeStamp = DateTime.Parse(elementRecord.Value);
                    }
                    else if (elementRecord.Name.ToString().Equals("children"))
                    {
                        List <int> children = new List <int>();
                        for (int j = 0; j < elementRecord.Descendants().Count(); j++)
                        {
                            children.Add(Int32.Parse(elementRecord.Descendants().ElementAt(j).Value));
                        }
                        dbElement.children = children;
                    }
                    else if (elementRecord.Name.ToString().Equals("payload"))
                    {
                        ListOfStrings payload = new ListOfStrings();
                        for (int j = 0; j < elementRecord.Descendants().Count(); j++)
                        {
                            payload.theWrappedData.Add(elementRecord.Descendants().ElementAt(j).Value);
                        }
                        dbElement.payload = payload;
                    }
                }
                dbEngine.Dictionary.Add(key, dbElement);
            }
        }
Beispiel #10
0
 public void scheduledSave(DBEngine <Key, DBElement <Key, List <string> > > db)
 {
     //Setting scheduler parameters
     scheduler.Interval  = 1000;
     scheduler.AutoReset = true;
     scheduler.Elapsed  += (object source, ElapsedEventArgs e) =>
     {
         Console.WriteLine("\nScheduled Save started at {0}", e.SignalTime);
         PE.createXML(db);       //Calling persist engine to create a XML
     };
     scheduler.Enabled = true;
     Console.ReadKey();
     Console.Write("Persisted database into XML -----\n\n");
     Console.WriteLine("\nXML Saved @/bin/Debug");
     Console.WriteLine("\nPlease open the XML file in the specified path to see the contents\n\n");
     Console.WriteLine();
 }
Beispiel #11
0
        /*----------------------------------Category implementation----------------------------*/
        public List <string> getKeyForCategory(DBEngine <string, DBElement <string, List <string> > > dbCat, List <string> category)
        {
            dynamic       keys        = dbCat.Keys();
            List <string> matchedKeys = new List <string>();

            foreach (var cat in category)
            {
                foreach (var key in keys)
                {
                    if (cat == key)
                    {
                        matchedKeys.Add(key);
                    }
                }
            }
            return(matchedKeys);
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            "Testing Scheduler package".title();
            //Loading DB for testing
            DBEngine <string, DBElement <string, List <string> > > dbString = new DBEngine <string, DBElement <string, List <string> > >();
            DBElement <string, List <String> > elemString = new DBElement <string, List <String> >();

            elemString.name      = "Element2";
            elemString.descr     = "testelement2";
            elemString.timeStamp = DateTime.Now;
            elemString.children.AddRange(new List <string> {
                "SMA1", "Syracuse2", "NY3"
            });
            elemString.payload = new List <string>();
            elemString.payload.AddRange(new List <string> {
                "we", "rock", "the ", "world"
            });

            dbString.insert("Prohject2", elemString);

            DBElement <string, List <String> > elemString2 = new DBElement <string, List <String> >();

            elemString2.name      = "Element3";
            elemString2.descr     = "test element3";
            elemString2.timeStamp = DateTime.Now;
            elemString2.children.AddRange(new List <string> {
                "SMA2", "Syracuse22", "NY33"
            });
            elemString2.payload = new List <string>();
            elemString2.payload.AddRange(new List <string> {
                "Thug", "Life"
            });

            dbString.insert("Thug3", elemString2);

            Scheduler <string> sch = new Scheduler <string>();

            sch.scheduledSave(dbString);
        }
        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");
        }
 // This function will edit children index  details in item's metadata.
 public bool editByChildIndex(ref DBEngine <Key, DBElement <Key, ListOfStrings> > dbEngine, Key key, int index, Key childKey)
 {
     if (dbEngine.Dictionary.Keys.Contains(key))
     {
         dbElement = dbEngine.Dictionary[key];
         clone();
         List <Key> childrens = dbElementCloned.children;
         if (index < childrens.Count)
         {
             childrens[index - 1] = childKey;
             dbElement.children   = childrens;
             editDictionary(ref dbEngine, key);
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Beispiel #15
0
 /*--------------Constructor where keys obtained from a query result are stored to a dictionary---------*/
 public QueryEngine(DBEngine <Key, Value> dbEngine)
 {
     db = dbEngine;
 }
 public QueryEngine(DBEngine <Key, DBElement <Key, Value> > dbEngine)
 {
     db = dbEngine;
 }
Beispiel #17
0
        static void Main(string[] args)
        {
            "Testing PersistEngine Package".title('=');
            WriteLine();
            DBEngine <int, DBElement <int, string> > db = new DBEngine <int, DBElement <int, string> >();

            "\nSave to an XML file".title();
            DBElement <int, string> elem1 = new DBElement <int, string>();

            elem1.name      = "Usain Bolt";
            elem1.descr     = "Athelte";
            elem1.timeStamp = DateTime.Now;
            elem1.children.AddRange(new List <int> {
                2
            });
            elem1.payload = "Fastest in the world";
            db.insert(1, elem1);

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

            elem2.name      = "Saina Nehwal";
            elem2.descr     = "Badminton Player";
            elem2.timeStamp = DateTime.Now;
            elem2.children.AddRange(new List <int> {
                1
            });
            elem2.payload = "Famous badminton player";
            db.insert(2, elem2);
            db.showDB();
            WriteLine();

            dynamic allKeys = db.Keys();
            PersistEngine <int, DBElement <int, string> > pEngine = new PersistEngine <int, DBElement <int, string> >(db);

            pEngine.persistToXML(allKeys);
            WriteLine("\n\nAbove database is stored as XML file in local machine");
            WriteLine();

            WriteLine("\nThe persisted XML file along with new key/value pairs are augmented to the database.\n");
            WriteLine("Below shown key/value pairs are augmented to the database.\n");
            pEngine.augmentDatabaseFromXML(db);                                         //Augment the persisted database along with new values to the main database
            pEngine.persistToXML(allKeys);
            db.showDB();
            WriteLine();
            WriteLine();

            "\nPersist database every 5 seconds until its cancelled".title();
            WriteLine();

            pEngine.scheduledSaveDatabase();
            WriteLine();
            WriteLine();

            "\nProject dependancy and realtionships".title();
            WriteLine();
            DBEngine <string, DBElement <string, List <string> > >      dependancyDb  = new DBEngine <string, DBElement <string, List <string> > >();
            PersistEngine <string, DBElement <string, List <string> > > pEngineString = new PersistEngine <string, DBElement <string, List <string> > >(dependancyDb);

            try
            {
                Console.WriteLine("\nBelow details provide information on dependancy of every package in the project\n");
                pEngine.displayDependancy();
                dependancyDb.showEnumerableDB();
                WriteLine();
            }
            catch (Exception e)
            {
                WriteLine("\n" + e.Message + "\n");
            }
        }
        static void Main(string[] args)
        {
            "Testing QueryProcessing Package".title('=');
            WriteLine();

            DBEngine <int, DBElement <int, ListOfStrings> > db1 = new DBEngine <int, DBElement <int, ListOfStrings> >();
            DBElement <int, ListOfStrings> elem1 = new DBElement <int, ListOfStrings>();

            elem1.name      = "1st Key/Value = Int/ListOfStrings";
            elem1.descr     = "This is first element of Int/ListOfStrings key value pair.";
            elem1.timeStamp = DateTime.Now;
            elem1.children.AddRange(new List <int> {
                100, 101, 102, 103, 104, 105
            });
            elem1.payload = new ListOfStrings();
            elem1.payload.theWrappedData = new List <string> {
                "CSE681", "SMA", "C#.net", "AI"
            };
            db1.insert(1, elem1);

            DBElement <int, ListOfStrings> elem2 = new DBElement <int, ListOfStrings>();

            elem2.name      = "element int-ListOfString 2";
            elem2.descr     = "test element int-ListOfString 2";
            elem2.timeStamp = DateTime.Now;
            elem2.children.AddRange(new List <int> {
                10, 22, 23, 24, 25, 26
            });
            elem2.payload = new ListOfStrings();
            elem2.payload.theWrappedData = new List <string> {
                "CSE6812", "SMA2", "C#.net2", "AI2"
            };
            db1.insert(2, elem2);

            WriteLine("  Query : value of key = 2");
            QueryProcessEngine <int, ListOfStrings> queryEngine = new QueryProcessEngine <int, ListOfStrings>(db1);
            DBElement <int, ListOfStrings>          result;

            queryEngine.processValueQuery(14, out result);
            result.showElement();

            WriteLine("  Query : Children of key = 1");
            List <int> childrens;

            queryEngine.processChildrenQuery(1, out childrens);
            foreach (var item in childrens)
            {
                WriteLine(item);
            }
            WriteLine();

            "The set of all keys matching a specified pattern which defaults to all keys.".title('-');
            Dictionary <int, DBElement <int, ListOfStrings> > results;

            queryEngine.processPatternMatchInKeysQuery(queryEngine.defineQueryKeyPatternSearch("1"), out results);
            DBFactory <int, DBElement <int, ListOfStrings> > dbFactory = new DBFactory <int, DBElement <int, ListOfStrings> >(results);

            dbFactory.showDBFactory();

            WriteLine();
            "All keys that contain a specified string in their metadata section.".title('-');
            results.Clear();
            queryEngine.processPatternMatchInMetaDataQuery(queryEngine.defineQueryValuePatternSearch("Scheduler"), out results);
            dbFactory = new DBFactory <int, DBElement <int, ListOfStrings> >(results);
            dbFactory.showDBFactory();

            WriteLine();
            "All keys that contain values written within a specified time-date interval".title('-');
            DateTime dt1 = new DateTime(1990, 6, 14, 0, 0, 0);
            DateTime dt2 = new DateTime(1990, 6, 17, 0, 0, 0);

            results.Clear();
            queryEngine.processTimeIntervalQuery(queryEngine.defineTimeStampQuery(dt1, dt2), out results);
            dbFactory.showDBFactory();
        }
Beispiel #19
0
        static void Main(string[] args)
        {
            "Testing ItemEditor Package".title('=');
            WriteLine();

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

            elem1.name      = "Usain Bolt";
            elem1.descr     = "Athelte";
            elem1.timeStamp = DateTime.Now;
            elem1.children.AddRange(new List <int> {
                2
            });
            elem1.payload = "Fastest in the world";
            db.insert(1, elem1);

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

            elem2.name      = "Saina Nehwal";
            elem2.descr     = "Badminton Player";
            elem2.timeStamp = DateTime.Now;
            elem2.children.AddRange(new List <int> {
                1
            });
            elem2.payload = "Famous badminton player";
            db.insert(2, elem2);
            db.showDB();
            WriteLine();

            ItemEditor <int, DBElement <int, string> > iEditor = new ItemEditor <int, DBElement <int, string> >(db);

            "\n1) Editing metadata".title();
            "\nBefore editing metadata for key 1".title();
            db.showDB();
            WriteLine();
            "\nAfter editing metadata for key 1".title();
            iEditor = new ItemEditor <int, DBElement <int, string> >(db);
            iEditor.editMetaData(1, "Sachin Tendulkar", "Cricket player");                     //send the values to be edited to the editMetaData() function
            db.showDB();
            WriteLine();
            WriteLine();

            "\n2) Adding children".title();
            "\nBefore adding relationship(children) for key 1".title();
            db.showDB();
            WriteLine();
            "\nAfter adding relationship(children) for Key 1".title();
            iEditor.addrelationships(1, new List <int> {
                3
            });                                                                              //send a new list with children to be added to a key
            db.showDB();
            WriteLine();
            WriteLine();

            "\n3) Deleting children".title();
            "\nBefore deleting relationship(children) for key 1".title();
            db.showDB();
            WriteLine();
            "\nAfter deleting relationship(children) to Key 1".title();                           //send a new list with children to be deleted from a key
            iEditor.deleteRelationships(1, new List <int> {
                3
            });
            db.showDB();
            WriteLine();
            WriteLine();

            "\n4) Replacing value instance".title();
            DBElement <int, string> elem = new DBElement <int, string>();                         //create a new element for replacing value

            elem.name    = "Messi";
            elem.payload = "Plays for Argentina";
            elem.descr   = "Football player";
            elem.children.AddRange(new List <int> {
                2
            });
            elem.timeStamp = DateTime.Now;

            "\nBefore replacing the value instance for key 2".title();
            db.showDB();
            WriteLine();
            "\nAfter replacing the value instance for key 2".title();
            iEditor.replaceValueInstance(2, elem);                                              //send value to be replaced for a key
            db.showDB();
            WriteLine();
        }
 // show DB which has key as integer and value as ListOfStrings.
 public static void showDB(this DBEngine <int, DBElement <int, ListOfStrings> > db)
 {
     db.show <int, DBElement <int, ListOfStrings>, ListOfStrings>();
 }
        public void createXML(DBEngine<Key, DBElement<Key, List<string>>> db)
        {
            XmlDocument doc = new XmlDocument();

            
            XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
            XmlElement root = doc.DocumentElement;
            doc.InsertBefore(xmlDeclaration, root);

            
            XmlElement element1 = doc.CreateElement(string.Empty, "noSqlDb", string.Empty);
            doc.AppendChild(element1);

            XmlElement element2 = doc.CreateElement(string.Empty, "keytype", string.Empty);
            element1.AppendChild(element2);

            XmlText text2 = doc.CreateTextNode("string");
            element2.AppendChild(text2);

            XmlElement element3 = doc.CreateElement(string.Empty, "payloadtype", string.Empty);
            element1.AppendChild(element3);

            XmlText text3 = doc.CreateTextNode("ListOfStrings");
            element3.AppendChild(text3);

            foreach (Key key in db.Keys())
            {
                
                DBElement<Key, List<string>> elem = new DBElement<Key, List<string>>();
                db.getValue(key, out elem);

                XmlElement element4 = doc.CreateElement(string.Empty, "key", string.Empty);
                element1.AppendChild(element4);

                string xmlNode = key.ToString();
                XmlText text4 = doc.CreateTextNode(xmlNode);
                element4.AppendChild(text4);

                XmlElement element5 = doc.CreateElement(string.Empty, "element", string.Empty);
                element1.AppendChild(element5);

                XmlElement element6 = doc.CreateElement(string.Empty, "name", string.Empty);
                element5.AppendChild(element6);

                string nodeText = elem.name;
                XmlText text6 = doc.CreateTextNode(nodeText);
                element6.AppendChild(text6);

                XmlElement element7 = doc.CreateElement(string.Empty, "descr", string.Empty);
                element5.AppendChild(element7);

                nodeText = elem.descr;
                XmlText text7 = doc.CreateTextNode(nodeText);
                element7.AppendChild(text7);

                XmlElement element8 = doc.CreateElement(string.Empty, "timeStamp", string.Empty);
                element5.AppendChild(element8);

                nodeText = elem.timeStamp.ToString();
                XmlText text8 = doc.CreateTextNode(nodeText);
                element8.AppendChild(text8);

                XmlElement element9 = doc.CreateElement(string.Empty, "children", string.Empty);
                element5.AppendChild(element9);
                foreach (Key child in elem.children)
                {
                    XmlElement element10 = doc.CreateElement(string.Empty, "key", string.Empty);
                    element9.AppendChild(element10);
                    xmlNode = "key" + child;
                    XmlText text10 = doc.CreateTextNode(xmlNode);
                    element10.AppendChild(text10);
                }

                XmlElement element11 = doc.CreateElement(string.Empty, "payload", string.Empty);
                element5.AppendChild(element11);

                foreach (String pay in elem.payload)
                {
                    XmlElement element12 = doc.CreateElement(string.Empty, "item", string.Empty);
                    element11.AppendChild(element12);
                    nodeText = pay;
                    XmlText text12 = doc.CreateTextNode(nodeText);
                    element12.AppendChild(text12);
                }
            }


            doc.Save("xxx.xml");
        
        Console.WriteLine("\nXML Saved @/bin/Debug");
            Console.WriteLine("\nPlease open the XML file in the specified path to see the contents");
        }
Beispiel #22
0
 public static void showEnumerableDB(this DBEngine <string, DBElement <string, List <string> > > db)
 {
     db.showEnumerable <string, DBElement <string, List <string> >, List <string>, string>();
 }
Beispiel #23
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.showElementWithTestType1 <int>());
            WriteLine();

            DBElement <int, string> elem2 = new DBElement <int, string>("Darth Vader", "Evil Overlord");

            elem2.payload = "The Empire strikes back!";
            Write(elem2.showElementWithTestType1 <int>());
            WriteLine();

            var elem3 = new DBElement <int, string>("Luke Skywalker", "Young HotShot");

            elem3.payload = "X-Wing fighter in swamp - Oh oh!";
            Write(elem3.showElementWithTestType1 <int>());
            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.showWithTestType1 <int>();
            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.showElementWithTestType2 <string>());
            WriteLine();

            Write("\n --- Test DBElement<string,IEnumWrapper<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.showElementWithTestType2 <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.showElementWithTestType2 <string>());
            WriteLine();

            Write("\n --- Test DBEngine<string,DBElement<string,IEnumWrapper<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.showWithTestType2 <string>();
            Write("\n\n");
        }
        static void Main(string[] args)
        {
            QueryEngine <int, string>    QE  = new QueryEngine <int, string>();
            QueryEngine <string, string> QE1 = new QueryEngine <string, string>();

            DBEngine <int, DBElement <int, List <string> > >       dbPay    = new DBEngine <int, DBElement <int, List <string> > >();
            DBEngine <string, DBElement <string, List <string> > > dbString = new DBEngine <string, DBElement <string, List <string> > >();
            DBElement <string, List <String> > elemString = new DBElement <string, List <String> >(); //Populating DBEngine

            elemString.name      = "Element2";                                                        //object dbString
            elemString.descr     = "testelement2";                                                    //for testing data string and list of string type.
            elemString.timeStamp = DateTime.Now;
            elemString.children.AddRange(new List <string> {
                "SMA1", "Syracuse2", "NY3"
            });
            elemString.payload = new List <string>();
            elemString.payload.AddRange(new List <string> {
                "we", "rock", "the ", "world"
            });
            dbString.insert("Prohject2", elemString);
            DBElement <string, List <String> > elemString2 = new DBElement <string, List <String> >(); //Populating DBEngine

            elemString2.name      = "Element3";                                                        //object dbString
            elemString2.descr     = "test element3";                                                   //for testing data string and list of string type.
            elemString2.timeStamp = DateTime.Now;
            elemString2.children.AddRange(new List <string> {
                "SMA2", "Syracuse22", "NY33"
            });
            elemString2.payload = new List <string>();
            elemString2.payload.AddRange(new List <string> {
                "Thug", "Life"
            });
            dbString.insert("Thug3", elemString2);
            DBElement <int, List <string> > elemPayload = new DBElement <int, List <string> >();    //Populating DBEngine

            elemPayload.name      = "Element4";                                                     //object dbPay
            elemPayload.descr     = "test element4";                                                //for testing data int and list of string type.
            elemPayload.timeStamp = DateTime.Now;
            elemPayload.children.AddRange(new List <int> {
                1, 2, 3
            });
            elemPayload.payload = new List <string>();
            elemPayload.payload.AddRange(new List <string> {
                "Project 2", " ", "demo", " ", "starts"
            });
            dbPay.insert(1, elemPayload);
            DBElement <int, List <string> > elemPayload2 = new DBElement <int, List <string> >();   //Populating DBEngine

            elemPayload2.name      = "Element5";                                                    //object dbPay
            elemPayload2.descr     = "test element5";                                               //for testing data int and list of string type.
            elemPayload2.timeStamp = DateTime.Now;
            elemPayload2.children.AddRange(new List <int> {
                98, 22, 35
            });
            elemPayload2.payload = new List <string>();
            elemPayload2.payload.AddRange(new List <string> {
                "we", "rock", "the", "world"
            });
            dbPay.insert(2, elemPayload2);

            QE.valueByKey(1, dbPay);
            WriteLine();

            QE.childrenByKey(1, dbPay);

            //QE1.keyPattern(".*h.*", dbString);
            WriteLine();
            QE1.keyPattern(".*hjbbj.*", dbString);
            WriteLine();
            QE.metaDataPattern("t2", dbString);

            //DateTime toDate = new DateTime(2015, 10, 7);
            DateTime toDate   = new DateTime(2015, 10, 7);
            DateTime fromDate = new DateTime(2015, 10, 1);

            //System.Threading.Thread.Sleep(500);

            QE.dateTimeSearch(fromDate, toDate, dbString);
        }
Beispiel #25
0
        static void Main(string[] args)
        {
            "Testing DBFactory Package".title('=');
            WriteLine();

            "\nCreation of immutable database".title();
            WriteLine();

            "\nOriginal database".title();
            DBEngine <int, DBElement <int, string> > db = new DBEngine <int, DBElement <int, string> >();

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

            elem1.name      = "India";
            elem1.descr     = "Country";
            elem1.timeStamp = DateTime.Now;
            elem1.children.AddRange(new List <int> {
                2, 3
            });
            elem1.payload = "Famous cricket player";
            db.insert(1, elem1);

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

            elem2.name      = "Roger federer";
            elem2.descr     = "Tennis player";
            elem2.timeStamp = DateTime.Now.AddDays(-15);
            elem2.children.AddRange(new List <int> {
                3
            });
            elem2.payload = "Famous tennis player";
            db.insert(2, elem2);

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

            elem3.name      = "Usain Bolt";
            elem3.descr     = "Athelte";
            elem3.timeStamp = DateTime.Now;
            elem3.children.AddRange(new List <int> {
                1
            });
            elem3.payload = "Fastest in the world";
            db.insert(3, elem3);

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

            elem4.name      = "Saina Nehwal";
            elem4.descr     = "Badminton Player";
            elem4.timeStamp = DateTime.Now;
            elem4.children.AddRange(new List <int> {
                2
            });
            elem4.payload = "Famous badminton player";
            db.insert(4, elem4);
            db.showDB();
            WriteLine();

            "\n Fetch all the keys which are even from the above database".title();
            try
            {
                QueryEngine <int, DBElement <int, string> > qEngine     = new QueryEngine <int, DBElement <int, string> >(db);
                Dictionary <int, DBElement <int, string> >  dictFactory = new Dictionary <int, DBElement <int, string> >();
                DBFactory <int, DBElement <int, string> >   dbFactory;
                var keys = qEngine.getListKeyPattern();
                if (keys != null)
                {
                    foreach (var key in keys)
                    {
                        var val = db.getValueOfKey(key);
                        dictFactory.Add(key, val);                                                              //add keys and values to the dictionary
                    }
                    dbFactory = new DBFactory <int, DBElement <int, string> >(dictFactory);                     //store the dictionary in the
                    WriteLine("\nThe below key/value pairs with even keys pattern are saved as an immutable database\n");
                    dbFactory.showDB();                                                                         //display the immutable database
                    WriteLine();
                    WriteLine();
                }
                else
                {
                    WriteLine("\nNo keys are obtained from a query for creation of immutable database\n");
                }
                WriteLine();
                WriteLine();
            }
            catch (Exception e)
            {
                Console.WriteLine("\n" + e.Message + "\n");
            }
        }
Beispiel #26
0
        public void readXml(DBEngine <Key, DBElement <Key, List <string> > > dbRead)
        {
            XmlDocument doc = new XmlDocument();                //creating object of XmlDocument Class

            if (File.Exists("yyy.xml"))
            {
                try
                { doc.Load("yyy.xml"); }
                catch (Exception e)
                {
                    WriteLine("\n Wrong Input file. Error Message : {0}\n", e.Message);
                }
            }
            else
            {
                WriteLine("\n  File \" yyy.xml \" does not exist.");
                return;
            }
            doc.Save(Console.Out);                                 //Printing XML file on the console
            foreach (XmlNode node in doc.GetElementsByTagName("noSqlDb"))
            {
                DBElement <Key, List <string> > elemRead = null;
                foreach (XmlNode node2 in node.ChildNodes)
                {
                    if (node2.Name == "key")                        // Capturing the Parent key
                    {
                        first += 1;
                        if (first > 0 && first % 2 == 1)
                        {
                            elemRead = new DBElement <Key, List <string> >();
                        }
                        keyParent = (Key)Convert.ChangeType(node2.InnerText, typeof(Key));
                    }
                    else if (node2.Name == "element")               //Capturing Element Tag
                    {
                        first += 1;
                        foreach (XmlNode node3 in node2.ChildNodes)
                        {
                            if (node3.Name == "name")                   // Capturing Metadata "Name"
                            {
                                elemRead.name = node3.InnerText;
                            }
                            else if (node3.Name == "descr")             // Capturing Metadata "description"
                            {
                                elemRead.descr = node3.InnerText;
                            }
                            else if (node3.Name == "timeStamp")         // Capturing Metadata "Time Stamp"
                            {
                                elemRead.timeStamp = DateTime.Parse(node3.InnerText);
                            }
                            else if (node3.Name == "children")              // Capturing childen of the Parent Key
                            {
                                List <Key> childRead = new List <Key>();
                                foreach (XmlNode node4 in node3.ChildNodes)
                                {
                                    if (node4.Name == "key")
                                    {
                                        childRead.Add((Key)Convert.ChangeType(node4.InnerText, typeof(Key)));
                                    }
                                }
                                elemRead.children = childRead;
                            }
                            else if (node3.Name == "payload")                   // Capturing Value/Payload
                            {
                                List <string> payloadRead = new List <string>();
                                foreach (XmlNode node5 in node3.ChildNodes)
                                {
                                    if (node5.Name == "item")
                                    {
                                        payloadRead.Add(node5.InnerText);
                                    }
                                }
                                elemRead.payload = payloadRead;
                            }
                        }
                    }
                    if (first > 0 && first % 2 == 0)
                    {
                        dbRead.insert(keyParent, elemRead);             // Inserting captured records into the database
                        first = 0;
                    }
                }
            }
        }
Beispiel #27
0
 public static void showDB(this DBEngine <int, DBElement <int, string> > db)
 {
     db.show <int, DBElement <int, string>, string>();
 }
 // This function will updated new updated things in main dictionary.
 private void editDictionary(ref DBEngine <Key, DBElement <Key, ListOfStrings> > dbEngine, Key key)
 {
     dbEngine.Dictionary[key] = dbElementCloned;
 }
Beispiel #29
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");
        }
 //// show dependency xml which stores in db.
 public static void showDependencyDB(this DBEngine <string, DBElement <string, ListOfStrings> > db)
 {
     db.show <string, DBElement <string, ListOfStrings>, ListOfStrings>();
 }