/// <summary> /// Immutable clone db constructed here /// </summary> /// <param name="msg"></param> /// <param name="msgid"></param> /// <param name="value"></param> /// <param name="lstChi"></param> private void ImmutableCloneDb(string msg, out string msgid, out string value, out List<int> lstChi) { Write("\n Creation of immutable database from query"); WriteLine(); bool status = false; value = ""; DBElement<string, string> elem = new DBElement<string, string>(); XDocument doc = XDocument.Load(new StringReader(msg)); msgid = doc.Descendants("MessageID").Select(i => i).Single().Value; int key = int.Parse(doc.Descendants("Key").Select(i => i).Single().Value); WriteLine("..Creation of new immutable Database from compound queries..\n"); WriteLine("..First we will retrieve the results from the main DB..\n"); DBElement<int, string> elem1 = new DBElement<int, string>(); WriteLine("\n\n..Getting the children of specific key..\n"); status = query.getChildren(db, key, out elem1); //get the children based on the key provided DBFactoryGen<int, string> el = new DBFactoryGen<int, string>(); WriteLine("\n..Children with Key {0} successfully retrieved..\n", key); WriteLine(" Key : {0}", key); elem1.showChildren(); //show the child elements lstChi = new List<int>(); WriteLine("\n..We will store the same in a immutable DB..\n"); if (elem1 != null && elem1.children != null) { foreach (var i in elem1.children) { lstChi.Add(i); } } }
/// <summary> /// Creation of a new immutable database constructed from the result of any query that returns a collection of keys /// </summary> public void ImmutableDB(string msg, ref string msgid) { try { string value; List<int> lstChi; ImmutableCloneDb(msg, out msgid, out value, out lstChi); DBFactoryGen<int, DBElement<int, string>> clon = new DBFactoryGen<int, DBElement<int, string>>(); clon.CloneDB(lstChi); //clone the Db WriteLine("..The results have been stored in a Immutable DB can be verified in Line 20 of DBFactoryClass..\n"); WriteLine("..The DB cannot be edited or will not change over time.\n"); WriteLine("DB is immutable since there are no insert or edit methods\n"); WriteLine("..The results are now being retreived from Immutable DB..\n"); int j = 0; WriteLine("***************************************************************************************************************\n"); WriteLine(" IMMUTABLE DATABASE \n"); foreach (var i in lstChi) { clon.getValue(j, out value); //get the value from the immutable Db WriteLine("Key : {0} , Value : {1} \n", j, value); j++; } WriteLine("***************************************************************************************************************\n"); } catch (CustomException) { WriteLine("Error in immutable db \n"); } }