private List <object> ExecuteCommand(bool stringOutput, bool marshallResults = true) { var jobManager = TypeResolver.ResolveFromCache <IJobManager>(); var job = jobManager.GetContextJob(); JobName = job?.Name; if (stringOutput) { powerShell.Commands.AddCommand(OutDefaultCommand); } if (Runspace.DefaultRunspace == null) { Runspace.DefaultRunspace = host.Runspace; } if (Debugging) { host.Runspace.Debugger.DebuggerStop += DebuggerOnDebuggerStop; host.Runspace.Debugger.BreakpointUpdated += DebuggerOnBreakpointUpdated; SetVariable("SpeDebug", true); if (Interactive) { var message = Message.Parse(this, "ise:debugstart"); SendUiMessage(message); } } else { Engine.SessionState.PSVariable.Remove("SpeDebug"); } abortRequested = false; LastErrors?.Clear(); // execute the commands in the pipeline now var execResults = powerShell.Invoke(); if (powerShell.HadErrors) { LastErrors = powerShell.Streams.Error.ToList(); } LogErrors(powerShell, execResults); if (Interactive && Debugging) { host.Runspace.Debugger.DebuggerStop -= DebuggerOnDebuggerStop; host.Runspace.Debugger.BreakpointUpdated -= DebuggerOnBreakpointUpdated; var message = Message.Parse(this, "ise:debugend"); SendUiMessage(message); Debugging = false; } JobName = string.Empty; return(marshallResults ? execResults?.Select(p => p?.BaseObject).ToList() : execResults?.Cast <object>().ToList()); }
private List <object> ExecuteCommand(bool stringOutput, bool marshallResults = true) { JobName = Context.Job?.Name; if (stringOutput) { powerShell.Commands.AddCommand(OutDefaultCommand); } if (Runspace.DefaultRunspace == null) { Runspace.DefaultRunspace = host.Runspace; } if (Debugging) { host.Runspace.Debugger.DebuggerStop += DebuggerOnDebuggerStop; host.Runspace.Debugger.BreakpointUpdated += DebuggerOnBreakpointUpdated; SetVariable("SpeDebug", true); if (Interactive) { var message = Message.Parse(this, "ise:debugstart"); SendUiMessage(message); } } else { Engine.SessionState.PSVariable.Remove("SpeDebug"); } abortRequested = false; LastErrors?.Clear(); // execute the commands in the pipeline now var execResults = powerShell.Invoke(); if (powerShell.HadErrors) { LastErrors = powerShell.Streams.Error.ToList(); } if (execResults != null && execResults.Any()) { foreach (var record in execResults.Where(r => r != null).Select(p => p.BaseObject).OfType <ErrorRecord>()) { LogUtils.Debug(record + record.InvocationInfo.PositionMessage, this); } } if (Interactive && Debugging) { host.Runspace.Debugger.DebuggerStop -= DebuggerOnDebuggerStop; host.Runspace.Debugger.BreakpointUpdated -= DebuggerOnBreakpointUpdated; var message = Message.Parse(this, "ise:debugend"); SendUiMessage(message); Debugging = false; } JobName = string.Empty; return(marshallResults ? execResults?.Select(p => p?.BaseObject).ToList() : execResults?.Cast <object>().ToList()); }