예제 #1
0
        protected override void EndProcessing()
        {
            if (this._multipleIdProvided)
            {
                Exception exception = new ArgumentException(StringUtil.Format(HistoryStrings.InvokeHistoryMultipleCommandsError, new object[0]));
                base.ThrowTerminatingError(new ErrorRecord(exception, "InvokeHistoryMultipleCommandsError", ErrorCategory.InvalidArgument, null));
            }
            History       history = ((LocalRunspace)base.Context.CurrentRunspace).History;
            HistoryInfo   historyEntryToInvoke     = this.GetHistoryEntryToInvoke(history);
            LocalPipeline currentlyRunningPipeline = (LocalPipeline)((LocalRunspace)base.Context.CurrentRunspace).GetCurrentlyRunningPipeline();

            if (!currentlyRunningPipeline.PresentInInvokeHistoryEntryList(historyEntryToInvoke))
            {
                currentlyRunningPipeline.AddToInvokeHistoryEntryList(historyEntryToInvoke);
            }
            else
            {
                Exception exception2 = new InvalidOperationException(StringUtil.Format(HistoryStrings.InvokeHistoryLoopDetected, new object[0]));
                base.ThrowTerminatingError(new ErrorRecord(exception2, "InvokeHistoryLoopDetected", ErrorCategory.InvalidOperation, null));
            }
            this.ReplaceHistoryString(historyEntryToInvoke);
            string commandLine = historyEntryToInvoke.CommandLine;

            if (base.ShouldProcess(commandLine))
            {
                try
                {
                    base.Host.UI.WriteLine(commandLine);
                }
                catch (HostException)
                {
                }
                Collection <PSObject> sendToPipeline = base.InvokeCommand.InvokeScript(commandLine, false, PipelineResultTypes.Warning, null, null);
                if (sendToPipeline.Count > 0)
                {
                    base.WriteObject(sendToPipeline, true);
                }
                currentlyRunningPipeline.RemoveFromInvokeHistoryEntryList(historyEntryToInvoke);
            }
        }
예제 #2
0
 protected override void EndProcessing()
 {
     using (InvokeHistoryCommand._trace.TraceMethod())
     {
         if (this._multipleIdProvided)
         {
             this.ThrowTerminatingError(new ErrorRecord((Exception) new ArgumentException(ResourceManagerCache.FormatResourceString("History", "InvokeHistoryMultipleCommandsError")), "InvokeHistoryMultipleCommandsError", ErrorCategory.InvalidArgument, (object)null));
         }
         HistoryInfo   historyEntryToInvoke     = this.GetHistoryEntryToInvoke(((LocalRunspace)this.Context.CurrentRunspace).History);
         LocalPipeline currentlyRunningPipeline = (LocalPipeline)this.Context.CurrentRunspace.GetCurrentlyRunningPipeline();
         if (!currentlyRunningPipeline.PresentInInvokeHistoryEntryList(historyEntryToInvoke))
         {
             currentlyRunningPipeline.AddToInvokeHistoryEntryList(historyEntryToInvoke);
         }
         else
         {
             this.ThrowTerminatingError(new ErrorRecord((Exception) new InvalidOperationException(ResourceManagerCache.FormatResourceString("History", "InvokeHistoryLoopDetected")), "InvokeHistoryLoopDetected", ErrorCategory.InvalidOperation, (object)null));
         }
         this.ReplaceHistoryString(historyEntryToInvoke);
         string commandLine = historyEntryToInvoke.CommandLine;
         if (!this.ShouldProcess(commandLine))
         {
             return;
         }
         try
         {
             this.Host.UI.WriteLine(commandLine);
         }
         catch (HostException ex)
         {
         }
         Collection <PSObject> collection = this.InvokeCommand.InvokeScript(commandLine, false, PipelineResultTypes.Output | PipelineResultTypes.Error, (IList)null, (object[])null);
         if (collection.Count > 0)
         {
             this.WriteObject((object)collection, true);
         }
         currentlyRunningPipeline.RemoveFromInvokeHistoryEntryList(historyEntryToInvoke);
     }
 }