// hack to fix the xsd creation long names (where each name contains all element names up to it (which makes it very hard to read) /* private void fixXsdNodeNameIssue(TreeNodeCollection tncTargetNodeCollection, String sParentText) * { * if (tncTargetNodeCollection != null) * foreach (TreeNode tnNode in tncTargetNodeCollection) * { * // DI.log.info(tnNode.Text); * //if (tnNode.Parent != null && tnNode.Parent.Parent != null) * if (sParentText != "") * { * // String sParentText = tnNode.Parent.Text.Substring(0,tnNode.Parent.Parent.Text).Trim(); * tnNode.Text = tnNode.Text.Replace(sParentText, ""); * //if (tnNode.Parent.Parent != null) * // tnNode.Text = tnNode.Text.Replace(tnNode.Parent.Parent.Text, "...parentParent..."); * } * if (tnNode.Parent != null && (tnNode.Parent.Parent != null)) * { * int iIndexOfBracket = tnNode.Parent.Parent.Text.IndexOf('('); * if (iIndexOfBracket > -1) * sParentText = tnNode.Parent.Parent.Text.Substring(0, iIndexOfBracket).Trim(); * else * sParentText = tnNode.Parent.Text; * // .Substring(0, tnNode.Parent.Parent.Text).Trim(); * } * / * if (tnNode.Parent != null) * { * int iIndexOfBracket = tnNode.Parent.Text.IndexOf('('); * if (iIndexOfBracket > -1) * sParentText = tnNode.Parent.Text.Substring(0,iIndexOfBracket).Trim(); * else * sParentText = tnNode.Parent.Text; * }* / * // tnNode.ExpandAll(); * fixXsdNodeNameIssue(tnNode.Nodes, sParentText); * } * } */ // recursive method to load objects in nodes public void loadObjectInTreeNodeCollection(Object oObjectToLoad, String sNodeName, String sParentNodeName, String sParentParentNodeName, TreeNodeCollection tncTargetNodeCollection, UInt32 uRecursiveLevel, addMode amAddMode) { UInt32 uMaxArrayRecordsToFetch = uDefaultMaxArrayRecordsToFetch; if (null != oObjectToLoad && // there is nothing to load 0 < uRecursiveLevel--) // don't continue recursion { switch (oObjectToLoad.GetType().Name) { //all these basic types can be processed in the same since the .ToString() correctly gets the value case "String": case "Int32": case "Int64": case "UInt32": case "UInt64": case "Byte": case "Boolean": const int iStringImageType = 2; TreeNode tnNewNodeForObject = getNewNode(sNodeName + " = " + oObjectToLoad, "", iStringImageType, null); if (null != tnNewNodeForObject) { tncTargetNodeCollection.Add(tnNewNodeForObject); } break; default: { switch (amAddMode) { case addMode.ObjectValue: // means we are loading the value of the current object Int32 iObjectImageType = 0; // 'class' icon if (oObjectToLoad.GetType().IsArray) // if it is an array, dont' show it if it doesn't have any items { iObjectImageType = 1; // 'array' icon int iCount = ((Object[])oObjectToLoad).Length; if (iCount > uMaxArrayRecordsToFetch) { DI.log.error( "The number of items in the {0}[{1}] array is bigger than the current uMaxArrayRecordsToFetch: {2}", oObjectToLoad.GetType().Name, iCount, uMaxArrayRecordsToFetch); } if (iCount == 0) { break; } } // get the name of the node and if it not set, get its value from the type name String sNewNodeName = sNodeName; if (sNewNodeName == "") { sNewNodeName = oObjectToLoad.GetType().Name; } if (sNewNodeName == "CommonIRDumpCommonIRClassMethodsClassMemberFunctionVariable") { } DI.log.info("{0} - {1} - {2} ", sNewNodeName, sParentNodeName, sParentParentNodeName); if (sParentParentNodeName != "") { sNewNodeName = sNewNodeName.Replace(sParentParentNodeName, ""); } // remove parent's parent name to make it easier to read (XML Serialization objects have their parents in their name) if (sParentNodeName != "") { sNewNodeName = sNewNodeName.Replace(sParentNodeName, ""); } // remove parent name to make it easier to read (XML Serialization objects have their parents in their name) // give the user a visual representation of how many subnodes exist in this node sNewNodeName += getNumberOfSubNodes(oObjectToLoad); // create a new node for this objects's data (puting the object valuer in the new TreeNode's Tag) TreeNode tnNewNode = getNewNode(sNewNodeName, oObjectToLoad.GetType().Name, iObjectImageType, oObjectToLoad); if (tnNewNode != null) { // add it to the current tncTargetNodeCollection tncTargetNodeCollection.Add(tnNewNode); // move the tncTargetNodeCollection pointer to the new node tncTargetNodeCollection = tnNewNode.Nodes; } // and call addObjectPropertiesToTreeNodeCollection to add this node's properties (the iRecursiveLevel controls as sub nodes (uRecursiveLevel controls how deep this one goes) addObjectPropertiesToTreeNodeCollection(oObjectToLoad, tncTargetNodeCollection, uRecursiveLevel, sParentNodeName); break; case addMode.ObjectProperties: // we are loading the object's properties (which are usually the Xml attributes Elements if (oObjectToLoad.GetType().IsArray) // if it is an array we need to add all items { foreach (Object oObjectInArray in (Object[])oObjectToLoad) { if (0 == uMaxArrayRecordsToFetch--) // until we reach our limit { break; } else // invoke loadObjectInTreeNodeCollection recursively (note how now we use addMode.ObjectValue since we only want to add this node) { // loadObjectInTreeNodeCollection(oObjectInArray, "", oObjectToLoad.GetType().Name,sParentNodeName, tncTargetNodeCollection, uRecursiveLevel, addMode.ObjectValue); loadObjectInTreeNodeCollection(oObjectInArray, "", sParentNodeName, sParentParentNodeName, tncTargetNodeCollection, uRecursiveLevel, addMode.ObjectValue); } } } else { // if it is not an array let's add all its properties to teh current TreeNode Collection addObjectPropertiesToTreeNodeCollection(oObjectToLoad, tncTargetNodeCollection, uRecursiveLevel, sParentNodeName); } break; } } break; } } }
// hack to fix the xsd creation long names (where each name contains all element names up to it (which makes it very hard to read) /* private void fixXsdNodeNameIssue(TreeNodeCollection tncTargetNodeCollection, String sParentText) { if (tncTargetNodeCollection != null) foreach (TreeNode tnNode in tncTargetNodeCollection) { // DI.log.info(tnNode.Text); //if (tnNode.Parent != null && tnNode.Parent.Parent != null) if (sParentText != "") { // String sParentText = tnNode.Parent.Text.Substring(0,tnNode.Parent.Parent.Text).Trim(); tnNode.Text = tnNode.Text.Replace(sParentText, ""); //if (tnNode.Parent.Parent != null) // tnNode.Text = tnNode.Text.Replace(tnNode.Parent.Parent.Text, "...parentParent..."); } if (tnNode.Parent != null && (tnNode.Parent.Parent != null)) { int iIndexOfBracket = tnNode.Parent.Parent.Text.IndexOf('('); if (iIndexOfBracket > -1) sParentText = tnNode.Parent.Parent.Text.Substring(0, iIndexOfBracket).Trim(); else sParentText = tnNode.Parent.Text; // .Substring(0, tnNode.Parent.Parent.Text).Trim(); } / * if (tnNode.Parent != null) { int iIndexOfBracket = tnNode.Parent.Text.IndexOf('('); if (iIndexOfBracket > -1) sParentText = tnNode.Parent.Text.Substring(0,iIndexOfBracket).Trim(); else sParentText = tnNode.Parent.Text; }* / // tnNode.ExpandAll(); fixXsdNodeNameIssue(tnNode.Nodes, sParentText); } } */ // recursive method to load objects in nodes public void loadObjectInTreeNodeCollection(Object oObjectToLoad, String sNodeName, String sParentNodeName, String sParentParentNodeName, TreeNodeCollection tncTargetNodeCollection, UInt32 uRecursiveLevel, addMode amAddMode) { UInt32 uMaxArrayRecordsToFetch = uDefaultMaxArrayRecordsToFetch; if (null != oObjectToLoad && // there is nothing to load 0 < uRecursiveLevel--) // don't continue recursion { switch (oObjectToLoad.GetType().Name) { //all these basic types can be processed in the same since the .ToString() correctly gets the value case "String": case "Int32": case "Int64": case "UInt32": case "UInt64": case "Byte": case "Boolean": const int iStringImageType = 2; TreeNode tnNewNodeForObject = getNewNode(sNodeName + " = " + oObjectToLoad, "", iStringImageType, null); if (null != tnNewNodeForObject) tncTargetNodeCollection.Add(tnNewNodeForObject); break; default: { switch (amAddMode) { case addMode.ObjectValue: // means we are loading the value of the current object Int32 iObjectImageType = 0; // 'class' icon if (oObjectToLoad.GetType().IsArray) // if it is an array, dont' show it if it doesn't have any items { iObjectImageType = 1; // 'array' icon int iCount = ((Object[]) oObjectToLoad).Length; if (iCount > uMaxArrayRecordsToFetch) DI.log.error( "The number of items in the {0}[{1}] array is bigger than the current uMaxArrayRecordsToFetch: {2}", oObjectToLoad.GetType().Name, iCount, uMaxArrayRecordsToFetch); if (iCount == 0) break; } // get the name of the node and if it not set, get its value from the type name String sNewNodeName = sNodeName; if (sNewNodeName == "") { sNewNodeName = oObjectToLoad.GetType().Name; } if (sNewNodeName == "CommonIRDumpCommonIRClassMethodsClassMemberFunctionVariable") { } DI.log.info("{0} - {1} - {2} ", sNewNodeName, sParentNodeName, sParentParentNodeName); if (sParentParentNodeName != "") sNewNodeName = sNewNodeName.Replace(sParentParentNodeName, ""); // remove parent's parent name to make it easier to read (XML Serialization objects have their parents in their name) if (sParentNodeName != "") sNewNodeName = sNewNodeName.Replace(sParentNodeName, ""); // remove parent name to make it easier to read (XML Serialization objects have their parents in their name) // give the user a visual representation of how many subnodes exist in this node sNewNodeName += getNumberOfSubNodes(oObjectToLoad); // create a new node for this objects's data (puting the object valuer in the new TreeNode's Tag) TreeNode tnNewNode = getNewNode(sNewNodeName, oObjectToLoad.GetType().Name, iObjectImageType, oObjectToLoad); if (tnNewNode != null) { // add it to the current tncTargetNodeCollection tncTargetNodeCollection.Add(tnNewNode); // move the tncTargetNodeCollection pointer to the new node tncTargetNodeCollection = tnNewNode.Nodes; } // and call addObjectPropertiesToTreeNodeCollection to add this node's properties (the iRecursiveLevel controls as sub nodes (uRecursiveLevel controls how deep this one goes) addObjectPropertiesToTreeNodeCollection(oObjectToLoad, tncTargetNodeCollection, uRecursiveLevel, sParentNodeName); break; case addMode.ObjectProperties: // we are loading the object's properties (which are usually the Xml attributes Elements if (oObjectToLoad.GetType().IsArray) // if it is an array we need to add all items { foreach (Object oObjectInArray in (Object[]) oObjectToLoad) if (0 == uMaxArrayRecordsToFetch--) // until we reach our limit break; else // invoke loadObjectInTreeNodeCollection recursively (note how now we use addMode.ObjectValue since we only want to add this node) { // loadObjectInTreeNodeCollection(oObjectInArray, "", oObjectToLoad.GetType().Name,sParentNodeName, tncTargetNodeCollection, uRecursiveLevel, addMode.ObjectValue); loadObjectInTreeNodeCollection(oObjectInArray, "", sParentNodeName, sParentParentNodeName, tncTargetNodeCollection, uRecursiveLevel, addMode.ObjectValue); } } else // if it is not an array let's add all its properties to teh current TreeNode Collection addObjectPropertiesToTreeNodeCollection(oObjectToLoad, tncTargetNodeCollection, uRecursiveLevel, sParentNodeName); break; } } break; } } }