Clean up uses of CommandTypes.Workflow and WorkflowInfo (#6708)

[breaking change] Clean up code related to the uses of `CommandTypes.Workflow` and `WorkflowInfo` in `System.Management.Automation`. This change mainly affects help provider code.

This PR includes a few minor breaking changes:
- Change the `public` constructors of `WorkflowInfo` to `internal`. We don't support workflow in PSCore, so I think it makes sense to not allow people to create `Workflow` instances.
- Remove the type `System.Management.Automation.DebugSource` since it's only used for workflow debugging.
- Remove the overload of `SetParent` from the abstract class `Debugger` that is only used for workflow debugging.
- Remove the same overload of `SetParent` from the derived class `RemotingJobDebugger`.
This commit is contained in:
Dongbo Wang
2018-04-27 23:02:15 -07:00
committed by GitHub
parent 24069241bc
commit 8aec158519
23 changed files with 52 additions and 447 deletions
@@ -254,19 +254,11 @@ else { '-{0}{1} ' }) -f $_.Name, $parameterValue")
.EndEntry()
.EndControl();
var control6 = CustomControl.Create()
.StartEntry()
.AddText(StringUtil.Format("[{0}]", HelpDisplayStrings.CommonWorkflowParameters))
.EndEntry()
.EndControl();
var control5 = CustomControl.Create()
.StartEntry()
.AddPropertyExpressionBinding(@"name")
.AddText(" ")
.AddPropertyExpressionBinding(@"Parameter", enumerateCollection: true, customControl: sharedControls[1])
.AddScriptBlockExpressionBinding(@" ", selectedByScript: "$_.WorkflowCommonParameters -eq $true", customControl: control6)
.AddText(" ")
.AddScriptBlockExpressionBinding(@" ", selectedByScript: "$_.CommonParameters -eq $true", customControl: control7)
.AddNewline()
.AddNewline()
@@ -340,18 +332,6 @@ else { '-{0}{1} ' }) -f $_.Name, $parameterValue")
.EndEntry()
.EndControl();
var control15 = CustomControl.Create()
.StartEntry()
.AddText(HelpDisplayStrings.CommonWorkflowParameters)
.AddNewline()
.StartFrame(leftIndent: 4)
.AddText(HelpDisplayStrings.BaseWorkflowCmdletInformation)
.EndFrame()
.AddNewline()
.AddNewline()
.EndEntry()
.EndControl();
var control14 = CustomControl.Create()
.StartEntry()
.AddText("-")
@@ -376,21 +356,11 @@ else { '-{0}{1} ' }) -f $_.Name, $parameterValue")
.EndEntry()
.EndControl();
var control11 = CustomControl.Create()
.StartEntry()
.AddText("[")
.AddText(HelpDisplayStrings.CommonWorkflowParameters)
.AddText("]")
.EndEntry()
.EndControl();
var control10 = CustomControl.Create()
.StartEntry()
.AddPropertyExpressionBinding(@"name")
.AddText(" ")
.AddPropertyExpressionBinding(@"Parameter", enumerateCollection: true, customControl: sharedControls[1])
.AddScriptBlockExpressionBinding(@" ", selectedByScript: "$_.WorkflowCommonParameters -eq $true", customControl: control11)
.AddText(" ")
.AddScriptBlockExpressionBinding(@" ", selectedByScript: "$_.CommonParameters -eq $true", customControl: control12)
.AddNewline()
.AddNewline()
@@ -429,7 +399,6 @@ else { '-{0}{1} ' }) -f $_.Name, $parameterValue")
.AddNewline()
.StartFrame(leftIndent: 4)
.AddPropertyExpressionBinding(@"Parameters", customControl: control13)
.AddScriptBlockExpressionBinding(@" ", selectedByScript: "$_.WorkflowCommonParameters -eq $true", customControl: control15)
.AddScriptBlockExpressionBinding(@" ", selectedByScript: "$_.CommonParameters -eq $true", customControl: control16)
.AddScriptBlockExpressionBinding(@" ", selectedByScript: "($_.CommonParameters -eq $false) -and ($_.parameters.parameter.count -eq 0)", customControl: control17)
.EndFrame()
@@ -499,18 +468,6 @@ else { '-{0}{1} ' }) -f $_.Name, $parameterValue")
.EndEntry()
.EndControl();
var control29 = CustomControl.Create()
.StartEntry()
.AddText(HelpDisplayStrings.CommonWorkflowParameters)
.AddNewline()
.StartFrame(leftIndent: 4)
.AddText(HelpDisplayStrings.BaseWorkflowCmdletInformation)
.EndFrame()
.AddNewline()
.AddNewline()
.EndEntry()
.EndControl();
var control28 = CustomControl.Create()
.StartEntry()
.AddText(HelpDisplayStrings.NamedParameter)
@@ -584,21 +541,11 @@ else { '-{0}{1} ' }) -f $_.Name, $parameterValue")
.EndEntry()
.EndControl();
var control21 = CustomControl.Create()
.StartEntry()
.AddText("[")
.AddText(HelpDisplayStrings.CommonWorkflowParameters)
.AddText("]")
.EndEntry()
.EndControl();
var control20 = CustomControl.Create()
.StartEntry()
.AddPropertyExpressionBinding(@"name")
.AddText(" ")
.AddPropertyExpressionBinding(@"Parameter", enumerateCollection: true, customControl: sharedControls[1])
.AddScriptBlockExpressionBinding(@" ", selectedByScript: "$_.WorkflowCommonParameters -eq $true", customControl: control21)
.AddText(" ")
.AddScriptBlockExpressionBinding(@" ", selectedByScript: "$_.CommonParameters -eq $true", customControl: control22)
.AddNewline()
.AddNewline()
@@ -637,7 +584,6 @@ else { '-{0}{1} ' }) -f $_.Name, $parameterValue")
.AddNewline()
.StartFrame(leftIndent: 4)
.AddPropertyExpressionBinding(@"Parameters", customControl: control23)
.AddScriptBlockExpressionBinding(@" ", selectedByScript: "$_.WorkflowCommonParameters -eq $true", customControl: control29)
.AddScriptBlockExpressionBinding(@" ", selectedByScript: "$_.CommonParameters -eq $true", customControl: control30)
.AddScriptBlockExpressionBinding(@" ", selectedByScript: "($_.CommonParameters -eq $false) -and ($_.parameters.parameter.count -eq 0)", customControl: control31)
.AddNewline()
@@ -140,16 +140,6 @@ else { '-{0}{1} ' }) -f $_.Name, $parameterValue")
.EndEntry()
.EndControl();
var CommonWorkflowParametersControl = CustomControl.Create()
.StartEntry()
.AddScriptBlockExpressionBinding(StringUtil.Format(@"$wfp = $_.psobject.Properties['WorkflowCommonParameters']
if ($null -ne $wfp -and $wfp.Value)
{{
'[{0}] '
}}", HelpDisplayStrings.CommonWorkflowParameters))
.EndEntry()
.EndControl();
var RelatedLinksHelpInfoControl = CustomControl.Create()
.StartEntry()
.StartFrame(leftIndent: 4)
@@ -270,7 +260,6 @@ if (($_.relatedLinks -ne $()) -and ($_.relatedLinks.navigationLink -ne $()) -and
.AddPropertyExpressionBinding(@"name")
.AddText(" ")
.AddPropertyExpressionBinding(@"Parameter", enumerateCollection: true, customControl: MamlParameterControl)
.AddCustomControlExpressionBinding(CommonWorkflowParametersControl)
.AddText("[" + HelpDisplayStrings.CommonParameters + "]")
.AddNewline(2)
.EndEntry()
@@ -413,7 +402,6 @@ if (($_.relatedLinks -ne $()) -and ($_.relatedLinks.navigationLink -ne $()) -and
MamlPossibleValueControl,
MamlTrueFalseShortControl,
MamlIndentedSyntaxControl,
CommonWorkflowParametersControl,
MamlSyntaxControl,
MamlTypeWithDescriptionControl,
RelatedLinksHelpInfoControl,
@@ -578,7 +566,7 @@ if (($_.relatedLinks -ne $()) -and ($_.relatedLinks.navigationLink -ne $()) -and
.AddText(HelpDisplayStrings.RelatedLinks)
.AddNewline()
.StartFrame(leftIndent: 4)
.AddPropertyExpressionBinding(@"relatedLinks", customControl: sharedControls[20])
.AddPropertyExpressionBinding(@"relatedLinks", customControl: sharedControls[19])
.EndFrame()
.AddNewline()
.AddText(HelpDisplayStrings.RemarksSection)
@@ -597,7 +585,7 @@ if (($_.relatedLinks -ne $()) -and ($_.relatedLinks.navigationLink -ne $()) -and
.AddScriptBlockExpressionBinding(@"""get-help "" + $_.Details.Name + "" -full""")
.AddText(@""".")
.AddNewline()
.AddCustomControlExpressionBinding(sharedControls[19])
.AddCustomControlExpressionBinding(sharedControls[18])
.EndFrame()
.EndEntry()
.EndControl());
@@ -634,7 +622,6 @@ if (($_.relatedLinks -ne $()) -and ($_.relatedLinks.navigationLink -ne $()) -and
.AddNewline()
.StartFrame(leftIndent: 4)
.AddPropertyExpressionBinding(@"Parameters", customControl: control9)
.AddCustomControlExpressionBinding(sharedControls[16])
.AddText(HelpDisplayStrings.CommonParameters)
.AddNewline()
.StartFrame(leftIndent: 4)
@@ -664,7 +651,7 @@ if (($_.relatedLinks -ne $()) -and ($_.relatedLinks.navigationLink -ne $()) -and
.AddScriptBlockExpressionBinding(@"""get-help "" + $_.Details.Name + "" -full""")
.AddText(@""".")
.AddNewline()
.AddCustomControlExpressionBinding(sharedControls[19])
.AddCustomControlExpressionBinding(sharedControls[18])
.EndFrame()
.EndEntry()
.EndControl());
@@ -711,7 +698,7 @@ if (($_.relatedLinks -ne $()) -and ($_.relatedLinks.navigationLink -ne $()) -and
.AddText(HelpDisplayStrings.NonHyphenTerminatingErrors)
.AddNewline()
.StartFrame(leftIndent: 4)
.AddPropertyExpressionBinding(@"nonTerminatingError", enumerateCollection: true, customControl: sharedControls[21])
.AddPropertyExpressionBinding(@"nonTerminatingError", enumerateCollection: true, customControl: sharedControls[20])
.EndFrame()
.EndEntry()
.EndControl();
@@ -721,20 +708,20 @@ if (($_.relatedLinks -ne $()) -and ($_.relatedLinks.navigationLink -ne $()) -and
.AddText(HelpDisplayStrings.TerminatingErrors)
.AddNewline()
.StartFrame(leftIndent: 4)
.AddPropertyExpressionBinding(@"terminatingError", enumerateCollection: true, customControl: sharedControls[21])
.AddPropertyExpressionBinding(@"terminatingError", enumerateCollection: true, customControl: sharedControls[20])
.EndFrame()
.EndEntry()
.EndControl();
var control12 = CustomControl.Create()
.StartEntry()
.AddPropertyExpressionBinding(@"ReturnValue", enumerateCollection: true, customControl: sharedControls[18])
.AddPropertyExpressionBinding(@"ReturnValue", enumerateCollection: true, customControl: sharedControls[17])
.EndEntry()
.EndControl();
var control11 = CustomControl.Create()
.StartEntry()
.AddPropertyExpressionBinding(@"InputType", enumerateCollection: true, customControl: sharedControls[18])
.AddPropertyExpressionBinding(@"InputType", enumerateCollection: true, customControl: sharedControls[17])
.EndEntry()
.EndControl();
@@ -747,7 +734,7 @@ if (($_.relatedLinks -ne $()) -and ($_.relatedLinks.navigationLink -ne $()) -and
.AddText(HelpDisplayStrings.Parameters)
.AddNewline()
.StartFrame(leftIndent: 4)
.AddPropertyExpressionBinding(@"Parameters", customControl: sharedControls[23])
.AddPropertyExpressionBinding(@"Parameters", customControl: sharedControls[22])
.EndFrame()
.AddText(HelpDisplayStrings.InputType)
.AddNewline()
@@ -778,7 +765,7 @@ if (($_.relatedLinks -ne $()) -and ($_.relatedLinks.navigationLink -ne $()) -and
.AddText(HelpDisplayStrings.RelatedLinks)
.AddNewline()
.StartFrame(leftIndent: 4)
.AddPropertyExpressionBinding(@"relatedLinks", customControl: sharedControls[20])
.AddPropertyExpressionBinding(@"relatedLinks", customControl: sharedControls[19])
.EndFrame()
.EndEntry()
.EndControl());
@@ -946,7 +933,7 @@ if (($_.relatedLinks -ne $()) -and ($_.relatedLinks.navigationLink -ne $()) -and
.AddText(HelpDisplayStrings.RelatedLinks)
.AddNewline()
.StartFrame(leftIndent: 4)
.AddPropertyExpressionBinding(@"relatedLinks", customControl: sharedControls[20])
.AddPropertyExpressionBinding(@"relatedLinks", customControl: sharedControls[19])
.EndFrame()
.EndEntry()
.EndControl());
@@ -1085,7 +1072,7 @@ if (($_.relatedLinks -ne $()) -and ($_.relatedLinks.navigationLink -ne $()) -and
CustomControl.Create()
.StartEntry()
.StartFrame(leftIndent: 4)
.AddCustomControlExpressionBinding(sharedControls[23])
.AddCustomControlExpressionBinding(sharedControls[22])
.EndFrame()
.EndEntry()
.EndControl());
@@ -1096,7 +1083,7 @@ if (($_.relatedLinks -ne $()) -and ($_.relatedLinks.navigationLink -ne $()) -and
yield return new FormatViewDefinition("MamlCommandParameterView",
CustomControl.Create()
.StartEntry()
.AddScriptBlockExpressionBinding(@"$_", customControl: sharedControls[22])
.AddScriptBlockExpressionBinding(@"$_", customControl: sharedControls[21])
.EndEntry()
.EndControl());
}
@@ -1106,7 +1093,7 @@ if (($_.relatedLinks -ne $()) -and ($_.relatedLinks.navigationLink -ne $()) -and
yield return new FormatViewDefinition("MamlCommandSyntax",
CustomControl.Create()
.StartEntry()
.AddScriptBlockExpressionBinding(@"$_", customControl: sharedControls[17])
.AddScriptBlockExpressionBinding(@"$_", customControl: sharedControls[16])
.EndEntry()
.EndControl());
}
@@ -1126,7 +1113,7 @@ if (($_.relatedLinks -ne $()) -and ($_.relatedLinks.navigationLink -ne $()) -and
yield return new FormatViewDefinition("MamlInputTypes",
CustomControl.Create()
.StartEntry()
.AddPropertyExpressionBinding(@"InputType", enumerateCollection: true, customControl: sharedControls[18])
.AddPropertyExpressionBinding(@"InputType", enumerateCollection: true, customControl: sharedControls[17])
.EndEntry()
.EndControl());
}
@@ -1136,7 +1123,7 @@ if (($_.relatedLinks -ne $()) -and ($_.relatedLinks.navigationLink -ne $()) -and
yield return new FormatViewDefinition("MamlNonTerminatingErrors",
CustomControl.Create()
.StartEntry()
.AddPropertyExpressionBinding(@"nonTerminatingError", enumerateCollection: true, customControl: sharedControls[21])
.AddPropertyExpressionBinding(@"nonTerminatingError", enumerateCollection: true, customControl: sharedControls[20])
.EndEntry()
.EndControl());
}
@@ -1146,7 +1133,7 @@ if (($_.relatedLinks -ne $()) -and ($_.relatedLinks.navigationLink -ne $()) -and
yield return new FormatViewDefinition("MamlTerminatingErrors",
CustomControl.Create()
.StartEntry()
.AddPropertyExpressionBinding(@"terminatingError", enumerateCollection: true, customControl: sharedControls[21])
.AddPropertyExpressionBinding(@"terminatingError", enumerateCollection: true, customControl: sharedControls[20])
.EndEntry()
.EndControl());
}
@@ -1156,7 +1143,7 @@ if (($_.relatedLinks -ne $()) -and ($_.relatedLinks.navigationLink -ne $()) -and
yield return new FormatViewDefinition("MamlRelatedLinks",
CustomControl.Create()
.StartEntry()
.AddScriptBlockExpressionBinding(@"$_", customControl: sharedControls[20])
.AddScriptBlockExpressionBinding(@"$_", customControl: sharedControls[19])
.EndEntry()
.EndControl());
}
@@ -1166,7 +1153,7 @@ if (($_.relatedLinks -ne $()) -and ($_.relatedLinks.navigationLink -ne $()) -and
yield return new FormatViewDefinition("MamlReturnTypes",
CustomControl.Create()
.StartEntry()
.AddPropertyExpressionBinding(@"ReturnValue", enumerateCollection: true, customControl: sharedControls[18])
.AddPropertyExpressionBinding(@"ReturnValue", enumerateCollection: true, customControl: sharedControls[17])
.EndEntry()
.EndControl());
}
@@ -297,7 +297,7 @@ namespace System.Management.Automation
_verb,
StringLiterals.CommandVerbNounSeparator,
_noun,
parameterSet.ToString((this.CommandType & CommandTypes.Workflow) == CommandTypes.Workflow)));
parameterSet.ToString()));
}
}
else
@@ -651,7 +651,6 @@ namespace System.Management.Automation
break;
case CommandTypes.Filter:
case CommandTypes.Function:
case CommandTypes.Workflow:
case CommandTypes.Configuration:
FunctionInfo functionInfo = (FunctionInfo)commandInfo;
processor = CreateCommandProcessorForScript(functionInfo, Context, useLocalScope ?? true, sessionState);
@@ -277,10 +277,6 @@ namespace System.Management.Automation
CommandType = newType;
}
internal const int HasWorkflowKeyWord = 0x0008;
internal const int IsCimCommand = 0x0010;
internal const int IsFile = 0x0020;
/// <summary>
/// A string representing the definition of the command.
/// </summary>
@@ -268,7 +268,7 @@ namespace System.Management.Automation
CommandInfo currentMatch = null;
if (_context.EngineSessionState != null &&
(_commandTypes & (CommandTypes.Function | CommandTypes.Filter | CommandTypes.Workflow | CommandTypes.Configuration)) != 0)
(_commandTypes & (CommandTypes.Function | CommandTypes.Filter | CommandTypes.Configuration)) != 0)
{
currentMatch = GetNextFunction();
}
@@ -35,41 +35,9 @@ namespace System.Management.Automation.Internal
}
_commandRuntime = commandRuntime;
} // ctor
#endregion ctor
internal static string[] CommonWorkflowParameters = { "PSComputerName", "JobName", "PSApplicationName", "PSCredential", "PSPort", "PSConfigurationName",
"PSConnectionURI", "PSSessionOption", "PSAuthentication", "PSAuthenticationLevel", "PSCertificateThumbprint",
"PSConnectionRetryCount", "PSConnectionRetryIntervalSec", "PSRunningTimeoutSec", "PSElapsedTimeoutSec",
"PSPersist", "PSPrivateMetadata", "InputObject", "PSParameterCollection",
"AsJob", "PSUseSSL", "PSAllowRedirection" };
#if !CORECLR // Workflow Not Supported On CSS
internal static Type[] CommonWorkflowParameterTypes = {
/* PSComputerName */ typeof(string[]),
/* JobName */ typeof(string),
/* PSApplicationName */ typeof(string),
/* PSCredential */ typeof(PSCredential),
/* PSPort */ typeof(uint),
/* PSConfigurationName */ typeof(string),
/* PSConnectionURI */ typeof(string[]),
/* PSSessionOption */ typeof(PSSessionOption),
/* PSAuthentication */ typeof(AuthenticationMechanism),
/* PSAuthenticationLevel */ typeof(AuthenticationLevel),
/* PSCertificateThumbprint */ typeof(string),
/* PSConnectionRetryCount */ typeof(uint),
/* PSConnectionRetryIntervalSec */ typeof(uint),
/* ??? PSRunningTimeoutSec */ typeof(int),
/* ??? PSElapsedTimeoutSec */ typeof(int),
/* PSPersist */ typeof(bool),
/* ??? PSPrivateMetadata */ typeof(object),
/* ??? InputObject */ typeof(object),
/* ??? PSParameterCollection */ typeof(Hashtable),
/* AsJob */ typeof(bool),
/* PSUseSSL */ typeof(bool),
/* PSAllowRedirection */ typeof(bool),
};
#endif
#region parameters
/// <summary>
@@ -484,7 +484,7 @@ namespace System.Management.Automation
Globalization.CultureInfo.CurrentCulture,
"{0} {1}",
Name,
parameterSet.ToString((this.CommandType & CommandTypes.Workflow) == CommandTypes.Workflow)));
parameterSet.ToString()));
}
return synopsis.ToString();
@@ -574,7 +574,7 @@ namespace Microsoft.PowerShell.Commands
private void AccumulateMatchingCmdlets()
{
_commandType = CommandTypes.Cmdlet | CommandTypes.Function | CommandTypes.Filter | CommandTypes.Alias | CommandTypes.Workflow | CommandTypes.Configuration;
_commandType = CommandTypes.Cmdlet | CommandTypes.Function | CommandTypes.Filter | CommandTypes.Alias | CommandTypes.Configuration;
Collection<string> commandNames = new Collection<string>();
commandNames.Add("*");
@@ -683,7 +683,7 @@ namespace Microsoft.PowerShell.Commands
options |= SearchResolutionOptions.ResolveAliasPatterns;
}
if ((this.CommandType & (CommandTypes.Function | CommandTypes.Filter | CommandTypes.Workflow | CommandTypes.Configuration)) != 0)
if ((this.CommandType & (CommandTypes.Function | CommandTypes.Filter | CommandTypes.Configuration)) != 0)
{
options |= SearchResolutionOptions.ResolveFunctionPatterns;
}
@@ -1108,14 +1108,13 @@ namespace Microsoft.PowerShell.Commands
isCommandMatch = true;
}
// If the command in question is a cmdlet or (a function/filter/workflow/configuration/alias and we are filtering on nouns or verbs),
// then do the verb/moun check
// If the command in question is a cmdlet or (a function/filter/configuration/alias and we are filtering on nouns or verbs),
// then do the verb/noun check
if (current.CommandType == CommandTypes.Cmdlet ||
((_verbs.Length > 0 || _nouns.Length > 0) &&
(current.CommandType == CommandTypes.Function ||
current.CommandType == CommandTypes.Filter ||
current.CommandType == CommandTypes.Workflow ||
current.CommandType == CommandTypes.Configuration ||
current.CommandType == CommandTypes.Alias)))
{
@@ -1166,24 +1166,12 @@ namespace System.Management.Automation
if (SessionStateUtilities.MatchesAnyWildcardPattern(entry.Key, functionPatterns, false))
{
string message;
if (entry.Value.CommandType == CommandTypes.Workflow)
{
message = StringUtil.Format(Modules.ExportingWorkflow, entry.Key);
sessionState.ExportedWorkflows.Add((WorkflowInfo)entry.Value);
}
else
{
message = StringUtil.Format(Modules.ExportingFunction, entry.Key);
sessionState.ExportedFunctions.Add(entry.Value);
}
sessionState.ExportedFunctions.Add(entry.Value);
string message = StringUtil.Format(Modules.ExportingFunction, entry.Key);
cmdlet.WriteVerbose(message);
}
}
SortAndRemoveDuplicates(sessionState.ExportedFunctions, delegate (FunctionInfo ci) { return ci.Name; });
SortAndRemoveDuplicates(sessionState.ExportedWorkflows, delegate (WorkflowInfo ci) { return ci.Name; });
}
if (cmdletPatterns != null)
@@ -372,9 +372,6 @@ namespace System.Management.Automation.Internal
case CommandTypes.Alias:
current = new AliasInfo(entry.Value.Name, null, context);
break;
case CommandTypes.Workflow:
current = new WorkflowInfo(entry.Value.Name, ScriptBlock.EmptyScriptBlock, context);
break;
case CommandTypes.Function:
current = new FunctionInfo(entry.Value.Name, ScriptBlock.EmptyScriptBlock, context);
break;
@@ -484,13 +481,6 @@ namespace System.Management.Automation.Internal
Module = tempModuleInfo
};
}
if ((commandTypes & CommandTypes.Workflow) == CommandTypes.Workflow)
{
yield return new WorkflowInfo(commandName, ScriptBlock.EmptyScriptBlock, context)
{
Module = tempModuleInfo
};
}
}
}
}
@@ -3210,7 +3210,7 @@ namespace System.Management.Automation
}
set
{
if ((!(_commandInfo is WorkflowInfo)) && (value == ActionPreference.Suspend))
if (value == ActionPreference.Suspend)
{
throw PSTraceSource.NewNotSupportedException(ErrorPackage.SuspendActionPreferenceSupportedOnlyOnWorkflow);
}
@@ -94,24 +94,11 @@ namespace System.Management.Automation
/// Gets the synopsis for the cmdlet as a string
/// </summary>
public override string ToString()
{
return ToString(false);
}
/// <summary>
///
/// </summary>
/// <param name="isCapabilityWorkflow">
/// This boolean is used to suppress common workflow parameters (or) display
/// them separately towards the end
/// </param>
/// <returns></returns>
internal string ToString(bool isCapabilityWorkflow)
{
Text.StringBuilder result = new Text.StringBuilder();
GenerateParametersInDisplayOrder(isCapabilityWorkflow,
parameter => AppendFormatCommandParameterInfo(parameter, ref result),
GenerateParametersInDisplayOrder(
parameter => AppendFormatCommandParameterInfo(parameter, result),
delegate (string str)
{
if (result.Length > 0)
@@ -136,14 +123,10 @@ namespace System.Management.Automation
/// <paramref name="commonParameterAction"/> to handle
/// syntax generation etc.
/// </summary>
/// <param name="isCapabilityWorkflow">
/// This boolean is used to suppress common workflow parameters (or) display
/// them separately towards the end
/// </param>
/// <param name="parameterAction"></param>
/// <param name="commonParameterAction"></param>
/// <returns></returns>
internal void GenerateParametersInDisplayOrder(bool isCapabilityWorkflow,
internal void GenerateParametersInDisplayOrder(
Action<CommandParameterInfo> parameterAction,
Action<string> commonParameterAction)
{
@@ -187,9 +170,6 @@ namespace System.Management.Automation
}
}
// Now convert the sorted positional parameters into a string
List<CommandParameterInfo> commonWorkflowParameter = new List<CommandParameterInfo>();
foreach (CommandParameterInfo parameter in sortedPositionalParameters)
{
if (parameter == null)
@@ -197,14 +177,7 @@ namespace System.Management.Automation
continue;
}
if (!Internal.CommonParameters.CommonWorkflowParameters.Contains(parameter.Name, StringComparer.OrdinalIgnoreCase) || !isCapabilityWorkflow)
{
parameterAction(parameter);
}
else
{
commonWorkflowParameter.Add(parameter);
}
parameterAction(parameter);
}
// Now convert the named mandatory parameters into a string
@@ -232,14 +205,7 @@ namespace System.Management.Automation
bool isCommon = Cmdlet.CommonParameters.Contains(parameter.Name, StringComparer.OrdinalIgnoreCase);
if (!isCommon)
{
if (!Internal.CommonParameters.CommonWorkflowParameters.Contains(parameter.Name, StringComparer.OrdinalIgnoreCase) || !isCapabilityWorkflow)
{
parameterAction(parameter);
}
else
{
commonWorkflowParameter.Add(parameter);
}
parameterAction(parameter);
}
else
{
@@ -247,18 +213,6 @@ namespace System.Management.Automation
}
}
if (commonWorkflowParameter.Count == Internal.CommonParameters.CommonWorkflowParameters.Length)
{
commonParameterAction(HelpDisplayStrings.CommonWorkflowParameters);
}
else
{
foreach (CommandParameterInfo parameter in commonWorkflowParameter)
{
parameterAction(parameter);
}
}
// If all common parameters are present, group them together
if (commonParameters.Count == Cmdlet.CommonParameters.Count)
{
@@ -278,7 +232,7 @@ namespace System.Management.Automation
#region private members
private static void AppendFormatCommandParameterInfo(CommandParameterInfo parameter, ref Text.StringBuilder result)
private static void AppendFormatCommandParameterInfo(CommandParameterInfo parameter, Text.StringBuilder result)
{
if (result.Length > 0)
{
@@ -109,11 +109,6 @@ namespace System.Management.Automation
/// </summary>
internal List<FunctionInfo> ExportedFunctions { get; } = new List<FunctionInfo>();
/// <summary>
/// List of workflows to export from this session state object...
/// </summary>
internal List<WorkflowInfo> ExportedWorkflows { get; } = new List<WorkflowInfo>();
internal bool UseExportList { get; set; } = false;
/// <summary>
@@ -1826,10 +1826,6 @@ namespace System.Management.Automation
{
newValue = new FilterInfo(name, (FilterInfo)originalFunction);
}
else if (originalFunction is WorkflowInfo)
{
newValue = new WorkflowInfo(name, (WorkflowInfo)originalFunction);
}
else if (originalFunction is ConfigurationInfo)
{
newValue = new ConfigurationInfo(name, (ConfigurationInfo)originalFunction);
@@ -39,7 +39,7 @@ namespace System.Management.Automation
/// <exception cref="ArgumentNullException">
/// If <paramref name="workflow"/> is null.
/// </exception>
public WorkflowInfo(string name, string definition, ScriptBlock workflow, string xamlDefinition, WorkflowInfo[] workflowsCalled)
internal WorkflowInfo(string name, string definition, ScriptBlock workflow, string xamlDefinition, WorkflowInfo[] workflowsCalled)
: this(name, workflow, (ExecutionContext)null)
{
if (string.IsNullOrEmpty(xamlDefinition))
@@ -77,7 +77,7 @@ namespace System.Management.Automation
/// <exception cref="ArgumentNullException">
/// If <paramref name="workflow"/> is null.
/// </exception>
public WorkflowInfo(string name, string definition, ScriptBlock workflow, string xamlDefinition, WorkflowInfo[] workflowsCalled, PSModuleInfo module)
internal WorkflowInfo(string name, string definition, ScriptBlock workflow, string xamlDefinition, WorkflowInfo[] workflowsCalled, PSModuleInfo module)
: this(name, definition, workflow, xamlDefinition, workflowsCalled)
{
this.Module = module;
@@ -216,49 +216,6 @@ namespace System.Management.Automation
#endregion
#region DebugSource
/// <summary>
/// Contains debugger script and script file information.
/// </summary>
public sealed class DebugSource
{
/// <summary>
/// Full script.
/// </summary>
public string Script { get; private set; }
/// <summary>
/// Script file for script or null.
/// </summary>
public string ScriptFile { get; private set; }
/// <summary>
/// Xaml definition for Workflow script or null.
/// </summary>
public string XamlDefinition { get; private set; }
/// <summary>
/// Constructor.
/// </summary>
/// <param name="script">Script text</param>
/// <param name="scriptFile">Script file</param>
/// <param name="xamlDefinition">Xaml definition</param>
public DebugSource(
string script,
string scriptFile,
string xamlDefinition)
{
Script = script;
ScriptFile = scriptFile;
XamlDefinition = xamlDefinition;
}
private DebugSource() { }
}
#endregion
#region Runspace Debug Processing
/// <summary>
@@ -622,7 +579,7 @@ namespace System.Management.Automation
public abstract DebuggerStopEventArgs GetDebuggerStopArgs();
/// <summary>
/// Sets the parent debugger and breakpoints.
/// Sets the parent debugger, breakpoints and other debugging context information.
/// </summary>
/// <param name="parent">Parent debugger</param>
/// <param name="breakPoints">List of breakpoints</param>
@@ -639,27 +596,6 @@ namespace System.Management.Automation
throw new PSNotImplementedException();
}
/// <summary>
/// Sets the parent debugger, breakpoints, function source and other
/// debugging context information.
/// </summary>
/// <param name="parent">Parent debugger</param>
/// <param name="breakPoints">List of breakpoints</param>
/// <param name="startAction">Debugger mode</param>
/// <param name="host">PowerShell host</param>
/// <param name="path">Current path</param>
/// <param name="functionSourceMap">Function to source map</param>
public virtual void SetParent(
Debugger parent,
IEnumerable<Breakpoint> breakPoints,
DebuggerResumeAction? startAction,
PSHost host,
PathInfo path,
Dictionary<string, DebugSource> functionSourceMap)
{
throw new PSNotImplementedException();
}
/// <summary>
/// Sets the debugger mode.
/// </summary>
@@ -2970,8 +2906,7 @@ namespace System.Management.Automation
_idToBreakpoint.Values.ToArray<Breakpoint>(),
startAction,
_context.EngineHostInterface.ExternalHost,
_context.SessionState.Path.CurrentLocation,
GetFunctionToSourceMap());
_context.SessionState.Path.CurrentLocation);
}
else
{
@@ -3022,57 +2957,6 @@ namespace System.Management.Automation
}
}
private Dictionary<string, DebugSource> GetFunctionToSourceMap()
{
Dictionary<string, DebugSource> fnToSource = new Dictionary<string, DebugSource>();
// Get workflow function source information for workflow debugger.
Collection<PSObject> items = _context.SessionState.InvokeProvider.Item.Get("function:\\*");
foreach (var item in items)
{
var funcItem = item.BaseObject as WorkflowInfo;
if ((funcItem != null) &&
(!string.IsNullOrEmpty(funcItem.Name)))
{
if ((funcItem.Module != null) && (funcItem.Module.Path != null))
{
string scriptFile = funcItem.Module.Path;
string scriptSource = GetFunctionSource(scriptFile);
if (scriptSource != null)
{
fnToSource.Add(
funcItem.Name,
new DebugSource(
scriptSource,
scriptFile,
funcItem.XamlDefinition));
}
}
}
}
return fnToSource;
}
private string GetFunctionSource(
string scriptFile)
{
if (System.IO.File.Exists(scriptFile))
{
try
{
return System.IO.File.ReadAllText(scriptFile);
}
catch (ArgumentException) { }
catch (System.IO.IOException) { }
catch (UnauthorizedAccessException) { }
catch (NotSupportedException) { }
catch (System.Security.SecurityException) { }
}
return null;
}
private void RemoveFromRunningJobList(Job job)
{
job.StateChanged -= HandleJobStateChanged;
@@ -3882,35 +3882,13 @@ namespace System.Management.Automation
}
/// <summary>
/// Sets the parent debugger, breakpoints, function source and other
/// debugging context information.
/// Sets the parent debugger, breakpoints, and other debugging context information.
/// </summary>
/// <param name="parent">Parent debugger</param>
/// <param name="breakPoints">List of breakpoints</param>
/// <param name="startAction">Debugger mode</param>
/// <param name="host">PowerShell host</param>
/// <param name="path">Current path</param>
/// <param name="functionSourceMap">Function to source map</param>
public override void SetParent(
Debugger parent,
IEnumerable<Breakpoint> breakPoints,
DebuggerResumeAction? startAction,
PSHost host,
PathInfo path,
Dictionary<string, DebugSource> functionSourceMap)
{
// For now always enable step mode debugging.
SetDebuggerStepMode(true);
}
/// <summary>
/// Sets the parent debugger and breakpoints.
/// </summary>
/// <param name="parent">Parent debugger</param>
/// <param name="breakPoints">List of breakpoints</param>
/// <param name="startAction">Debugger mode</param>
/// <param name="host">host</param>
/// <param name="path">Current path</param>
public override void SetParent(
Debugger parent,
IEnumerable<Breakpoint> breakPoints,
@@ -68,18 +68,15 @@ namespace System.Management.Automation.Help
{
CmdletInfo cmdletInfo = commandInfo as CmdletInfo;
bool common = false;
bool commonWorkflow = false;
if (cmdletInfo.Parameters != null)
{
common = HasCommonParameters(cmdletInfo.Parameters);
commonWorkflow = ((cmdletInfo.CommandType & CommandTypes.Workflow) == CommandTypes.Workflow);
}
obj.Properties.Add(new PSNoteProperty("CommonParameters", common));
obj.Properties.Add(new PSNoteProperty("WorkflowCommonParameters", commonWorkflow));
AddDetailsProperties(obj, cmdletInfo.Name, cmdletInfo.Noun, cmdletInfo.Verb, TypeNameForDefaultHelp);
AddSyntaxProperties(obj, cmdletInfo.Name, cmdletInfo.ParameterSets, common, commonWorkflow, TypeNameForDefaultHelp);
AddParametersProperties(obj, cmdletInfo.Parameters, common, commonWorkflow, TypeNameForDefaultHelp);
AddSyntaxProperties(obj, cmdletInfo.Name, cmdletInfo.ParameterSets, common, TypeNameForDefaultHelp);
AddParametersProperties(obj, cmdletInfo.Parameters, common, TypeNameForDefaultHelp);
AddInputTypesProperties(obj, cmdletInfo.Parameters);
AddRelatedLinksProperties(obj, commandInfo.CommandMetadata.HelpUri);
@@ -109,13 +106,11 @@ namespace System.Management.Automation.Help
{
FunctionInfo funcInfo = commandInfo as FunctionInfo;
bool common = HasCommonParameters(funcInfo.Parameters);
bool commonWorkflow = ((commandInfo.CommandType & CommandTypes.Workflow) == CommandTypes.Workflow);
obj.Properties.Add(new PSNoteProperty("CommonParameters", common));
obj.Properties.Add(new PSNoteProperty("WorkflowCommonParameters", commonWorkflow));
AddDetailsProperties(obj, funcInfo.Name, String.Empty, String.Empty, TypeNameForDefaultHelp);
AddSyntaxProperties(obj, funcInfo.Name, funcInfo.ParameterSets, common, commonWorkflow, TypeNameForDefaultHelp);
AddParametersProperties(obj, funcInfo.Parameters, common, commonWorkflow, TypeNameForDefaultHelp);
AddSyntaxProperties(obj, funcInfo.Name, funcInfo.ParameterSets, common, TypeNameForDefaultHelp);
AddParametersProperties(obj, funcInfo.Parameters, common, TypeNameForDefaultHelp);
AddInputTypesProperties(obj, funcInfo.Parameters);
AddRelatedLinksProperties(obj, funcInfo.CommandMetadata.HelpUri);
@@ -194,16 +189,15 @@ namespace System.Management.Automation.Help
/// <param name="cmdletName">command name</param>
/// <param name="parameterSets">parameter sets</param>
/// <param name="common">common parameters</param>
/// <param name="commonWorkflow">common workflow parameters</param>
/// <param name="typeNameForHelp">type name for help</param>
internal static void AddSyntaxProperties(PSObject obj, string cmdletName, ReadOnlyCollection<CommandParameterSetInfo> parameterSets, bool common, bool commonWorkflow, string typeNameForHelp)
internal static void AddSyntaxProperties(PSObject obj, string cmdletName, ReadOnlyCollection<CommandParameterSetInfo> parameterSets, bool common, string typeNameForHelp)
{
PSObject mshObject = new PSObject();
mshObject.TypeNames.Clear();
mshObject.TypeNames.Add(String.Format(CultureInfo.InvariantCulture, "{0}#syntax", typeNameForHelp));
AddSyntaxItemProperties(mshObject, cmdletName, parameterSets, common, commonWorkflow, typeNameForHelp);
AddSyntaxItemProperties(mshObject, cmdletName, parameterSets, common, typeNameForHelp);
obj.Properties.Add(new PSNoteProperty("Syntax", mshObject));
}
@@ -215,9 +209,8 @@ namespace System.Management.Automation.Help
/// <param name="cmdletName">cmdlet name, you can't get this from parameterSets</param>
/// <param name="parameterSets">a collection of parameter sets</param>
/// <param name="common">common parameters</param>
/// <param name="commonWorkflow">common workflow parameters</param>
/// <param name="typeNameForHelp">type name for help</param>
private static void AddSyntaxItemProperties(PSObject obj, string cmdletName, ReadOnlyCollection<CommandParameterSetInfo> parameterSets, bool common, bool commonWorkflow, string typeNameForHelp)
private static void AddSyntaxItemProperties(PSObject obj, string cmdletName, ReadOnlyCollection<CommandParameterSetInfo> parameterSets, bool common, string typeNameForHelp)
{
ArrayList mshObjects = new ArrayList();
@@ -230,18 +223,15 @@ namespace System.Management.Automation.Help
mshObject.Properties.Add(new PSNoteProperty("name", cmdletName));
mshObject.Properties.Add(new PSNoteProperty("CommonParameters", common));
mshObject.Properties.Add(new PSNoteProperty("WorkflowCommonParameters", commonWorkflow));
Collection<CommandParameterInfo> parameters = new Collection<CommandParameterInfo>();
// GenerateParameters parameters in display order
// ie., Positional followed by
// Named Mandatory (in alpha numeric) followed by
// Named (in alpha numeric)
parameterSet.GenerateParametersInDisplayOrder(commonWorkflow,
parameters.Add,
delegate { });
parameterSet.GenerateParametersInDisplayOrder(parameters.Add, delegate { });
AddSyntaxParametersProperties(mshObject, parameters, common, commonWorkflow, parameterSet.Name);
AddSyntaxParametersProperties(mshObject, parameters, common, parameterSet.Name);
mshObjects.Add(mshObject);
}
@@ -260,20 +250,14 @@ namespace System.Management.Automation.Help
/// Named (in alpha numeric)
/// </param>
/// <param name="common">common parameters</param>
/// <param name="commonWorkflow">common workflow</param>
/// <param name="parameterSetName">Name of the parameter set for which the syntax is generated</param>
private static void AddSyntaxParametersProperties(PSObject obj, IEnumerable<CommandParameterInfo> parameters,
bool common, bool commonWorkflow, string parameterSetName)
bool common, string parameterSetName)
{
ArrayList mshObjects = new ArrayList();
foreach (CommandParameterInfo parameter in parameters)
{
if (commonWorkflow && IsCommonWorkflowParameter(parameter.Name))
{
continue;
}
if (common && Cmdlet.CommonParameters.Contains(parameter.Name))
{
continue;
@@ -372,9 +356,8 @@ namespace System.Management.Automation.Help
/// <param name="obj">HelpInfo object</param>
/// <param name="parameters">parameters</param>
/// <param name="common">common parameters</param>
/// <param name="commonWorkflow">common workflow parameters</param>
/// <param name="typeNameForHelp">type name for help</param>
internal static void AddParametersProperties(PSObject obj, Dictionary<string, ParameterMetadata> parameters, bool common, bool commonWorkflow, string typeNameForHelp)
internal static void AddParametersProperties(PSObject obj, Dictionary<string, ParameterMetadata> parameters, bool common, string typeNameForHelp)
{
PSObject paramsObject = new PSObject();
@@ -397,11 +380,6 @@ namespace System.Management.Automation.Help
foreach (string parameter in sortedParameters)
{
if (commonWorkflow && IsCommonWorkflowParameter(parameter))
{
continue;
}
if (common && Cmdlet.CommonParameters.Contains(parameter))
{
continue;
@@ -911,22 +889,6 @@ namespace System.Management.Automation.Help
return (commonParams.Count == Cmdlet.CommonParameters.Count);
}
/// <summary>
/// Checks if a parameter is a common workflow parameter
/// </summary>
/// <param name="name">parameter name</param>
/// <returns>true if it is a common parameter, false if not</returns>
private static bool IsCommonWorkflowParameter(string name)
{
foreach (string parameter in CommonParameters.CommonWorkflowParameters)
{
if (name == parameter)
return true;
}
return false;
}
/// <summary>
/// Checks if the module contains HelpInfoUri
/// </summary>
@@ -905,27 +905,10 @@ namespace System.Management.Automation
HelpCategory.ExternalScript |
HelpCategory.Filter |
HelpCategory.Function |
HelpCategory.ScriptCommand |
HelpCategory.Workflow);
HelpCategory.ScriptCommand);
}
}
WorkflowInfo workflowInfo = commandInfo as WorkflowInfo;
if (workflowInfo != null)
{
bool common = DefaultCommandHelpObjectBuilder.HasCommonParameters(commandInfo.Parameters);
bool commonWorkflow = ((commandInfo.CommandType & CommandTypes.Workflow) ==
CommandTypes.Workflow);
localHelpInfo.FullHelp.Properties.Add(new PSNoteProperty("CommonParameters", common));
localHelpInfo.FullHelp.Properties.Add(new PSNoteProperty("WorkflowCommonParameters", commonWorkflow));
DefaultCommandHelpObjectBuilder.AddDetailsProperties(obj: localHelpInfo.FullHelp, name: workflowInfo.Name,
noun: workflowInfo.Noun, verb: workflowInfo.Verb,
typeNameForHelp: "MamlCommandHelpInfo", synopsis: localHelpInfo.Synopsis);
DefaultCommandHelpObjectBuilder.AddSyntaxProperties(localHelpInfo.FullHelp, workflowInfo.Name,
workflowInfo.ParameterSets, common, commonWorkflow, "MamlCommandHelpInfo");
}
// Add HelpUri if necessary
if (localHelpInfo.GetUriForOnlineHelp() == null)
{
@@ -443,22 +443,6 @@ To update help again, add the Force parameter to your command.</value>
<data name="SavedHelpContent" xml:space="preserve">
<value>Saved {0}</value>
</data>
<data name="CommonWorkflowParameters" xml:space="preserve">
<value>&lt;WorkflowCommonParameters&gt;</value>
</data>
<data name="BaseWorkflowCmdletInformation" xml:space="preserve">
<value> This cmdlet supports the workflow common parameters:
PSComputerName, JobName, PSApplicationName, PSCredential,
PSPort, PSConfigurationName, PSConnectionURI, PSSessionOption,
PSAuthentication, PSAuthenticationLevel,
PSCertificateThumbprint, PSConnectionRetryCount,
PSConnectionRetryIntervalSec, PSRunningTimeoutSec,
PSElapsedTimeoutSec, PSPersist,
PSPrivateMetadata, InputObject,
PSParameterCollection, AsJob, PSUseSSL, and PSAllowRedirection.
For more information, see about_Workflow_Common_Parameters
(https://go.microsoft.com/fwlink/?LinkID=222527).</value>
</data>
<data name="InvalidHelpInfoUriFormat" xml:space="preserve">
<value>The HelpInfoURI {0} does not start with HTTP.</value>
</data>
@@ -537,9 +537,6 @@
<data name="RemoteDiscoveryWorksOnlyInListAvailableMode" xml:space="preserve">
<value>Running the Get-Module cmdlet against a remote computer can only list available modules. Add the ListAvailable parameter to your command, and then try again.</value>
</data>
<data name="ExportingWorkflow" xml:space="preserve">
<value>Exporting workflow '{0}'.</value>
</data>
<data name="ModuleLoadedAsASnapin" xml:space="preserve">
<value>The '{0}' module was not imported because the '{0}' snap-in was already imported.</value>
</data>
@@ -597,7 +597,6 @@ namespace Microsoft.PowerShell
case CommandTypes.Function:
case CommandTypes.Filter:
case CommandTypes.Workflow:
case CommandTypes.Configuration:
//
// we do not check functions/filters.