Example #1
0
        /// <summary>
        /// Execute the current program node.
        /// </summary>
        /// <remarks>
        /// The node will either be a script file or script content; depending on the node
        /// passed to this function.
        /// </remarks>
        /// <param name="node"></param>
        public void Execute(ScriptProgramNode node)
        {
            CurrentExecutingNode = node;

            if (node.IsAttachedProgram)
            {
                string result = string.Empty;
                if (!node.IsRemoteProgram)
                {
                    result = DebuggingService.AttachToRunspace(node.Process.ProcessId);
                }
                else
                {
                    result = DebuggingService.AttachToRemoteRunspace(node.Process.ProcessId, node.Process.HostName);
                }

                if (!string.IsNullOrEmpty(result))
                {
                    // if either of the attaches returns an error, let the user know
                    MessageBox.Show(result, Resources.AttachErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // see what state we are in post error, if not in a local state, we need to try and get there
                    DebugScenario postCleanupScenario = DebuggingService.GetDebugScenario();

                    // try as hard as we can to detach/cleanup the mess for the length of CleanupRetryTimeout
                    TimeSpan  retryTimeSpan = TimeSpan.FromMilliseconds(DebugEngineConstants.CleanupRetryTimeout);
                    Stopwatch timeElapsed   = Stopwatch.StartNew();
                    while (timeElapsed.Elapsed < retryTimeSpan && postCleanupScenario != DebugScenario.Local)
                    {
                        postCleanupScenario = DebuggingService.CleanupAttach();
                    }

                    // if our efforts to cleanup the mess were unsuccessful, inform the user
                    if (postCleanupScenario != DebugScenario.Local)
                    {
                        MessageBox.Show(Resources.CleanupErrorMessage, Resources.DetachErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    RefreshPrompt();
                    DebuggerFinished();
                }
            }
            else
            {
                string commandLine = node.FileName;

                if (node.IsFile)
                {
                    commandLine = String.Format(DebugEngineConstants.ExecutionCommandFormat, node.FileName, node.Arguments);
                    HostUi.VsOutputString(string.Format("{0}{1}{2}", GetPrompt(), node.FileName, Environment.NewLine));
                }
                Execute(commandLine);
            }
        }