/// <summary>
        ///     Attaches to the specified program nodes. This is the main entry point to debugging.
        /// </summary>
        /// <remarks>
        ///     This method is responsible for firing the correct Visual Studio events to begin debugging
        ///     and then to start the actual PowerShell execution.
        /// </remarks>
        /// <param name="rgpPrograms">The programs.</param>
        /// <param name="rgpProgramNodes">The program nodes.</param>
        /// <param name="celtPrograms">The celt programs.</param>
        /// <param name="pCallback">The callback.</param>
        /// <param name="dwReason">The reason.</param>
        /// <returns></returns>
        public int Attach(IDebugProgram2[] rgpPrograms, IDebugProgramNode2[] rgpProgramNodes, uint celtPrograms,
                          IDebugEventCallback2 pCallback, enum_ATTACH_REASON dwReason)
        {
            Log.Debug("Attaching the debug engine.");

            Guid id;

            rgpPrograms[0].GetProgramId(out id);

            if (_node == null)
            {
                _node = rgpProgramNodes[0] as ScriptProgramNode;
                _node.IsAttachedProgram = dwReason == enum_ATTACH_REASON.ATTACH_REASON_USER;
            }

            _node.Id = id;

            var publisher = (IDebugProgramPublisher2) new DebugProgramPublisher();

            publisher.PublishProgramNode(_node);

            _events = new EngineEvents(this, pCallback);
            _events.RunspaceRequest();
            _events.EngineCreated();
            _events.ProgramCreated(_node);
            _events.EngineLoaded();

            _events.DebugEntryPoint();

            Task.Factory.StartNew(Execute);

            return(VSConstants.S_OK);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Attaches to the specified program nodes. This is the main entry point to debugging.
        /// </summary>
        /// <remarks>
        ///     This method is responsible for firing the correct Visual Studio events to begin debugging
        ///     and then to start the actual PowerShell execution.
        /// </remarks>
        /// <param name="rgpPrograms">The programs.</param>
        /// <param name="rgpProgramNodes">The program nodes.</param>
        /// <param name="celtPrograms">The celt programs.</param>
        /// <param name="pCallback">The callback.</param>
        /// <param name="dwReason">The reason.</param>
        /// <returns></returns>
        public int Attach(IDebugProgram2[] rgpPrograms, IDebugProgramNode2[] rgpProgramNodes, uint celtPrograms,
                          IDebugEventCallback2 pCallback, enum_ATTACH_REASON dwReason)
        {
            Log.Debug("Attaching the debug engine.");

            Guid id;
            rgpPrograms[0].GetProgramId(out id);

            if (_node == null)
            {
                _node = rgpProgramNodes[0] as ScriptProgramNode;
                _node.IsAttachedProgram = dwReason == enum_ATTACH_REASON.ATTACH_REASON_USER;
            }

            _node.Id = id;

            var publisher = (IDebugProgramPublisher2) new DebugProgramPublisher();
            publisher.PublishProgramNode(_node);

            _events = new EngineEvents(this, pCallback);
            _events.RunspaceRequest();
            _events.EngineCreated();
            _events.ProgramCreated(_node);
            _events.EngineLoaded();

            _events.DebugEntryPoint();

            Task.Factory.StartNew(Execute);

            return VSConstants.S_OK;
        }