コード例 #1
0
ファイル: Server.cs プロジェクト: rakeshh91/Android-Projects
 public void performOperations(DBEngine <string, DBElement <string, List <string> > > testDict, DBElement <string, List <string> > value)
 {       /*----------Perform operations as per the input given in the XML document--------------*/
     if (value.operation == "addition")
     {
         testDict.insert(value.key, value);          //insert the key/value pairs to the main database
         string s = "Database after inserting key " + value.key + " is";
         printDatabase(testDict, s);
     }
     if (value.operation == "edit")
     {
         testDict.saveValue(value.key, value);       //edit the value for the given key
         string s = "Database after editing key " + value.key + " is";
         printDatabase(testDict, s);
     }
     if (value.operation == "delete")
     {
         testDict.delete(value.key);                 //delete the key/value pair
         string s = "Database after deleting key " + value.key + " is";
         printDatabase(testDict, s);
     }
     if (value.operation == "persist database")
     {
         PersistEngine <string, DBElement <string, List <string> > > persist = new PersistEngine <string, DBElement <string, List <string> > >(testDict);
         var keys = testDict.Keys();
         persist.persistToXMLListPayload(keys);
         printDatabase(testDict, "Persisted database is:");
     }
     if (value.operation == "Query value")
     {
         DBElement <string, List <string> > valueOfKey = testDict.getValueOfKey(value.key);
         printQuery("Querying the database for value of key " + value.key + " is");
         Console.WriteLine("\n\nThe value of the Key {0} is:\n", value.key);
         valueOfKey.showEnumerableElement();
     }
     if (value.operation == "Query children")
     {
         QueryEngine <string, DBElement <string, List <string> > > qEngine = new QueryEngine <string, DBElement <string, List <string> > >(testDict);
         printQuery("Querying the database for value of key " + value.key + " is");
         List <string> children = qEngine.getChildrenOfKey(value.key);
         Console.WriteLine("\nThe children of the Key {0} are:\n", value.key);
         displayChildren(children);
     }
     if (value.operation == "Augment database")
     {
         PersistEngine <string, DBElement <string, List <string> > > persist = new PersistEngine <string, DBElement <string, List <string> > >(testDict);
         string fileName = "C:\\Users\\rakeshh91\\Documents\\Rakesh Documents\\Class Materials\\SMA\\Assignments\\Assignment 4 - Implementation\\CommPrototype\\augmentDatabase.xml";
         persist.augmentDatabaseFromXMLStringList(testDict, fileName);
         printDatabase(testDict, "Database after augmenting is:");
     }
 }
コード例 #2
0
 /*-----------------Function to replace the instance of the value----------------------*/
 public bool replaceValueInstance(Key key, Value val)
 {
     try
     {
         if (db.Contains(key))
         {
             db.saveValue(key, val);
             return(true);
         }
         else
         {
             WriteLine("\nKey is not present in the dictionary\n");
             return(false);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message.ToString()); return(false);
     }
 }