private async Task FetchStackFrames()
        {
            PSCommand psCommand = new PSCommand();

            psCommand.AddCommand("Get-PSCallStack");

            var results = await this.powerShellContext.ExecuteCommand <CallStackFrame>(psCommand);

            var callStackFrames = results.ToArray();

            this.stackFrameDetails = new StackFrameDetails[callStackFrames.Length];

            for (int i = 0; i < callStackFrames.Length; i++)
            {
                VariableContainerDetails autoVariables =
                    new VariableContainerDetails(
                        this.nextVariableId++,
                        VariableContainerDetails.AutoVariablesName);

                this.variables.Add(autoVariables);

                VariableContainerDetails localVariables =
                    await FetchVariableContainer(i.ToString(), autoVariables);

                this.stackFrameDetails[i] =
                    StackFrameDetails.Create(callStackFrames[i], autoVariables, localVariables);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an instance of the StackFrameDetails class from a
        /// CallStackFrame instance provided by the PowerShell engine.
        /// </summary>
        /// <param name="callStackFrameObject">
        /// A PSObject representing the CallStackFrame instance from which details will be obtained.
        /// </param>
        /// <param name="autoVariables">
        /// A variable container with all the filtered, auto variables for this stack frame.
        /// </param>
        /// <param name="localVariables">
        /// A variable container with all the local variables for this stack frame.
        /// </param>
        /// <param name="workspaceRootPath">
        /// Specifies the path to the root of an open workspace, if one is open. This path is used to
        /// determine whether individua stack frames are external to the workspace.
        /// </param>
        /// <returns>A new instance of the StackFrameDetails class.</returns>
        static internal StackFrameDetails Create(
            PSObject callStackFrameObject,
            VariableContainerDetails autoVariables,
            VariableContainerDetails localVariables,
            string workspaceRootPath = null)
        {
            string moduleId   = string.Empty;
            var    isExternal = false;

            var    invocationInfo  = callStackFrameObject.Properties["InvocationInfo"]?.Value as InvocationInfo;
            string scriptPath      = (callStackFrameObject.Properties["ScriptName"].Value as string) ?? NoFileScriptPath;
            int    startLineNumber = (int)(callStackFrameObject.Properties["ScriptLineNumber"].Value ?? 0);

            // TODO: RKH 2019-03-07 Temporarily disable "external" code until I have a chance to add
            // settings to control this feature.
            //if (workspaceRootPath != null &&
            //    invocationInfo != null &&
            //    !scriptPath.StartsWith(workspaceRootPath, StringComparison.OrdinalIgnoreCase))
            //{
            //    isExternal = true;
            //}

            return(new StackFrameDetails
            {
                ScriptPath = scriptPath,
                FunctionName = callStackFrameObject.Properties["FunctionName"].Value as string,
                StartLineNumber = startLineNumber,
                EndLineNumber = startLineNumber, // End line number isn't given in PowerShell stack frames
                StartColumnNumber = 0,           // Column number isn't given in PowerShell stack frames
                EndColumnNumber = 0,
                AutoVariables = autoVariables,
                LocalVariables = localVariables,
                IsExternalCode = isExternal
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates an instance of the StackFrameDetails class from a
        /// CallStackFrame instance provided by the PowerShell engine.
        /// </summary>
        /// <param name="callStackFrameObject">
        /// A PSObject representing the CallStackFrame instance from which details will be obtained.
        /// </param>
        /// <param name="autoVariables">
        /// A variable container with all the filtered, auto variables for this stack frame.
        /// </param>
        /// <param name="localVariables">
        /// A variable container with all the local variables for this stack frame.
        /// </param>
        /// <param name="workspaceRootPath">
        /// Specifies the path to the root of an open workspace, if one is open. This path is used to
        /// determine whether individua stack frames are external to the workspace.
        /// </param>
        /// <returns>A new instance of the StackFrameDetails class.</returns>
        static internal StackFrameDetails Create(
            PSObject callStackFrameObject,
            VariableContainerDetails autoVariables,
            VariableContainerDetails localVariables,
            string workspaceRootPath = null)
        {
            string moduleId   = string.Empty;
            var    isExternal = false;

            var    invocationInfo  = callStackFrameObject.Properties["InvocationInfo"]?.Value as InvocationInfo;
            string scriptPath      = (callStackFrameObject.Properties["ScriptName"].Value as string) ?? NoFileScriptPath;
            int    startLineNumber = (int)(callStackFrameObject.Properties["ScriptLineNumber"].Value ?? 0);

            if (workspaceRootPath != null &&
                invocationInfo != null &&
                !scriptPath.StartsWith(workspaceRootPath, StringComparison.OrdinalIgnoreCase))
            {
                isExternal = true;
            }

            return(new StackFrameDetails
            {
                ScriptPath = scriptPath,
                FunctionName = callStackFrameObject.Properties["FunctionName"].Value as string,
                StartLineNumber = startLineNumber,
                EndLineNumber = startLineNumber, // End line number isn't given in PowerShell stack frames
                StartColumnNumber = 0,           // Column number isn't given in PowerShell stack frames
                EndColumnNumber = 0,
                AutoVariables = autoVariables,
                LocalVariables = localVariables,
                IsExternalCode = isExternal
            });
        }
        private async Task FetchGlobalAndScriptVariables()
        {
            // Retrieve globals first as script variable retrieval needs to search globals.
            this.globalScopeVariables =
                await FetchVariableContainer(VariableContainerDetails.GlobalScopeName, null);

            this.scriptScopeVariables =
                await FetchVariableContainer(VariableContainerDetails.ScriptScopeName, null);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates an instance of the StackFrameDetails class from a
 /// CallStackFrame instance provided by the PowerShell engine.
 /// </summary>
 /// <param name="callStackFrame">
 /// The original CallStackFrame instance from which details will be obtained.
 /// </param>
 /// <param name="autoVariables">
 /// A variable container with all the filtered, auto variables for this stack frame.
 /// </param>
 /// <param name="localVariables">
 /// A variable container with all the local variables for this stack frame.
 /// </param>
 /// <returns>A new instance of the StackFrameDetails class.</returns>
 static internal StackFrameDetails Create(
     CallStackFrame callStackFrame,
     VariableContainerDetails autoVariables,
     VariableContainerDetails localVariables)
 {
     return(new StackFrameDetails
     {
         ScriptPath = callStackFrame.ScriptName ?? "<No File>",
         FunctionName = callStackFrame.FunctionName,
         LineNumber = callStackFrame.Position.StartLineNumber,
         ColumnNumber = callStackFrame.Position.StartColumnNumber,
         AutoVariables = autoVariables,
         LocalVariables = localVariables
     });
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates an instance of the StackFrameDetails class from a
 /// CallStackFrame instance provided by the PowerShell engine.
 /// </summary>
 /// <param name="callStackFrameObject">
 /// A PSObject representing the CallStackFrame instance from which details will be obtained.
 /// </param>
 /// <param name="autoVariables">
 /// A variable container with all the filtered, auto variables for this stack frame.
 /// </param>
 /// <param name="localVariables">
 /// A variable container with all the local variables for this stack frame.
 /// </param>
 /// <returns>A new instance of the StackFrameDetails class.</returns>
 static internal StackFrameDetails Create(
     PSObject callStackFrameObject,
     VariableContainerDetails autoVariables,
     VariableContainerDetails localVariables)
 {
     return(new StackFrameDetails
     {
         ScriptPath = (callStackFrameObject.Properties["ScriptName"].Value as string) ?? NoFileScriptPath,
         FunctionName = callStackFrameObject.Properties["FunctionName"].Value as string,
         LineNumber = (int)(callStackFrameObject.Properties["ScriptLineNumber"].Value ?? 0),
         ColumnNumber = 0,   // Column number isn't given in PowerShell stack frames
         AutoVariables = autoVariables,
         LocalVariables = localVariables
     });
 }
 /// <summary>
 /// Creates an instance of the StackFrameDetails class from a
 /// CallStackFrame instance provided by the PowerShell engine.
 /// </summary>
 /// <param name="callStackFrame">
 /// The original CallStackFrame instance from which details will be obtained.
 /// </param>
 /// <param name="autoVariables">
 /// A variable container with all the filtered, auto variables for this stack frame.
 /// </param>
 /// <param name="localVariables">
 /// A variable container with all the local variables for this stack frame.
 /// </param>
 /// <returns>A new instance of the StackFrameDetails class.</returns>
 static internal StackFrameDetails Create(
     CallStackFrame callStackFrame,
     VariableContainerDetails autoVariables,
     VariableContainerDetails localVariables)
 {
     return new StackFrameDetails
     {
         ScriptPath = callStackFrame.ScriptName,
         FunctionName = callStackFrame.FunctionName,
         LineNumber = callStackFrame.Position.StartLineNumber,
         ColumnNumber = callStackFrame.Position.StartColumnNumber,
         AutoVariables = autoVariables,
         LocalVariables = localVariables
     };
 }
        private async Task <VariableContainerDetails> FetchVariableContainer(
            string scope,
            VariableContainerDetails autoVariables)
        {
            PSCommand psCommand = new PSCommand();

            psCommand.AddCommand("Get-Variable");
            psCommand.AddParameter("Scope", scope);

            var scopeVariableContainer =
                new VariableContainerDetails(this.nextVariableId++, "Scope: " + scope);

            this.variables.Add(scopeVariableContainer);

            var results = await this.powerShellContext.ExecuteCommand <PSVariable>(psCommand, sendErrorToHost : false);

            if (results != null)
            {
                foreach (PSVariable psvariable in results)
                {
                    var variableDetails = new VariableDetails(psvariable)
                    {
                        Id = this.nextVariableId++
                    };
                    this.variables.Add(variableDetails);
                    scopeVariableContainer.Children.Add(variableDetails.Name, variableDetails);

                    if ((autoVariables != null) && AddToAutoVariables(psvariable, scope))
                    {
                        autoVariables.Children.Add(variableDetails.Name, variableDetails);
                    }
                }
            }

            return(scopeVariableContainer);
        }
        private async Task FetchStackFrames()
        {
            PSCommand psCommand = new PSCommand();
            psCommand.AddCommand("Get-PSCallStack");

            var results = await this.powerShellContext.ExecuteCommand<CallStackFrame>(psCommand);

            var callStackFrames = results.ToArray();
            this.stackFrameDetails = new StackFrameDetails[callStackFrames.Length];

            for (int i = 0; i < callStackFrames.Length; i++)
            {
                VariableContainerDetails autoVariables =
                    new VariableContainerDetails(
                        this.nextVariableId++, 
                        VariableContainerDetails.AutoVariablesName);

                this.variables.Add(autoVariables);

                VariableContainerDetails localVariables =
                    await FetchVariableContainer(i.ToString(), autoVariables);

                this.stackFrameDetails[i] = 
                    StackFrameDetails.Create(callStackFrames[i], autoVariables, localVariables);
            }
        }
        private async Task<VariableContainerDetails> FetchVariableContainer(
            string scope, 
            VariableContainerDetails autoVariables)
        {
            PSCommand psCommand = new PSCommand();
            psCommand.AddCommand("Get-Variable");
            psCommand.AddParameter("Scope", scope);

            var scopeVariableContainer = 
                new VariableContainerDetails(this.nextVariableId++, "Scope: " + scope);
            this.variables.Add(scopeVariableContainer);

            var results = await this.powerShellContext.ExecuteCommand<PSVariable>(psCommand, sendErrorToHost: false);
            if (results != null)
            {
                foreach (PSVariable psvariable in results)
                {
                    var variableDetails = new VariableDetails(psvariable) {Id = this.nextVariableId++};
                    this.variables.Add(variableDetails);
                    scopeVariableContainer.Children.Add(variableDetails.Name, variableDetails);

                    if ((autoVariables != null) && AddToAutoVariables(psvariable, scope))
                    {
                        autoVariables.Children.Add(variableDetails.Name, variableDetails);
                    }
                }
            }

            return scopeVariableContainer;
        }
        private async Task FetchGlobalAndScriptVariables()
        {
            // Retrieve globals first as script variable retrieval needs to search globals.
            this.globalScopeVariables = 
                await FetchVariableContainer(VariableContainerDetails.GlobalScopeName, null);

            this.scriptScopeVariables = 
                await FetchVariableContainer(VariableContainerDetails.ScriptScopeName, null);
        }