/// <summary> /// Clone the help object with a new category. /// </summary> /// <param name="newCategoryToUse"></param> /// <returns>MamlClassHelpInfo.</returns> internal MamlClassHelpInfo Copy(HelpCategory newCategoryToUse) { MamlClassHelpInfo result = new MamlClassHelpInfo(_fullHelpObject.Copy(), newCategoryToUse); result.FullHelp.Properties["Category"].Value = newCategoryToUse; return(result); }
/// <summary> /// Create a MamlClassHelpInfo object from an XmlNode. /// </summary> /// <param name="xmlNode">xmlNode that contains help info</param> /// <param name="helpCategory">help category this maml object fits into</param> /// <returns>MamlCommandHelpInfo object created</returns> internal static MamlClassHelpInfo Load(XmlNode xmlNode, HelpCategory helpCategory) { MamlClassHelpInfo mamlClassHelpInfo = new MamlClassHelpInfo(xmlNode, helpCategory); if (String.IsNullOrEmpty(mamlClassHelpInfo.Name)) return null; mamlClassHelpInfo.AddCommonHelpProperties(); return mamlClassHelpInfo; }
/// <summary> /// Create a MamlClassHelpInfo object from an XmlNode. /// </summary> /// <param name="xmlNode">XmlNode that contains help info.</param> /// <param name="helpCategory">Help category this maml object fits into.</param> /// <returns>MamlCommandHelpInfo object created.</returns> internal static MamlClassHelpInfo Load(XmlNode xmlNode, HelpCategory helpCategory) { MamlClassHelpInfo mamlClassHelpInfo = new MamlClassHelpInfo(xmlNode, helpCategory); if (string.IsNullOrEmpty(mamlClassHelpInfo.Name)) { return(null); } mamlClassHelpInfo.AddCommonHelpProperties(); return(mamlClassHelpInfo); }
/// <summary> /// Gets the HelpInfo object corresponding to the command. /// </summary> /// <param name="helpFileIdentifier">Help file identifier (either name of PSSnapIn or simply full path to help file).</param> /// <param name="helpCategory">Help Category for search.</param> /// <returns>HelpInfo object.</returns> private HelpInfo GetFromPSClassHelpCache(string helpFileIdentifier, HelpCategory helpCategory) { Debug.Assert(!string.IsNullOrEmpty(helpFileIdentifier), "helpFileIdentifier should not be null or empty."); HelpInfo result = GetCache(helpFileIdentifier); if (result != null) { MamlClassHelpInfo original = (MamlClassHelpInfo)result; result = original.Copy(helpCategory); } return(result); }
/// <summary> /// Load help file for HelpInfo objects. The HelpInfo objects will be /// put into help cache. /// </summary> /// <remarks> /// 1. Needs to pay special attention about error handling in this function. /// Common errors include: file not found and invalid xml. None of these error /// should cause help search to stop. /// 2. a helpfile cache is used to avoid same file got loaded again and again. /// </remarks> private void LoadHelpFile(string helpFile, string helpFileIdentifier) { Dbg.Assert(!string.IsNullOrEmpty(helpFile), "HelpFile cannot be null or empty."); Dbg.Assert(!string.IsNullOrEmpty(helpFileIdentifier), "helpFileIdentifier cannot be null or empty."); XmlDocument doc = InternalDeserializer.LoadUnsafeXmlDocument( new FileInfo(helpFile), false, /* ignore whitespace, comments, etc. */ null); /* default maxCharactersInDocument */ // Add this file into _helpFiles hashtable to prevent it to be loaded again. _helpFiles[helpFile] = 0; XmlNode helpItemsNode = null; if (doc.HasChildNodes) { for (int i = 0; i < doc.ChildNodes.Count; i++) { XmlNode node = doc.ChildNodes[i]; if (node.NodeType == XmlNodeType.Element && string.Equals(node.LocalName, "helpItems", StringComparison.OrdinalIgnoreCase)) { helpItemsNode = node; break; } } } if (helpItemsNode == null) { s_tracer.WriteLine("Unable to find 'helpItems' element in file {0}", helpFile); return; } bool isMaml = IsMamlHelp(helpFile, helpItemsNode); using (this.HelpSystem.Trace(helpFile)) { if (helpItemsNode.HasChildNodes) { for (int i = 0; i < helpItemsNode.ChildNodes.Count; i++) { XmlNode node = helpItemsNode.ChildNodes[i]; string nodeLocalName = node.LocalName; bool isClass = (string.Equals(nodeLocalName, "class", StringComparison.OrdinalIgnoreCase)); if (node.NodeType == XmlNodeType.Element && isClass) { MamlClassHelpInfo helpInfo = null; if (isMaml) { if (isClass) { helpInfo = MamlClassHelpInfo.Load(node, HelpCategory.Class); } } if (helpInfo != null) { this.HelpSystem.TraceErrors(helpInfo.Errors); AddCache(helpFileIdentifier, helpInfo); } } } } } }
/// <summary> /// Clone the help info object. /// </summary> /// <returns>MamlClassHelpInfo object.</returns> internal MamlClassHelpInfo Copy() { MamlClassHelpInfo result = new MamlClassHelpInfo(_fullHelpObject.Copy(), this.HelpCategory); return(result); }
/// <summary> /// Clone the help object with a new category. /// </summary> /// <param name="newCategoryToUse"></param> /// <returns>MamlClassHelpInfo</returns> internal MamlClassHelpInfo Copy(HelpCategory newCategoryToUse) { MamlClassHelpInfo result = new MamlClassHelpInfo(_fullHelpObject.Copy(), newCategoryToUse); result.FullHelp.Properties["Category"].Value = newCategoryToUse; return result; }
/// <summary> /// Clone the help info object. /// </summary> /// <returns>MamlClassHelpInfo object.</returns> internal MamlClassHelpInfo Copy() { MamlClassHelpInfo result = new MamlClassHelpInfo(_fullHelpObject.Copy(), this.HelpCategory); return result; }