Exemple #1
0
        public Task Start(List <KeyValuePair <string, object> > inputParameters)
        {
            IsActiveDebugging = true;

            if (_cachedScriptPath == null)
            {
                CacheRunbook();
            }

            var scriptFile        = _editorSession.Workspace.GetFile(_cachedScriptPath);
            var breakpointDetails = _breakpoints.Select(breakpoint => BreakpointDetails.Create("", breakpoint.Line + 2)).ToArray();

            // Set the breakpoints
            return(_editorSession.DebugService
                   .SetLineBreakpoints(scriptFile, breakpointDetails)
                   .ContinueWith(
                       (t) =>
            {
                // Debug the script
                _editorSession.PowerShellContext
                .ExecuteScriptAtPath(_cachedScriptPath)
                .ContinueWith(
                    (t2) =>
                {
                    if (_cachedScriptPath != null)
                    {
                        File.Delete(_cachedScriptPath);
                        _cachedScriptPath = null;
                    }

                    IsActiveDebugging = false;
                    DebuggerFinished?.Invoke(this, new EventArgs());
                });
            }));
        }
Exemple #2
0
        public void Stop()
        {
            _editorSession.DebugService.Abort();
            IsActiveDebugging = false;

            _debuggerExecutionTask = null;

            DebuggerFinished?.Invoke(this, new EventArgs());
        }
Exemple #3
0
        public async Task Start(List <KeyValuePair <string, object> > inputParameters)
        {
            IsActiveDebugging = true;

            if (_cachedScriptPath == null)
            {
                CacheRunbook();
            }

            // Set the breakpoints
            var command = new PSCommand();

            if (_setBreakpoints != null)
            {
                command.AddCommand(@"Microsoft.PowerShell.Utility\Get-PSBreakpoint");
                command.AddCommand(@"Microsoft.PowerShell.Utility\Remove-PSBreakpoint");

                await ExecuteCommand <object>(command);

                command.Clear();
            }

            if (_breakpoints.Count > 0)
            {
                foreach (var bp in _breakpoints)
                {
                    command.AddCommand("Set-PSBreakpoint")
                    .AddParameter("Script", _cachedScriptPath)
                    .AddParameter("Line", bp.Line + 2);
                }
            }

            if (command.Commands.Count > 0)
            {
                _setBreakpoints = await ExecuteCommand <Breakpoint>(command);

                command.Clear();
            }

            var inputArgs = string.Empty;

            foreach (var input in inputParameters)
            {
                if (input.Key.StartsWith("-"))
                {
                    inputArgs += " " + input.Key;
                }
                else
                {
                    inputArgs += " -" + input.Key;
                }

                if (input.Value is string)
                {
                    inputArgs += " \"" + input.Value + "\"";
                }
                else if (input.Value is bool)
                {
                    if (((bool)input.Value) == true)
                    {
                        inputArgs += " $true";
                    }
                    else
                    {
                        inputArgs += " $false";
                    }
                }
                else
                {
                    inputArgs += " " + input.Value;
                }
            }

            command.AddScript(_cachedScriptPath + inputArgs);
            await ExecuteCommand <object>(command, true);

            if (_cachedScriptPath != null)
            {
                File.Delete(_cachedScriptPath);
                _cachedScriptPath = null;
            }

            IsActiveDebugging = false;
            DebuggerFinished?.Invoke(this, new EventArgs());

            Stop();
        }