public void processQuery3(XDocument xdoc, Sender sndr, Message msg) { string pattern = getPattern(xdoc); DBElement <string, List <string> > element = new DBElement <string, List <string> >(); QueryEngine <string, string> QE1 = new QueryEngine <string, string>(); Message testMsg = new Message(); testMsg.toUrl = msg.fromUrl; testMsg.fromUrl = msg.toUrl; List <string> values = new List <string>(); values = QE1.keyPattern(pattern, db); if (values.Count() > 0) { StringBuilder sb = new StringBuilder(); foreach (string str in values) { sb.Append(str); sb.Append("\n"); } testMsg.content = "\n*************************\n" + "\nResult of Query3\n" + "Keys with pattern like " + pattern + " are :\n" + sb + "\n"; } else { testMsg.content = "\n*************************\n" + "\nKeys with pattern like " + pattern + " not found\n"; } sndr.sendMessage(testMsg); }
public void processEditMsg(XDocument xdoc, Sender sndr, Message msg) { IEnumerable <string> keys = db.Keys(); List <string> keyList = keys.ToList(); string keyToEdit = getKey(xdoc); if (!keyList.Contains(keyToEdit)) { Message testMsg = new Message(); testMsg.toUrl = msg.fromUrl; testMsg.fromUrl = msg.toUrl; testMsg.content = "\n********************************\n" + "Key " + keyToEdit + " is not present in the DB\n"; sndr.sendMessage(testMsg); } else { DBElement <string, List <string> > element = new DBElement <string, List <string> >(); string key = createAddDBElement(xdoc, out element); Message testMsg = new Message(); testMsg.toUrl = msg.fromUrl; testMsg.fromUrl = msg.toUrl; if (db.edit(key, element)) { testMsg.content = "\n***********************\n" + "Key= " + key + " is edited Successfully.\n"; } else { testMsg.content = "\n**************************\n" + key + " record is not edited.\n"; } sndr.sendMessage(testMsg); } }
public void processQuery5(XDocument xdoc, Sender sndr, Message msg) { DateTime fromDate = getFromDate(xdoc); DateTime toDate = getToDate(xdoc); DBElement <string, List <string> > element = new DBElement <string, List <string> >(); QueryEngine <string, string> QE1 = new QueryEngine <string, string>(); Message testMsg = new Message(); testMsg.toUrl = msg.fromUrl; testMsg.fromUrl = msg.toUrl; List <string> values = new List <string>(); values = QE1.dateTimeSearch(fromDate, toDate, db); if (values.Count() > 0) { StringBuilder sb = new StringBuilder(); foreach (string str in values) { sb.Append(str); sb.Append("\n"); } testMsg.content = "\n**********************" + "\nResult of Query5" + "\nKeys within Date pattern are:\n" + sb + "\n"; } else { testMsg.content = "\n*************************\n" + "\nKeys within Date pattern not found\n"; } sndr.sendMessage(testMsg); }
//-------< Get keys of DBElements containing a pattern in the metadata section >------------- public List <Key> get_keys_with_metadata <Key, Value, Data>(DBEngine <Key, Value> db, string pat) { List <Key> key_collection = new List <Key>(); foreach (Key key in db.Keys()) { Value value; db.getValue(key, out value); DBElement <Key, Data> elem = value as DBElement <Key, Data>; if (elem.name.Contains(pat) || elem.descr.Contains(pat) || elem.timeStamp.ToString().Contains(pat)) { key_collection.Add(key); } else if (elem.children.Count() > 0) { foreach (Key x in elem.children) { if (x.ToString().Contains(pat)) { key_collection.Add(key); } } } } if (key_collection.Count > 0) { return(key_collection); } else { return(default(List <Key>)); } }
public Action<Message>edit(DBEngine<int, DBElement<int, string>> db) { Action<Message> Edit = (msg) => { XDocument xml = XDocument.Parse(msg.content.ToString()); XElement element = xml.Descendants("Msg").ElementAt(0).Descendants("Data").ElementAt(0); int key = int.Parse(element.Descendants("key").ElementAt(0).Value); DBElement<int, string> elem = new DBElement<int, string>(); Console.Write("\n\n --- edit a element which key ={0}--- ",key); Write("\n\n ---Database before edit---"); db.showDB(); if (!db.getValue(key, out elem)) { msg.content = "edit fail"; return; } elem.name = element.Descendants("value").Descendants("name").ElementAt(0).Value; elem.descr = element.Descendants("value").Descendants("descr").ElementAt(0).Value; elem.timeStamp = (DateTime)element.Descendants("value").Descendants("timestamp").ElementAt(0); IEnumerable<XElement> children = element.Descendants("value").Descendants("children").Descendants("key"); elem.children = new List<int>(); foreach (var child in children) elem.children.Add(int.Parse(child.Value)); IEnumerable<XElement> items = element.Descendants("value").Descendants("payload"); if (items.Count() == 1) elem.payload = items.ElementAt(0).Value; msg.content = "edit success"; Utilities.swapUrls(ref msg); Console.Write("\n\n --- Database after edit ---"); db.showDB(); }; return Edit; }
public Action<Message>insert(DBEngine<int,DBElement<int,string>>db) { Action<Message> Insert = (msg) => { XDocument doc = XDocument.Parse(msg.content); int key = int.Parse(doc.Descendants("Msg").Descendants("Data").Descendants("key").ElementAt(0).Value); DBElement<int, string> elem = new DBElement<int, string>(); elem.name = doc.Descendants("Msg").Descendants("Data").Descendants("value").Descendants("name").ElementAt(0).Value; elem.descr = doc.Descendants("Msg").Descendants("Data").Descendants("value").Descendants("descr").ElementAt(0).Value; elem.timeStamp = (DateTime)doc.Descendants("Msg").Descendants("Data").Descendants("value").Descendants("timestamp").ElementAt(0); IEnumerable<XElement> children = doc.Descendants("Msg").Descendants("Data").Descendants("value").Descendants("children").Descendants("key"); foreach (var child in children) elem.children.Add(int.Parse(child.Value)); IEnumerable<XElement> items = doc.Descendants("Msg").Descendants("Data").Descendants("value").Descendants("payload"); if (items.Count() == 1) elem.payload = items.ElementAt(0).Value; if (!db.insert(key, elem)) msg.content = "Insert fail"; else { msg.content = "Insert success"; Console.Write("\n\n --- insert a DBElement<int,string>---"); elem.showElement(); } Utilities.swapUrls(ref msg); }; return Insert; }
// delegate for time stamp query. public Func <Key, bool> defineTimeStampQuery(DateTime startTime, DateTime?endTime = null) { Func <Key, bool> queryPredicate = (Key key) => { if (!db.Keys().Contains(key)) { return(false); } else { if (endTime == null) { endTime = DateTime.Now; } DBElement <Key, Value> value; db.getValue(key, out value); DBElement <Key, Value> elem = value as DBElement <Key, Value>; int cond1 = DateTime.Compare(elem.timeStamp, startTime); int cond2 = DateTime.Compare(elem.timeStamp, (DateTime)endTime); if (cond1 >= 0 && cond2 <= 0) { return(true); } } return(false); }; return(queryPredicate); }
//retrieves data from XMLTypeTwo to dictionary public bool retrieveDataFromXMLTypeTwo(DBEngine <int, DBElement <int, string> > dbEngine, string inputFile, int limit) { fileName = inputFile; loadXmlFile(); var elem = from c in xDocument.Descendants("elements") select c; if (limit > elem.Elements().Count()) { limit = elem.Elements().Count(); } for (int i = 0; i < limit; i++) { DBElement <int, string> dbElement = new DBElement <int, string>(); int key = int.Parse(elem.Elements().Attributes().ElementAt(i).Value); for (int count = 0; count < elem.Elements().Attributes().ElementAt(i).Parent.Descendants().Count(); count++) { XElement elementRecord = elem.Elements().Attributes().ElementAt(i).Parent.Descendants().ElementAt(count); retrieveTypeTwo(elementRecord, dbElement); } //does not adds key to dictonary if already present to avoid exception if (!dbEngine.Dictionary.Keys.Contains(key)) { dbEngine.Dictionary.Add(key, dbElement); } else { return(false); } } return(true); }
//----< write metadata to string >------------------------------------- public static string showMetaData <Key, Data>(this DBElement <Key, Data> elem) { StringBuilder accum = new StringBuilder(); accum.Append(String.Format("\n name: {0}", elem.name)); accum.Append(String.Format("\n desc: {0}", elem.descr)); accum.Append(String.Format("\n time: {0}", elem.timeStamp)); if (elem.children.Count() > 0) { accum.Append(String.Format("\n Children: ")); bool first = true; foreach (Key key in elem.children) { if (first) { accum.Append(String.Format("{0}", key.ToString())); first = false; } else { accum.Append(String.Format(", {0}", key.ToString())); } } } return(accum.ToString()); }
public void insertData(DBEngine <int, DBElement <int, string> > db) { 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(); }
//-------< Add child relation to a particular DB-element >--------------------------- public static bool addRelation <Key, Value, Data>(this DBEngine <Key, Value> db_edit, Key key1, Key key2) { Value val1, val2; bool key2_present = db_edit.getValue(key2, out val2); if (key2_present) { bool key1_present = db_edit.getValue(key1, out val1); if (key1_present) { DBElement <Key, Data> elem = val1 as DBElement <Key, Data>; elem.children.Add(key2); elem.timeStamp = DateTime.Now; return(true); } else { return(false); } } else { return(false); } }
//retrieves data from XMLTypeOne to dictionary public bool retrieveDataFromXMLTypeOne(DBEngine <string, DBElement <string, ListOfStrings> > dbEngine, string inputFile) { fileName = inputFile; xDocument = XDocument.Load(fileName); var elem = from c in xDocument.Descendants("elements") select c; for (int i = 0; i < elem.Elements().Count(); i++) { DBElement <string, ListOfStrings> dbElement = new DBElement <string, ListOfStrings>(); string key = elem.Elements().Attributes().ElementAt(i).Value; for (int count = 0; count < elem.Elements().Attributes().ElementAt(i).Parent.Descendants().Count(); count++) { XElement elementRecord = elem.Elements().Attributes().ElementAt(i).Parent.Descendants().ElementAt(count); retrieveTypeOne(elementRecord, dbElement); } //does not adds key to dictonary if already present to avoid exception if (!dbEngine.Dictionary.Keys.Contains(key)) { dbEngine.Dictionary.Add(key, dbElement); } else { return(false); } } return(true); }
//----< process edit message request >----- public string processEditMessage(XDocument xdoc) { string content = ""; IEnumerable <string> keys = db.Keys(); List <string> keyList = keys.ToList(); string keyToEdit = getKey(xdoc); if (!keyList.Contains(keyToEdit)) { Console.WriteLine("Key {0} is not present in the DB", keyToEdit); } else { int type = getKeyValueType(xdoc); if (type == 1) { DBElement <string, List <string> > element = new DBElement <string, List <string> >(); string key = createAddDBElement(xdoc, out element); if (db.edit(key, element)) { content = key + " record is edited Successfully."; } else { content = key + " record is not edited."; } } } return(content); }
// a subfunction of retrieveDataFromXMLTypeTwo void retrieveTypeTwo(XElement elementRecord, DBElement <int, string> dbElement) { //retireving all the metadata values one by one into DBElement if (elementRecord.Name.ToString().Equals("name")) { dbElement.name = elementRecord.Value; } else if (elementRecord.Name.ToString().Equals("descr")) { dbElement.descr = elementRecord.Value; } else if (elementRecord.Name.ToString().Equals("timestamp")) { dbElement.timeStamp = DateTime.Parse(elementRecord.Value); } else if (elementRecord.Name.ToString().Equals("children")) { List <int> children = new List <int>(); for (int j = 0; j < elementRecord.Descendants().Count(); j++) { children.Add(int.Parse(elementRecord.Descendants().ElementAt(j).Value)); } dbElement.children = children; } //no need to put string data into wrapper else if (elementRecord.Name.ToString().Equals("payload")) { dbElement.payload = elementRecord.Descendants().ElementAt(0).Value; } }
//-------< Save name,description, children list and payload into a single XML Element. >---------- public XElement persistDBelement <Key, Data>(DBElement <Key, Data> elem) { XElement element = new XElement("Element"); XElement name = new XElement("Name", elem.name); XElement descr = new XElement("Descr", elem.descr); element.Add(name); element.Add(descr); if (elem.children.Count() > 0) { XElement children = new XElement("Children"); foreach (Key key in elem.children) { XElement k = new XElement("Key", key); children.Add(k); } element.Add(children); } XElement time = new XElement("timestamp", elem.timeStamp); element.Add(time); if (elem.payload != null) { XElement payload = new XElement("payload", elem.payload); element.Add(payload); } return(element); }
// a subfunction of retrieveDataFromXMLTypeOne void retrieveTypeOne(XElement elementRecord, DBElement <string, ListOfStrings> dbElement) { //retireving all the metadata values one by one into DBElement if (elementRecord.Name.ToString().Equals("name")) { dbElement.name = elementRecord.Value; } else if (elementRecord.Name.ToString().Equals("descr")) { dbElement.descr = elementRecord.Value; } else if (elementRecord.Name.ToString().Equals("timestamp")) { dbElement.timeStamp = DateTime.Parse(elementRecord.Value); } else if (elementRecord.Name.ToString().Equals("children")) { List <string> children = new List <string>(); for (int j = 0; j < elementRecord.Descendants().Count(); j++) { children.Add(elementRecord.Descendants().ElementAt(j).Value); } dbElement.children = children; } //have to put payload data of type ListOFStrings into wrapper else if (elementRecord.Name.ToString().Equals("payload")) { ListOfStrings payload = new ListOfStrings(); for (int j = 0; j < elementRecord.Descendants().Count(); j++) { payload.theWrappedData.Add(elementRecord.Descendants().ElementAt(j).Value); } dbElement.payload = payload; } }
public Action<Message> insert(DBEngine<string, DBElement<string, List<string>>> db) { Action<Message> Insert =(msg)=> { XDocument xml = XDocument.Parse(msg.content); XElement element = xml.Descendants("Msg").ElementAt(0).Descendants("Data").ElementAt(0); string key = element.Descendants("key").ElementAt(0).Value; DBElement<string, List<string>> elem = new DBElement<string, List<string>>(); elem.name = element.Descendants("value").Descendants("name").ElementAt(0).Value; elem.descr= element.Descendants("value").Descendants("descr").ElementAt(0).Value; elem.timeStamp = (DateTime)element.Descendants("value").Descendants("timestamp").ElementAt(0); IEnumerable<XElement> children = element.Descendants("value").Descendants("children").Descendants("key"); foreach(var child in children) elem.children.Add(child.Value); IEnumerable<XElement> items = element.Descendants("value").Descendants("payload").Descendants("item"); elem.payload = new List<string>(); foreach (var item in items) elem.payload.Add(item.Value); if (!db.insert(key, elem)) msg.content = "Insert fail"; else { msg.content = "Insert success"; Console.Write("\n\n --- insert a DBElement<string,List<string>>---"); elem.showEnumerableElement(); } Utilities.swapUrls(ref msg); }; return Insert; }
public List <string> dateTimeSearch(DateTime fromDate, DateTime toDate, DBEngine <string, DBElement <string, List <string> > > db) { if (toDate == default(DateTime)) { toDate = DateTime.Now; } List <string> foundKeys = new List <string>(); IEnumerable <string> keys = db.Keys(); foreach (string key in keys) { DBElement <string, List <string> > elem = new DBElement <string, List <string> >(); db.getValue(key, out elem); if (elem.timeStamp <= toDate && elem.timeStamp > fromDate) { foundKeys.Add(key); } } if (foundKeys.Count == 0) { return(null); } else { return(foundKeys); } }
public List <string> metaDataPattern(string pattern, DBEngine <string, DBElement <string, List <string> > > db) { List <string> foundKeys = new List <string>(); IEnumerable <string> keys = db.Keys(); foreach (string key in keys) { DBElement <string, List <string> > elem = new DBElement <string, List <string> >(); db.getValue(key, out elem); if (elem.name.Contains(pattern)) { foundKeys.Add(key); } else if (elem.descr.Contains(pattern)) { foundKeys.Add(key); } else if (elem.timeStamp.ToString().Contains(pattern)) { foundKeys.Add(key); } } if (foundKeys.Count == 0) { return(null); } else { return(foundKeys); } }
//----< write details of element with enumerable Data to string >------ public static string showElement <Key, Data, T>(this DBElement <Key, Data> elem) where Data : IEnumerable <T> // constraint clause { StringBuilder accum = new StringBuilder(); accum.Append(elem.showMetaData()); if (elem.payload != null) { IEnumerable <object> d = elem.payload as IEnumerable <object>; if (d == null) { accum.Append(String.Format("\n payload: {0}", elem.payload.ToString())); } else { bool first = true; accum.Append(String.Format("\n payload:\n ")); foreach (var item in elem.payload) // won't compile without constraint clause { if (first) { accum.Append(String.Format("{0}", item)); first = false; } else { accum.Append(String.Format(", {0}", item)); } } } } return(accum.ToString()); }
//--------------check operation and assign the response to be done------------------// public void chkOperation(dynamic op, XElement request, DBEngine <string, DBElement <string, List <string> > > testDict) { if (op == "addition" || op == "edit") { DBElement <string, List <string> > elem1 = new DBElement <string, List <string> >(); elem1.name = request.Descendants("Value").Descendants("name").FirstOrDefault().Value; elem1.descr = request.Descendants("Value").Descendants("descr").FirstOrDefault().Value; elem1.children = request.Descendants("Value").Descendants("children").Descendants("child").Select(child => { return(child.Value); }).ToList(); elem1.timeStamp = DateTime.Now; elem1.payload = request.Descendants("Value").Descendants("payload").Descendants("payloads").Select(payload => { return(payload.Value); }).ToList(); elem1.operation = request.Descendants("Operation").FirstOrDefault().Value; elem1.key = request.Descendants("Key").FirstOrDefault().Value; performOperations(testDict, elem1); } if (op == "delete" || op == "Query value" || op == "Query children") { DBElement <string, List <string> > elem2 = new DBElement <string, List <string> >(); elem2.operation = request.Descendants("Operation").FirstOrDefault().Value; elem2.key = request.Descendants("Key").FirstOrDefault().Value; performOperations(testDict, elem2); } if (op == "persist database") { DBElement <string, List <string> > elem3 = new DBElement <string, List <string> >(); elem3.operation = request.Descendants("Operation").FirstOrDefault().Value; performOperations(testDict, elem3); } if (op == "Augment database") { DBElement <string, List <string> > elem3 = new DBElement <string, List <string> >(); elem3.operation = request.Descendants("Operation").FirstOrDefault().Value; performOperations(testDict, elem3); } }
/// <summary> /// show enumerable element. /// </summary> /// <param name="enumElement"></param> public static string showEnumerableElement(this DBElement <string, List <string> > enumElement) { string result = enumElement.showElement <string, List <string>, string>(); Console.Write(result); return(result); }
static void Main(string[] args) { "Testing ItemEditor Package".title('='); WriteLine(); ItemEditorTest iET = new ItemEditorTest(); iET.insertData(db); DBEngine <int, DBElement <int, string> > db = new DBEngine <int, DBElement <int, string> >(); 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(); "\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(); "\n2) Adding children".title(); "\nBefore adding relationship(children) for key 1".title(); db.showDB(); "\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(); "\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(); "\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(); }
static void Main(string[] args) { DBEngine <int, DBElement <int, string> > db = new DBEngine <int, DBElement <int, string> >(); DBEngine <string, DBElement <string, List <string> > > dbString = new DBEngine <string, DBElement <string, List <string> > >(); ItemFactory <int, string> itemFactory = new ItemFactory <int, string>(); DBElement <int, string> elem = itemFactory.Create(); elem.name = "element"; elem.descr = "test element"; elem.timeStamp = DateTime.Now.AddDays(-4); elem.children.AddRange(new List <int> { 1, 2, 3 }); elem.payload = "elem's payload"; WriteLine("\n Item to be inserted.. \n"); elem.showElement(); db.insert(1, elem); db.showDB(); WriteLine(); WriteLine("\n Inserting second element into DB :"); DBElement <int, string> elem2 = new DBElement <int, string>(); elem2.name = "element2"; elem2.descr = "test element2"; elem2.timeStamp = DateTime.Now; elem2.children.AddRange(new List <int> { 1, 2, 3, 4 }); elem2.payload = "elem2's payload"; WriteLine("\nItem to be inserted.. \n"); elem2.showElement(); db.insert(2, elem2); WriteLine("\n\n DB after insertion:"); db.showDB(); //Inserting element 3 WriteLine("\n Inserting third element into DB :"); DBElement <int, string> elem3 = new DBElement <int, string>(); elem3.name = "element3"; elem3.descr = "test element3"; elem3.timeStamp = DateTime.Now.AddDays(-5); elem3.children.AddRange(new List <int> { 5, 8, 10 }); elem3.payload = "elem3's payload"; WriteLine("\nItem to be inserted.. \n"); elem3.showElement(); db.insert(3, elem3); WriteLine("\n\n DB after insertion:"); db.showDB(); QueryEngineTest engineTest = new QueryEngineTest(); engineTest.test1(); engineTest.test2(); engineTest.test3(); }
static void Main(string[] args) { DBEngine <int, DBElement <int, string> > db = new DBEngine <int, DBElement <int, string> >(); ItemFactory <int, string> itemFactory = new ItemFactory <int, string>(); "Demonstrating Requirement #2".title(); DBElement <int, string> elem = itemFactory.Create(); elem.name = "element"; elem.descr = "test element"; elem.timeStamp = DateTime.Now.AddDays(-4); elem.children.AddRange(new List <int> { 1, 2, 3 }); elem.payload = "elem's payload"; WriteLine("\n Item to be inserted.. \n"); elem.showElement(); db.insert(1, elem); db.showDB(); WriteLine(); WriteLine("\n Inserting second element into DB :"); DBElement <int, string> elem2 = new DBElement <int, string>(); elem2.name = "element2"; elem2.descr = "test element2"; elem2.timeStamp = DateTime.Now; elem2.children.AddRange(new List <int> { 1, 2, 3, 4 }); elem2.payload = "elem2's payload"; WriteLine("\nItem to be inserted.. \n"); elem2.showElement(); db.insert(2, elem2); WriteLine("\n\n DB after insertion:"); db.showDB(); "Adding relationship :".title('.'); WriteLine("\n Elements in DB :"); db.showDB(); int key = 2; var children = new List <int> { 5, 6 }; WriteLine("\n Add children for key {0} : ", key); foreach (var child in children) { Write("{0}, ", child); } WriteLine(); db.addRelationship(key, children); WriteLine("\n\n DB after the change :"); db.showDB(); WriteLine(); "".demarcation(); ItemEditorTest editorTest = new ItemEditorTest(); editorTest.test(); }
// process get value for input key query. public void processValueQuery(Key key, out DBElement <Key, Value> value) { value = default(DBElement <Key, Value>); if (db != null && db.Dictionary.Keys.Contains(key)) { db.getValue(key, out value); } }
//----< create data element in preload data >----- private void createDataElement(DBElement <string, List <string> > elem, List <string> childrens, List <string> payload, string name = "unnamed preload data", string descr = "no description") { elem.name = name + "preload"; elem.descr = descr; elem.timeStamp = new DateTime(2014, 6, 15, 0, 0, 0); elem.children = childrens; elem.payload = payload; }
//wrapper of addByrecord Function bool addRecord(Key key, DBElement <Key, Data> data) { if (!keyPresent(key, data)) { addByRecord(key, data); } return(true); }
static void Main(string[] args) { ItemFactory <int, string> itemFactory = new ItemFactory <int, string>(); DBElement <int, string> elem = itemFactory.Create(); WriteLine("\n DB Element of type {0} is created.\n", elem.GetType()); }
static void Main(string[] args) { "Testing DBElement Package".title('='); WriteLine(); Write("\n --- Test DBElement<int,string> ---"); WriteLine(); DBElement <int, string> elem1 = new DBElement <int, string>(); Write(elem1.showElement <int, string>()); WriteLine(); DBElement <int, string> elem2 = new DBElement <int, string>("Darth Vader", "Evil Overlord"); elem2.payload = "The Empire strikes back!"; Write(elem2.showElement <int, string>()); WriteLine(); var elem3 = new DBElement <int, string>("Luke Skywalker", "Young HotShot"); elem3.children = new List <int> { 1, 2, 7 }; elem3.payload = "X-Wing fighter in swamp - Oh oh!"; Write(elem3.showElement <int, string>()); WriteLine(); Write("\n --- Test DBElement<string,List<string>> ---"); WriteLine(); DBElement <string, List <string> > newelem1 = new DBElement <string, List <string> >(); newelem1.name = "newelem1"; newelem1.descr = "test new type"; newelem1.payload = new List <string> { "one", "two", "three" }; Write(newelem1.showElement <string, List <string>, string>()); WriteLine(); DBElement <string, List <string> > newerelem1 = new DBElement <string, List <string> >(); newerelem1.name = "newerelem1"; newerelem1.descr = "same stuff"; newerelem1.children.Add("first_key"); newerelem1.children.Add("second_key"); newerelem1.payload = new List <string> { "alpha", "beta", "gamma" }; newerelem1.payload.AddRange(new[] { "delta", "epsilon" }); Write(newerelem1.showElement <string, List <string>, string>()); WriteLine(); Write("\n\n"); }