public void RemoveDocumentationForHiddenNodes() { ZeroTouchModule module = new ZeroTouchModule("ProtoGeometry.dll"); XmlDocumentationsUtility.RemoveDocumentationForHiddenNodes("ProtoGeometry.xml", module); XmlDocument xmlTestFile = new XmlDocument(); xmlTestFile.Load("ProtoGeometry.xml"); XmlNodeList elemTestList = xmlTestFile.GetElementsByTagName("member"); for(int i= 0;i<elemTestList.Count;i++) { var memberElement = XmlDocumentationsUtility.ParseMemberElement(elemTestList[i].Attributes["name"].Value); switch (memberElement.type) { case XmlDocumentationsUtility.Type.Field: case XmlDocumentationsUtility.Type.Property: Assert.IsTrue(module.PropertyExists(memberElement.TypeName, memberElement.MemberName)); break; case XmlDocumentationsUtility.Type.Method: Assert.IsTrue(module.MethodExists(memberElement.TypeName, memberElement.MemberName)); break; case XmlDocumentationsUtility.Type.Type: Assert.IsTrue(module.TypeExists(memberElement.TypeName)) ; break; default: break; } } }
/// <summary> /// iterates through member nodes inside the given xml file, /// and remove the node if it's hidden. /// If there's no member nodes/ all of the member nodes have been removed, /// the files is deleted /// </summary> /// <param name="xmlPath"></param> /// <param name="zeroTouchModule"></param> internal static void RemoveDocumentationForHiddenNodes(string xmlPath,ZeroTouchModule zeroTouchModule) { XmlDocument xml = new XmlDocument(); xml.Load(xmlPath); XmlNodeList elemList = xml.GetElementsByTagName("member"); MemberData memberData; for (int i = 0; i < elemList.Count; i++) { string elementName = elemList[i].Attributes["name"].Value; bool hasToBeRemoved = false; memberData = ParseMemberElement(elementName); if (zeroTouchModule == null) { if (memberData.TypeName.Contains("Properties.Resources")) hasToBeRemoved = true; } else { switch (memberData.type) { case Type.Field: case Type.Property: if (!zeroTouchModule.PropertyExists(memberData.TypeName, memberData.MemberName)) hasToBeRemoved = true; break; case Type.Method: if (!zeroTouchModule.MethodExists(memberData.TypeName, memberData.MemberName)) hasToBeRemoved = true; break; case Type.Type: if (!zeroTouchModule.TypeExists(memberData.TypeName)) hasToBeRemoved = true; break; default: break; } } if (hasToBeRemoved) { elemList[i].ParentNode.RemoveChild(elemList[i]); i--; } } //save the update xml.Save(xmlPath); //node is empty, delete the xml file if (elemList.Count == 0) File.Delete(xmlPath); }
public void SetUp() { module = new ZeroTouchModule("ProtoGeometry.dll"); }
/// <summary> /// recursively search for xml files inside en-US folder /// to remove hidden nodes inside xml. /// only en-US needs to be iterated since other language resources /// is derived from the en-US resources /// </summary> /// <param name="searchDirectory"></param> private static void RecursiveCultureXmlSearch(string searchDirectory) { foreach (string directory in Directory.GetDirectories(searchDirectory)) { DirectoryInfo dirInfo = new DirectoryInfo(directory); if(dirInfo.Name == "en-US") { string[] xmlFiles = Directory.GetFiles(directory, "*.xml"); foreach (string xmlPath in xmlFiles) { string xmlName = Path.GetFileNameWithoutExtension(xmlPath); string dllPath = Path.Combine(Path.GetDirectoryName(xmlPath), @"..\", string.Format("{0}.dll", xmlName)); if (!File.Exists(dllPath)) continue; string path = Path.GetFullPath(dllPath); ZeroTouchModule zeroTouchModule = null; try { zeroTouchModule = new ZeroTouchModule(path); } catch(System.Exception e) { Console.WriteLine("Cannot load the ZeroTouchModule dll\n" +"Only Properties.Resources will be removed for this xml documentation\n" + e.Message); } RemoveDocumentationForHiddenNodes(Path.GetFullPath(xmlPath), zeroTouchModule); } } RecursiveCultureXmlSearch(directory); } }