本文整理汇总了C#中DBElement类的典型用法代码示例。如果您正苦于以下问题:C# DBElement类的具体用法?C# DBElement怎么用?C# DBElement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DBElement类属于命名空间,在下文中一共展示了DBElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: insert
// function to insert into database
public XElement insert(XElement dbe, DBEngine<int, DBElement<int, string>> db)
{
DBElement<int, string> elem = new DBElement<int, string>();
Console.WriteLine("\n");
Console.WriteLine("\n----------Insert operation----------");
elem.name = dbe.Element("name").Value;
elem.descr = dbe.Element("descr").Value;
elem.payload = dbe.Element("payload").Value;
List<int> childrenlist = new List<int>();
XElement db1 = dbe.Element("children");
foreach (var v in db1.Elements("dbkey")) childrenlist.Add(Int32.Parse(v.Value));
elem.children = childrenlist;
bool result = db.insert(Int32.Parse((dbe.Element("key").Value)), elem);
db.showDB();
if (result == true)
{
XElement s = new XElement("result", "\n element inserted successfully ");
return s;
}
else
{
XElement f = new XElement("result", "Failure");
return f;
}
}
示例2: TestR3
void TestR3()
{
"\n1) Inserting key/value pairs to the database".title();
DBElement<int, string> elem2 = new DBElement<int, string>(); //Add new key/value pairs to the database
elem2.name = "Roger federer";
elem2.descr = "Tennis player";
elem2.timeStamp = DateTime.Now;
elem2.children.AddRange(new List<int> { 3 });
elem2.payload = "Famous tennis player";
db.insert(2, elem2);
DBElement<int, string> elem3 = new DBElement<int, string>();
elem3.name = "Usain Bolt";
elem3.descr = "Athelte";
elem3.timeStamp = DateTime.Now;
elem3.children.AddRange(new List<int> { 1 });
elem3.payload = "Fastest in the world";
db.insert(3, elem3);
DBElement<int, string> elem4 = new DBElement<int, string>();
elem4.name = "Saina Nehwal";
elem4.descr = "Badminton Player";
elem4.timeStamp = DateTime.Now;
elem4.children.AddRange(new List<int> { 2 });
elem4.payload = "Famous badminton player";
db.insert(4, elem4);
db.showDB();
WriteLine();
"\n2) Removing key 4 from the database".title();
db.delete(4);
db.showDB();
WriteLine();
}
示例3: key_value_search
/* Defining a query using lambda function to search specific key
*/
public void key_value_search(DBEngine<int, DBElement<int, string>> db, IQuery<int, DBElement<int, string>> i_query, QueryEngine<int, DBElement<int, string>> qe )
{
"Query for value with specified key (key = 2):".title();
WriteLine();
int key_to_search = 2;
Func<int, string, bool> keyValueSearch = (int key, string search) => //lambda function
{
if (!db.Keys().Contains(key))
return false;
else
{
if (key == int.Parse(search))
{
DBElement<int, string> ele = new DBElement<int, string>();
db.getValue(key, out ele);
return true;
}
else { return false; }
}
};
// pass query to query engine and call simpleQuery to make query on DBEngine
qe.simpleQuery(keyValueSearch, key_to_search.ToString(), out i_query);
WriteLine();
foreach (var key in i_query.Keys())
{
DBElement<int, string> temp = new DBElement<int, string>();
i_query.getValue(key, out temp);
WriteLine("key : {0}", key);
temp.showElement();
WriteLine();
}
}
示例4: TestR2
void TestR2()
{
"Demonstrating Requirement #2".title();
//creating new element of type int and string
DBElement<int, string> element = new DBElement<int, string>();
element.name = "first element of db";
element.descr = "int and string type";
element.timeStamp = DateTime.Now;
element.children.AddRange(new List<int> { 0, 2, 4, 8 });
element.payload = "first element's payload";
element.showElement();
db.insert(1, element);
db.showDB();
WriteLine();
//creating new element of type string and list of strings
DBElement<string, List<string>> element2 = new DBElement<string, List<string>>();
element2.name = "second element of db";
element2.descr = "strings and strings of string types";
element2.timeStamp = DateTime.Now;
element2.children.AddRange(new List<string> { "SMA", "OOD", "Project2" });
element2.payload = new List<string> { "second", "SMA", "project" };
element2.showEnumerableElement();
db2.insert("2", element2);
db2.showEnumerableDB();
WriteLine();
}
示例5: testDBlement
public void testDBlement()
{
Write("\n --- Test DBElement<int,string> ---");
DBElement<int, string> elem1 = new DBElement<int, string>();
elem1.payload = "a payload";
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.AddRange(new List<int> { 1, 5, 23 });
elem3.payload = "X-Wing fighter in swamp - Oh oh!";
Write(elem3.showElement<int, string>());
WriteLine();
Write("\n --- Test DBEngine<int,DBElement<int,string>> ---");
int key = 0;
Func<int> keyGen = () => { ++key; return key; }; // anonymous function to generate keys
DBEngine<int, DBElement<int, string>> db = new DBEngine<int, DBElement<int, string>>();
bool p1 = db.insert(keyGen(), elem1);
bool p2 = db.insert(keyGen(), elem2);
bool p3 = db.insert(keyGen(), elem3);
if (p1 && p2 && p3)
Write("\n all inserts succeeded");
else
Write("\n at least one insert failed");
db.show<int, DBElement<int, string>, string>();
WriteLine();
}
示例6: Server
public Server()
{
elem = new DBElement<int, string>();
strElem = new DBElement<string, List<string>>();
rh = new RequestHandler();
tot = new Hashtable();
}
示例7: TestR2
public void TestR2()
{
"Demonstrating Requirement #2".title('=');
"Database with string as payload".title();
DBElement<int, string> elem = new DBElement<int, string>();
elem.name = "element";
elem.descr = "test element";
elem.timeStamp = DateTime.Now;
elem.children.AddRange(new List<int>{ 1, 2, 3 });
elem.payload = "elem's payload";
elem.showElement();
db.insert(1, elem);
db.showDB();
WriteLine();
"database with list of strings as payload".title();
DBElement<string, List<string>> element = new DBElement<string, List<string>>();
element.name = "element2";
element.descr = "test element for list of strings as value";
element.timeStamp = DateTime.Now;
element.children.AddRange(new List<string> { "one","two"});
element.payload = new List<string> { "element's payload", "2nd payload" };
element.showEnumerableElement();
enum_db.insert("enum_one", element);
enum_db.showEnumerableDB();
WriteLine();
}
示例8: XMLWrite
public void XMLWrite(DBEngine<int, DBElement<int, string>> db, out string pathname)
{
pathname = "xmlDoc.xml";
// The root element is nosqldb or nosqldbLOS, which we can say, is the name
// of the database of the corresponding type. The declaration is important
// from an XML parser point of view.
DBElement<int, string> Val = new DBElement<int, string>();
XDocument doc = new XDocument(new XElement("nosqldb"));
doc.Declaration = new XDeclaration("1.0", "utf - 8", "yes");
XElement keyType = new XElement("keytype", "int");
XElement payloadType = new XElement("payloadtype", "string");
doc.Root.Add(keyType);
doc.Root.Add(payloadType);
foreach (var key in db.Keys())
{
XElement keyNode = new XElement("key", key);
db.getValue(key, out Val);
XElement elementNode = new XElement("element");
elementNode.Add(new XElement("name", Val.name));
elementNode.Add(new XElement("descr", Val.descr));
elementNode.Add(new XElement("timeStamp", Val.timeStamp.ToString()));
XElement childrenNode = new XElement("children"); //since children is List<Key>
foreach (var item in Val.children)
{
childrenNode.Add(new XElement("key", item));
}
elementNode.Add(childrenNode);
elementNode.Add(new XElement("payload", Val.payload)); //since payload is string for this type of database
doc.Root.Add(keyNode);
doc.Root.Add(elementNode);
}
doc.Save(pathname);
}
示例9: TestR3
void TestR3()//addition and deletion of key/value pairs
{
"Demonstrating Requirement #3".title();
WriteLine();
Write("\n --- Test addition of key/value pairs Start---");
WriteLine();
DBElement<int, string> elem1 = new DBElement<int, string>();
elem1.name = "element#1";//add a new key/value pairs
elem1.descr = "test element#1";
elem1.timeStamp = DateTime.Now;
elem1.children.AddRange(new List<int>{ 6, 8 });
elem1.payload = "elem#1's payload";
elem1.showElement();
db.insert(2, elem1);
Write("\n\n Show key/value pairs in data base:\n");
db.showDB();
WriteLine();
Write("\n --- Test addition of key/value pairs End---");
WriteLine();
Write("\n --- Test deletion of key/value pairs Start---");
WriteLine();
db.delete(1);//delete an existing key/value pairs
Write("\n\n Show key/value pairs in data base:\n");
db.showDB();
WriteLine();
db.delete(100);//try to delete a key/value pairs that doesn't exist
Write("\n --- Test deletion of key/value pairs End---");
WriteLine();
}
示例10: Test2
private static void Test2(out DBElement<string, string> newelem1, out DBElement<string, string> newerelem1, out DBElement<string, string> newerelem2)
{
newelem1 = new DBElement<string, string>();
newelem1.name = "newelem1";
newelem1.descr = "test new type";
newelem1.payload = "one";
//Load the second element
newerelem1 = new DBElement<string, string>();
newerelem1.name = "newerelem1";
newerelem1.descr = "better formatting";
newerelem1.payload = "alpha";
//Load the third element
newerelem2 = new DBElement<string, string>();
newerelem2.name = "newerelem2";
newerelem2.descr = "better formatting";
newerelem2.children.AddRange(new List<string> { "first", "second" });
newerelem2.payload = "a";
if (verbose)
{
Write("\n --- Test DBElement<string,List<string>> ---");
WriteLine();
newelem1.showEnumerableElement(); //Display the element
WriteLine();
newerelem1.showEnumerableElement(); //Display the element
WriteLine();
newerelem2.showEnumerableElement();
WriteLine();
}
}
示例11: Main
static void Main(string[] args)
{
WriteLine("Testing DBExtensions Package\n");
WriteLine();
//Insert first element
Write("\n --- Test DBElement<int,string> ---");
DBElement<int, string> elem1 = new DBElement<int, string>();
elem1.payload = "a payload";
Write(elem1.showElement<int, string>());
//Insert first element into DB
DBEngine<int, DBElement<int, string>> dbs = new DBEngine<int, DBElement<int, string>>();
dbs.insert(1, elem1);
dbs.show<int, DBElement<int, string>, string>();
WriteLine();
//Insert first element into String Key/Value DB
Write("\n --- Test DBElement<string,List<string>> ---");
DBElement<string, List<string>> newelem1 = new DBElement<string, List<string>>();
newelem1.name = "newelem1";
newelem1.descr = "test new type";
newelem1.children = new List<string> { "Key1", "Key2" };
newelem1.payload = new List<string> { "one", "two", "three" };
Write(newelem1.showElement<string, List<string>, string>());
DBEngine<string, DBElement<string, List<string>>> dbe = new DBEngine<string, DBElement<string, List<string>>>();
dbe.insert("key1", newelem1);
dbe.show<string, DBElement<string, List<string>>, List<string>, string>();
Write("\n\n");
}
示例12: writeXML
public void writeXML()
{
if(db1.emptyDictionary())
Write("\n\nThe database is empty.\n");
else{//if the dictionary is not empty store key/value pairs into a XML file
DBElement<int, string> temp = new DBElement<int, string>();
IEnumerable<int> keys = db1.Keys();
XDocument xml = new XDocument();
xml.Declaration = new XDeclaration("1.0", "utf-8", "yes");
XElement noSqlDb = new XElement("noSqlDb");
xml.Add(noSqlDb);
XElement keytype = new XElement("keytype", "int");
XElement payloadtype = new XElement("payloadtype", "string");
noSqlDb.Add(keytype);
noSqlDb.Add(payloadtype);
foreach(var i in keys)
{
db1.getValue(2, out temp);
XElement key = new XElement("key", ("key"+i));
noSqlDb.Add(key);//noSqlDb's children
XElement element = new XElement("element");
noSqlDb.Add(element);//noSqlDb's children
XElement name = new XElement("name", temp.name);//name of the element
element.Add(name);
XElement descr = new XElement("descr", temp.descr);//description of the element
element.Add(descr);
XElement timeStamp = new XElement("timeStamp", temp.timeStamp);//timeStamp of the element
element.Add(timeStamp);
if(temp.children.Count!=0)//children of the element
{
XElement children = new XElement("children");
element.Add(children);
foreach(var j in temp.children)
{
XElement childkey = new XElement("key", ("key"+j));
children.Add(childkey);
}
}
XElement payload = new XElement("payload", temp.payload);//payload of the element
element.Add(payload);
}
Console.Write("\n{0}\n", xml.Declaration);
Console.Write(xml.ToString());
Console.Write("\n\n");
xml.Save(@"C:\Users\lxinghe\Downloads\Project2Starter\Test.xml");
db1.emptyDBEngine();//empty DBEngine
}
}
示例13: RequestHandler
public RequestHandler()
{
sb = new StringBuilder();
db = new DBEngine<int, DBElement<int, string>>();
query = new QueryEngine<int, DBElement<int, string>>();
dbString = new DBEngine<string, DBElement<string, List<string>>>();
strElem = new DBElement<string, List<string>>();
}
示例14: writeXML
public void writeXML(string path)
{
if(db1.emptyDictionary())
Write("\n\nThe database is empty.\n");
else{//if the dictionary is not empty store key/value pairs into a XML file
DBElement<int, string> temp = new DBElement<int, string>();
IEnumerable<int> keys = db1.Keys();
xml.Declaration = new XDeclaration("1.0", "utf-8", "yes");
XElement noSqlDb = new XElement("noSqlDb");
xml.Add(noSqlDb);
XElement keytype = new XElement("keytype", "int");
XElement payloadtype = new XElement("payloadtype", "string");
noSqlDb.Add(keytype);
noSqlDb.Add(payloadtype);
foreach(var i in keys)
{
db1.getValue(i, out temp);
XElement key = new XElement("key", ("key"+i));
noSqlDb.Add(key);//noSqlDb's children
XElement element = new XElement("element");
noSqlDb.Add(element);//noSqlDb's children
XElement name = new XElement("name", temp.name);//name of the element
element.Add(name);
XElement descr = new XElement("descr", temp.descr);//description of the element
element.Add(descr);
XElement timeStamp = new XElement("timeStamp", temp.timeStamp);//timeStamp of the element
element.Add(timeStamp);
if(temp.children.Count!=0)//children of the element
{
XElement children = new XElement("children");
element.Add(children);
foreach(var j in temp.children)
{
XElement childkey = new XElement("key", ("key"+j));
children.Add(childkey);
}
}
XElement payload = new XElement("payload", temp.payload);//payload of the element
element.Add(payload);
}
xml.Save(path);
}
}
示例15: EditData
/// <summary>
/// Editing Data while updating.This returns element to be modified
/// </summary>
/// <param name="dbStore"></param>
/// <param name="key"></param>
/// <param name="element"></param>
/// <param name="Operation"></param>
/// <param name="error"></param>
/// <returns></returns>
public bool EditData(ref DBEngine<int, DBElement<int, string>> dbStore, int key, out DBElement<int, string> element, string Operation, out string error)
{
try
{
DBElement<int, string> elem = new DBElement<int, string>();
error = "success"; bool success = true;
success = dbStore.getValue(key, out element);
if (success != true)
{
error = "Key not found in DB";
return false;
}
elem = element;
switch (Operation)
{
case "EditName": //Modify Name
{
element.name = elem.name;
break;
}
case "EditDescription": //Modify Description
{
element.descr = elem.descr;
break;
}
case "EditPayload": //Modify Payload
{
element.payload = elem.payload;
break;
}
case "EditChildren": //Modify Children
{
element.children = new List<int>();
element.children = elem.children;
break;
}
case "EditKeyNotValid": //Key editing is not valid
{
error = "Editing of Key is not allowed";
return false;
}
default:
break;
}
return true;
}
catch (Exception ex)
{
throw new CustomException("error at itemeditor editdata", ex);
}
}