internal void Initialize(ExecutionContext executionContext)
 {
     lock (this._syncObject)
     {
         if (!this._initialized)
         {
             this._initialized      = true;
             this.Types.OnUpdate   += new RunspaceConfigurationEntryUpdateEventHandler(this.UpdateTypes);
             this.Formats.OnUpdate += new RunspaceConfigurationEntryUpdateEventHandler(this.UpdateFormats);
             runspaceInitTracer.WriteLine("initializing types information", new object[0]);
             try
             {
                 this.UpdateTypes(true);
             }
             catch (RuntimeException exception)
             {
                 runspaceInitTracer.WriteLine("type information initialization failed", new object[0]);
                 MshLog.LogEngineHealthEvent(executionContext, 0x67, exception, Severity.Warning);
                 executionContext.ReportEngineStartupError(exception.Message);
             }
             runspaceInitTracer.WriteLine("initializing format information", new object[0]);
             try
             {
                 this.UpdateFormats(true);
             }
             catch (RuntimeException exception2)
             {
                 runspaceInitTracer.WriteLine("format information initialization failed", new object[0]);
                 MshLog.LogEngineHealthEvent(executionContext, 0x67, exception2, Severity.Warning);
                 executionContext.ReportEngineStartupError(exception2.Message);
             }
         }
     }
 }
Beispiel #2
0
 internal void Bind(ExecutionContext executionContext)
 {
     this._host = (PSHost)executionContext.EngineHostInterface;
     this.Initialize(executionContext);
     this.Assemblies.OnUpdate += new RunspaceConfigurationEntryUpdateEventHandler(executionContext.UpdateAssemblyCache);
     RunspaceConfiguration.runspaceInitTracer.WriteLine("initializing assembly list", new object[0]);
     try
     {
         this.Assemblies.Update(true);
     }
     catch (RuntimeException ex)
     {
         RunspaceConfiguration.runspaceInitTracer.WriteLine("assembly list initialization failed", new object[0]);
         RunspaceConfiguration.runspaceInitTracer.TraceException((Exception)ex);
         RunspaceConfiguration.tracer.TraceException((Exception)ex);
         MshLog.LogEngineHealthEvent(executionContext, 103, (Exception)ex, Severity.Error);
         executionContext.ReportEngineStartupError(ex.Message);
         throw;
     }
     if (executionContext.CommandDiscovery != null)
     {
         this.Cmdlets.OnUpdate += new RunspaceConfigurationEntryUpdateEventHandler(executionContext.CommandDiscovery.UpdateCmdletCache);
         RunspaceConfiguration.runspaceInitTracer.WriteLine("initializing cmdlet list", new object[0]);
         try
         {
             this.Cmdlets.Update(true);
         }
         catch (PSNotSupportedException ex)
         {
             RunspaceConfiguration.runspaceInitTracer.WriteLine("cmdlet list initialization failed", new object[0]);
             RunspaceConfiguration.runspaceInitTracer.TraceException((Exception)ex);
             RunspaceConfiguration.tracer.TraceException((Exception)ex);
             MshLog.LogEngineHealthEvent(executionContext, 103, (Exception)ex, Severity.Error);
             executionContext.ReportEngineStartupError(ex.Message);
             throw;
         }
     }
     if (executionContext.EngineSessionState == null)
     {
         return;
     }
     this.Providers.OnUpdate += new RunspaceConfigurationEntryUpdateEventHandler(executionContext.EngineSessionState.UpdateProviders);
     RunspaceConfiguration.runspaceInitTracer.WriteLine("initializing provider list", new object[0]);
     try
     {
         this.Providers.Update(true);
     }
     catch (PSNotSupportedException ex)
     {
         RunspaceConfiguration.runspaceInitTracer.WriteLine("provider list initialization failed", new object[0]);
         RunspaceConfiguration.runspaceInitTracer.TraceException((Exception)ex);
         RunspaceConfiguration.tracer.TraceException((Exception)ex);
         MshLog.LogEngineHealthEvent(executionContext, 103, (Exception)ex, Severity.Error);
         executionContext.ReportEngineStartupError(ex.Message);
         throw;
     }
 }
