diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Update-TypeData.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Update-TypeData.cs index f1b405ea84..77c3cd12fe 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Update-TypeData.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Update-TypeData.cs @@ -980,7 +980,7 @@ namespace Microsoft.PowerShell.Commands FormatAndTypeDataHelper.ThrowExceptionOnError("ErrorsUpdatingFormats", null, entries, - RunspaceConfigurationCategory.Formats); + FormatAndTypeDataHelper.Category.Formats); } } catch (RuntimeException e) diff --git a/src/System.Management.Automation/engine/CommandDiscovery.cs b/src/System.Management.Automation/engine/CommandDiscovery.cs index 8b37264332..5d4546d506 100644 --- a/src/System.Management.Automation/engine/CommandDiscovery.cs +++ b/src/System.Management.Automation/engine/CommandDiscovery.cs @@ -137,15 +137,6 @@ namespace System.Management.Automation discoveryTracer.ShowHeaders = false; } - private void AddCmdletToCache(CmdletConfigurationEntry entry) - { - if (!IsSpecialCmdlet(entry.ImplementingType)) - { - CmdletInfo newCmdletInfo = NewCmdletInfo(entry, SessionStateEntryVisibility.Public); - AddCmdletInfoToCache(newCmdletInfo.Name, newCmdletInfo, isGlobal: true); - } - } - /// /// Determines if the cmdlet is a cmdlet that shouldn't be in the discovery list. /// @@ -163,13 +154,6 @@ namespace System.Management.Automation return implementingType == typeof(OutLineOutputCommand) || implementingType == typeof(FormatDefaultCommand); } - private CmdletInfo NewCmdletInfo(CmdletConfigurationEntry entry, SessionStateEntryVisibility visibility) - { - CmdletInfo ci = new CmdletInfo(entry.Name, entry.ImplementingType, entry.HelpFileName, entry.PSSnapIn, Context); - ci.Visibility = visibility; - return ci; - } - private CmdletInfo NewCmdletInfo(SessionStateCmdletEntry entry) { return NewCmdletInfo(entry, Context); @@ -1555,49 +1539,6 @@ namespace System.Management.Automation } } - /// - /// Removes a cmdlet from the cmdlet cache. - /// - /// - /// The configuration entry for the cmdlet which is being removed. - /// - private void RemoveCmdletFromCache(CmdletConfigurationEntry entry) - { - IDictionary> cmdletTable = Context.EngineSessionState.GetCmdletTable(); - List cacheEntry; - if (cmdletTable.TryGetValue(entry.Name, out cacheEntry)) - { - int removalIndex = GetCmdletRemovalIndex(cacheEntry, entry.PSSnapIn == null ? String.Empty : entry.PSSnapIn.Name); - - if (removalIndex >= 0) - { - string name = cacheEntry[removalIndex].Name; - cacheEntry.RemoveAt(removalIndex); - Context.EngineSessionState.RemoveCmdlet(name, removalIndex, true); - } - - // Remove the entry from the cache if there are no more cmdlets - if (cacheEntry.Count == 0) - { - Context.EngineSessionState.RemoveCmdletEntry(entry.Name, true); - } - } - } - - private int GetCmdletRemovalIndex(List cacheEntry, string PSSnapin) - { - int removalIndex = -1; - for (int index = 0; index < cacheEntry.Count; ++index) - { - if (String.Equals(cacheEntry[index].ModuleName, PSSnapin, StringComparison.OrdinalIgnoreCase)) - { - removalIndex = index; - break; - } - } - return removalIndex; - } - internal ExecutionContext Context { get; } internal static PSModuleAutoLoadingPreference GetCommandDiscoveryPreference(ExecutionContext context, VariablePath variablePath, string environmentVariable) diff --git a/src/System.Management.Automation/engine/RunspaceConfigurationEntry.cs b/src/System.Management.Automation/engine/RunspaceConfigurationEntry.cs deleted file mode 100644 index 774944fd10..0000000000 --- a/src/System.Management.Automation/engine/RunspaceConfigurationEntry.cs +++ /dev/null @@ -1,529 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#pragma warning disable 1634, 1691 -#pragma warning disable 56506 - -namespace System.Management.Automation.Runspaces -{ - /// - /// Enum for describing different kind information that can be configured in runspace configuration. - /// - internal enum RunspaceConfigurationCategory - { - /// - /// Cmdlets - /// - Cmdlets, - - /// - /// Providers - /// - Providers, - - /// - /// Assemblies - /// - Assemblies, - - /// - /// Scripts - /// - Scripts, - - /// - /// Initialization scripts - /// - InitializationScripts, - - /// - /// Types - /// - Types, - - /// - /// Formats - /// - Formats, - } - - /// - /// Define class for runspace configuration entry. - /// - /// - /// This abstract class is to be derived internally by Monad for different - /// runspace configuration entries only. Developers should not derive from - /// this class. - /// - internal abstract class RunspaceConfigurationEntry - { - /// - /// Initiate an instance of runspace configuration entry. - /// - /// Name for the runspace configuration entry - /// - protected RunspaceConfigurationEntry(string name) - { - if (String.IsNullOrEmpty(name) || String.IsNullOrEmpty(name.Trim())) - { - throw PSTraceSource.NewArgumentNullException("name"); - } - - Name = name.Trim(); - } - - /// - /// Initiate an instance of runspace configuration entry. - /// - /// Name for the runspace configuration entry - /// The name of the PSSnapin the entry comes from. - /// - internal RunspaceConfigurationEntry(string name, PSSnapInInfo psSnapin) - { - if (String.IsNullOrEmpty(name) || String.IsNullOrEmpty(name.Trim())) - { - throw PSTraceSource.NewArgumentNullException("name"); - } - - Name = name.Trim(); - - if (psSnapin == null) - { - throw PSTraceSource.NewArgumentException("psSnapin"); - } - - PSSnapIn = psSnapin; - } - - /// - /// Gets name of configuration entry - /// - public string Name { get; } - - /// - /// Gets name of PSSnapin that this configuration entry belongs to. - /// - public PSSnapInInfo PSSnapIn { get; } = null; - - internal bool _builtIn = false; - /// - /// Get whether this entry is a built-in entry. - /// - public bool BuiltIn - { - get - { - return _builtIn; - } - } - - internal UpdateAction _action = UpdateAction.None; - internal UpdateAction Action - { - get - { - return _action; - } - } - } - - /// - /// Defines class for type configuration entry. - /// - internal sealed class TypeConfigurationEntry : RunspaceConfigurationEntry - { - /// - /// Initiate an instance for type configuration entry. - /// - /// Name of the type configuration entry - /// File name that contains the types configuration information. - /// when is null or empty - public TypeConfigurationEntry(string name, string fileName) - : base(name) - { - if (String.IsNullOrEmpty(fileName) || String.IsNullOrEmpty(fileName.Trim())) - { - throw PSTraceSource.NewArgumentException("fileName"); - } - - FileName = fileName.Trim(); - } - - /// - /// Initiate an instance for type configuration entry. - /// - /// TypeData instance - /// Specify the operation with the typedata - public TypeConfigurationEntry(TypeData typeData, bool isRemove) - : base("*") - { - if (typeData == null) - { - throw PSTraceSource.NewArgumentException("typeData"); - } - - TypeData = typeData; - IsRemove = isRemove; - } - - /// - /// Initiate an instance for type configuration entry. - /// - /// Name of the type configuration entry - /// File name that contains the types configuration information. - /// PSSnapin from which type info comes. - /// when is null, empty or does not end in .ps1xml - internal TypeConfigurationEntry(string name, string fileName, PSSnapInInfo psSnapinInfo) - : base(name, psSnapinInfo) - { - if (String.IsNullOrEmpty(fileName) || String.IsNullOrEmpty(fileName.Trim())) - { - throw PSTraceSource.NewArgumentException("fileName"); - } - - FileName = fileName.Trim(); - } - - /// - /// Initiate an instance for type configuration entry. - /// - /// File name that contains the types configuration information. - /// when is null, empty or does not end in .ps1xml - public TypeConfigurationEntry(string fileName) - : base(fileName) - { - if (String.IsNullOrEmpty(fileName) || String.IsNullOrEmpty(fileName.Trim())) - { - throw PSTraceSource.NewArgumentException("fileName"); - } -#pragma warning suppress 56506 - FileName = fileName.Trim(); - } - - /// - /// Gets file name that contains the types configuration information. - /// - /// - public string FileName { get; } - - /// - /// Get the strong type data contains the type configuration information - /// - public TypeData TypeData { get; } - - /// - /// Set to true if the strong type data is to be removed - /// - public bool IsRemove { get; } - } - - /// - /// Defines class for type configuration entry. - /// - internal sealed class FormatConfigurationEntry : RunspaceConfigurationEntry - { - /// - /// Initiate an instance for type configuration entry. - /// - /// Name of the format configuration entry - /// File name that contains the format configuration information. - /// when is null or empty - public FormatConfigurationEntry(string name, string fileName) - : base(name) - { - if (String.IsNullOrEmpty(fileName) || String.IsNullOrEmpty(fileName.Trim())) - { - throw PSTraceSource.NewArgumentException("fileName"); - } - - FileName = fileName.Trim(); - } - - /// - /// Initiate an instance for Format configuration entry. - /// - /// Name of the Format configuration entry - /// File name that contains the Formats configuration information. - /// PSSnapin from which the format comes. - /// when is null, empty or does not end in .ps1xml - internal FormatConfigurationEntry(string name, string fileName, PSSnapInInfo psSnapinInfo) - : base(name, psSnapinInfo) - { - if (String.IsNullOrEmpty(fileName) || String.IsNullOrEmpty(fileName.Trim())) - { - throw PSTraceSource.NewArgumentException("fileName"); - } - - FileName = fileName.Trim(); - } - - /// - /// Initiate an instance for type configuration entry. - /// - /// File name that contains the format configuration information. - /// when is null or empty - public FormatConfigurationEntry(string fileName) - : base(fileName) - { - if (String.IsNullOrEmpty(fileName) || String.IsNullOrEmpty(fileName.Trim())) - { - throw PSTraceSource.NewArgumentException("fileName"); - } -#pragma warning suppress 56506 - FileName = fileName.Trim(); - } - - /// - /// Initiate an instance for type configuration entry. - /// - /// - public FormatConfigurationEntry(ExtendedTypeDefinition typeDefinition) - : base("*") - { - if (typeDefinition == null) - { - throw PSTraceSource.NewArgumentNullException("typeDefinition"); - } - FormatData = typeDefinition; - } - - /// - /// Gets file name that contains the format configuration information. - /// - /// File name that contains the format configuration information. - public string FileName { get; } - - /// - /// Get the typeDefinition that contains the format configuration information - /// - public ExtendedTypeDefinition FormatData { get; } - } - - /// - /// Class to define configuration data for cmdlets - /// - internal sealed class CmdletConfigurationEntry : RunspaceConfigurationEntry - { - /// - /// Initiate an instance for cmdlet configuration entry. - /// - /// Name of the cmdlet configuration entry - /// Class that include implementation of the cmdlet - /// Name of the help file that include help information for the cmdlet - public CmdletConfigurationEntry(string name, Type implementingType, string helpFileName) - : base(name) - { - if (implementingType == null) - { - throw PSTraceSource.NewArgumentNullException("implementingType"); - } - - ImplementingType = implementingType; - - if (!String.IsNullOrEmpty(helpFileName)) - { - HelpFileName = helpFileName.Trim(); - } - else - { - HelpFileName = helpFileName; - } - } - - /// - /// Initiate an instance for cmdlet configuration entry. - /// - /// Name of the cmdlet configuration entry - /// Class that include implementation of the cmdlet - /// PSSnapin from which the cmdlet comes. - /// Name of the help file that include help information for the cmdlet - internal CmdletConfigurationEntry(string name, Type implementingType, string helpFileName, PSSnapInInfo psSnapinInfo) - : base(name, psSnapinInfo) - { - if (implementingType == null) - { - throw PSTraceSource.NewArgumentNullException("implementingType"); - } - - ImplementingType = implementingType; - - if (!String.IsNullOrEmpty(helpFileName)) - { - HelpFileName = helpFileName.Trim(); - } - else - { - HelpFileName = helpFileName; - } - } - - /// - /// Get class that include implementation of the cmdlet - /// - public Type ImplementingType { get; } - - /// - /// Get name of the help file that include help information for the cmdlet - /// - /// - public string HelpFileName { get; } - } - - /// - /// Define class for provider configuration entry - /// - internal sealed class ProviderConfigurationEntry : RunspaceConfigurationEntry - { - /// - /// Initiate an instance for provider configuration entry. - /// - /// Name of the provider configuration entry - /// Class that include implementation of the provider - /// Name of the help file that include help information for the provider - public ProviderConfigurationEntry(string name, Type implementingType, string helpFileName) - : base(name) - { - if (implementingType == null) - { - throw PSTraceSource.NewArgumentNullException("implementingType"); - } - - ImplementingType = implementingType; - - if (!String.IsNullOrEmpty(helpFileName)) - { - HelpFileName = helpFileName.Trim(); - } - else - { - HelpFileName = helpFileName; - } - } - - /// - /// Initiate an instance for provider configuration entry. - /// - /// Name of the provider configuration entry - /// Class that include implementation of the provider - /// Name of the help file that include help information for the provider - /// PSSnapin from which provider comes from. - internal ProviderConfigurationEntry(string name, Type implementingType, string helpFileName, PSSnapInInfo psSnapinInfo) - : base(name, psSnapinInfo) - { - if (implementingType == null) - { - throw PSTraceSource.NewArgumentNullException("implementingType"); - } - - ImplementingType = implementingType; - - if (!String.IsNullOrEmpty(helpFileName)) - { - HelpFileName = helpFileName.Trim(); - } - else - { - HelpFileName = helpFileName; - } - } - - /// - /// Get class that include implementation of the provider. - /// - /// - public Type ImplementingType { get; } - - /// - /// Get name of the help file that include help information for the provider - /// - public string HelpFileName { get; } - } - - /// - /// Define class for script configuration entry - /// - internal sealed class ScriptConfigurationEntry : RunspaceConfigurationEntry - { - /// - /// Initiate an instance for script configuration entry. - /// - /// Name of the script configuration entry - /// Content of the script - public ScriptConfigurationEntry(string name, string definition) - : base(name) - { - if (String.IsNullOrEmpty(definition) || String.IsNullOrEmpty(definition.Trim())) - { - throw PSTraceSource.NewArgumentNullException("definition"); - } - - Definition = definition.Trim(); - } - - /// - /// Get content for the script. - /// - public string Definition { get; } - } - - /// - /// Configuration data for assemblies. - /// - internal sealed class AssemblyConfigurationEntry : RunspaceConfigurationEntry - { - /// - /// Initiate an instance for assembly configuration entry. - /// - /// Strong name of the assembly - /// Name of the assembly file - public AssemblyConfigurationEntry(string name, string fileName) - : base(name) - { - if (String.IsNullOrEmpty(fileName) || String.IsNullOrEmpty(fileName.Trim())) - { - throw PSTraceSource.NewArgumentNullException("fileName"); - } - - FileName = fileName.Trim(); - } - - /// - /// Initiate an instance for assembly configuration entry. - /// - /// Strong name of the assembly - /// Name of the assembly file - /// PSSnapin information. - /// when is null, empty or does not end in .ps1xml - internal AssemblyConfigurationEntry(string name, string fileName, PSSnapInInfo psSnapinInfo) - : base(name, psSnapinInfo) - { - if (String.IsNullOrEmpty(fileName) || String.IsNullOrEmpty(fileName.Trim())) - { - throw PSTraceSource.NewArgumentNullException("fileName"); - } - - FileName = fileName.Trim(); - } - - /// - /// Get name of the assembly file - /// - /// Name of the assembly file - public string FileName { get; } - } - - internal enum UpdateAction - { - Add, - Remove, - None - } -} - -#pragma warning restore 56506 \ No newline at end of file diff --git a/src/System.Management.Automation/engine/TypeTable.cs b/src/System.Management.Automation/engine/TypeTable.cs index 0070b0e689..0d3e2181ee 100644 --- a/src/System.Management.Automation/engine/TypeTable.cs +++ b/src/System.Management.Automation/engine/TypeTable.cs @@ -4214,7 +4214,7 @@ namespace System.Management.Automation.Runspaces Update(errors, typeData, false); StandardMembersUpdated(); // Throw exception if there are any errors - FormatAndTypeDataHelper.ThrowExceptionOnError("ErrorsUpdatingTypes", errors, RunspaceConfigurationCategory.Types); + FormatAndTypeDataHelper.ThrowExceptionOnError("ErrorsUpdatingTypes", errors, FormatAndTypeDataHelper.Category.Types); } /// @@ -4240,7 +4240,7 @@ namespace System.Management.Automation.Runspaces Update(errors, typeData, true); StandardMembersUpdated(); // Throw exception if there are any errors - FormatAndTypeDataHelper.ThrowExceptionOnError("ErrorsUpdatingTypes", errors, RunspaceConfigurationCategory.Types); + FormatAndTypeDataHelper.ThrowExceptionOnError("ErrorsUpdatingTypes", errors, FormatAndTypeDataHelper.Category.Types); } /// diff --git a/src/System.Management.Automation/utils/FormatAndTypeDataHelper.cs b/src/System.Management.Automation/utils/FormatAndTypeDataHelper.cs index 3b5c3e31c1..18a493aa69 100644 --- a/src/System.Management.Automation/utils/FormatAndTypeDataHelper.cs +++ b/src/System.Management.Automation/utils/FormatAndTypeDataHelper.cs @@ -114,7 +114,7 @@ namespace System.Management.Automation.Runspaces string errorId, Collection independentErrors, Collection PSSnapinFilesCollection, - RunspaceConfigurationCategory category) + Category category) { Collection errors = new Collection(); if (independentErrors != null) @@ -148,12 +148,12 @@ namespace System.Management.Automation.Runspaces } string message = string.Empty; - if (category == RunspaceConfigurationCategory.Types) + if (category == Category.Types) { message = StringUtil.Format(ExtendedTypeSystem.TypesXmlError, allErrors.ToString()); } - else if (category == RunspaceConfigurationCategory.Formats) + else if (category == Category.Formats) { message = StringUtil.Format(FormatAndOutXmlLoadingStrings.FormatLoadingErrors, allErrors.ToString()); } @@ -165,7 +165,7 @@ namespace System.Management.Automation.Runspaces internal static void ThrowExceptionOnError( string errorId, ConcurrentBag errors, - RunspaceConfigurationCategory category) + Category category) { if (errors.Count == 0) { @@ -182,12 +182,12 @@ namespace System.Management.Automation.Runspaces } string message = string.Empty; - if (category == RunspaceConfigurationCategory.Types) + if (category == Category.Types) { message = StringUtil.Format(ExtendedTypeSystem.TypesXmlError, allErrors.ToString()); } - else if (category == RunspaceConfigurationCategory.Formats) + else if (category == Category.Formats) { message = StringUtil.Format(FormatAndOutXmlLoadingStrings.FormatLoadingErrors, allErrors.ToString()); } @@ -195,6 +195,12 @@ namespace System.Management.Automation.Runspaces ex.SetErrorId(errorId); throw ex; } + + internal enum Category + { + Types, + Formats, + } } }