Ejemplo n.º 1
0
 private void InitializeCommon(AutomationEngine engine, PSHost hostInterface)
 {
     this._engine = engine;
     if (!_assemblyEventHandlerSet)
     {
         lock (lockObject)
         {
             if (!_assemblyEventHandlerSet)
             {
                 AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(ExecutionContext.PowerShellAssemblyResolveHandler);
                 _assemblyEventHandlerSet = true;
             }
         }
     }
     this._debugger          = new System.Management.Automation.Debugger(this);
     this.eventManager       = new PSLocalEventManager(this);
     this.transactionManager = new PSTransactionManager();
     this.myHostInterface    = hostInterface as System.Management.Automation.Internal.Host.InternalHost;
     if (this.myHostInterface == null)
     {
         this.myHostInterface = new System.Management.Automation.Internal.Host.InternalHost(hostInterface, this);
     }
     this._assemblyCache        = new Dictionary <string, Assembly>();
     this._topLevelSessionState = this._engineSessionState = new SessionStateInternal(this);
     if (this._authorizationManager == null)
     {
         this._authorizationManager = new System.Management.Automation.AuthorizationManager(null);
     }
     this._modules = new ModuleIntrinsics(this);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Process Record.
        /// </summary>
        protected override void ProcessRecord()
        {
            if (this.ParameterSetName.Equals(CommonRunspaceCommandBase.ProcessNameParameterSet))
            {
                SetDebugPreferenceHelper(ProcessName, AppDomainName, true, "EnableRunspaceDebugCommandPersistDebugPreferenceFailure");
                return;
            }

            IReadOnlyList <Runspace> results = GetRunspaces();

            foreach (var runspace in results)
            {
                if (runspace.RunspaceStateInfo.State != RunspaceState.Opened)
                {
                    WriteError(
                        new ErrorRecord(new PSInvalidOperationException(string.Format(CultureInfo.InvariantCulture, Debugger.RunspaceOptionInvalidRunspaceState, runspace.Name)),
                                        "SetRunspaceDebugOptionCommandInvalidRunspaceState",
                                        ErrorCategory.InvalidOperation,
                                        this));

                    continue;
                }

                System.Management.Automation.Debugger debugger = GetDebuggerFromRunspace(runspace);
                if (debugger == null)
                {
                    continue;
                }

                // Enable debugging by preserving debug stop events.
                debugger.UnhandledBreakpointMode = UnhandledBreakpointProcessingMode.Wait;

                if (this.MyInvocation.BoundParameters.ContainsKey(nameof(BreakAll)))
                {
                    if (BreakAll)
                    {
                        try
                        {
                            debugger.SetDebuggerStepMode(true);
                        }
                        catch (PSInvalidOperationException e)
                        {
                            WriteError(
                                new ErrorRecord(
                                    e,
                                    "SetRunspaceDebugOptionCommandCannotEnableDebuggerStepping",
                                    ErrorCategory.InvalidOperation,
                                    this));
                        }
                    }
                    else
                    {
                        debugger.SetDebuggerStepMode(false);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 internal void ResetManagers()
 {
     this._debugger = new System.Management.Automation.Debugger(this);
     if (this.eventManager != null)
     {
         this.eventManager.Dispose();
     }
     this.eventManager = new PSLocalEventManager(this);
     if (this.transactionManager != null)
     {
         this.transactionManager.Dispose();
     }
     this.transactionManager = new PSTransactionManager();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Process Record.
        /// </summary>
        protected override void ProcessRecord()
        {
            IReadOnlyList <Runspace> results = GetRunspaces();

            foreach (var runspace in results)
            {
                System.Management.Automation.Debugger debugger = GetDebuggerFromRunspace(runspace);
                if (debugger != null)
                {
                    WriteObject(
                        new PSRunspaceDebug((debugger.UnhandledBreakpointMode == UnhandledBreakpointProcessingMode.Wait),
                                            debugger.IsDebuggerSteppingEnabled,
                                            runspace.Name,
                                            runspace.Id)
                        );
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns Runspace Debugger.
        /// </summary>
        /// <param name="runspace">Runspace.</param>
        /// <returns>Debugger.</returns>
        protected System.Management.Automation.Debugger GetDebuggerFromRunspace(Runspace runspace)
        {
            System.Management.Automation.Debugger debugger = null;
            try
            {
                debugger = runspace.Debugger;
            }
            catch (PSInvalidOperationException) { }

            if (debugger == null)
            {
                WriteError(
                    new ErrorRecord(
                        new PSInvalidOperationException(string.Format(CultureInfo.InvariantCulture, Debugger.RunspaceOptionNoDebugger, runspace.Name)),
                        "RunspaceDebugOptionNoDebugger",
                        ErrorCategory.InvalidOperation,
                        this)
                    );
            }

            return(debugger);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Process Record.
        /// </summary>
        protected override void ProcessRecord()
        {
            if (this.ParameterSetName.Equals(CommonRunspaceCommandBase.ProcessNameParameterSet))
            {
                SetDebugPreferenceHelper(ProcessName.ToLowerInvariant(), AppDomainName, false, "DisableRunspaceDebugCommandPersistDebugPreferenceFailure");
            }
            else
            {
                IReadOnlyList <Runspace> results = GetRunspaces();

                foreach (var runspace in results)
                {
                    if (runspace.RunspaceStateInfo.State != RunspaceState.Opened)
                    {
                        WriteError(
                            new ErrorRecord(
                                new PSInvalidOperationException(string.Format(CultureInfo.InvariantCulture, Debugger.RunspaceOptionInvalidRunspaceState, runspace.Name)),
                                "SetRunspaceDebugOptionCommandInvalidRunspaceState",
                                ErrorCategory.InvalidOperation,
                                this)
                            );

                        continue;
                    }

                    System.Management.Automation.Debugger debugger = GetDebuggerFromRunspace(runspace);
                    if (debugger == null)
                    {
                        continue;
                    }

                    debugger.SetDebuggerStepMode(false);
                    debugger.UnhandledBreakpointMode = UnhandledBreakpointProcessingMode.Ignore;
                }
            }
        }