mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Merge pull request #2363 from lzybkr/maxvars
Remove most Maximum* capacity variables
This commit is contained in:
@@ -1732,11 +1732,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
pathNotFound));
|
||||
return;
|
||||
}
|
||||
catch (SessionStateOverflowException)
|
||||
{
|
||||
// This is terminating condition
|
||||
throw;
|
||||
}
|
||||
catch (SessionStateException sessionStateException)
|
||||
{
|
||||
WriteError(
|
||||
|
||||
@@ -114,10 +114,6 @@ namespace System.Management.Automation
|
||||
/// <exception cref="ProviderInvocationException">
|
||||
/// If the provider threw an exception or returned null.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If creating the drive will overflow the MaximumDriveCount limit.
|
||||
/// </exception>
|
||||
public PSDriveInfo New(PSDriveInfo drive, string scope)
|
||||
{
|
||||
Dbg.Diagnostics.Assert(
|
||||
@@ -173,11 +169,6 @@ namespace System.Management.Automation
|
||||
/// <exception cref="ProviderInvocationException">
|
||||
/// If the provider threw an exception or returned null.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If creating the drive will overflow the MaximumDriveCount limit.
|
||||
/// </exception>
|
||||
///
|
||||
internal void New(
|
||||
PSDriveInfo drive,
|
||||
string scope,
|
||||
|
||||
@@ -802,39 +802,8 @@ namespace System.Management.Automation
|
||||
return;
|
||||
}
|
||||
|
||||
// 1045384-2004/12/14-JonN implementing $MaximumErrorCount
|
||||
object maxcountobj = EngineSessionState.CurrentScope.ErrorCapacity.FastValue;
|
||||
if (null != maxcountobj)
|
||||
{
|
||||
try
|
||||
{
|
||||
maxcountobj = LanguagePrimitives.ConvertTo(maxcountobj, typeof(int), CultureInfo.InvariantCulture);
|
||||
}
|
||||
catch (PSInvalidCastException)
|
||||
{
|
||||
}
|
||||
catch (System.OverflowException)
|
||||
{
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Diagnostics.Assert(false,
|
||||
"Unexpected exception in LanguagePrimitives.ConvertTo: "
|
||||
+ e.GetType().FullName);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
int maxErrorCount = (maxcountobj is int) ? (int)maxcountobj : 256;
|
||||
if (0 > maxErrorCount)
|
||||
maxErrorCount = 0;
|
||||
else if (32768 < maxErrorCount)
|
||||
maxErrorCount = 32768;
|
||||
const int maxErrorCount = 256;
|
||||
|
||||
if (0 >= maxErrorCount)
|
||||
{
|
||||
arraylist.Clear();
|
||||
return;
|
||||
}
|
||||
int numToErase = arraylist.Count - (maxErrorCount - 1);
|
||||
if (0 < numToErase)
|
||||
{
|
||||
|
||||
@@ -3138,7 +3138,6 @@ namespace System.Management.Automation.Runspaces
|
||||
catch (NotSupportedException e) { ex = e; }
|
||||
catch (ProviderNotFoundException e) { ex = e; }
|
||||
catch (ProviderInvocationException e) { ex = e; }
|
||||
catch (SessionStateOverflowException e) { ex = e; }
|
||||
catch (KeyNotFoundException e) { ex = e; }
|
||||
catch (IOException e) { ex = e; }
|
||||
catch (UnauthorizedAccessException e) { ex = e; }
|
||||
|
||||
@@ -158,9 +158,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Execute the begin scriptblock at the start of processing
|
||||
/// </summary>
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// The maximum scope depth would be exceeded
|
||||
/// </exception>
|
||||
/// <exception cref="ParseException">could not parse script</exception>
|
||||
/// <exception cref="RuntimeException">see Pipeline.Invoke</exception>
|
||||
/// <exception cref="ParameterBindingException">see Pipeline.Invoke</exception>
|
||||
@@ -242,9 +239,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// Execute the processing script blocks on the current pipeline object
|
||||
/// which is passed as it's only parameter.
|
||||
/// </summary>
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// The maximum scope depth would be exceeded
|
||||
/// </exception>
|
||||
/// <exception cref="ParseException">could not parse script</exception>
|
||||
/// <exception cref="RuntimeException">see Pipeline.Invoke</exception>
|
||||
/// <exception cref="ParameterBindingException">see Pipeline.Invoke</exception>
|
||||
@@ -733,9 +727,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Execute the end scriptblock when the pipeline is complete
|
||||
/// </summary>
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// The maximum scope depth would be exceeded
|
||||
/// </exception>
|
||||
/// <exception cref="ParseException">could not parse script</exception>
|
||||
/// <exception cref="RuntimeException">see Pipeline.Invoke</exception>
|
||||
/// <exception cref="ParameterBindingException">see Pipeline.Invoke</exception>
|
||||
@@ -1456,9 +1447,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// Execute the script block passing in the current pipeline object as
|
||||
/// it's only parameter.
|
||||
/// </summary>
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// The maximum scope depth would be exceeded
|
||||
/// </exception>
|
||||
/// <exception cref="ParseException">could not parse script</exception>
|
||||
/// <exception cref="RuntimeException">see Pipeline.Invoke</exception>
|
||||
/// <exception cref="ParameterBindingException">see Pipeline.Invoke</exception>
|
||||
|
||||
@@ -1058,8 +1058,7 @@ namespace System.Management.Automation
|
||||
}
|
||||
|
||||
internal static string[] _builtinVariables = new string[] { "_", "this", "input", "args", "true", "false", "null",
|
||||
"MaximumErrorCount", "MaximumVariableCount", "MaximumFunctionCount","MaximumAliasCount", "PSDefaultParameterValues",
|
||||
"MaximumDriveCount", "Error", "PSScriptRoot", "PSCommandPath", "MyInvocation", "ExecutionContext", "StackTrace" };
|
||||
"PSDefaultParameterValues", "Error", "PSScriptRoot", "PSCommandPath", "MyInvocation", "ExecutionContext", "StackTrace" };
|
||||
|
||||
/// <summary>
|
||||
/// Lists the variables exported by this module.
|
||||
|
||||
@@ -1846,10 +1846,6 @@ namespace System.Management.Automation
|
||||
args: new object[] { value });
|
||||
return value;
|
||||
}
|
||||
catch (SessionStateOverflowException e)
|
||||
{
|
||||
throw NewSetValueException(e, "ScriptSetValueSessionStateOverflowException");
|
||||
}
|
||||
catch (RuntimeException e)
|
||||
{
|
||||
throw NewSetValueException(e, "ScriptSetValueRuntimeException");
|
||||
@@ -1881,10 +1877,6 @@ namespace System.Management.Automation
|
||||
scriptThis: scriptThis,
|
||||
args: Utils.EmptyArray<object>());
|
||||
}
|
||||
catch (SessionStateOverflowException e)
|
||||
{
|
||||
throw NewGetValueException(e, "ScriptGetValueSessionStateOverflowException");
|
||||
}
|
||||
catch (RuntimeException e)
|
||||
{
|
||||
throw NewGetValueException(e, "ScriptGetValueRuntimeException");
|
||||
@@ -2424,14 +2416,6 @@ namespace System.Management.Automation
|
||||
scriptThis: @this,
|
||||
args: arguments);
|
||||
}
|
||||
catch (SessionStateOverflowException e)
|
||||
{
|
||||
throw new MethodInvocationException(
|
||||
"ScriptMethodSessionStateOverflowException",
|
||||
e,
|
||||
ExtendedTypeSystem.MethodInvocationException,
|
||||
methodName, arguments.Length, e.Message);
|
||||
}
|
||||
catch (RuntimeException e)
|
||||
{
|
||||
throw new MethodInvocationException(
|
||||
|
||||
@@ -277,10 +277,6 @@ namespace System.Management.Automation
|
||||
/// If the alias is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of aliases has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal AliasInfo SetAliasValue(string aliasName, string value, bool force, CommandOrigin origin)
|
||||
{
|
||||
if (String.IsNullOrEmpty(aliasName))
|
||||
@@ -328,10 +324,6 @@ namespace System.Management.Automation
|
||||
/// If the alias is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of aliases has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal AliasInfo SetAliasValue(string aliasName, string value, bool force)
|
||||
{
|
||||
return SetAliasValue(aliasName, value, force, CommandOrigin.Internal);
|
||||
@@ -373,10 +365,6 @@ namespace System.Management.Automation
|
||||
/// If the alias is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of aliases has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal AliasInfo SetAliasValue(
|
||||
string aliasName,
|
||||
string value,
|
||||
@@ -432,10 +420,6 @@ namespace System.Management.Automation
|
||||
/// If the alias is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of aliases has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal AliasInfo SetAliasValue(
|
||||
string aliasName,
|
||||
string value,
|
||||
@@ -474,10 +458,6 @@ namespace System.Management.Automation
|
||||
/// If the alias is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of aliases has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal AliasInfo SetAliasItem(AliasInfo alias, bool force, CommandOrigin origin)
|
||||
{
|
||||
if (alias == null)
|
||||
@@ -535,10 +515,6 @@ namespace System.Management.Automation
|
||||
/// If the alias is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of aliases has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal AliasInfo SetAliasItemAtScope(AliasInfo alias, string scopeID, bool force, CommandOrigin origin)
|
||||
{
|
||||
if (alias == null)
|
||||
@@ -602,10 +578,6 @@ namespace System.Management.Automation
|
||||
/// If the alias is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of aliases has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal AliasInfo SetAliasItemAtScope(AliasInfo alias, string scopeID, bool force)
|
||||
{
|
||||
return SetAliasItemAtScope(alias, scopeID, force, CommandOrigin.Internal);
|
||||
|
||||
@@ -1,175 +0,0 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System.Diagnostics.CodeAnalysis; // for fxcop
|
||||
using System.Globalization;
|
||||
using Dbg = System.Management.Automation;
|
||||
|
||||
namespace System.Management.Automation
|
||||
{
|
||||
/// <summary>
|
||||
/// A variable that represents the maximum capacity for object types in a scope.
|
||||
/// An separate instance is created for functions, aliases, variables, and drives.
|
||||
/// </summary>
|
||||
internal class SessionStateCapacityVariable : PSVariable
|
||||
{
|
||||
#region ctor
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an instance of the variable with the specified name and
|
||||
/// initial capacity.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="name">
|
||||
/// The name of the variable.
|
||||
/// </param>
|
||||
///
|
||||
/// <param name="defaultCapacity">
|
||||
/// The initial capacity
|
||||
/// </param>
|
||||
///
|
||||
/// <param name="maxCapacity">
|
||||
/// The maximum capacity for the scope.
|
||||
/// </param>
|
||||
///
|
||||
/// <param name="minCapacity">
|
||||
/// The minimum capacity for the scope.
|
||||
/// </param>
|
||||
///
|
||||
/// <param name="options">Scoped item options for this variable</param>
|
||||
internal SessionStateCapacityVariable(
|
||||
string name,
|
||||
int defaultCapacity,
|
||||
int maxCapacity,
|
||||
int minCapacity,
|
||||
ScopedItemOptions options)
|
||||
: base(name, defaultCapacity, options)
|
||||
{
|
||||
// Now add a range constraint to the variable so that
|
||||
// it is discoverable...
|
||||
|
||||
ValidateRangeAttribute validateRange =
|
||||
new ValidateRangeAttribute(minCapacity, maxCapacity);
|
||||
_minCapacity = minCapacity;
|
||||
_maxCapacity = maxCapacity;
|
||||
base.Attributes.Add(validateRange);
|
||||
_fastValue = defaultCapacity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an instance of the variable with the specified name and
|
||||
/// initial capacity.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="name">
|
||||
/// The name of the variable.
|
||||
/// </param>
|
||||
///
|
||||
/// <param name="sharedCapacityVariable">
|
||||
/// A reference to a SessionStateCapacityVariable in another scope. The value
|
||||
/// will be shared in this scope unless the capacity gets set in this scope.
|
||||
/// </param>
|
||||
///
|
||||
/// <param name="options">The scoped item options for this variable</param>
|
||||
[SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "This is internal code and is verified to behave correctly.")]
|
||||
public SessionStateCapacityVariable(
|
||||
string name,
|
||||
SessionStateCapacityVariable sharedCapacityVariable,
|
||||
ScopedItemOptions options)
|
||||
: base(name, sharedCapacityVariable.Value, options)
|
||||
{
|
||||
// Now add range constraints to the variable.
|
||||
|
||||
ValidateRangeAttribute validateRange =
|
||||
new ValidateRangeAttribute(0, int.MaxValue);
|
||||
base.Attributes.Add(validateRange);
|
||||
|
||||
_sharedCapacityVariable = sharedCapacityVariable;
|
||||
|
||||
// Also propagate the description to prevent re-fetching them from the
|
||||
// resource manager. That causes a measurable performance degradation.
|
||||
this.Description = sharedCapacityVariable.Description;
|
||||
|
||||
// Initialize the fast value...
|
||||
_fastValue = (int)sharedCapacityVariable.Value;
|
||||
}
|
||||
#endregion ctor
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the variable.
|
||||
/// This class will always return an int from the getter. The value is
|
||||
/// either inherited from a parent scope, or stored locally
|
||||
/// </summary>
|
||||
///
|
||||
public override object Value
|
||||
{
|
||||
get
|
||||
{
|
||||
object result;
|
||||
|
||||
if (_sharedCapacityVariable != null)
|
||||
{
|
||||
result = _sharedCapacityVariable.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = base.Value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_sharedCapacityVariable = null;
|
||||
base.Value = LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
|
||||
_fastValue = (int)base.Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides fast access to the capacity variable as an int, eliminating the need
|
||||
/// for casts...
|
||||
/// </summary>
|
||||
internal int FastValue
|
||||
{
|
||||
get { return _fastValue; }
|
||||
}
|
||||
private int _fastValue;
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the base IsValidValue to ensure the value is an int.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="value">
|
||||
/// The value to test.
|
||||
/// </param>
|
||||
///
|
||||
/// <returns>
|
||||
/// true if the value is an int and the base class IsValidValue is true, otherwise
|
||||
/// false.
|
||||
/// </returns>
|
||||
///
|
||||
/// <exception cref="ValidationMetadataException">
|
||||
/// If the validation metadata throws an exception.
|
||||
/// </exception>
|
||||
///
|
||||
public override bool IsValidValue(object value)
|
||||
{
|
||||
int capacity = (int)value;
|
||||
// If the value is within the limits, then return true
|
||||
// otherwise call the base validator so we'll get the error
|
||||
// from the validation attribute...
|
||||
if (capacity >= _minCapacity && capacity <= _maxCapacity)
|
||||
return true;
|
||||
else
|
||||
return base.IsValidValue(value);
|
||||
}
|
||||
|
||||
private int _minCapacity;
|
||||
private int _maxCapacity = int.MaxValue;
|
||||
|
||||
private SessionStateCapacityVariable _sharedCapacityVariable;
|
||||
} // class SessionStateCapacityVariable
|
||||
}
|
||||
|
||||
@@ -71,10 +71,6 @@ namespace System.Management.Automation
|
||||
/// If the provider threw an exception or returned null.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If creating the drive will overflow the MaximumDriveCount limit.
|
||||
/// </exception>
|
||||
///
|
||||
internal PSDriveInfo NewDrive(PSDriveInfo drive, string scopeID)
|
||||
{
|
||||
if (drive == null)
|
||||
@@ -160,10 +156,6 @@ namespace System.Management.Automation
|
||||
/// If the provider threw an exception or returned null.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If creating the drive will overflow the MaximumDriveCount limit.
|
||||
/// </exception>
|
||||
///
|
||||
internal void NewDrive(PSDriveInfo drive, string scopeID, CmdletProviderContext context)
|
||||
{
|
||||
if (drive == null)
|
||||
|
||||
@@ -245,10 +245,6 @@ namespace System.Management.Automation
|
||||
/// If the function is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of functions have been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal FunctionInfo SetFunctionRaw(
|
||||
string name,
|
||||
ScriptBlock function,
|
||||
@@ -397,10 +393,6 @@ namespace System.Management.Automation
|
||||
/// If the function is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of functions have been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal FunctionInfo SetFunction(
|
||||
string name,
|
||||
ScriptBlock function,
|
||||
@@ -456,10 +448,6 @@ namespace System.Management.Automation
|
||||
/// If the function is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of functions have been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal FunctionInfo SetFunction(
|
||||
string name,
|
||||
ScriptBlock function,
|
||||
@@ -519,10 +507,6 @@ namespace System.Management.Automation
|
||||
/// If the function is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of functions have been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal FunctionInfo SetFunction(
|
||||
string name,
|
||||
ScriptBlock function,
|
||||
@@ -588,10 +572,6 @@ namespace System.Management.Automation
|
||||
/// If the function is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of functions have been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal FunctionInfo SetFunction(
|
||||
string name,
|
||||
ScriptBlock function,
|
||||
@@ -685,10 +665,6 @@ namespace System.Management.Automation
|
||||
/// If the function is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of functions have been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal FunctionInfo SetFunction(
|
||||
string name,
|
||||
ScriptBlock function,
|
||||
@@ -806,10 +782,6 @@ namespace System.Management.Automation
|
||||
/// If the function is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of functions have been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal FunctionInfo SetFunction(string name, ScriptBlock function, bool force)
|
||||
{
|
||||
return SetFunction(name, function, null, force, CommandOrigin.Internal);
|
||||
|
||||
@@ -1135,11 +1135,6 @@ namespace System.Management.Automation
|
||||
/// provider tries to add.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the provider tries to add default drives which exceed the maximum
|
||||
/// limit for the number of drives in the current scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal void InitializeProvider(
|
||||
Provider.CmdletProvider providerInstance,
|
||||
ProviderInfo provider,
|
||||
|
||||
@@ -41,56 +41,6 @@ namespace System.Management.Automation
|
||||
}
|
||||
} // SessionStateScope constructor
|
||||
|
||||
private SessionStateCapacityVariable CreateCapacityVariable(
|
||||
string variableName,
|
||||
int defaultCapacity,
|
||||
int maxCapacity,
|
||||
int minCapacity,
|
||||
string descriptionResourceString
|
||||
)
|
||||
{
|
||||
// First do the lookup to see if a variable already exists.
|
||||
|
||||
SessionStateCapacityVariable capacityVariable = null;
|
||||
|
||||
if (Parent != null)
|
||||
{
|
||||
capacityVariable =
|
||||
Parent.GetVariable(variableName) as SessionStateCapacityVariable;
|
||||
}
|
||||
|
||||
if (capacityVariable == null)
|
||||
{
|
||||
// Since we weren't able to find an existing one, create a new one
|
||||
capacityVariable =
|
||||
new SessionStateCapacityVariable(
|
||||
variableName,
|
||||
defaultCapacity,
|
||||
maxCapacity,
|
||||
minCapacity,
|
||||
ScopedItemOptions.None);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Since we did find one, create a local capacity variable with a reference
|
||||
// to it.
|
||||
|
||||
capacityVariable =
|
||||
new SessionStateCapacityVariable(
|
||||
variableName,
|
||||
capacityVariable,
|
||||
ScopedItemOptions.None);
|
||||
}
|
||||
|
||||
// Only initialize the description if it is null or empty. Initializing it every time
|
||||
// causes a measurable performance degradation.
|
||||
if (String.IsNullOrEmpty(capacityVariable.Description))
|
||||
{
|
||||
capacityVariable.Description = descriptionResourceString;
|
||||
}
|
||||
return capacityVariable;
|
||||
}
|
||||
|
||||
#endregion constructor
|
||||
|
||||
#region Internal properties
|
||||
@@ -172,10 +122,6 @@ namespace System.Management.Automation
|
||||
/// If a drive of the same name already exists in this scope.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum drive count has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal void NewDrive(PSDriveInfo newDrive)
|
||||
{
|
||||
if (newDrive == null)
|
||||
@@ -200,20 +146,6 @@ namespace System.Management.Automation
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (!newDrive.IsAutoMounted &&
|
||||
driveInfos.Count > DriveCapacity.FastValue - 1)
|
||||
{
|
||||
SessionStateOverflowException e =
|
||||
new SessionStateOverflowException(
|
||||
newDrive.Name,
|
||||
SessionStateCategory.Drive,
|
||||
"DriveOverflow",
|
||||
SessionStateStrings.DriveOverflow,
|
||||
DriveCapacity.FastValue);
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (!newDrive.IsAutoMounted)
|
||||
{
|
||||
driveInfos.Add(newDrive.Name, newDrive);
|
||||
@@ -491,10 +423,6 @@ namespace System.Management.Automation
|
||||
/// If the variable is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of variables has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal PSVariable SetVariable(string name, object value, bool asValue, bool force, SessionStateInternal sessionState, CommandOrigin origin = CommandOrigin.Internal, bool fastPath = false)
|
||||
{
|
||||
Diagnostics.Assert(name != null, "The caller should verify the name");
|
||||
@@ -592,22 +520,6 @@ namespace System.Management.Automation
|
||||
variable = (LocalsTuple != null ? LocalsTuple.TrySetVariable(name, value) : null) ?? new PSVariable(name, value);
|
||||
}
|
||||
|
||||
// Now check to make sure we don't exceed the max variable count
|
||||
// if this is a new variable.
|
||||
|
||||
if (!varExists && _variables.Count > VariableCapacity.FastValue - 1)
|
||||
{
|
||||
SessionStateOverflowException e =
|
||||
new SessionStateOverflowException(
|
||||
name,
|
||||
SessionStateCategory.Variable,
|
||||
"VariableOverflow",
|
||||
SessionStateStrings.VariableOverflow,
|
||||
VariableCapacity.FastValue);
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Don't let people set AllScope variables in ConstrainedLanguage,
|
||||
// as they can be used to interfere with the session state of
|
||||
// trusted commands.
|
||||
@@ -671,10 +583,6 @@ namespace System.Management.Automation
|
||||
/// If the variable is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of variables has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal PSVariable NewVariable(PSVariable newVariable, bool force, SessionStateInternal sessionState)
|
||||
{
|
||||
PSVariable variable;
|
||||
@@ -727,22 +635,6 @@ namespace System.Management.Automation
|
||||
variable = newVariable;
|
||||
}
|
||||
|
||||
// Now check to make sure we don't exceed the max variable count
|
||||
// if this is a new variable.
|
||||
|
||||
if (!varExists && _variables.Count > VariableCapacity.FastValue - 1)
|
||||
{
|
||||
SessionStateOverflowException e =
|
||||
new SessionStateOverflowException(
|
||||
newVariable.Name,
|
||||
SessionStateCategory.Variable,
|
||||
"VariableOverflow",
|
||||
SessionStateStrings.VariableOverflow,
|
||||
VariableCapacity.FastValue);
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Don't let people set AllScope variables in ConstrainedLanguage,
|
||||
// as they can be used to interfere with the session state of
|
||||
// trusted commands.
|
||||
@@ -799,18 +691,6 @@ namespace System.Management.Automation
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (variable is SessionStateCapacityVariable)
|
||||
{
|
||||
SessionStateUnauthorizedAccessException e =
|
||||
new SessionStateUnauthorizedAccessException(
|
||||
name,
|
||||
SessionStateCategory.Variable,
|
||||
"VariableNotRemovableSystem",
|
||||
SessionStateStrings.VariableNotRemovableSystem);
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (variable is LocalVariable)
|
||||
{
|
||||
SessionStateUnauthorizedAccessException e =
|
||||
@@ -935,10 +815,6 @@ namespace System.Management.Automation
|
||||
/// if the alias is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of aliases has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal AliasInfo SetAliasValue(string name, string value, ExecutionContext context, bool force, CommandOrigin origin)
|
||||
{
|
||||
Diagnostics.Assert(
|
||||
@@ -949,18 +825,6 @@ namespace System.Management.Automation
|
||||
AliasInfo aliasInfo;
|
||||
if (!aliasInfos.TryGetValue(name, out aliasInfo))
|
||||
{
|
||||
if (aliasInfos.Count > AliasCapacity.FastValue - 1)
|
||||
{
|
||||
SessionStateOverflowException e =
|
||||
new SessionStateOverflowException(
|
||||
name,
|
||||
SessionStateCategory.Alias,
|
||||
"AliasOverflow",
|
||||
SessionStateStrings.AliasOverflow,
|
||||
AliasCapacity.FastValue);
|
||||
|
||||
throw e;
|
||||
}
|
||||
aliasInfos[name] = new AliasInfo(name, value, context);
|
||||
}
|
||||
else
|
||||
@@ -1035,10 +899,6 @@ namespace System.Management.Automation
|
||||
/// If the alias is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of aliases has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal AliasInfo SetAliasValue(
|
||||
string name,
|
||||
string value,
|
||||
@@ -1056,18 +916,6 @@ namespace System.Management.Automation
|
||||
AliasInfo result;
|
||||
if (!aliasInfos.TryGetValue(name, out aliasInfo))
|
||||
{
|
||||
if (aliasInfos.Count > AliasCapacity.FastValue - 1)
|
||||
{
|
||||
SessionStateOverflowException e =
|
||||
new SessionStateOverflowException(
|
||||
name,
|
||||
SessionStateCategory.Alias,
|
||||
"AliasOverflow",
|
||||
SessionStateStrings.AliasOverflow,
|
||||
AliasCapacity.FastValue);
|
||||
|
||||
throw e;
|
||||
}
|
||||
result = new AliasInfo(name, value, context, options);
|
||||
aliasInfos[name] = result;
|
||||
}
|
||||
@@ -1167,10 +1015,6 @@ namespace System.Management.Automation
|
||||
/// If the alias is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of aliases has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal AliasInfo SetAliasItem(AliasInfo aliasToSet, bool force, CommandOrigin origin = CommandOrigin.Internal)
|
||||
{
|
||||
Diagnostics.Assert(
|
||||
@@ -1180,22 +1024,7 @@ namespace System.Management.Automation
|
||||
|
||||
var aliasInfos = GetAliases();
|
||||
AliasInfo aliasInfo;
|
||||
if (!aliasInfos.TryGetValue(aliasToSet.Name, out aliasInfo))
|
||||
{
|
||||
if (aliasInfos.Count > AliasCapacity.FastValue - 1)
|
||||
{
|
||||
SessionStateOverflowException e =
|
||||
new SessionStateOverflowException(
|
||||
aliasToSet.Name,
|
||||
SessionStateCategory.Alias,
|
||||
"AliasOverflow",
|
||||
SessionStateStrings.AliasOverflow,
|
||||
AliasCapacity.FastValue);
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
else
|
||||
if (aliasInfos.TryGetValue(aliasToSet.Name, out aliasInfo))
|
||||
{
|
||||
// An existing alias cannot be set if it is ReadOnly or Constant unless
|
||||
// force is specified, in which case an existing ReadOnly alias can
|
||||
@@ -1361,10 +1190,6 @@ namespace System.Management.Automation
|
||||
/// If the function is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of functions have been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal FunctionInfo SetFunction(
|
||||
string name,
|
||||
ScriptBlock function,
|
||||
@@ -1411,10 +1236,6 @@ namespace System.Management.Automation
|
||||
/// If the function is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of functions have been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal FunctionInfo SetFunction(
|
||||
string name,
|
||||
ScriptBlock function,
|
||||
@@ -1467,10 +1288,6 @@ namespace System.Management.Automation
|
||||
/// If the function is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of functions have been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal FunctionInfo SetFunction(
|
||||
string name,
|
||||
ScriptBlock function,
|
||||
@@ -1545,10 +1362,6 @@ namespace System.Management.Automation
|
||||
/// If the function is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of functions have been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal FunctionInfo SetFunction(
|
||||
string name,
|
||||
ScriptBlock function,
|
||||
@@ -1569,19 +1382,6 @@ namespace System.Management.Automation
|
||||
FunctionInfo result;
|
||||
if (!functionInfos.TryGetValue(name, out existingValue))
|
||||
{
|
||||
if (functionInfos.Count > FunctionCapacity.FastValue - 1)
|
||||
{
|
||||
SessionStateOverflowException e =
|
||||
new SessionStateOverflowException(
|
||||
name,
|
||||
SessionStateCategory.Function,
|
||||
"FunctionOverflow",
|
||||
SessionStateStrings.FunctionOverflow,
|
||||
FunctionCapacity.FastValue);
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
||||
result = functionFactory(name, function, originalFunction, options, context, helpFile);
|
||||
functionInfos[name] = result;
|
||||
|
||||
@@ -2123,55 +1923,6 @@ namespace System.Management.Automation
|
||||
_variables.Add(variable.Name, variable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Now create the capacity variables with a reference to a parent scope
|
||||
// capacity variable if one exists. If not, the defaults will be used.
|
||||
|
||||
string varName = "MaximumErrorCount";
|
||||
_errorCapacity = CreateCapacityVariable(
|
||||
varName,
|
||||
SessionStateConstants.DefaultErrorCapacity,
|
||||
SessionStateConstants.MaxErrorCapacity,
|
||||
SessionStateConstants.MinErrorCapacity,
|
||||
SessionStateStrings.MaxErrorCountDescription);
|
||||
_variables.Add(varName, _errorCapacity);
|
||||
|
||||
varName = "MaximumVariableCount";
|
||||
_variableCapacity = CreateCapacityVariable(
|
||||
varName,
|
||||
SessionStateConstants.DefaultVariableCapacity,
|
||||
SessionStateConstants.MaxVariablesCapacity,
|
||||
SessionStateConstants.MinVariablesCapacity,
|
||||
SessionStateStrings.MaxVariableCountDescription);
|
||||
_variables.Add(varName, _variableCapacity);
|
||||
|
||||
varName = "MaximumFunctionCount";
|
||||
_functionCapacity = CreateCapacityVariable(
|
||||
varName,
|
||||
SessionStateConstants.DefaultFunctionCapacity,
|
||||
SessionStateConstants.MaxFunctionCapacity,
|
||||
SessionStateConstants.MinFunctionCapacity,
|
||||
SessionStateStrings.MaxFunctionCountDescription);
|
||||
_variables.Add(varName, _functionCapacity);
|
||||
|
||||
varName = "MaximumAliasCount";
|
||||
_aliasCapacity = CreateCapacityVariable(
|
||||
varName,
|
||||
SessionStateConstants.DefaultAliasCapacity,
|
||||
SessionStateConstants.MaxAliasCapacity,
|
||||
SessionStateConstants.MinAliasCapacity,
|
||||
SessionStateStrings.MaxAliasCountDescription);
|
||||
_variables.Add(varName, _aliasCapacity);
|
||||
|
||||
varName = "MaximumDriveCount";
|
||||
_driveCapacity = CreateCapacityVariable(
|
||||
varName,
|
||||
SessionStateConstants.DefaultDriveCapacity,
|
||||
SessionStateConstants.MaxDriveCapacity,
|
||||
SessionStateConstants.MinDriveCapacity,
|
||||
SessionStateStrings.MaxDriveCountDescription);
|
||||
_variables.Add(varName, _driveCapacity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -2274,57 +2025,6 @@ namespace System.Management.Automation
|
||||
|
||||
private readonly Dictionary<string, List<CmdletInfo>> _allScopeCmdlets = new Dictionary<string, List<CmdletInfo>>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
|
||||
internal SessionStateCapacityVariable ErrorCapacity
|
||||
{
|
||||
get
|
||||
{
|
||||
GetPrivateVariables(); // Make sure that the variable table is initialized...
|
||||
return _errorCapacity;
|
||||
}
|
||||
}
|
||||
private SessionStateCapacityVariable _errorCapacity;
|
||||
|
||||
internal SessionStateCapacityVariable VariableCapacity
|
||||
{
|
||||
get
|
||||
{
|
||||
GetPrivateVariables(); // Make sure that the variable table is initialized...
|
||||
return _variableCapacity;
|
||||
}
|
||||
}
|
||||
private SessionStateCapacityVariable _variableCapacity;
|
||||
|
||||
private SessionStateCapacityVariable FunctionCapacity
|
||||
{
|
||||
get
|
||||
{
|
||||
GetPrivateVariables(); // Make sure that the variable table is initialized...
|
||||
return _functionCapacity;
|
||||
}
|
||||
}
|
||||
private SessionStateCapacityVariable _functionCapacity;
|
||||
|
||||
private SessionStateCapacityVariable AliasCapacity
|
||||
{
|
||||
get
|
||||
{
|
||||
GetPrivateVariables(); // Make sure that the variable table is initialized...
|
||||
return _aliasCapacity;
|
||||
}
|
||||
}
|
||||
private SessionStateCapacityVariable _aliasCapacity;
|
||||
|
||||
private SessionStateCapacityVariable DriveCapacity
|
||||
{
|
||||
get
|
||||
{
|
||||
GetPrivateVariables(); // Make sure that the variable table is initialized...
|
||||
return _driveCapacity;
|
||||
}
|
||||
}
|
||||
private SessionStateCapacityVariable _driveCapacity;
|
||||
|
||||
/// <summary>
|
||||
/// The variable that represents $true in the language.
|
||||
/// We don't need a new reference in each scope since it
|
||||
|
||||
@@ -1030,10 +1030,6 @@ namespace System.Management.Automation
|
||||
/// If the variable is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of variables has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="ProviderNotFoundException">
|
||||
/// If the <paramref name="name"/> refers to a provider that could not be found.
|
||||
/// </exception>
|
||||
@@ -1089,10 +1085,6 @@ namespace System.Management.Automation
|
||||
/// If the variable is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of variables has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="ProviderNotFoundException">
|
||||
/// If the <paramref name="name"/> refers to a provider that could not be found.
|
||||
/// </exception>
|
||||
@@ -1145,10 +1137,6 @@ namespace System.Management.Automation
|
||||
/// If the variable is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of variables has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal object SetVariable(PSVariable variable, bool force, CommandOrigin origin)
|
||||
{
|
||||
if (variable == null || String.IsNullOrEmpty(variable.Name))
|
||||
@@ -1195,10 +1183,6 @@ namespace System.Management.Automation
|
||||
/// If the variable is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of variables has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="ProviderNotFoundException">
|
||||
/// If the <paramref name="variablePath"/> refers to a provider that could not be found.
|
||||
/// </exception>
|
||||
@@ -1263,10 +1247,6 @@ namespace System.Management.Automation
|
||||
/// If the variable is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of variables has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="ProviderNotFoundException">
|
||||
/// If the <paramref name="variablePath"/> refers to a provider that could not be found.
|
||||
/// </exception>
|
||||
@@ -1567,10 +1547,6 @@ namespace System.Management.Automation
|
||||
/// If the variable is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of variables has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal object SetVariableAtScope(PSVariable variable, string scopeID, bool force, CommandOrigin origin)
|
||||
{
|
||||
if (variable == null || String.IsNullOrEmpty(variable.Name))
|
||||
@@ -1612,10 +1588,6 @@ namespace System.Management.Automation
|
||||
/// If the variable is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of variables has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal object NewVariable(PSVariable variable, bool force)
|
||||
{
|
||||
if (variable == null || String.IsNullOrEmpty(variable.Name))
|
||||
@@ -1668,10 +1640,6 @@ namespace System.Management.Automation
|
||||
/// If the variable is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of variables has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
internal object NewVariableAtScope(PSVariable variable, string scopeID, bool force)
|
||||
{
|
||||
if (variable == null || String.IsNullOrEmpty(variable.Name))
|
||||
|
||||
@@ -305,10 +305,6 @@ namespace System.Management.Automation
|
||||
/// If the variable is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of variables has been reached for this scope.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="ProviderNotFoundException">
|
||||
/// If the <paramref name="name"/> refers to a provider that could not be found.
|
||||
/// </exception>
|
||||
@@ -353,9 +349,6 @@ namespace System.Management.Automation
|
||||
/// If the variable is read-only or constant.
|
||||
/// </exception>
|
||||
///
|
||||
/// <exception cref="SessionStateOverflowException">
|
||||
/// If the maximum number of variables has been reached for this scope.
|
||||
/// </exception>
|
||||
public void Set(PSVariable variable)
|
||||
{
|
||||
Dbg.Diagnostics.Assert(
|
||||
|
||||
@@ -1340,7 +1340,6 @@ namespace System.Management.Automation
|
||||
/// <param name="callStatic">Set to true if you want to call a static method.</param>
|
||||
/// <param name="valueToSet">If not automation null, then this must be a settable property</param>
|
||||
/// <exception cref="RuntimeException">Wraps the exception returned from the method call</exception>
|
||||
/// <exception cref="SessionStateOverflowException">The maximum scope depth would be exceeded</exception>
|
||||
/// <exception cref="FlowControlException">Internal exception from a flow control statement</exception>
|
||||
/// <returns></returns>
|
||||
internal static object CallMethod(
|
||||
|
||||
@@ -377,7 +377,6 @@ namespace System.Management.Automation
|
||||
/// <param name="args">The arguments to this script.</param>
|
||||
/// <returns>The object(s) generated during the execution of
|
||||
/// the script block returned as a collection of PSObjects</returns>
|
||||
/// <exception cref="SessionStateOverflowException">Thrown if the maximum scope depth has been exceeded</exception>
|
||||
/// <exception cref="RuntimeException">Thrown if a script runtime exceptionexception occurred</exception>
|
||||
/// <exception cref="FlowControlException">An internal (non-public) exception from a flow control statement</exception>
|
||||
public Collection<PSObject> Invoke(params object[] args)
|
||||
@@ -499,7 +498,6 @@ namespace System.Management.Automation
|
||||
/// <param name="args">The arguments to pass to this scriptblock.</param>
|
||||
/// <returns>The object(s) generated during the execution of the
|
||||
/// script block. They may or may not be wrapped in PSObject. It's up to the caller to check.</returns>
|
||||
/// <exception cref="SessionStateOverflowException">Thrown if the maximum scope depth has been exceeded</exception>
|
||||
/// <exception cref="RuntimeException">Thrown if a script runtime exceptionexception occurred</exception>
|
||||
/// <exception cref="FlowControlException">An internal (non-public) exception from a flow control statement</exception>
|
||||
public object InvokeReturnAsIs(params object[] args)
|
||||
@@ -833,7 +831,6 @@ namespace System.Management.Automation
|
||||
/// <param name="args">The arguments to this script.</param>
|
||||
/// <returns>The object(s) generated during the execution of
|
||||
/// the script block returned as a collection of PSObjects</returns>
|
||||
/// <exception cref="SessionStateOverflowException">The maximum scope depth would be exceeded</exception>
|
||||
/// <exception cref="RuntimeException">A script exception occurred</exception>
|
||||
/// <exception cref="FlowControlException">Internal exception from a flow control statement</exception>
|
||||
internal Collection<PSObject> DoInvoke(object dollarUnder, object input, object[] args)
|
||||
@@ -893,7 +890,6 @@ namespace System.Management.Automation
|
||||
///
|
||||
/// <returns>The object(s) generated during the execution of
|
||||
/// the script block returned as a collection of PSObjects</returns>
|
||||
/// <exception cref="SessionStateOverflowException">The maximum scope depth would be exceeded</exception>
|
||||
/// <exception cref="RuntimeException">A script exception occurred</exception>
|
||||
/// <exception cref="FlowControlException">Internal exception from a flow control statement</exception>
|
||||
internal object DoInvokeReturnAsIs(bool useLocalScope,
|
||||
|
||||
@@ -369,21 +369,6 @@
|
||||
<data name="VariableNotRemovable" xml:space="preserve">
|
||||
<value>Cannot remove variable {0} because it is constant or read-only. If the variable is read-only, try the operation again specifying the Force option.</value>
|
||||
</data>
|
||||
<data name="VariableNotRemovableSystem" xml:space="preserve">
|
||||
<value>Cannot remove variable {0} because it is owned by the system.</value>
|
||||
</data>
|
||||
<data name="AliasOverflow" xml:space="preserve">
|
||||
<value>Alias {0} cannot be created because alias capacity {1} has been exceeded for this scope.</value>
|
||||
</data>
|
||||
<data name="DriveOverflow" xml:space="preserve">
|
||||
<value>Drive {0} cannot be created because drive capacity {1} has been exceeded for this scope.</value>
|
||||
</data>
|
||||
<data name="FunctionOverflow" xml:space="preserve">
|
||||
<value>Function {0} cannot be created because function capacity {1} has been exceeded for this scope.</value>
|
||||
</data>
|
||||
<data name="VariableOverflow" xml:space="preserve">
|
||||
<value>Cannot create variable {0} because variable capacity {1} is exceeded for this scope.</value>
|
||||
</data>
|
||||
<data name="AliasIsConstant" xml:space="preserve">
|
||||
<value>Alias {0} cannot be modified because it is constant.</value>
|
||||
</data>
|
||||
|
||||
@@ -275,10 +275,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
e = sue;
|
||||
}
|
||||
catch (SessionStateOverflowException sof)
|
||||
{
|
||||
e = sof;
|
||||
}
|
||||
catch (ProviderNotFoundException pnf)
|
||||
{
|
||||
e = pnf;
|
||||
|
||||
@@ -582,6 +582,8 @@ namespace System.Management.Automation
|
||||
#endregion Private
|
||||
} // SessionStateException
|
||||
|
||||
// This class is no longer used, but kept in Windows PowerShell for backwards compatibility
|
||||
#if !CORECLR
|
||||
/// <summary>
|
||||
/// SessionStateOverflowException occurs when the number of
|
||||
/// session state objects of this type in this scope
|
||||
@@ -678,6 +680,7 @@ namespace System.Management.Automation
|
||||
}
|
||||
#endregion Serialization
|
||||
} // SessionStateOverflowException
|
||||
#endif // !CORECLR
|
||||
|
||||
/// <summary>
|
||||
/// SessionStateUnauthorizedAccessException occurs when
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
Describe "InitialSessionState capacity" -Tags CI {
|
||||
BeforeAll {
|
||||
$iss = [initialsessionstate]::CreateDefault()
|
||||
|
||||
for ($i = 0; $i -lt 5000; $i++)
|
||||
{
|
||||
$ssfe = [System.Management.Automation.Runspaces.SessionStateFunctionEntry]::new("f$i", "'fn f$i'")
|
||||
$iss.Commands.Add($ssfe)
|
||||
|
||||
$ssve = [System.Management.Automation.Runspaces.SessionStateVariableEntry]::new("v$i", "var v$i", $null)
|
||||
$iss.Variables.Add($ssve)
|
||||
|
||||
$ssae = [System.Management.Automation.Runspaces.SessionStateAliasEntry]::new("a$i", "f$i")
|
||||
$iss.Commands.Add($ssae)
|
||||
}
|
||||
|
||||
$ps = [PowerShell]::Create($iss)
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
$ps.Dispose()
|
||||
}
|
||||
|
||||
BeforeEach {
|
||||
$ps.Commands.Clear()
|
||||
}
|
||||
|
||||
It "function capacity in initial session state should not be limited" {
|
||||
$ps.AddCommand('f4999').Invoke() | Should Be "fn f4999"
|
||||
$ps.Streams.Error | Should Be $null
|
||||
}
|
||||
|
||||
It "alias capacity in initial session state should not be limited" {
|
||||
$ps.AddCommand('a4999').Invoke() | Should Be "fn f4999"
|
||||
$ps.Streams.Error | Should Be $null
|
||||
}
|
||||
|
||||
It "variable capacity in initial session state should not be limited" {
|
||||
$ps.AddScript('$v4999').Invoke() | Should Be "var v4999"
|
||||
$ps.Streams.Error | Should Be $null
|
||||
}
|
||||
|
||||
It "function capacity should not be limited after runspace is opened" {
|
||||
$ps.AddScript('function f5000 { "in f5000" } f5000').Invoke() | Should Be "in f5000"
|
||||
$ps.Streams.Error | Should Be $null
|
||||
}
|
||||
|
||||
It "variable capacity should not be limited after runspace is opened" {
|
||||
$ps.AddScript('$v5000 = "var v5000"; $v5000').Invoke() | Should Be "var v5000"
|
||||
$ps.Streams.Error | Should Be $null
|
||||
}
|
||||
|
||||
It "alias capacity should not be limited after runspace is opened" {
|
||||
$ps.AddScript('New-Alias -Name a5000 -Value f1; a5000').Invoke() | Should Be "fn f1"
|
||||
$ps.Streams.Error | Should Be $null
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user