public static BsonDocument ToBsonDocument(this XElement xElement) { var bsonDocument = new BsonDocument(); var type = xElement.Name.ToString(); bsonDocument.Add(Constants._TYPE, type); var mainId = xElement.Attribute(Constants._ID) != null?xElement.Attribute(Constants._ID).Value : null; foreach (XAttribute attribure in xElement.Attributes()) { var key = attribure.Name.ToString(); var value = attribure.Value; if (bsonDocument.Contains(key)) { bsonDocument.Set(key, value); } else { bsonDocument.Add(key, value); } } foreach (XElement kid in xElement.Descendants()) { var id = kid.Attribute(Constants._ID); if (id == null || mainId == null) { bsonDocument.Add(kid.Name.ToString(), kid.ToBsonDocument()); } else { kid.SetAttributeValue(Constants.PARENT_ID, mainId); DBFactory.GetData().Save(kid); } } return(bsonDocument); }
public XElement GetChildren(string parentId) { var kids = new XElement("Children"); var kidsList = DBFactory.GetMemcachedRelationship(parentId); if (kidsList != null && kidsList.Count > 0) { foreach (var directKid in kidsList) { kids.Add(Find(directKid)); } return(kids); } var directKids = GetKids(parentId); foreach (var directKid in directKids) { DBFactory.AddMemcachedRelationship(parentId, directKid); kids.Add(Find(directKid)); } return(kids); }
public static string ExportReulstToHtml(XElement xElement) { var toBeExportdId = xElement.GetAttributeValue(Constants._ID); var tag = xElement.Name.ToString(); if (!tag.Equals(Constants.RESULT) && !tag.Contains("." + Constants.RESULT)) { return(""); } //this is a result node var name = xElement.GetAttributeValue(Constants.NAME); var origianl = xElement.GetAttributeValue("Original"); var final = xElement.GetAttributeValue("Final"); if (String.IsNullOrEmpty(final)) { final = " "; } var created = xElement.GetAttributeValue("Created"); var updated = xElement.GetAttributeValue("Updated"); var authors = xElement.GetAttributeValue("Authors"); var maturity = xElement.GetAttributeValue("Maturity"); if (!string.IsNullOrEmpty(maturity)) { maturity = "<span>  Maturity : </span><span>" + maturity + "</span>"; } var descriptionAttrValue = xElement.GetAttributeValue("Description"); var description = ""; if (!string.IsNullOrEmpty(descriptionAttrValue)) { var descriptionList = descriptionAttrValue.Split('\n'); description = descriptionList.Aggregate(description, (current, block) => current + ("<span>" + block + "</span><br>")); } var color = final.Equals("Success") ? "GREEN" : "RED"; var ret = "<li><span title=\"Start:" + created + "
End:" + updated + "\" onclick=\"ShowOrUnShow(this)\"> " + name + " </span> <span title=\"Original:" + origianl + "
Final:" + final + "\" style=\"color:" + color + "\" > " + final + " </span><ul style=\"display:none\"><span>Authors: " + authors + "</span>" + maturity + "<br><span>Description: " + description + "</span>"; var children = DBFactory.GetData().GetChildren(toBeExportdId); var kidTag = children.Descendants().First().Name.ToString(); if (kidTag.Equals(Constants.RESULT) || kidTag.Contains("." + Constants.RESULT)) { ret = children.Descendants().Aggregate(ret, (current, kid) => current + ExportReulstToHtml(kid)); } else { //add table header ret += "<table cellspacing=\"0\" cellpadding=\"1\" border=\"1\" width=\"100%\"><thead><tr id=\"headingrow\">" + "<th nowrap=\"nowrap\" >Action </th>" + "<th nowrap=\"nowrap\" >UI Object </th>" + "<th nowrap=\"nowrap\" >Data </th>" + "<th nowrap=\"nowrap\" >Result </th>" + "<th nowrap=\"nowrap\" >Duration </th>" + "<th nowrap=\"nowrap\" >Reason </th>" + "</tr></thead><tbody>"; foreach (var kid in children.Descendants()) { ret += "<tr>"; var action = kid.GetAttributeValue("Action"); var uiobject = kid.GetAttributeValue("UIObject"); var data = kid.GetAttributeValue("Data"); var result = kid.GetAttributeValue("Result"); var duration = kid.GetAttributeValue("Duration"); var reason = kid.GetAttributeValue("Reason"); if (String.IsNullOrEmpty(reason)) { reason = "  "; } var snapshot = kid.GetAttributeValue("Link"); var starttime = kid.GetAttributeValue("StartTime"); var endtime = kid.GetAttributeValue("EndTime"); var id = kid.GetAttributeValue("_id"); var uiid = kid.GetAttributeValue("UIId"); var colour = result.Equals("Success") ? "GREEN" : "RED"; ret += "<td title=\"" + id + "\">" + action + "</td>"; ret += "<td title=\"" + uiid + "\">" + uiobject + "</td>"; ret += "<td>" + data + "</td>"; ret += "<td align=\"center\" style=\"color:" + colour + "\">" + result.ToUpper() + "</td>"; ret += "<td align=\"right\" title=\"Start At:" + starttime + "
End At:" + endtime + "\">" + duration + "</td>"; if (!string.IsNullOrEmpty(snapshot)) { ret += "<td><a href=\"#\" onclick=\"javascript:popUpWindow(this)\" snapshot=\"" + snapshot + "\">" + reason + "</a></td>"; } else { ret += "<td>" + reason + "</td>"; } ret += "</tr>"; } //add table footer ret += "</tbody></table>"; } return(ret + "</ul></li>"); }