Exemple #1
0
 private void ValidateAndThrowRunspaceOpenModuleLoadException(PowerShell pse, List <ErrorRecord> errors, bool startLifeCycleEventWritten, string moduleName, RunspaceOpenModuleLoadException exception)
 {
     if (this.InitialSessionState.ThrowOnRunspaceOpenError)
     {
         RunspaceOpenModuleLoadException exception2 = null;
         if (exception != null)
         {
             exception2 = exception;
         }
         else if ((pse.Streams.Error.Count > 0) || (errors.Count > 0))
         {
             ErrorRecord record;
             Exception   exception3;
             PSDataCollection <ErrorRecord> datas = new PSDataCollection <ErrorRecord>();
             if (errors.Count > 0)
             {
                 record     = errors[0];
                 exception3 = record.Exception;
                 foreach (ErrorRecord record2 in errors)
                 {
                     datas.Add(record2);
                 }
             }
             else
             {
                 record     = pse.Streams.Error[0];
                 exception3 = record.Exception;
                 foreach (ErrorRecord record3 in pse.Streams.Error)
                 {
                     datas.Add(record3);
                 }
             }
             runspaceInitTracer.WriteLine("Runspace open failed while loading module '{0}': First error {1}", new object[] { moduleName, exception3 });
             exception2 = new RunspaceOpenModuleLoadException(moduleName, datas);
         }
         if (exception2 != null)
         {
             this.LogEngineHealthEvent(exception2);
             if (startLifeCycleEventWritten)
             {
                 MshLog.LogEngineLifecycleEvent(this._engine.Context, EngineState.Stopped);
             }
             base.SetRunspaceState(RunspaceState.Broken, exception2);
             base.RaiseRunspaceStateEvents();
             throw exception2;
         }
     }
 }
Exemple #2
0
 private void ProcessImportModule(IEnumerable moduleList, bool startLifeCycleEventWritten)
 {
     foreach (object obj2 in moduleList)
     {
         string name = obj2 as string;
         if (name != null)
         {
             this.ProcessImportModule(name, null, startLifeCycleEventWritten);
         }
         else
         {
             ModuleSpecification requiredModule = obj2 as ModuleSpecification;
             if (requiredModule != null)
             {
                 if ((requiredModule.Version == null) && !requiredModule.Guid.HasValue)
                 {
                     this.ProcessImportModule(requiredModule.Name, null, startLifeCycleEventWritten);
                 }
                 else
                 {
                     Collection <PSModuleInfo> moduleIfAvailable = ModuleCmdletBase.GetModuleIfAvailable(requiredModule, this);
                     if ((moduleIfAvailable != null) && (moduleIfAvailable.Count > 0))
                     {
                         foreach (PSModuleInfo info in moduleIfAvailable)
                         {
                             this.ProcessImportModule(requiredModule.Name, info, startLifeCycleEventWritten);
                         }
                     }
                     else
                     {
                         RunspaceOpenModuleLoadException exception = new RunspaceOpenModuleLoadException(StringUtil.Format(Modules.RequiredModuleNotFoundWrongGuidVersion, new object[] { requiredModule.Name, requiredModule.Guid, (requiredModule.Version == null) ? "0.0.0.0" : requiredModule.Version.ToString() }));
                         this.ValidateAndThrowRunspaceOpenModuleLoadException(null, null, startLifeCycleEventWritten, requiredModule.Name, exception);
                     }
                 }
             }
         }
     }
 }
Exemple #3
0
 private void ValidateAndThrowRunspaceOpenModuleLoadException(PowerShell pse, List<ErrorRecord> errors, bool startLifeCycleEventWritten, string moduleName, RunspaceOpenModuleLoadException exception)
 {
     if (this.InitialSessionState.ThrowOnRunspaceOpenError)
     {
         RunspaceOpenModuleLoadException exception2 = null;
         if (exception != null)
         {
             exception2 = exception;
         }
         else if ((pse.Streams.Error.Count > 0) || (errors.Count > 0))
         {
             ErrorRecord record;
             Exception exception3;
             PSDataCollection<ErrorRecord> datas = new PSDataCollection<ErrorRecord>();
             if (errors.Count > 0)
             {
                 record = errors[0];
                 exception3 = record.Exception;
                 foreach (ErrorRecord record2 in errors)
                 {
                     datas.Add(record2);
                 }
             }
             else
             {
                 record = pse.Streams.Error[0];
                 exception3 = record.Exception;
                 foreach (ErrorRecord record3 in pse.Streams.Error)
                 {
                     datas.Add(record3);
                 }
             }
             runspaceInitTracer.WriteLine("Runspace open failed while loading module '{0}': First error {1}", new object[] { moduleName, exception3 });
             exception2 = new RunspaceOpenModuleLoadException(moduleName, datas);
         }
         if (exception2 != null)
         {
             this.LogEngineHealthEvent(exception2);
             if (startLifeCycleEventWritten)
             {
                 MshLog.LogEngineLifecycleEvent(this._engine.Context, EngineState.Stopped);
             }
             base.SetRunspaceState(RunspaceState.Broken, exception2);
             base.RaiseRunspaceStateEvents();
             throw exception2;
         }
     }
 }
Exemple #4
0
 private void ProcessImportModule(IEnumerable moduleList, bool startLifeCycleEventWritten)
 {
     foreach (object obj2 in moduleList)
     {
         string name = obj2 as string;
         if (name != null)
         {
             this.ProcessImportModule(name, null, startLifeCycleEventWritten);
         }
         else
         {
             ModuleSpecification requiredModule = obj2 as ModuleSpecification;
             if (requiredModule != null)
             {
                 if ((requiredModule.Version == null) && !requiredModule.Guid.HasValue)
                 {
                     this.ProcessImportModule(requiredModule.Name, null, startLifeCycleEventWritten);
                 }
                 else
                 {
                     Collection<PSModuleInfo> moduleIfAvailable = ModuleCmdletBase.GetModuleIfAvailable(requiredModule, this);
                     if ((moduleIfAvailable != null) && (moduleIfAvailable.Count > 0))
                     {
                         foreach (PSModuleInfo info in moduleIfAvailable)
                         {
                             this.ProcessImportModule(requiredModule.Name, info, startLifeCycleEventWritten);
                         }
                     }
                     else
                     {
                         RunspaceOpenModuleLoadException exception = new RunspaceOpenModuleLoadException(StringUtil.Format(Modules.RequiredModuleNotFoundWrongGuidVersion, new object[] { requiredModule.Name, requiredModule.Guid, (requiredModule.Version == null) ? "0.0.0.0" : requiredModule.Version.ToString() }));
                         this.ValidateAndThrowRunspaceOpenModuleLoadException(null, null, startLifeCycleEventWritten, requiredModule.Name, exception);
                     }
                 }
             }
         }
     }
 }