コード例 #1
0
        public void processDelMsg(XDocument xdoc, Sender sndr, Message msg)
        {
            IEnumerable <string> keys = db.Keys();
            int numKeys = Convert.ToInt32(getNumberOfKeys(xdoc));

            if (numKeys > keys.Count())
            {
                numKeys = keys.Count() - 1;
            }
            List <string> keyList = keys.ToList();

            for (int i = 0; i < numKeys; i++)
            {
                string keyToDeleted = keyList.ElementAt(i);
                if (db.delete(keyToDeleted))
                {
                    msg.content = "\n\n***************************\n" + keyToDeleted + " record is deleted.\n";
                }
                else
                {
                    msg.content = "\n*********************\n" + keyToDeleted + " record is  not deleted.";
                }
                Message testMsg = new Message();
                testMsg.toUrl   = msg.fromUrl;
                testMsg.fromUrl = msg.toUrl;
                testMsg.content = msg.content;
                sndr.sendMessage(testMsg);
            }
        }
コード例 #2
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:");
     }
 }
コード例 #3
0
        //----< process delete message request >-----
        public string processDeleteMessage(XDocument xdoc)
        {
            string content = "";
            int    type    = getKeyValueType(xdoc);

            if (type == 1)
            {
                string keyToDeleted = getKey(xdoc);
                if (db.delete(keyToDeleted))
                {
                    content = keyToDeleted + " record is deleted.";
                }
                else
                {
                    content = keyToDeleted + " record is  not deleted.";
                }
            }
            return(content);
        }
コード例 #4
0
 public Action<Message>delete(DBEngine<int, DBElement<int, string>> db)
 {
     Action<Message> Delete = (msg) =>
        {
            XDocument doc = XDocument.Parse(msg.content.ToString());
            int key = int.Parse(doc.Descendants("Msg").Descendants("Data").Descendants("key").ElementAt(0).Value);
            Console.Write("\n\n delete an element which key = {0}", key);
            Write("\n\n --- Database before delete ---");
            db.showDB();
            if (db.delete(key))
            {
                msg.content = "Delete success";
                Console.Write("\n\n --- Database after delete---", key);
                db.showDB();
            }                       
            else
                msg.content = "Delete fail";
            Utilities.swapUrls(ref msg);                  
        };
     return Delete;
 }
コード例 #5
0
        /// <summary>
        /// Queries the database.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns></returns>
        public String QueryDatabase(String input)
        {
            String result    = String.Empty;
            var    dbElement = ParseXml(input);

            switch (dbElement.dbOperation)
            {
            case "Add":
                db.insert(dbElement.key, dbElement);
                result = "Key " + dbElement.key + " inserted successfully!";
                break;

            case "Edit":
                db.replaceKeyInstance(dbElement.key, dbElement);
                result = "Key " + dbElement.key + "'s value modified successfully!";
                break;

            case "Delete":
                if (db.delete(dbElement.key))
                {
                    result = "Key " + dbElement.key + " deleted successfully!";
                }
                else
                {
                    result = "Key " + dbElement.key + " not found!!";
                }
                break;

            case "SearchChild":
                var children = db.searchChildren(dbElement.key);
                result = "Children are " + string.Join(", ", children.ToArray());
                break;

            case "Search":
                var value = db.searchValue(dbElement.key);
                if (value != null)
                {
                    result  = "Key " + dbElement.key + " found!!!!!\n\n";
                    result += value.showEnumerableElement();
                }
                else
                {
                    result = "Key " + dbElement.key + " not found!!";
                }
                break;

            case "Persist":
                db.toXml();
                result = "Database persisted successfully";
                break;

            case "Restore":
                db.restoreDatabase();
                result = "Database successfully restored!!";
                break;

            default: break;
            }
            string dbView = db.showEnumerableDB();

            "\nDB Contents:\n".title();
            result += dbView;
            return(result);
        }