public async Task <IEnumerable <BreakpointDetails> > SetBreakpointsAsync(string escapedScriptPath, IEnumerable <BreakpointDetails> breakpoints)
        {
            if (BreakpointApiUtils.SupportsBreakpointApis)
            {
                foreach (BreakpointDetails breakpointDetails in breakpoints)
                {
                    try
                    {
                        BreakpointApiUtils.SetBreakpoint(_powerShellContextService.CurrentRunspace.Runspace.Debugger, breakpointDetails, _debugStateService.RunspaceId);
                    }
                    catch (InvalidOperationException e)
                    {
                        breakpointDetails.Message  = e.Message;
                        breakpointDetails.Verified = false;
                    }
                }

                return(breakpoints);
            }

            // Legacy behavior
            PSCommand psCommand = null;
            List <BreakpointDetails> configuredBreakpoints = new List <BreakpointDetails>();

            foreach (BreakpointDetails breakpoint in breakpoints)
            {
                ScriptBlock actionScriptBlock = null;

                // Check if this is a "conditional" line breakpoint.
                if (!string.IsNullOrWhiteSpace(breakpoint.Condition) ||
                    !string.IsNullOrWhiteSpace(breakpoint.HitCondition) ||
                    !string.IsNullOrWhiteSpace(breakpoint.LogMessage))
                {
                    actionScriptBlock = BreakpointApiUtils.GetBreakpointActionScriptBlock(
                        breakpoint.Condition,
                        breakpoint.HitCondition,
                        breakpoint.LogMessage,
                        out string errorMessage);

                    if (!string.IsNullOrEmpty(errorMessage))
                    {
                        breakpoint.Verified = false;
                        breakpoint.Message  = errorMessage;
                        configuredBreakpoints.Add(breakpoint);
                        continue;
                    }
                }

                // On first iteration psCommand will be null, every subsequent
                // iteration will need to start a new statement.
                if (psCommand == null)
                {
                    psCommand = new PSCommand();
                }
                else
                {
                    psCommand.AddStatement();
                }

                psCommand
                .AddCommand(@"Microsoft.PowerShell.Utility\Set-PSBreakpoint")
                .AddParameter("Script", escapedScriptPath)
                .AddParameter("Line", breakpoint.LineNumber);

                // Check if the user has specified the column number for the breakpoint.
                if (breakpoint.ColumnNumber.HasValue && breakpoint.ColumnNumber.Value > 0)
                {
                    // It bums me out that PowerShell will silently ignore a breakpoint
                    // where either the line or the column is invalid.  I'd rather have an
                    // error or warning message I could relay back to the client.
                    psCommand.AddParameter("Column", breakpoint.ColumnNumber.Value);
                }

                if (actionScriptBlock != null)
                {
                    psCommand.AddParameter("Action", actionScriptBlock);
                }
            }

            // If no PSCommand was created then there are no breakpoints to set.
            if (psCommand != null)
            {
                IEnumerable <Breakpoint> setBreakpoints =
                    await _powerShellContextService.ExecuteCommandAsync <Breakpoint>(psCommand);

                configuredBreakpoints.AddRange(
                    setBreakpoints.Select(BreakpointDetails.Create));
            }

            return(configuredBreakpoints);
        }
        public async Task <IEnumerable <CommandBreakpointDetails> > SetCommandBreakpoints(IEnumerable <CommandBreakpointDetails> breakpoints)
        {
            if (BreakpointApiUtils.SupportsBreakpointApis)
            {
                foreach (CommandBreakpointDetails commandBreakpointDetails in breakpoints)
                {
                    try
                    {
                        BreakpointApiUtils.SetBreakpoint(_powerShellContextService.CurrentRunspace.Runspace.Debugger, commandBreakpointDetails, _debugStateService.RunspaceId);
                    }
                    catch (InvalidOperationException e)
                    {
                        commandBreakpointDetails.Message  = e.Message;
                        commandBreakpointDetails.Verified = false;
                    }
                }

                return(breakpoints);
            }

            // Legacy behavior
            PSCommand psCommand = null;
            List <CommandBreakpointDetails> configuredBreakpoints = new List <CommandBreakpointDetails>();

            foreach (CommandBreakpointDetails breakpoint in breakpoints)
            {
                // On first iteration psCommand will be null, every subsequent
                // iteration will need to start a new statement.
                if (psCommand == null)
                {
                    psCommand = new PSCommand();
                }
                else
                {
                    psCommand.AddStatement();
                }

                psCommand
                .AddCommand(@"Microsoft.PowerShell.Utility\Set-PSBreakpoint")
                .AddParameter("Command", breakpoint.Name);

                // Check if this is a "conditional" line breakpoint.
                if (!string.IsNullOrWhiteSpace(breakpoint.Condition) ||
                    !string.IsNullOrWhiteSpace(breakpoint.HitCondition))
                {
                    ScriptBlock actionScriptBlock =
                        BreakpointApiUtils.GetBreakpointActionScriptBlock(
                            breakpoint.Condition,
                            breakpoint.HitCondition,
                            logMessage: null,
                            out string errorMessage);

                    // If there was a problem with the condition string,
                    // move onto the next breakpoint.
                    if (!string.IsNullOrEmpty(errorMessage))
                    {
                        breakpoint.Verified = false;
                        breakpoint.Message  = errorMessage;
                        configuredBreakpoints.Add(breakpoint);
                        continue;
                    }

                    psCommand.AddParameter("Action", actionScriptBlock);
                }
            }

            // If no PSCommand was created then there are no breakpoints to set.
            if (psCommand != null)
            {
                IEnumerable <Breakpoint> setBreakpoints =
                    await _powerShellContextService.ExecuteCommandAsync <Breakpoint>(psCommand);

                configuredBreakpoints.AddRange(
                    setBreakpoints.Select(CommandBreakpointDetails.Create));
            }

            return(configuredBreakpoints);
        }