internal static Collection <PSSnapInTypeAndFormatErrors> GetFormatAndTypesErrors( RunspaceConfiguration runspaceConfiguration, PSHost host, IEnumerable <RunspaceConfigurationEntry> configurationEntryCollection, Collection <string> independentErrors, Collection <int> entryIndicesToRemove) { Collection <PSSnapInTypeAndFormatErrors> returnValue = new Collection <PSSnapInTypeAndFormatErrors>(); string baseFolder = GetBaseFolder(runspaceConfiguration, independentErrors); var psHome = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID); // this hashtable will be used to check whether this is duplicated file for types or formats. HashSet <string> fullFileNameSet = new HashSet <string>(StringComparer.OrdinalIgnoreCase); int index = -1; foreach (var configurationEntry in configurationEntryCollection) { string fileName; string psSnapinName = configurationEntry.PSSnapIn == null ? runspaceConfiguration.ShellId : configurationEntry.PSSnapIn.Name; index++; var typeEntry = configurationEntry as TypeConfigurationEntry; if (typeEntry != null) { fileName = typeEntry.FileName; if (fileName == null) { returnValue.Add(new PSSnapInTypeAndFormatErrors(psSnapinName, typeEntry.TypeData, typeEntry.IsRemove)); continue; } } else { FormatConfigurationEntry formatEntry = (FormatConfigurationEntry)configurationEntry; fileName = formatEntry.FileName; if (fileName == null) { returnValue.Add(new PSSnapInTypeAndFormatErrors(psSnapinName, formatEntry.FormatData)); continue; } } bool checkFileExists = configurationEntry.PSSnapIn == null || string.Equals(psHome, configurationEntry.PSSnapIn.AbsoluteModulePath, StringComparison.OrdinalIgnoreCase); bool needToRemoveEntry = false; string fullFileName = GetAndCheckFullFileName(psSnapinName, fullFileNameSet, baseFolder, fileName, independentErrors, ref needToRemoveEntry, checkFileExists); if (fullFileName == null) { if (needToRemoveEntry) { entryIndicesToRemove.Add(index); } continue; } returnValue.Add(new PSSnapInTypeAndFormatErrors(psSnapinName, fullFileName)); } return(returnValue); }
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); }
internal static Collection <PSSnapInTypeAndFormatErrors> GetFormatAndTypesErrors( RunspaceConfiguration runspaceConfiguration, PSHost host, IEnumerable configurationEntryCollection, RunspaceConfigurationCategory category, Collection <string> independentErrors) { Collection <PSSnapInTypeAndFormatErrors> collection = new Collection <PSSnapInTypeAndFormatErrors>(); string baseFolder = FormatAndTypeDataHelper.GetBaseFolder(runspaceConfiguration, independentErrors); Hashtable fullFileNameHash = new Hashtable((IEqualityComparer)StringComparer.OrdinalIgnoreCase); foreach (object configurationEntry1 in configurationEntryCollection) { string fileName; string str; if (category == RunspaceConfigurationCategory.Types) { TypeConfigurationEntry configurationEntry2 = (TypeConfigurationEntry)configurationEntry1; fileName = configurationEntry2.FileName; str = configurationEntry2.PSSnapIn == null ? runspaceConfiguration.ShellId : configurationEntry2.PSSnapIn.Name; } else { FormatConfigurationEntry configurationEntry2 = (FormatConfigurationEntry)configurationEntry1; fileName = configurationEntry2.FileName; str = configurationEntry2.PSSnapIn == null ? runspaceConfiguration.ShellId : configurationEntry2.PSSnapIn.Name; } string checkFullFileName1 = FormatAndTypeDataHelper.GetAndCheckFullFileName(str, fullFileNameHash, runspaceConfiguration, baseFolder, fileName, independentErrors); if (checkFullFileName1 != null) { if (checkFullFileName1.EndsWith("filelist.ps1xml", StringComparison.OrdinalIgnoreCase)) { foreach (string readFile in runspaceConfiguration.TypeTable.ReadFiles(str, checkFullFileName1, independentErrors, runspaceConfiguration.AuthorizationManager, host)) { string checkFullFileName2 = FormatAndTypeDataHelper.GetAndCheckFullFileName(str, fullFileNameHash, runspaceConfiguration, baseFolder, readFile, independentErrors); if (checkFullFileName2 != null) { collection.Add(new PSSnapInTypeAndFormatErrors(str, checkFullFileName2)); } } } else { collection.Add(new PSSnapInTypeAndFormatErrors(str, checkFullFileName1)); } } } return(collection); }
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 LoadPSSnapIn(PSSnapInInfo mshsnapinInfo) { if (mshsnapinInfo != null) { if (!string.IsNullOrEmpty(mshsnapinInfo.CustomPSSnapInType)) { this.LoadCustomPSSnapIn(mshsnapinInfo); } else { 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 { _mshsnapinTracer.WriteLine("Loading assembly for mshsnapin {0} succeeded", new object[] { mshsnapinInfo.Name }); this.AnalyzeMshSnapinAssembly(assembly, mshsnapinInfo); foreach (string str in mshsnapinInfo.Types) { string name = Path.Combine(mshsnapinInfo.ApplicationBase, str); TypeConfigurationEntry entry = new TypeConfigurationEntry(name, name, mshsnapinInfo); this.Types.AddBuiltInItem(entry); } foreach (string str3 in mshsnapinInfo.Formats) { string str4 = Path.Combine(mshsnapinInfo.ApplicationBase, str3); FormatConfigurationEntry entry2 = new FormatConfigurationEntry(str4, str4, mshsnapinInfo); this.Formats.AddBuiltInItem(entry2); } AssemblyConfigurationEntry item = new AssemblyConfigurationEntry(mshsnapinInfo.AssemblyName, mshsnapinInfo.AbsoluteModulePath, mshsnapinInfo); this.Assemblies.AddBuiltInItem(item); } } } }
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 LoadPSSnapIn(PSSnapInInfo mshsnapinInfo) { if (mshsnapinInfo == null) return; #if !CORECLR // CustomPSSnapIn Not Supported On CSS. if (!String.IsNullOrEmpty(mshsnapinInfo.CustomPSSnapInType)) { LoadCustomPSSnapIn(mshsnapinInfo); return; } #endif 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; } s_mshsnapinTracer.WriteLine("Loading assembly for mshsnapin {0} succeeded", mshsnapinInfo.Name); Dictionary<string, SessionStateCmdletEntry> cmdlets = null; Dictionary<string, List<SessionStateAliasEntry>> aliases = null; Dictionary<string, SessionStateProviderEntry> providers = null; string throwAwayHelpFile = null; PSSnapInHelpers.AnalyzePSSnapInAssembly(assembly, assembly.Location, mshsnapinInfo, null, false, out cmdlets, out aliases, out providers, out throwAwayHelpFile); if (cmdlets != null) { foreach (var c in cmdlets) { CmdletConfigurationEntry cmdlet = new CmdletConfigurationEntry(c.Key, c.Value.ImplementingType, c.Value.HelpFileName, mshsnapinInfo); _cmdlets.AddBuiltInItem(cmdlet); } } if (providers != null) { foreach (var p in providers) { ProviderConfigurationEntry provider = new ProviderConfigurationEntry(p.Key, p.Value.ImplementingType, p.Value.HelpFileName, mshsnapinInfo); _providers.AddBuiltInItem(provider); } } foreach (string file in mshsnapinInfo.Types) { string path = Path.Combine(mshsnapinInfo.ApplicationBase, file); TypeConfigurationEntry typeEntry = new TypeConfigurationEntry(path, path, mshsnapinInfo); this.Types.AddBuiltInItem(typeEntry); } foreach (string file in mshsnapinInfo.Formats) { string path = Path.Combine(mshsnapinInfo.ApplicationBase, file); FormatConfigurationEntry formatEntry = new FormatConfigurationEntry(path, path, mshsnapinInfo); this.Formats.AddBuiltInItem(formatEntry); } AssemblyConfigurationEntry assemblyEntry = new AssemblyConfigurationEntry(mshsnapinInfo.AssemblyName, mshsnapinInfo.AbsoluteModulePath, mshsnapinInfo); this.Assemblies.AddBuiltInItem(assemblyEntry); return; }
private void LoadPSSnapIn(PSSnapInInfo mshsnapinInfo) { if (mshsnapinInfo == null) { return; } #if !CORECLR // CustomPSSnapIn Not Supported On CSS. if (!String.IsNullOrEmpty(mshsnapinInfo.CustomPSSnapInType)) { LoadCustomPSSnapIn(mshsnapinInfo); return; } #endif 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; } s_mshsnapinTracer.WriteLine("Loading assembly for mshsnapin {0} succeeded", mshsnapinInfo.Name); Dictionary <string, SessionStateCmdletEntry> cmdlets = null; Dictionary <string, List <SessionStateAliasEntry> > aliases = null; Dictionary <string, SessionStateProviderEntry> providers = null; string throwAwayHelpFile = null; PSSnapInHelpers.AnalyzePSSnapInAssembly(assembly, assembly.Location, mshsnapinInfo, null, false, out cmdlets, out aliases, out providers, out throwAwayHelpFile); if (cmdlets != null) { foreach (var c in cmdlets) { CmdletConfigurationEntry cmdlet = new CmdletConfigurationEntry(c.Key, c.Value.ImplementingType, c.Value.HelpFileName, mshsnapinInfo); _cmdlets.AddBuiltInItem(cmdlet); } } if (providers != null) { foreach (var p in providers) { ProviderConfigurationEntry provider = new ProviderConfigurationEntry(p.Key, p.Value.ImplementingType, p.Value.HelpFileName, mshsnapinInfo); _providers.AddBuiltInItem(provider); } } foreach (string file in mshsnapinInfo.Types) { string path = Path.Combine(mshsnapinInfo.ApplicationBase, file); TypeConfigurationEntry typeEntry = new TypeConfigurationEntry(path, path, mshsnapinInfo); this.Types.AddBuiltInItem(typeEntry); } foreach (string file in mshsnapinInfo.Formats) { string path = Path.Combine(mshsnapinInfo.ApplicationBase, file); FormatConfigurationEntry formatEntry = new FormatConfigurationEntry(path, path, mshsnapinInfo); this.Formats.AddBuiltInItem(formatEntry); } AssemblyConfigurationEntry assemblyEntry = new AssemblyConfigurationEntry(mshsnapinInfo.AssemblyName, mshsnapinInfo.AbsoluteModulePath, mshsnapinInfo); this.Assemblies.AddBuiltInItem(assemblyEntry); return; }
internal static Collection <PSSnapInTypeAndFormatErrors> GetFormatAndTypesErrors(RunspaceConfiguration runspaceConfiguration, PSHost host, IEnumerable configurationEntryCollection, RunspaceConfigurationCategory category, Collection <string> independentErrors, Collection <int> entryIndicesToRemove) { Collection <PSSnapInTypeAndFormatErrors> collection = new Collection <PSSnapInTypeAndFormatErrors>(); string baseFolder = GetBaseFolder(runspaceConfiguration, independentErrors); HashSet <string> fullFileNameSet = new HashSet <string>(StringComparer.OrdinalIgnoreCase); int item = -1; foreach (object obj2 in configurationEntryCollection) { string fileName; string str3; bool flag; item++; if (category == RunspaceConfigurationCategory.Types) { TypeConfigurationEntry entry = (TypeConfigurationEntry)obj2; fileName = entry.FileName; str3 = (entry.PSSnapIn == null) ? runspaceConfiguration.ShellId : entry.PSSnapIn.Name; if (fileName != null) { goto Label_00DD; } collection.Add(new PSSnapInTypeAndFormatErrors(str3, entry.TypeData, entry.IsRemove)); continue; } FormatConfigurationEntry entry2 = (FormatConfigurationEntry)obj2; fileName = entry2.FileName; str3 = (entry2.PSSnapIn == null) ? runspaceConfiguration.ShellId : entry2.PSSnapIn.Name; if (fileName == null) { collection.Add(new PSSnapInTypeAndFormatErrors(str3, entry2.FormatData)); continue; } Label_00DD: flag = false; string xmlFileListFileName = GetAndCheckFullFileName(str3, fullFileNameSet, baseFolder, fileName, independentErrors, ref flag); if (xmlFileListFileName == null) { if (flag) { entryIndicesToRemove.Add(item); } } else if (xmlFileListFileName.EndsWith("filelist.ps1xml", StringComparison.OrdinalIgnoreCase)) { bool flag2; foreach (string str5 in runspaceConfiguration.TypeTable.ReadFiles(str3, xmlFileListFileName, independentErrors, runspaceConfiguration.AuthorizationManager, host, out flag2)) { string fullPath = GetAndCheckFullFileName(str3, fullFileNameSet, baseFolder, str5, independentErrors, ref flag); if (fullPath != null) { collection.Add(new PSSnapInTypeAndFormatErrors(str3, fullPath)); } } } else { collection.Add(new PSSnapInTypeAndFormatErrors(str3, xmlFileListFileName)); } } return(collection); }