src/System.Management.Automation/help/GeneralHelpProvider.cs
/// <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. 
/// </remarks>
/// <param name="helpFile"></param>
Load help file for HelpInfo objects. The HelpInfo objects will be
put into help cache.
Load help file for HelpInfo objects . The HelpInfo objects will be put into help cache .
private void LoadHelpFile(string helpFile)
        {
            if (String.IsNullOrEmpty(helpFile))
            {
                return;
            }
            XmlDocument doc;
            try
            {
                doc = InternalDeserializer.LoadUnsafeXmlDocument(
                    new FileInfo(helpFile),
                    false, 
                    null); 
            }
            catch (IOException ioException)
            {
                ErrorRecord errorRecord = new ErrorRecord(ioException, "HelpFileLoadFailure", ErrorCategory.OpenError, null);
                errorRecord.ErrorDetails = new ErrorDetails(typeof(GeneralHelpProvider).GetTypeInfo().Assembly, "HelpErrors", "HelpFileLoadFailure", helpFile, ioException.Message);
                this.HelpSystem.LastErrors.Add(errorRecord);
                return;
            }
            catch (System.Security.SecurityException securityException)
            {
                ErrorRecord errorRecord = new ErrorRecord(securityException, "HelpFileNotAccessible", ErrorCategory.OpenError, null);
                errorRecord.ErrorDetails = new ErrorDetails(typeof(GeneralHelpProvider).GetTypeInfo().Assembly, "HelpErrors", "HelpFileNotAccessible", helpFile, securityException.Message);
                this.HelpSystem.LastErrors.Add(errorRecord);
                return;
            }
            catch (XmlException xmlException)
            {
                ErrorRecord errorRecord = new ErrorRecord(xmlException, "HelpFileNotValid", ErrorCategory.SyntaxError, null);
                errorRecord.ErrorDetails = new ErrorDetails(typeof(GeneralHelpProvider).GetTypeInfo().Assembly, "HelpErrors", "HelpFileNotValid", helpFile, xmlException.Message);
                this.HelpSystem.LastErrors.Add(errorRecord);
                return;
            }
            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.Compare(node.Name, "conceptuals", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        helpItemsNode = node;
                        break;
                    }
                }
            }
            if (helpItemsNode == null)
                return;
            using (this.HelpSystem.Trace(helpFile))
            {
                if (helpItemsNode.HasChildNodes)
                {
                    for (int i = 0; i < helpItemsNode.ChildNodes.Count; i++)
                    {
                        XmlNode node = helpItemsNode.ChildNodes[i];
                        if (node.NodeType == XmlNodeType.Element && String.Compare(node.Name, "conceptual", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            HelpInfo helpInfo = null;
                            helpInfo = GeneralHelpInfo.Load(node);
                            if (helpInfo != null)
                            {
                                this.HelpSystem.TraceErrors(helpInfo.Errors);
                                AddCache(helpInfo.Name, helpInfo);
                            }
                        }
                    }
                }
            }
        }
private void LoadHelpFile ( string helpFile ) { if ( String . IsNullOrEmpty ( helpFile ) ) { return ; } XmlDocument doc ; try { doc = InternalDeserializer . LoadUnsafeXmlDocument ( new FileInfo ( helpFile ) , false , null ) ; } catch ( IOException ioException ) { ErrorRecord errorRecord = new ErrorRecord ( ioException , " " , ErrorCategory . OpenError , null ) ; errorRecord . ErrorDetails = new ErrorDetails ( typeof ( GeneralHelpProvider ) . GetTypeInfo ( ) . Assembly , " " , " " , helpFile , ioException . Message ) ; this . HelpSystem . LastErrors . Add ( errorRecord ) ; return ; } catch ( System . Security . SecurityException securityException ) { ErrorRecord errorRecord = new ErrorRecord ( securityException , " " , ErrorCategory . OpenError , null ) ; errorRecord . ErrorDetails = new ErrorDetails ( typeof ( GeneralHelpProvider ) . GetTypeInfo ( ) . Assembly , " " , " " , helpFile , securityException . Message ) ; this . HelpSystem . LastErrors . Add ( errorRecord ) ; return ; } catch ( XmlException xmlException ) { ErrorRecord errorRecord = new ErrorRecord ( xmlException , " " , ErrorCategory . SyntaxError , null ) ; errorRecord . ErrorDetails = new ErrorDetails ( typeof ( GeneralHelpProvider ) . GetTypeInfo ( ) . Assembly , " " , " " , helpFile , xmlException . Message ) ; this . HelpSystem . LastErrors . Add ( errorRecord ) ; return ; } 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 . Compare ( node . Name , " " , StringComparison . OrdinalIgnoreCase ) == 0 ) { helpItemsNode = node ; break ; } } } if ( helpItemsNode == null ) return ; using ( this . HelpSystem . Trace ( helpFile ) ) { if ( helpItemsNode . HasChildNodes ) { for ( int i = 0 ; i < helpItemsNode . ChildNodes . Count ; i ++ ) { XmlNode node = helpItemsNode . ChildNodes [ i ] ; if ( node . NodeType == XmlNodeType . Element && String . Compare ( node . Name , " " , StringComparison . OrdinalIgnoreCase ) == 0 ) { HelpInfo helpInfo = null ; helpInfo = GeneralHelpInfo . Load ( node ) ; if ( helpInfo != null ) { this . HelpSystem . TraceErrors ( helpInfo . Errors ) ; AddCache ( helpInfo . Name , helpInfo ) ; } } } } } }
Load help file for HelpInfo objects.
Load help file for HelpInfo objects .
/* ignore whitespace, comments, etc. */ /* default maxCharactersInDocument */
helpFile
string
None
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.
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 .