Пример #1
0
        /// <summary>
        /// Implements the ProcessRecord() method for get-help command.
        /// </summary>
        protected override void ProcessRecord()
        {
            HelpSystem helpSystem = this.Context.HelpSystem;

            try
            {
#if !UNIX
                if (this.ShowWindow)
                {
                    this.graphicalHostReflectionWrapper = GraphicalHostReflectionWrapper.GetGraphicalHostReflectionWrapper(this, "Microsoft.PowerShell.Commands.Internal.HelpWindowHelper");
                }
#endif
                helpSystem.OnProgress += new HelpSystem.HelpProgressHandler(HelpSystem_OnProgress);

                bool         failed       = false;
                HelpCategory helpCategory = ToHelpCategory(Category, ref failed);

                if (failed)
                {
                    return;
                }

                // Validate input parameters
                ValidateAndThrowIfError(helpCategory);

                HelpRequest helpRequest = new HelpRequest(this.Name, helpCategory);

                helpRequest.Provider        = _provider;
                helpRequest.Component       = Component;
                helpRequest.Role            = Role;
                helpRequest.Functionality   = Functionality;
                helpRequest.ProviderContext = new ProviderContext(
                    this.Path,
                    this.Context.Engine.Context,
                    this.SessionState.Path);
                helpRequest.CommandOrigin = this.MyInvocation.CommandOrigin;

                // the idea is to use yield statement in the help lookup to speed up
                // perceived user experience....So HelpSystem.GetHelp returns an
                // IEnumerable..
                IEnumerable <HelpInfo> helpInfos = helpSystem.GetHelp(helpRequest);
                // HelpCommand acts differently when there is just one help object and when
                // there are more than one object...so handling this behavior through
                // some variables.
                HelpInfo firstHelpInfoObject = null;
                int      countOfHelpInfos    = 0;
                foreach (HelpInfo helpInfo in helpInfos)
                {
                    // honor Ctrl-C from user.
                    if (IsStopping)
                    {
                        return;
                    }

                    if (0 == countOfHelpInfos)
                    {
                        firstHelpInfoObject = helpInfo;
                    }
                    else
                    {
                        // write first help object only once.
                        if (firstHelpInfoObject != null)
                        {
                            WriteObjectsOrShowOnlineHelp(firstHelpInfoObject, false);
                            firstHelpInfoObject = null;
                        }

                        WriteObjectsOrShowOnlineHelp(helpInfo, false);
                    }

                    countOfHelpInfos++;
                }

                _timer.Stop();

#if LEGACYTELEMETRY
                if (!string.IsNullOrEmpty(Name))
                {
                    Microsoft.PowerShell.Telemetry.Internal.TelemetryAPI.ReportGetHelpTelemetry(Name, countOfHelpInfos, _timer.ElapsedMilliseconds, _updatedHelp);
                }
#endif
                // Write full help as there is only one help info object
                if (1 == countOfHelpInfos)
                {
                    WriteObjectsOrShowOnlineHelp(firstHelpInfoObject, true);
                }
                else if (_showOnlineHelp && (countOfHelpInfos > 1))
                {
                    throw PSTraceSource.NewInvalidOperationException(HelpErrors.MultipleOnlineTopicsNotSupported, "Online");
                }

                // show errors only if there is no wildcard search or VerboseHelpErrors is true.
                if (((countOfHelpInfos == 0) && (!WildcardPattern.ContainsWildcardCharacters(helpRequest.Target))) ||
                    helpSystem.VerboseHelpErrors)
                {
                    // Check if there is any error happened. If yes,
                    // pipe out errors.
                    if (helpSystem.LastErrors.Count > 0)
                    {
                        foreach (ErrorRecord errorRecord in helpSystem.LastErrors)
                        {
                            WriteError(errorRecord);
                        }
                    }
                }
            }
            finally
            {
                helpSystem.OnProgress -= new HelpSystem.HelpProgressHandler(HelpSystem_OnProgress);
                HelpSystem_OnComplete();

                // finally clear the ScriptBlockAst -> Token[] cache
                helpSystem.ClearScriptBlockTokenCache();
            }
        }
Пример #2
0
 internal ColumnInfo(string staleObjectPropertyName, string displayName)
 {
     this.displayName             = displayName;
     this.staleObjectPropertyName = GraphicalHostReflectionWrapper.EscapeBinding(staleObjectPropertyName);
 }
Пример #3
0
 internal ShowCommandProxy(ShowCommandCommand cmdlet)
 {
     _cmdlet = cmdlet;
     _graphicalHostReflectionWrapper = GraphicalHostReflectionWrapper.GetGraphicalHostReflectionWrapper(cmdlet, ShowCommandProxy.ShowCommandHelperName);
 }
Пример #4
0
 protected override void ProcessRecord()
 {
     try
     {
         if (this.ShowWindow != 0)
         {
             this.graphicalHostReflectionWrapper = GraphicalHostReflectionWrapper.GetGraphicalHostReflectionWrapper(this, "Microsoft.PowerShell.Commands.Internal.HelpWindowHelper");
         }
         base.Context.HelpSystem.OnProgress += new HelpSystem.HelpProgressHandler(this.HelpSystem_OnProgress);
         bool         failed = false;
         HelpCategory cat    = this.ToHelpCategory(this._category, ref failed);
         if (!failed)
         {
             this.ValidateAndThrowIfError(cat);
             HelpRequest helpRequest = new HelpRequest(this.Name, cat)
             {
                 Provider        = this._provider,
                 Component       = this._component,
                 Role            = this._role,
                 Functionality   = this._functionality,
                 ProviderContext = new ProviderContext(this.Path, base.Context.Engine.Context, base.SessionState.Path),
                 CommandOrigin   = base.MyInvocation.CommandOrigin
             };
             IEnumerable <HelpInfo> help = base.Context.HelpSystem.GetHelp(helpRequest);
             HelpInfo helpInfo           = null;
             int      num = 0;
             foreach (HelpInfo info2 in help)
             {
                 if (base.IsStopping)
                 {
                     return;
                 }
                 if (num == 0)
                 {
                     helpInfo = info2;
                 }
                 else
                 {
                     if (helpInfo != null)
                     {
                         this.WriteObjectsOrShowOnlineHelp(helpInfo, false);
                         helpInfo = null;
                     }
                     this.WriteObjectsOrShowOnlineHelp(info2, false);
                 }
                 num++;
             }
             if (1 == num)
             {
                 this.WriteObjectsOrShowOnlineHelp(helpInfo, true);
             }
             else if (this.showOnlineHelp && (num > 1))
             {
                 throw PSTraceSource.NewInvalidOperationException("HelpErrors", "MultipleOnlineTopicsNotSupported", new object[] { "Online" });
             }
             if ((((num == 0) && !WildcardPattern.ContainsWildcardCharacters(helpRequest.Target)) || base.Context.HelpSystem.VerboseHelpErrors) && (base.Context.HelpSystem.LastErrors.Count > 0))
             {
                 foreach (ErrorRecord record in base.Context.HelpSystem.LastErrors)
                 {
                     base.WriteError(record);
                 }
             }
         }
     }
     finally
     {
         base.Context.HelpSystem.OnProgress -= new HelpSystem.HelpProgressHandler(this.HelpSystem_OnProgress);
         base.Context.HelpSystem.ClearScriptBlockTokenCache();
     }
 }