Exemplo n.º 1
0
        //----< Process request to Restore DB >----------------------------------
        private Message ProcessRestore(Message msg)
        {
            bool   success = false;
            string filename;

            parser.decodeRestoreRequest(msg, out filename);

            perfTimer.Start();

            PersistEngine.augment <int, DBElem, string>(db, filename);
            if (db.Keys().Count() > 0)
            {
                success = true;
            }
            else
            {
                success = false;
            }

            perfTimer.Stop();
            reqCount++;
            totalTime += perfTimer.ElapsedMicroseconds;

            Message result = maker.makeRestoreResult(msg, success);

            return(result);
        }
Exemplo n.º 2
0
        //----< Process request to Persist DB>-----------------------------------
        private Message ProcessPersist(Message msg)
        {
            bool   success = false;
            string filename;

            parser.decodePersistRequest(msg, out filename);

            perfTimer.Start();

            PersistEngine.persist <int, DBElem, string>(db, filename);
            if (File.Exists(filename))
            {
                success = true;
            }
            else
            {
                success = false;
            }

            perfTimer.Stop();
            reqCount++;
            totalTime += perfTimer.ElapsedMicroseconds;

            Message result = maker.makePersistResult(msg, success);

            return(result);
        }
Exemplo n.º 3
0
        //-------------< call the appropriate package from NoSQLdb based on request type >-----------
        public bool call(string request)
        {
            switch (request)
            {
            case "add":
                if (db.insert(key, elem))
                {
                    return(true);                                             //this will fail if multiple write clients write the same key to the db
                }
                break;

            case "edit":
                if (db.remove(key, out editElement))                         //if no element present, editing cannot happen
                {
                    editElement.name      = elem.name;
                    editElement.descr     = elem.descr;
                    editElement.timeStamp = DateTime.Now;
                    editElement.children.Clear();
                    editElement.children = elem.children;
                    editElement.payload  = elem.payload;
                    if (db.insert(key, editElement))
                    {
                        return(true);
                    }
                }
                break;

            case "delete":
                if (db.remove(key, out elem))
                {
                    return(true);
                }
                break;

            case "persist":
                PersistEngine pe = new PersistEngine();
                pe.XMLWriteLOS(db, out pathname);                         // this will always return true, since it will always write out
                return(true);                                             // something, even if it's blank, to a file

            case "restore":
                pe = new PersistEngine();
                if (pe.XMLRestoreLOS(elem.name, db))
                {
                    return(true);
                }
                break;

            default: return(false);
            }
            return(false);
        }
Exemplo n.º 4
0
        //----< Process request to Display DB >----------------------------------
        private Message ProcessDBDisplay(Message msg)
        {
            Console.WriteLine("Received Request to Retrieve DB");

            perfTimer.Start();

            XDocument xDocument = PersistEngine.ToXML <int, DBElem, string>(db);

            perfTimer.Stop();
            reqCount++;
            totalTime += perfTimer.ElapsedMicroseconds;

            Message result = maker.makeDisplayResult(msg, xDocument.ToString());

            return(result);
        }
        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();
            PersistEngineTest p1 = new PersistEngineTest();
            p1.insertData(db);
            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");
            }
        }
Exemplo n.º 6
0
 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:");
     }
 }
Exemplo n.º 7
0
 //----< Import DB<Key, Value> from file >--------------------------------
 public void SetupDB()
 {
     db = new DB();
     PersistEngine.augment <int, DBElem, string>(db, "persistFile.xml");
 }