internal static void ThrowExceptionOnError( string errorId, ConcurrentBag <string> errors, RunspaceConfigurationCategory category) { if (errors.Count == 0) { return; } StringBuilder allErrors = new StringBuilder(); allErrors.Append('\n'); foreach (string error in errors) { allErrors.Append(error); allErrors.Append('\n'); } string message = ""; if (category == RunspaceConfigurationCategory.Types) { message = StringUtil.Format(ExtendedTypeSystem.TypesXmlError, allErrors.ToString()); } else if (category == RunspaceConfigurationCategory.Formats) { message = StringUtil.Format(FormatAndOutXmlLoadingStrings.FormatLoadingErrors, allErrors.ToString()); } RuntimeException ex = new RuntimeException(message); ex.SetErrorId(errorId); throw ex; }
internal static void ThrowExceptionOnError( string errorId, Collection <string> independentErrors, Collection <PSSnapInTypeAndFormatErrors> PSSnapinFilesCollection, RunspaceConfigurationCategory category) { Collection <string> errors = new Collection <string>(); if (independentErrors != null) { foreach (string error in independentErrors) { errors.Add(error); } } foreach (PSSnapInTypeAndFormatErrors PSSnapinFiles in PSSnapinFilesCollection) { foreach (string error in PSSnapinFiles.Errors) { errors.Add(error); } } if (errors.Count == 0) { return; } StringBuilder allErrors = new StringBuilder(); allErrors.Append('\n'); foreach (string error in errors) { allErrors.Append(error); allErrors.Append('\n'); } string message = ""; if (category == RunspaceConfigurationCategory.Types) { message = StringUtil.Format(ExtendedTypeSystem.TypesXmlError, allErrors.ToString()); } else if (category == RunspaceConfigurationCategory.Formats) { message = StringUtil.Format(FormatAndOutXmlLoadingStrings.FormatLoadingErrors, allErrors.ToString()); } RuntimeException ex = new RuntimeException(message); ex.SetErrorId(errorId); throw ex; }
/// <summary> /// Remove duplicate entries and entries with files that cannot be loaded from the Types and Formats /// </summary> /// <param name="category"></param> /// <param name="entryIndicesToRemove"></param> private void RemoveNeedlessEntries(RunspaceConfigurationCategory category, IList <int> entryIndicesToRemove) { for (int i = entryIndicesToRemove.Count - 1; i >= 0; i--) { if (category == RunspaceConfigurationCategory.Types) { this.Types.RemoveItem(entryIndicesToRemove[i]); } else if (category == RunspaceConfigurationCategory.Formats) { this.Formats.RemoveItem(entryIndicesToRemove[i]); } } }
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); }
internal static void ThrowExceptionOnError( string errorId, Collection <string> independentErrors, Collection <PSSnapInTypeAndFormatErrors> PSSnapinFilesCollection, RunspaceConfigurationCategory category) { Collection <string> collection = new Collection <string>(); foreach (string independentError in independentErrors) { collection.Add(independentError); } foreach (PSSnapInTypeAndFormatErrors psSnapinFiles in PSSnapinFilesCollection) { foreach (string error in psSnapinFiles.Errors) { collection.Add(error); } } if (collection.Count != 0) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append('\n'); foreach (string str in collection) { stringBuilder.Append(str); stringBuilder.Append('\n'); } string message = ""; switch (category) { case RunspaceConfigurationCategory.Types: message = ResourceManagerCache.FormatResourceString("ExtendedTypeSystem", "TypesXmlError", (object)stringBuilder.ToString()); break; case RunspaceConfigurationCategory.Formats: message = XmlLoadingResourceManager.FormatString("FormatLoadingErrors", (object)stringBuilder.ToString()); break; } RuntimeException runtimeException = new RuntimeException(message); runtimeException.SetErrorId(errorId); throw runtimeException; } }
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; }
internal static void ThrowExceptionOnError(string errorId, Collection<string> independentErrors, Collection<PSSnapInTypeAndFormatErrors> PSSnapinFilesCollection, RunspaceConfigurationCategory category) { Collection<string> collection = new Collection<string>(); if (independentErrors != null) { foreach (string str in independentErrors) { collection.Add(str); } } foreach (PSSnapInTypeAndFormatErrors errors in PSSnapinFilesCollection) { foreach (string str2 in errors.Errors) { collection.Add(str2); } } if (collection.Count != 0) { StringBuilder builder = new StringBuilder(); builder.Append('\n'); foreach (string str3 in collection) { builder.Append(str3); builder.Append('\n'); } string message = ""; if (category == RunspaceConfigurationCategory.Types) { message = StringUtil.Format(ExtendedTypeSystem.TypesXmlError, builder.ToString()); } else if (category == RunspaceConfigurationCategory.Formats) { message = StringUtil.Format(FormatAndOutXmlLoadingStrings.FormatLoadingErrors, builder.ToString()); } RuntimeException exception = new RuntimeException(message); exception.SetErrorId(errorId); throw exception; } }
internal static void ThrowExceptionOnError(string errorId, Collection<string> errors, RunspaceConfigurationCategory category) { if (errors.Count != 0) { StringBuilder builder = new StringBuilder(); builder.Append('\n'); foreach (string str in errors) { builder.Append(str); builder.Append('\n'); } string message = ""; if (category == RunspaceConfigurationCategory.Types) { message = StringUtil.Format(ExtendedTypeSystem.TypesXmlError, builder.ToString()); } else if (category == RunspaceConfigurationCategory.Formats) { message = StringUtil.Format(FormatAndOutXmlLoadingStrings.FormatLoadingErrors, builder.ToString()); } RuntimeException exception = new RuntimeException(message); exception.SetErrorId(errorId); throw exception; } }
/// <summary> /// Remove duplicate entries and entries with files that cannot be loaded from the Types and Formats /// </summary> /// <param name="category"></param> /// <param name="entryIndicesToRemove"></param> private void RemoveNeedlessEntries(RunspaceConfigurationCategory category, IList<int> entryIndicesToRemove) { for (int i = entryIndicesToRemove.Count - 1; i >= 0; i--) { if (category == RunspaceConfigurationCategory.Types) { this.Types.RemoveItem(entryIndicesToRemove[i]); } else if (category == RunspaceConfigurationCategory.Formats) { this.Formats.RemoveItem(entryIndicesToRemove[i]); } } }
internal static void ThrowExceptionOnError( string errorId, ConcurrentBag<string> errors, RunspaceConfigurationCategory category) { if (errors.Count == 0) { return; } StringBuilder allErrors = new StringBuilder(); allErrors.Append('\n'); foreach (string error in errors) { allErrors.Append(error); allErrors.Append('\n'); } string message = ""; if (category == RunspaceConfigurationCategory.Types) { message = StringUtil.Format(ExtendedTypeSystem.TypesXmlError, allErrors.ToString()); } else if (category == RunspaceConfigurationCategory.Formats) { message = StringUtil.Format(FormatAndOutXmlLoadingStrings.FormatLoadingErrors, allErrors.ToString()); } RuntimeException ex = new RuntimeException(message); ex.SetErrorId(errorId); throw ex; }
internal static void ThrowExceptionOnError( string errorId, Collection<string> independentErrors, Collection<PSSnapInTypeAndFormatErrors> PSSnapinFilesCollection, RunspaceConfigurationCategory category) { Collection<string> errors = new Collection<string>(); if (independentErrors != null) { foreach (string error in independentErrors) { errors.Add(error); } } foreach (PSSnapInTypeAndFormatErrors PSSnapinFiles in PSSnapinFilesCollection) { foreach (string error in PSSnapinFiles.Errors) { errors.Add(error); } } if (errors.Count == 0) { return; } StringBuilder allErrors = new StringBuilder(); allErrors.Append('\n'); foreach (string error in errors) { allErrors.Append(error); allErrors.Append('\n'); } string message = ""; if (category == RunspaceConfigurationCategory.Types) { message = StringUtil.Format(ExtendedTypeSystem.TypesXmlError, allErrors.ToString()); } else if (category == RunspaceConfigurationCategory.Formats) { message = StringUtil.Format(FormatAndOutXmlLoadingStrings.FormatLoadingErrors, allErrors.ToString()); } RuntimeException ex = new RuntimeException(message); ex.SetErrorId(errorId); throw ex; }
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); }
internal static void ThrowExceptionOnError(string errorId, Collection <string> independentErrors, Collection <PSSnapInTypeAndFormatErrors> PSSnapinFilesCollection, RunspaceConfigurationCategory category) { Collection <string> collection = new Collection <string>(); if (independentErrors != null) { foreach (string str in independentErrors) { collection.Add(str); } } foreach (PSSnapInTypeAndFormatErrors errors in PSSnapinFilesCollection) { foreach (string str2 in errors.Errors) { collection.Add(str2); } } if (collection.Count != 0) { StringBuilder builder = new StringBuilder(); builder.Append('\n'); foreach (string str3 in collection) { builder.Append(str3); builder.Append('\n'); } string message = ""; if (category == RunspaceConfigurationCategory.Types) { message = StringUtil.Format(ExtendedTypeSystem.TypesXmlError, builder.ToString()); } else if (category == RunspaceConfigurationCategory.Formats) { message = StringUtil.Format(FormatAndOutXmlLoadingStrings.FormatLoadingErrors, builder.ToString()); } RuntimeException exception = new RuntimeException(message); exception.SetErrorId(errorId); throw exception; } }
internal static void ThrowExceptionOnError(string errorId, Collection <string> errors, RunspaceConfigurationCategory category) { if (errors.Count != 0) { StringBuilder builder = new StringBuilder(); builder.Append('\n'); foreach (string str in errors) { builder.Append(str); builder.Append('\n'); } string message = ""; if (category == RunspaceConfigurationCategory.Types) { message = StringUtil.Format(ExtendedTypeSystem.TypesXmlError, builder.ToString()); } else if (category == RunspaceConfigurationCategory.Formats) { message = StringUtil.Format(FormatAndOutXmlLoadingStrings.FormatLoadingErrors, builder.ToString()); } RuntimeException exception = new RuntimeException(message); exception.SetErrorId(errorId); throw exception; } }