/// <summary> /// Assign values to the attributes of the report, from the instance passed as parameter. /// </summary> /// <param name="nodeProperties">XmlNode to be filled. It contains tha empty attributes.</param> /// <param name="Instance">Instance object that contains the values for the attributes.</param> /// <param name="Cloning">If True: the returned node is a new one (cloned from original). False: the returned node is the same, but modified.</param> /// <param name="attPos">Attributes value positions in the DataRow, keyed by the Attribute name.</param> /// <returns>A XmlNode, that can be a new one or a modified one.</returns> private static XmlNode SetValueOfNodeAttributeFromInstance(XmlNode nodeProperties, DataRow Instance, bool Cloning, Dictionary<string, int> attPos) { XmlNode nodeProp = null; if (nodeProperties != null) { if (Cloning) nodeProp = nodeProperties.Clone(); else nodeProp = nodeProperties; XmlNode[] aNodes = XMLQuery.SelectNodes(nodeProp ,"Attribute",false); int numReportAttr = aNodes.Length; for (int It = 0; It < numReportAttr; It++) { string Name = aNodes[It].Attributes["Name"].Value; XmlAttribute att = aNodes[It].OwnerDocument.CreateAttribute("Value"); if (Instance.ItemArray[attPos[Name]] == null) att.Value = ""; else att.Value = Instance.ItemArray[attPos[Name]].ToString(); aNodes[It].Attributes.Append(att); } } return nodeProp; }
private static void ProcessRoles(XmlNode nodeProperties, Oid oid) { XmlNode[] aRoles = XMLQuery.SelectRoles(nodeProperties,false); if (aRoles != null) { //Process existing roles for (int It=0; It<aRoles.Length; It++) { ProcessRole(aRoles[It],oid); } } }
void ExecuteMethod(XMLQuery finalObj) { BaseObject baseObject; ObjectManager.GetObject(finalObj.objectName, out baseObject); if (baseObject != null) { baseObject.SendMessage(finalObj.methodName, new CommandContext() { parameters = finalObj.parameters.ToArray() }); } //Debug.Log(finalObj.methodName + " / " + string.Join(", ", finalObj.parameters.ToArray())); }
/// <summary> /// Get the result after executing the queries of the report. /// </summary> /// <param name="oid">Root OID of the report.</param> /// <param name="nodeReport"></param> /// <returns>A XmlNode object with the XML result of the queries.</returns> public static XmlNode GetQueryXML(Oid oid, XmlNode nodeReport) { XmlNode nodeObject = null; XmlNode nodeRpt = null; if ((nodeReport != null) && (oid != null)) { XmlNode nodeOIDProperties = null; nodeObject= XMLQuery.SelectObject(nodeReport, true); //Process OID nodeOIDProperties = XMLQuery.SelectProperties(nodeObject, false); DataTable rootInstance = Logics.Logic.ExecuteQueryInstance(Logics.Logic.Agent, oid, XMLQuery.DisplaySetFromNodeProperties(nodeOIDProperties)); Dictionary<string, int> columNames = new Dictionary<string, int>(); int i = 0; foreach (DataColumn column in rootInstance.Columns) { columNames.Add(column.Caption, i); i++; } SetValueOfNodeAttributeFromInstance(nodeOIDProperties, rootInstance.Rows[0], false, columNames); // Assing value to OID field. XmlNode nodeOID = XMLQuery.SelectOID(nodeObject, false); for(int it=0; it < oid.Fields.Count; it++) { nodeOID.ChildNodes[it].Attributes["Value", string.Empty].Value = oid.GetValues()[it].ToString(); } //Process Roles ProcessRoles(nodeOIDProperties, oid); //Create the root node, representing the report nodeRpt = nodeObject.OwnerDocument.CreateElement("Report"); //Insert object in the root node nodeRpt.AppendChild(nodeObject); } return nodeRpt; }
bool FindMethod(XMLQuery obj) { if (obj.xmlPath.Count == 0) { nav.MoveToRoot(); nav.MoveToFirstChild(); } if (nav.HasChildren) { if (obj.commandWords.Length >= obj.progressionIndex) { int childCount = nav.SelectChildren(XPathNodeType.All).Count; nav.MoveToFirstChild(); for (int i = 0; i < childCount; i++) { if (nav.GetAttribute("name", string.Empty) != "") { string name = nav.GetAttribute("name", string.Empty); //special case if (name.Equals("system")) { obj.objectName = "system"; obj.xmlPath.Add(nav.Name); if (FindMethod(obj)) { return(true); } else { obj.xmlPath.Remove(nav.Name); obj.objectName = ""; } } if (name.Equals("player")) { obj.objectName = "player"; obj.xmlPath.Add(nav.Name); if (FindMethod(obj)) { return(true); } else { obj.xmlPath.Remove(nav.Name); obj.objectName = ""; } } if (obj.commandWords[obj.progressionIndex].StartsWith(name)) { obj.objectName = obj.commandWords[obj.progressionIndex]; obj.xmlPath.Add(nav.Name); obj.progressionIndex++; FindMethod(obj); return(true); } } else if (nav.GetAttribute("synonyms", string.Empty) != "") { string[] synonyms = nav.GetAttribute("synonyms", string.Empty).Split(' '); foreach (string synonym in synonyms) { if (synonym == obj.commandWords[obj.progressionIndex]) { obj.xmlPath.Add(nav.Name); obj.progressionIndex++; FindMethod(obj); return(true); } } } else if (nav.Name[0] == '_') { obj.xmlPath.Add(nav.Name); if (obj.commandWords.Length > obj.progressionIndex) { if (obj.commandWords[obj.progressionIndex] != null) { obj.parameters.Add(obj.commandWords[obj.progressionIndex]); obj.progressionIndex++; FindMethod(obj); return(true); } } else if (obj.xmlPath[obj.xmlPath.Count - 1] == "_amount") { obj.parameters.Add("1"); FindMethod(obj); return(true); } } else if (nav.Name == "method") { obj.xmlPath.Add(nav.Name); obj.progressionIndex++; obj.methodName = nav.Value; ExecuteMethod(obj); return(true); } nav.MoveToNext(); } } else { /////////////DEFAULT } } else { Debug.Log("XML has no child nodes at level: " + nav.Name); } nav.MoveToParent(); return(false); }
private static void ProcessRole(XmlNode nodeRole, Oid oid) { //Add <List.Object> node as a child of nodeRole DataTable rspRole; //Get related instances from Role string ClasOfRole = ""; try { ClasOfRole = nodeRole.Attributes.GetNamedItem("Class.Name").Value; } catch (Exception e) { string errorMsg = "Role class name not found.\r\nPlease check the template"; throw new Exception(errorMsg, e); } string InvRole = ""; try { InvRole = nodeRole.Attributes.GetNamedItem("InvRole.Name").Value; } catch (Exception e) { string errorMsg = "Inverse role name for class name '" + ClasOfRole + "' not found.\r\nPlease check the template"; throw new Exception(errorMsg, e); } string DisplaySet = ""; try { DisplaySet = XMLQuery.DisplaySetFromNodeProperties( XMLQuery.SelectProperties(nodeRole, false)); } catch (Exception e) { string errorMsg = "Display set for class name '" + ClasOfRole + "' not found.\r\nPlease check the template"; throw new Exception(errorMsg, e); } // Add the info about the related object Dictionary<string, Oid> linkItems = new Dictionary<string,Oid>(StringComparer.CurrentCultureIgnoreCase); linkItems.Add(InvRole, oid); try { rspRole = Logics.Logic.Adaptor.ExecuteQueryRelated( Logics.Logic.Agent, ClasOfRole, linkItems, DisplaySet, "", null, 0); } catch (Exception e) { string errorMsg = "Error in Query related. For class name '" + ClasOfRole + "', Inverse rol name '" + InvRole + "' and DisplaySet '" + DisplaySet + "'.\r\nPlease check the template"; throw new Exception(errorMsg, e); } //Get the properties from Properties node XmlNode nodeRoleProperties = XMLQuery.SelectProperties(nodeRole, true); //Create a List.Object node XmlNode lstObject = nodeRole.OwnerDocument.CreateElement("List.Object"); // Get the Column names Dictionary<string, int> columNames = new Dictionary<string, int>(); int i = 0; foreach (DataColumn column in rspRole.Columns) { columNames.Add(column.Caption, i); i++; } //For each instance --> Add the OID and the attributes for (int ItInst = 0; ItInst < rspRole.Rows.Count; ItInst++) { XmlNode nodeObject = nodeRole.OwnerDocument.CreateElement("Object"); //Create a copy and add the attributes, then insert it in the <Object> node XmlNode nodeObjectOID = CreateOIDNodeFromResponse(nodeObject.OwnerDocument, Adaptor.ServerConnection.GetOid(rspRole, rspRole.Rows[ItInst])); nodeObject.AppendChild(nodeObjectOID); //Create a copy and add the properties XmlNode nodeObjectProperties = SetValueOfNodeAttributeFromInstance(nodeRoleProperties, rspRole.Rows[ItInst], true, columNames); nodeObject.AppendChild(nodeObjectProperties); //Process sub-roles ProcessRoles(nodeObjectProperties, Adaptor.ServerConnection.GetOid(rspRole, rspRole.Rows[ItInst])); //Add the <Object> node in <List.Object> node lstObject.AppendChild(nodeObject); } nodeRole.AppendChild(lstObject); }