private void MergeCustomPSSnapIn(PSSnapInInfo mshsnapinInfo, CustomPSSnapIn customPSSnapIn) { if (mshsnapinInfo == null || customPSSnapIn == null) { return; } s_mshsnapinTracer.WriteLine("Merging configuration from custom mshsnapin {0}", mshsnapinInfo.Name); if (customPSSnapIn.Cmdlets != null) { foreach (CmdletConfigurationEntry entry in customPSSnapIn.Cmdlets) { CmdletConfigurationEntry cmdlet = new CmdletConfigurationEntry(entry.Name, entry.ImplementingType, entry.HelpFileName, mshsnapinInfo); _cmdlets.AddBuiltInItem(cmdlet); } } if (customPSSnapIn.Providers != null) { foreach (ProviderConfigurationEntry entry in customPSSnapIn.Providers) { ProviderConfigurationEntry provider = new ProviderConfigurationEntry(entry.Name, entry.ImplementingType, entry.HelpFileName, mshsnapinInfo); _providers.AddBuiltInItem(provider); } } if (customPSSnapIn.Types != null) { foreach (TypeConfigurationEntry entry in customPSSnapIn.Types) { string path = Path.Combine(mshsnapinInfo.ApplicationBase, entry.FileName); TypeConfigurationEntry type = new TypeConfigurationEntry(entry.Name, path, mshsnapinInfo); _types.AddBuiltInItem(type); } } if (customPSSnapIn.Formats != null) { foreach (FormatConfigurationEntry entry in customPSSnapIn.Formats) { string path = Path.Combine(mshsnapinInfo.ApplicationBase, entry.FileName); FormatConfigurationEntry format = new FormatConfigurationEntry(entry.Name, path, mshsnapinInfo); _formats.AddBuiltInItem(format); } } AssemblyConfigurationEntry assemblyEntry = new AssemblyConfigurationEntry(mshsnapinInfo.AssemblyName, mshsnapinInfo.AbsoluteModulePath, mshsnapinInfo); this.Assemblies.AddBuiltInItem(assemblyEntry); s_mshsnapinTracer.WriteLine("Configuration from custom mshsnapin {0} merged", mshsnapinInfo.Name); }
private void LoadCustomPSSnapIn(PSSnapInInfo mshsnapinInfo) { if ((mshsnapinInfo != null) && !string.IsNullOrEmpty(mshsnapinInfo.CustomPSSnapInType)) { Assembly assembly = null; _mshsnapinTracer.WriteLine("Loading assembly for mshsnapin {0}", new object[] { mshsnapinInfo.Name }); assembly = this.LoadMshSnapinAssembly(mshsnapinInfo); if (assembly == null) { _mshsnapinTracer.TraceError("Loading assembly for mshsnapin {0} failed", new object[] { mshsnapinInfo.Name }); } else { CustomPSSnapIn customPSSnapIn = null; try { if (assembly.GetType(mshsnapinInfo.CustomPSSnapInType, true) != null) { customPSSnapIn = (CustomPSSnapIn)assembly.CreateInstance(mshsnapinInfo.CustomPSSnapInType); } _mshsnapinTracer.WriteLine("Loading assembly for mshsnapin {0} succeeded", new object[] { mshsnapinInfo.Name }); } catch (TypeLoadException exception) { throw new PSSnapInException(mshsnapinInfo.Name, exception.Message); } catch (ArgumentException exception2) { throw new PSSnapInException(mshsnapinInfo.Name, exception2.Message); } catch (MissingMethodException exception3) { throw new PSSnapInException(mshsnapinInfo.Name, exception3.Message); } catch (InvalidCastException exception4) { throw new PSSnapInException(mshsnapinInfo.Name, exception4.Message); } catch (TargetInvocationException exception5) { if (exception5.InnerException != null) { throw new PSSnapInException(mshsnapinInfo.Name, exception5.InnerException.Message); } throw new PSSnapInException(mshsnapinInfo.Name, exception5.Message); } this.MergeCustomPSSnapIn(mshsnapinInfo, customPSSnapIn); } } }
private void MergeCustomPSSnapIn(PSSnapInInfo mshsnapinInfo, CustomPSSnapIn customPSSnapIn) { if ((mshsnapinInfo != null) && (customPSSnapIn != null)) { _mshsnapinTracer.WriteLine("Merging configuration from custom mshsnapin {0}", new object[] { mshsnapinInfo.Name }); if (customPSSnapIn.Cmdlets != null) { foreach (CmdletConfigurationEntry entry in customPSSnapIn.Cmdlets) { CmdletConfigurationEntry entry2 = new CmdletConfigurationEntry(entry.Name, entry.ImplementingType, entry.HelpFileName, mshsnapinInfo); this._cmdlets.AddBuiltInItem(entry2); } } if (customPSSnapIn.Providers != null) { foreach (ProviderConfigurationEntry entry3 in customPSSnapIn.Providers) { ProviderConfigurationEntry entry4 = new ProviderConfigurationEntry(entry3.Name, entry3.ImplementingType, entry3.HelpFileName, mshsnapinInfo); this._providers.AddBuiltInItem(entry4); } } if (customPSSnapIn.Types != null) { foreach (TypeConfigurationEntry entry5 in customPSSnapIn.Types) { string fileName = Path.Combine(mshsnapinInfo.ApplicationBase, entry5.FileName); TypeConfigurationEntry entry6 = new TypeConfigurationEntry(entry5.Name, fileName, mshsnapinInfo); this._types.AddBuiltInItem(entry6); } } if (customPSSnapIn.Formats != null) { foreach (FormatConfigurationEntry entry7 in customPSSnapIn.Formats) { string str2 = Path.Combine(mshsnapinInfo.ApplicationBase, entry7.FileName); FormatConfigurationEntry entry8 = new FormatConfigurationEntry(entry7.Name, str2, mshsnapinInfo); this._formats.AddBuiltInItem(entry8); } } AssemblyConfigurationEntry item = new AssemblyConfigurationEntry(mshsnapinInfo.AssemblyName, mshsnapinInfo.AbsoluteModulePath, mshsnapinInfo); this.Assemblies.AddBuiltInItem(item); _mshsnapinTracer.WriteLine("Configuration from custom mshsnapin {0} merged", new object[] { mshsnapinInfo.Name }); } }
private void MergeCustomPSSnapIn(PSSnapInInfo mshsnapinInfo, CustomPSSnapIn customPSSnapIn) { if (mshsnapinInfo == null || customPSSnapIn == null) return; s_mshsnapinTracer.WriteLine("Merging configuration from custom mshsnapin {0}", mshsnapinInfo.Name); if (customPSSnapIn.Cmdlets != null) { foreach (CmdletConfigurationEntry entry in customPSSnapIn.Cmdlets) { CmdletConfigurationEntry cmdlet = new CmdletConfigurationEntry(entry.Name, entry.ImplementingType, entry.HelpFileName, mshsnapinInfo); _cmdlets.AddBuiltInItem(cmdlet); } } if (customPSSnapIn.Providers != null) { foreach (ProviderConfigurationEntry entry in customPSSnapIn.Providers) { ProviderConfigurationEntry provider = new ProviderConfigurationEntry(entry.Name, entry.ImplementingType, entry.HelpFileName, mshsnapinInfo); _providers.AddBuiltInItem(provider); } } if (customPSSnapIn.Types != null) { foreach (TypeConfigurationEntry entry in customPSSnapIn.Types) { string path = Path.Combine(mshsnapinInfo.ApplicationBase, entry.FileName); TypeConfigurationEntry type = new TypeConfigurationEntry(entry.Name, path, mshsnapinInfo); _types.AddBuiltInItem(type); } } if (customPSSnapIn.Formats != null) { foreach (FormatConfigurationEntry entry in customPSSnapIn.Formats) { string path = Path.Combine(mshsnapinInfo.ApplicationBase, entry.FileName); FormatConfigurationEntry format = new FormatConfigurationEntry(entry.Name, path, mshsnapinInfo); _formats.AddBuiltInItem(format); } } AssemblyConfigurationEntry assemblyEntry = new AssemblyConfigurationEntry(mshsnapinInfo.AssemblyName, mshsnapinInfo.AbsoluteModulePath, mshsnapinInfo); this.Assemblies.AddBuiltInItem(assemblyEntry); s_mshsnapinTracer.WriteLine("Configuration from custom mshsnapin {0} merged", mshsnapinInfo.Name); }
private void LoadCustomPSSnapIn(PSSnapInInfo mshsnapinInfo) { if (mshsnapinInfo == null) { return; } if (String.IsNullOrEmpty(mshsnapinInfo.CustomPSSnapInType)) { return; } Assembly assembly = null; s_mshsnapinTracer.WriteLine("Loading assembly for mshsnapin {0}", mshsnapinInfo.Name); assembly = LoadMshSnapinAssembly(mshsnapinInfo); if (assembly == null) { s_mshsnapinTracer.TraceError("Loading assembly for mshsnapin {0} failed", mshsnapinInfo.Name); return; } CustomPSSnapIn customPSSnapIn = null; try { Type type = assembly.GetType(mshsnapinInfo.CustomPSSnapInType, true, false); if (type != null) { customPSSnapIn = (CustomPSSnapIn)Activator.CreateInstance(type); } s_mshsnapinTracer.WriteLine("Loading assembly for mshsnapin {0} succeeded", mshsnapinInfo.Name); } catch (TypeLoadException tle) { throw new PSSnapInException(mshsnapinInfo.Name, tle.Message); } catch (ArgumentException ae) { throw new PSSnapInException(mshsnapinInfo.Name, ae.Message); } catch (MissingMethodException mme) { throw new PSSnapInException(mshsnapinInfo.Name, mme.Message); } catch (InvalidCastException ice) { throw new PSSnapInException(mshsnapinInfo.Name, ice.Message); } catch (TargetInvocationException tie) { if (tie.InnerException != null) { throw new PSSnapInException(mshsnapinInfo.Name, tie.InnerException.Message); } throw new PSSnapInException(mshsnapinInfo.Name, tie.Message); } MergeCustomPSSnapIn(mshsnapinInfo, customPSSnapIn); return; }