Пример #1
0
 protected override void Dispose(bool disposing)
 {
     try
     {
         if (!this._disposed)
         {
             lock (base.SyncRoot)
             {
                 if (this._disposed)
                 {
                     return;
                 }
                 this._disposed = true;
             }
             if (disposing)
             {
                 this.Close();
                 this._engine             = null;
                 this._history            = null;
                 this._jobManager         = null;
                 this._jobRepository      = null;
                 this._runspaceRepository = null;
                 if (base.RunspaceOpening != null)
                 {
                     base.RunspaceOpening.Dispose();
                     base.RunspaceOpening = null;
                 }
                 if ((base.ExecutionContext != null) && (base.ExecutionContext.Events != null))
                 {
                     try
                     {
                         base.ExecutionContext.Events.Dispose();
                     }
                     catch (ObjectDisposedException)
                     {
                     }
                 }
             }
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
Пример #2
0
 private void DoOpenHelper()
 {
     if (this._disposed)
     {
         throw PSTraceSource.NewObjectDisposedException("runspace");
     }
     bool startLifeCycleEventWritten = false;
     runspaceInitTracer.WriteLine("begin open runspace", new object[0]);
     try
     {
         if (this.InitialSessionState != null)
         {
             this._engine = new AutomationEngine(base.Host, null, this.InitialSessionState);
         }
         else
         {
             this._engine = new AutomationEngine(base.Host, this.RunspaceConfiguration, null);
         }
         this._engine.Context.CurrentRunspace = this;
         MshLog.LogEngineLifecycleEvent(this._engine.Context, EngineState.Available);
         startLifeCycleEventWritten = true;
         this._commandFactory = new System.Management.Automation.CommandFactory(this._engine.Context);
         this._history = new Microsoft.PowerShell.Commands.History(this._engine.Context);
         this._jobRepository = new System.Management.Automation.JobRepository();
         this._jobManager = new System.Management.Automation.JobManager();
         this._runspaceRepository = new System.Management.Automation.RunspaceRepository();
         runspaceInitTracer.WriteLine("initializing built-in aliases and variable information", new object[0]);
         this.InitializeDefaults();
     }
     catch (Exception exception)
     {
         CommandProcessorBase.CheckForSevereException(exception);
         runspaceInitTracer.WriteLine("Runspace open failed", new object[0]);
         this.LogEngineHealthEvent(exception);
         if (startLifeCycleEventWritten)
         {
             MshLog.LogEngineLifecycleEvent(this._engine.Context, EngineState.Stopped);
         }
         base.SetRunspaceState(RunspaceState.Broken, exception);
         base.RaiseRunspaceStateEvents();
         throw;
     }
     base.SetRunspaceState(RunspaceState.Opened);
     base.RunspaceOpening.Set();
     base.RaiseRunspaceStateEvents();
     runspaceInitTracer.WriteLine("runspace opened successfully", new object[0]);
     string environmentVariable = Environment.GetEnvironmentVariable("PSMODULEPATH");
     if (this.InitialSessionState != null)
     {
         try
         {
             Environment.SetEnvironmentVariable("PSMODULEPATH", ModuleIntrinsics.GetSystemwideModulePath());
             this.ProcessImportModule(this.InitialSessionState.CoreModulesToImport, startLifeCycleEventWritten);
             this._engine.Context.EngineSessionState.Module = null;
         }
         finally
         {
             Environment.SetEnvironmentVariable("PSMODULEPATH", environmentVariable);
         }
         this.ProcessImportModule(this.InitialSessionState.ModuleSpecificationsToImport, startLifeCycleEventWritten);
         InitialSessionState.SetSessionStateDrive(this._engine.Context, true);
         if (this.InitialSessionState.WarmUpTabCompletionOnIdle)
         {
             ScriptBlock action = ScriptBlock.Create("$null = [System.Management.Automation.CommandCompletion]::CompleteInput('Set-Location', 12, $null)");
             this._engine.Context.Events.SubscribeEvent(null, null, "PowerShell.OnIdle", null, action, true, false, 1);
         }
     }
 }
Пример #3
0
 protected override void Dispose(bool disposing)
 {
     try
     {
         if (!this._disposed)
         {
             lock (base.SyncRoot)
             {
                 if (this._disposed)
                 {
                     return;
                 }
                 this._disposed = true;
             }
             if (disposing)
             {
                 this.Close();
                 this._engine = null;
                 this._history = null;
                 this._jobManager = null;
                 this._jobRepository = null;
                 this._runspaceRepository = null;
                 if (base.RunspaceOpening != null)
                 {
                     base.RunspaceOpening.Dispose();
                     base.RunspaceOpening = null;
                 }
                 if ((base.ExecutionContext != null) && (base.ExecutionContext.Events != null))
                 {
                     try
                     {
                         base.ExecutionContext.Events.Dispose();
                     }
                     catch (ObjectDisposedException)
                     {
                     }
                 }
             }
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
Пример #4
0
 protected JobIdentifier RetrieveJobIdForReuse(Guid instanceId)
 {
     return(JobManager.GetJobIdentifier(instanceId, base.GetType().Name));
 }
Пример #5
0
        private void DoOpenHelper()
        {
            if (this._disposed)
            {
                throw PSTraceSource.NewObjectDisposedException("runspace");
            }
            bool startLifeCycleEventWritten = false;

            runspaceInitTracer.WriteLine("begin open runspace", new object[0]);
            try
            {
                if (this.InitialSessionState != null)
                {
                    this._engine = new AutomationEngine(base.Host, null, this.InitialSessionState);
                }
                else
                {
                    this._engine = new AutomationEngine(base.Host, this.RunspaceConfiguration, null);
                }
                this._engine.Context.CurrentRunspace = this;
                MshLog.LogEngineLifecycleEvent(this._engine.Context, EngineState.Available);
                startLifeCycleEventWritten = true;
                this._commandFactory       = new System.Management.Automation.CommandFactory(this._engine.Context);
                this._history            = new Microsoft.PowerShell.Commands.History(this._engine.Context);
                this._jobRepository      = new System.Management.Automation.JobRepository();
                this._jobManager         = new System.Management.Automation.JobManager();
                this._runspaceRepository = new System.Management.Automation.RunspaceRepository();
                runspaceInitTracer.WriteLine("initializing built-in aliases and variable information", new object[0]);
                this.InitializeDefaults();
            }
            catch (Exception exception)
            {
                CommandProcessorBase.CheckForSevereException(exception);
                runspaceInitTracer.WriteLine("Runspace open failed", new object[0]);
                this.LogEngineHealthEvent(exception);
                if (startLifeCycleEventWritten)
                {
                    MshLog.LogEngineLifecycleEvent(this._engine.Context, EngineState.Stopped);
                }
                base.SetRunspaceState(RunspaceState.Broken, exception);
                base.RaiseRunspaceStateEvents();
                throw;
            }
            base.SetRunspaceState(RunspaceState.Opened);
            base.RunspaceOpening.Set();
            base.RaiseRunspaceStateEvents();
            runspaceInitTracer.WriteLine("runspace opened successfully", new object[0]);
            string environmentVariable = Environment.GetEnvironmentVariable("PSMODULEPATH");

            if (this.InitialSessionState != null)
            {
                try
                {
                    Environment.SetEnvironmentVariable("PSMODULEPATH", ModuleIntrinsics.GetSystemwideModulePath());
                    this.ProcessImportModule(this.InitialSessionState.CoreModulesToImport, startLifeCycleEventWritten);
                    this._engine.Context.EngineSessionState.Module = null;
                }
                finally
                {
                    Environment.SetEnvironmentVariable("PSMODULEPATH", environmentVariable);
                }
                this.ProcessImportModule(this.InitialSessionState.ModuleSpecificationsToImport, startLifeCycleEventWritten);
                InitialSessionState.SetSessionStateDrive(this._engine.Context, true);
                if (this.InitialSessionState.WarmUpTabCompletionOnIdle)
                {
                    ScriptBlock action = ScriptBlock.Create("$null = [System.Management.Automation.CommandCompletion]::CompleteInput('Set-Location', 12, $null)");
                    this._engine.Context.Events.SubscribeEvent(null, null, "PowerShell.OnIdle", null, action, true, false, 1);
                }
            }
        }