void TestR4()
        {
            " Demonstrating Requirement #4 ".title('=');
            WriteLine();
            "Before edit of Key=2 and Key=4 values.".title('-');
            DBElement <int, ListOfStrings> oldElement = db1.Dictionary[2];

            oldElement.showElement();
            ItemEditor <int, ListOfStrings> itemEditor = new ItemEditor <int, ListOfStrings>();

            // Creates a DateTime for the local time.
            itemEditor.editByName(ref db1, 2, "edited name for key=2");
            itemEditor.editByChild(ref db1, 2, new List <int> {
                205, 206, 207, 208, 209, 210
            });
            itemEditor.editByDescr(ref db1, 2, "edited descr for key=2");
            DBElement <int, ListOfStrings> newElement123d = db1.Dictionary[2];

            newElement123d.showElement();
            itemEditor.editPayloadByListOfString(ref db1, 2, new List <string> {
                "CSE681_2_New", "SMA_2_New", "C#.net_2_New", "AI_2_New"
            });
            DateTime newTime = new DateTime(1990, 6, 15, 0, 0, 0);

            itemEditor.editByTime(ref db1, 4, newTime);
            DateTime newTime2 = new DateTime(1990, 6, 16, 0, 0, 0);

            itemEditor.editByTime(ref db1, 2, newTime2);
            "After edit of Key = 2 and Key = 4 values.".title('-');
            WriteLine();
            WriteLine("You can see in updated element, Name,description,children,time and payload attributes are changed.");
            DBElement <int, ListOfStrings> newElement1 = db1.Dictionary[2];
            DBElement <int, ListOfStrings> newElement2 = db1.Dictionary[4];

            newElement1.showElement();
            newElement2.showElement();
            WriteLine();
        }
예제 #2
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();
        }