Beispiel #3
0
        internal void Initialize(ExecutionContext executionContext)
        {
#pragma warning disable 56517

            lock (_syncObject)
            {
                if (!_initialized)
                {
                    _initialized = true;

                    this.Types.OnUpdate   += this.UpdateTypes;
                    this.Formats.OnUpdate += this.UpdateFormats;

                    s_runspaceInitTracer.WriteLine("initializing types information");
                    try
                    {
                        this.UpdateTypes();
                    }
                    catch (RuntimeException e)
                    {
                        s_runspaceInitTracer.WriteLine("type information initialization failed");
                        MshLog.LogEngineHealthEvent(
                            executionContext,
                            MshLog.EVENT_ID_CONFIGURATION_FAILURE,
                            e,
                            Severity.Warning);
                        executionContext.ReportEngineStartupError(e.Message);
                    }

                    s_runspaceInitTracer.WriteLine("initializing format information");
                    try
                    {
                        this.UpdateFormats(true);
                    }
                    catch (RuntimeException e)
                    {
                        s_runspaceInitTracer.WriteLine("format information initialization failed");
                        MshLog.LogEngineHealthEvent(
                            executionContext,
                            MshLog.EVENT_ID_CONFIGURATION_FAILURE,
                            e,
                            Severity.Warning);
                        executionContext.ReportEngineStartupError(e.Message);
                    }
                }
            }

#pragma warning restore 56517
        }
Beispiel #4
0
        internal void LogEngineHealthEvent(Exception exception, Severity severity, int id, Dictionary <string, string> additionalInfo)
        {
            LogContext logContext = new LogContext {
                EngineVersion = this.Version.ToString(),
                HostId        = base.Host.InstanceId.ToString(),
                HostName      = base.Host.Name,
                HostVersion   = base.Host.Version.ToString(),
                RunspaceId    = base.InstanceId.ToString(),
                Severity      = severity.ToString()
            };

            if (this.RunspaceConfiguration == null)
            {
                logContext.ShellId = Utils.DefaultPowerShellShellID;
            }
            else
            {
                logContext.ShellId = this.RunspaceConfiguration.ShellId;
            }
            MshLog.LogEngineHealthEvent(logContext, id, exception, additionalInfo);
        }
Beispiel #5
0
        internal void Bind(ExecutionContext executionContext)
        {
            _host = executionContext.EngineHostInterface;

            Initialize(executionContext);

            this.Assemblies.OnUpdate += executionContext.UpdateAssemblyCache;

            s_runspaceInitTracer.WriteLine("initializing assembly list");
            try
            {
                this.Assemblies.Update(true);
            }
            catch (RuntimeException e)
            {
                s_runspaceInitTracer.WriteLine("assembly list initialization failed");
                MshLog.LogEngineHealthEvent(
                    executionContext,
                    MshLog.EVENT_ID_CONFIGURATION_FAILURE,
                    e,
                    Severity.Error);
                executionContext.ReportEngineStartupError(e.Message);

                throw;
            }

            if (executionContext.CommandDiscovery != null)
            {
                this.Cmdlets.OnUpdate += executionContext.CommandDiscovery.UpdateCmdletCache;

                // Force an update here so that cmdlet cache is updated in engine.
                s_runspaceInitTracer.WriteLine("initializing cmdlet list");
                try
                {
                    this.Cmdlets.Update(true);
                }
                catch (PSNotSupportedException e)
                {
                    s_runspaceInitTracer.WriteLine("cmdlet list initialization failed");
                    MshLog.LogEngineHealthEvent(
                        executionContext,
                        MshLog.EVENT_ID_CONFIGURATION_FAILURE,
                        e,
                        Severity.Error);
                    executionContext.ReportEngineStartupError(e.Message);
                    throw;
                }
            }

            if (executionContext.EngineSessionState != null)
            {
                this.Providers.OnUpdate += executionContext.EngineSessionState.UpdateProviders;

                // Force an update here so that provider cache is updated in engine.
                s_runspaceInitTracer.WriteLine("initializing provider list");
                try
                {
                    this.Providers.Update(true);
                }
                catch (PSNotSupportedException e)
                {
                    s_runspaceInitTracer.WriteLine("provider list initialization failed");
                    MshLog.LogEngineHealthEvent(
                        executionContext,
                        MshLog.EVENT_ID_CONFIGURATION_FAILURE,
                        e,
                        Severity.Error);
                    executionContext.ReportEngineStartupError(e.Message);
                    throw;
                }
            }
        }