From db33d90479793144837af197002f6c3c2d02d719 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Mon, 11 Sep 2017 08:55:13 -0700 Subject: [PATCH] First round of workflow cleanup (#4777) This round of cleanup focuses on the following areas - Tab completion code - InitialSessionState - Compiler/MiscOps - Utils/SessionStateFunctionAPIs Changes in the rest affected files are mainly some corresponding changes due to the cleanup work in the above areas. --- .../CommandCompletion/CompletionAnalysis.cs | 5 +- .../CommandCompletion/CompletionCompleters.cs | 84 +--- .../PseudoParameterBinder.cs | 197 +------- .../engine/CommandInfo.cs | 2 +- .../engine/CommandMetadata.cs | 18 - .../engine/ExecutionContext.cs | 1 - .../engine/InitialSessionState.cs | 433 +----------------- .../engine/Modules/ModuleCmdletBase.cs | 6 +- .../engine/Modules/ModuleIntrinsics.cs | 4 +- .../Modules/TestModuleManifestCommand.cs | 6 +- .../engine/SessionStateFunctionAPIs.cs | 72 +-- .../engine/SessionStateStrings.cs | 2 +- .../engine/Utils.cs | 53 --- .../engine/parser/Compiler.cs | 20 - .../engine/parser/SemanticChecks.cs | 13 - .../engine/parser/ast.cs | 32 -- .../engine/runtime/Operations/MiscOps.cs | 34 -- .../resources/AutomationExceptions.resx | 3 - .../resources/Modules.resx | 3 - 19 files changed, 28 insertions(+), 960 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs index f7d2b8b53..e63f3a3c5 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs @@ -1407,9 +1407,8 @@ namespace System.Management.Automation StringLiterals.PowerShellModuleFileExtension, StringLiterals.PowerShellDataFileExtension, StringLiterals.PowerShellNgenAssemblyExtension, - StringLiterals.DependentWorkflowAssemblyExtension, - StringLiterals.PowerShellCmdletizationFileExtension, - StringLiterals.WorkflowFileExtension + StringLiterals.PowerShellILAssemblyExtension, + StringLiterals.PowerShellCmdletizationFileExtension }; result = CompletionCompleters.CompleteFilename(completionContext, false, moduleExtensions).ToList(); if (completionContext.WordToComplete.IndexOfAny(Utils.Separators.DirectoryOrDrive) != -1) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index 4e4dea1a5..844a3588d 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -118,13 +118,6 @@ namespace System.Management.Automation Exception exceptionThrown; var commandInfos = context.Helper.ExecuteCurrentPowerShell(out exceptionThrown); - // Complete against pseudo commands that work only in the script workflow. - // If RelatedAst is null then it's for argument completion, because we don't complete pseudo commands for arguments - if (lastAst != null) - { - commandInfos = CompleteWorkflowCommand(commandName, lastAst, commandInfos); - } - if (commandInfos != null && commandInfos.Count > 1) { // OrderBy is using stable sorting @@ -197,21 +190,6 @@ namespace System.Management.Automation return commandResults; } - /// - /// Construct a new instance of CompletionContext with RelatedAst = null. - /// For argument completion, we don't want to complete against pseudo commands that only work in the script workflow. - /// The way to avoid that is to pass in a CompletionContext with RelatedAst = null. - /// - private static CompletionContext NewContextToCompleteCommandAsArgument(CompletionContext context) - { - return new CompletionContext { - WordToComplete = context.WordToComplete, - Helper = context.Helper, - ExecutionContext = context.ExecutionContext, - Options = context.Options - }; - } - private static readonly HashSet s_keywordsToExcludeFromAddingAmpersand = new HashSet(StringComparer.OrdinalIgnoreCase) { TokenKind.InlineScript.ToString(), TokenKind.Configuration.ToString() }; internal static CompletionResult GetCommandNameCompletionResult(string name, object command, bool addAmpersandIfNecessary, string quote) @@ -364,9 +342,7 @@ namespace System.Management.Automation for (int index = 1; index < commandList.Count; index++) { var commandInfo = commandList[index] as CommandInfo; - // If it's a pseudo command that only works in the script workflow, don't bother adding it to the result - // list since it's a duplicate - if (commandInfo == null) { continue; } + Diagnostics.Assert(commandInfo != null, "Elements should always be CommandInfo"); if (commandInfo.CommandType == CommandTypes.Application) { @@ -409,30 +385,6 @@ namespace System.Management.Automation return results; } - /// - /// Contains the pseudo commands that only work in the script workflow. - /// - internal static readonly List PseudoWorkflowCommands - = new List { "Checkpoint-Workflow", "Suspend-Workflow", "InlineScript" }; - private static Collection CompleteWorkflowCommand(string command, Ast lastAst, Collection commandInfos) - { - if (!lastAst.IsInWorkflow()) - return commandInfos; - - commandInfos = commandInfos ?? new Collection(); - var commandPattern = WildcardPattern.Get(command, WildcardOptions.IgnoreCase); - - foreach (string pseudoCommand in PseudoWorkflowCommands) - { - if (!commandPattern.IsMatch(pseudoCommand)) - continue; - - commandInfos.Add(PSObject.AsPSObject(pseudoCommand)); - } - - return commandInfos; - } - private class FindFunctionsVisitor : AstVisitor { internal readonly List FunctionDefinitions = new List(); @@ -1339,10 +1291,7 @@ namespace System.Management.Automation if (context.WordToComplete != string.Empty && context.WordToComplete.IndexOf('-') != -1) { - // For argument completion, we don't want to complete against pseudo commands that only work in the script workflow. - // The way to avoid that is to pass in a CompletionContext with RelatedAst = null - var newContext = NewContextToCompleteCommandAsArgument(context); - var commandResults = CompleteCommand(newContext); + var commandResults = CompleteCommand(context); if (commandResults != null) result.AddRange(commandResults); } @@ -2103,10 +2052,7 @@ namespace System.Management.Automation { if (parameterName.Equals("Command", StringComparison.OrdinalIgnoreCase)) { - // For argument completion, we don't want to complete against pseudo commands that only work in the script workflow. - // The way to avoid that is to pass in a CompletionContext with RelatedAst = null - var newContext = NewContextToCompleteCommandAsArgument(context); - var commandResults = CompleteCommand(newContext); + var commandResults = CompleteCommand(context); if (commandResults != null) result.AddRange(commandResults); } @@ -2796,10 +2742,7 @@ namespace System.Management.Automation RemoveLastNullCompletionResult(result); // Available commands - // For argument completion, we don't want to complete against pseudo commands that only work in the script workflow. - // The way to avoid that is to pass in a CompletionContext with RelatedAst = null - var newContext = NewContextToCompleteCommandAsArgument(context); - var commandResults = CompleteCommand(newContext, moduleName); + var commandResults = CompleteCommand(context, moduleName); if (commandResults != null) result.AddRange(commandResults); @@ -2858,11 +2801,8 @@ namespace System.Management.Automation RemoveLastNullCompletionResult(result); // Available commands - // For argument completion, we don't want to complete against pseudo commands that only work in the script workflow. - // The way to avoid that is to pass in a CompletionContext with RelatedAst = null - const CommandTypes commandTypes = CommandTypes.Cmdlet | CommandTypes.Function | CommandTypes.Alias | CommandTypes.ExternalScript | CommandTypes.Workflow | CommandTypes.Configuration; - var newContext = NewContextToCompleteCommandAsArgument(context); - var commandResults = CompleteCommand(newContext, /* moduleName: */ null, commandTypes); + const CommandTypes commandTypes = CommandTypes.Cmdlet | CommandTypes.Function | CommandTypes.Alias | CommandTypes.ExternalScript | CommandTypes.Configuration; + var commandResults = CompleteCommand(context, /* moduleName: */ null, commandTypes); if (commandResults != null) result.AddRange(commandResults); @@ -3113,9 +3053,8 @@ namespace System.Management.Automation StringLiterals.PowerShellModuleFileExtension, StringLiterals.PowerShellDataFileExtension, StringLiterals.PowerShellNgenAssemblyExtension, - StringLiterals.DependentWorkflowAssemblyExtension, - StringLiterals.PowerShellCmdletizationFileExtension, - StringLiterals.WorkflowFileExtension + StringLiterals.PowerShellILAssemblyExtension, + StringLiterals.PowerShellCmdletizationFileExtension }; var moduleFilesResults = new List(CompleteFilename(context, /* containerOnly: */ false, moduleExtensions)); if (moduleFilesResults.Count > 0) @@ -3514,11 +3453,8 @@ namespace System.Management.Automation { // Complete for the parameter Definition // Available commands - // For argument completion, we don't want to complete against pseudo commands that only work in the script workflow. - // The way to avoid that is to pass in a CompletionContext with RelatedAst = null - const CommandTypes commandTypes = CommandTypes.Cmdlet | CommandTypes.Function | CommandTypes.ExternalScript | CommandTypes.Workflow | CommandTypes.Configuration; - var newContext = NewContextToCompleteCommandAsArgument(context); - var commandResults = CompleteCommand(newContext, /* moduleName: */ null, commandTypes); + const CommandTypes commandTypes = CommandTypes.Cmdlet | CommandTypes.Function | CommandTypes.ExternalScript | CommandTypes.Configuration; + var commandResults = CompleteCommand(context, /* moduleName: */ null, commandTypes); if (commandResults != null && commandResults.Count > 0) result.AddRange(commandResults); diff --git a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs index cb13722f2..811136ed3 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs @@ -1137,18 +1137,11 @@ namespace System.Management.Automation.Language private Collection _duplicateParameters; private Dictionary _bindingExceptions; - // A corresponding list is also kept in WorkflowJobConverter.cs. - private List _ignoredWorkflowParameters = null; - /// /// Initialize collection/dictionary members when it's necessary /// private void InitializeMembers() { - List supportedCommonParameters = new List() { "Verbose", "Debug", "ErrorAction", "WarningAction", "InformationAction" }; - _ignoredWorkflowParameters = new List(Cmdlet.CommonParameters.Concat(Cmdlet.OptionalCommonParameters)); - _ignoredWorkflowParameters.RemoveAll(item => supportedCommonParameters.Contains(item, StringComparer.OrdinalIgnoreCase)); - // Initializing binding related members _function = false; _commandName = null; @@ -1193,7 +1186,6 @@ namespace System.Management.Automation.Language CommandProcessorBase processor = null; string commandName = null; - bool psuedoWorkflowCommand = false; try { processor = PrepareFromAst(context, out commandName) ?? context.CreateCommand(commandName, dotSource); @@ -1201,16 +1193,7 @@ namespace System.Management.Automation.Language catch (RuntimeException) { // Failed to create the CommandProcessor; - if (_commandAst.IsInWorkflow() && - commandName != null && - CompletionCompleters.PseudoWorkflowCommands.Contains(commandName, StringComparer.OrdinalIgnoreCase)) - { - psuedoWorkflowCommand = true; - } - else - { - return false; - } + return false; } var commandProcessor = processor as CommandProcessor; @@ -1221,7 +1204,7 @@ namespace System.Management.Automation.Language var argumentsToGetDynamicParameters = implementsDynamicParameters ? new List(_commandElements.Count) : null; - if (commandProcessor != null || scriptProcessor != null || psuedoWorkflowCommand) + if (commandProcessor != null || scriptProcessor != null) { // Pre-processing the arguments -- command arguments for (commandIndex++; commandIndex < _commandElements.Count; commandIndex++) @@ -1326,89 +1309,12 @@ namespace System.Management.Automation.Language _bindableParameters = scriptProcessor.ScriptParameterBinderController.BindableParameters; _defaultParameterSetFlag = 0; } - else if (!psuedoWorkflowCommand) + else { // The command is not a function, cmdlet and script cmdlet return false; } - if (_commandAst.IsInWorkflow()) - { - var converterType = Type.GetType(Utils.WorkflowType); - var activityParameters = (Dictionary) converterType?.GetMethod("GetActivityParameters").Invoke(null, new object[] { _commandAst }); - if (activityParameters != null) - { - bool needToRemoveReplacedProperty = activityParameters.ContainsKey("PSComputerName") && - !activityParameters.ContainsKey("ComputerName"); - - var parametersToAdd = new List(); - var attrCollection = new Collection { new ParameterAttribute() }; - foreach (var pair in activityParameters) - { - if (psuedoWorkflowCommand || !_bindableParameters.BindableParameters.ContainsKey(pair.Key)) - { - Type parameterType = GetActualActivityParameterType(pair.Value); - var runtimeDefinedParameter = new RuntimeDefinedParameter(pair.Key, parameterType, attrCollection); - var compiledCommandParameter = new CompiledCommandParameter(runtimeDefinedParameter, false) { IsInAllSets = true }; - var mergedCompiledCommandParameter = new MergedCompiledCommandParameter(compiledCommandParameter, ParameterBinderAssociation.DeclaredFormalParameters); - parametersToAdd.Add(mergedCompiledCommandParameter); - } - } - if (parametersToAdd.Any()) - { - var mergedBindableParameters = new MergedCommandParameterMetadata(); - if (!psuedoWorkflowCommand) - { - mergedBindableParameters.ReplaceMetadata(_bindableParameters); - } - foreach (var p in parametersToAdd) - { - mergedBindableParameters.BindableParameters.Add(p.Parameter.Name, p); - } - _bindableParameters = mergedBindableParameters; - } - - // Remove common parameters that are supported by all commands, but not - // by workflows - bool fixedReadOnly = false; - foreach (var ignored in _ignoredWorkflowParameters) - { - if (_bindableParameters.BindableParameters.ContainsKey(ignored)) - { - // However, some ignored parameters are explicitly implemented by - // activities, so keep them. - if (!activityParameters.ContainsKey(ignored)) - { - if (!fixedReadOnly) - { - _bindableParameters.ResetReadOnly(); - fixedReadOnly = true; - } - - _bindableParameters.BindableParameters.Remove(ignored); - } - } - } - - if (_bindableParameters.BindableParameters.ContainsKey("ComputerName") && needToRemoveReplacedProperty) - { - if (!fixedReadOnly) - { - _bindableParameters.ResetReadOnly(); - fixedReadOnly = true; - } - - _bindableParameters.BindableParameters.Remove("ComputerName"); - string aliasOfComputerName = (from aliasPair in _bindableParameters.AliasedParameters - where String.Equals("ComputerName", aliasPair.Value.Parameter.Name) - select aliasPair.Key).FirstOrDefault(); - if (aliasOfComputerName != null) - { - _bindableParameters.AliasedParameters.Remove(aliasOfComputerName); - } - } - } - } _unboundParameters.AddRange(_bindableParameters.BindableParameters.Values); // Pre-processing the arguments -- pipeline input @@ -1464,108 +1370,13 @@ namespace System.Management.Automation.Language FunctionDefinitionAst functionDefinitionAst; if (exportVisitor.DiscoveredFunctions.TryGetValue(resolvedCommandName, out functionDefinitionAst)) { - // We could use the IAstToScriptBlockConverter to get the actual script block, but that can be fairly expensive for workflows. - // IAstToScriptBlockConverter is public, so we might consider converting non-workflows, but the interface isn't really designed - // for Intellisense, so we can't really expect good performance, so instead we'll just fall back on the actual - // parameters we see in the ast. - var scriptBlock = functionDefinitionAst.IsWorkflow - ? CreateFakeScriptBlockForWorkflow(functionDefinitionAst) - : new ScriptBlock(functionDefinitionAst, functionDefinitionAst.IsFilter); + var scriptBlock = new ScriptBlock(functionDefinitionAst, functionDefinitionAst.IsFilter); commandProcessor = CommandDiscovery.CreateCommandProcessorForScript(scriptBlock, context, true, context.EngineSessionState); } - } return commandProcessor; } - private static ScriptBlock CreateFakeScriptBlockForWorkflow(FunctionDefinitionAst functionDefinitionAst) - { - // The common parameters for a workflow is are always the same, the only difference is what parameters - // the workflow specifies. When we generate the wrapper, the users parameters are "tweaked" slightly, - // but those differences shouldn't matter for Intellisense. They could for the syntax if we showed it, - // but the differences are very minor. See ImportWorkflowCommand.AddCommonWfParameters in - // admin\monad\src\m3p\product\ServiceCore\WorkflowCore\ImportWorkflowCommand.cs for the actual logic - // that creates this string. - - const string paramBlock = @" - [CmdletBinding()] - {0} - param ( - {1} - [hashtable[]] $PSParameterCollection, - [string[]] $PSComputerName, - [ValidateNotNullOrEmpty()] $PSCredential, - [uint32] $PSConnectionRetryCount, - [uint32] $PSConnectionRetryIntervalSec, - [ValidateRange(1, 2147483)][uint32] $PSRunningTimeoutSec, - [ValidateRange(1, 2147483)][uint32] $PSElapsedTimeoutSec, - [bool] $PSPersist, - [ValidateNotNullOrEmpty()] [System.Management.Automation.Runspaces.AuthenticationMechanism] $PSAuthentication, - [ValidateNotNullOrEmpty()][System.Management.AuthenticationLevel] $PSAuthenticationLevel, - [ValidateNotNullOrEmpty()] [string] $PSApplicationName, - [uint32] $PSPort, - [switch] $PSUseSSL, - [ValidateNotNullOrEmpty()] [string] $PSConfigurationName, - [ValidateNotNullOrEmpty()][string[]] $PSConnectionURI, - [switch] $PSAllowRedirection, - [ValidateNotNullOrEmpty()][System.Management.Automation.Remoting.PSSessionOption] $PSSessionOption, - [ValidateNotNullOrEmpty()] [string] $PSCertificateThumbprint, - [hashtable] $PSPrivateMetadata, - [switch] $AsJob, - [string] $JobName, - [Parameter(ValueFromPipeline=$true)]$InputObject - ) -"; - - var outputTypeText = new StringBuilder(); - var sb = new StringBuilder(); - - var paramBlockAst = functionDefinitionAst.Body.ParamBlock; - if (paramBlockAst != null) - { - var outputTypeAttrs = paramBlockAst.Attributes.Where(attribute => typeof(OutputTypeAttribute) == attribute.TypeName.GetReflectionAttributeType()); - - foreach (AttributeAst attributeAst in outputTypeAttrs) - { - outputTypeText.Append(attributeAst.Extent.Text); - } - } - - var parameterAsts = ((IParameterMetadataProvider)functionDefinitionAst).Parameters; - if (parameterAsts != null) - { - var first = true; - foreach (var parameter in parameterAsts) - { - if (!first) sb.Append(", "); - first = false; - sb.Append(parameter.Extent.Text); - } - if (!first) sb.Append(", "); - } - - Token[] tokens; - ParseError[] errors; - var ast = Parser.ParseInput(string.Format(CultureInfo.InvariantCulture, paramBlock, outputTypeText.ToString(), sb.ToString()), out tokens, out errors); - return ast.GetScriptBlock(); - } - - private static Type GetActualActivityParameterType(Type parameterType) - { - if (parameterType.GetTypeInfo().IsGenericType) - { - var fullName = parameterType.GetGenericTypeDefinition().FullName; - if (fullName.Equals("System.Activities.InArgument`1", StringComparison.Ordinal) || - fullName.Equals("System.Activities.InOutArgument`1", StringComparison.Ordinal)) - { - parameterType = parameterType.GetGenericArguments()[0]; - } - } - parameterType = Nullable.GetUnderlyingType(parameterType) ?? parameterType; - return parameterType; - } - - /// /// Parse the arguments to process switch parameters and parameters without a value /// specified. We always eat the error (such as parameter without value) and continue diff --git a/src/System.Management.Automation/engine/CommandInfo.cs b/src/System.Management.Automation/engine/CommandInfo.cs index 168fe41cd..278e3e5a1 100644 --- a/src/System.Management.Automation/engine/CommandInfo.cs +++ b/src/System.Management.Automation/engine/CommandInfo.cs @@ -225,7 +225,7 @@ namespace System.Management.Automation // Manifest module (.psd1) Module.SetVersion(ModuleIntrinsics.GetManifestModuleVersion(Module.Path)); } - else if (Module.Path.EndsWith(StringLiterals.DependentWorkflowAssemblyExtension, StringComparison.OrdinalIgnoreCase)) + else if (Module.Path.EndsWith(StringLiterals.PowerShellILAssemblyExtension, StringComparison.OrdinalIgnoreCase)) { // Binary module (.dll) Module.SetVersion(AssemblyName.GetAssemblyName(Module.Path).Version); diff --git a/src/System.Management.Automation/engine/CommandMetadata.cs b/src/System.Management.Automation/engine/CommandMetadata.cs index d1165546f..9eec48450 100644 --- a/src/System.Management.Automation/engine/CommandMetadata.cs +++ b/src/System.Management.Automation/engine/CommandMetadata.cs @@ -34,14 +34,6 @@ namespace System.Management.Automation /// RemoteServer = 0x1, - /// - /// Session with capabilities can be made available on - /// a server that wants to provide workflow hosting capabilities in the - /// specified end points. All jobs commands as well as commands for - /// implicit remoting and interactive remoting will be made available - /// - WorkflowServer = 0x2, - /// /// Include language capabilities /// @@ -1339,16 +1331,6 @@ end restrictedCommands.AddRange(GetRestrictedRemotingCommands()); } - if (SessionCapabilities.WorkflowServer == (sessionCapabilities & SessionCapabilities.WorkflowServer)) - { -#if CORECLR // Workflow Not Supported On PowerShell Core - throw PSTraceSource.NewNotSupportedException(ParserStrings.WorkflowNotSupportedInPowerShellCore); -#else - restrictedCommands.AddRange(GetRestrictedRemotingCommands()); - restrictedCommands.AddRange(GetRestrictedJobCommands()); -#endif - } - Dictionary result = new Dictionary(StringComparer.OrdinalIgnoreCase); foreach (CommandMetadata restrictedCommand in restrictedCommands) { diff --git a/src/System.Management.Automation/engine/ExecutionContext.cs b/src/System.Management.Automation/engine/ExecutionContext.cs index 0200aa592..af4db323f 100644 --- a/src/System.Management.Automation/engine/ExecutionContext.cs +++ b/src/System.Management.Automation/engine/ExecutionContext.cs @@ -393,7 +393,6 @@ namespace System.Management.Automation internal static List ModulesWithJobSourceAdapters = new List { - Utils.WorkflowModule, Utils.ScheduledJobModuleName, }; diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index 3bac5a590..e47498fdf 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -833,102 +833,6 @@ namespace System.Management.Automation.Runspaces public string HelpFile { get; private set; } } -#if !CORECLR // Workflow Not Supported On CSS - /// - /// - /// - public sealed class SessionStateWorkflowEntry : SessionStateCommandEntry - { - /// - /// Represents a workflow definition in an Initial session state object. - /// - /// The name of the workflow - /// The definition of the workflow - /// Options controlling scope-related elements of this object - /// The name of the help file associated with the workflow - public SessionStateWorkflowEntry(string name, string definition, ScopedItemOptions options, string helpFile) - : base(name, SessionStateEntryVisibility.Public) - { - Definition = definition; - CommandType = CommandTypes.Workflow; - Options = options; - HelpFile = helpFile; - } - - /// - /// Represents a workflow definition in an Initial session state object. - /// - /// The name of the workflow - /// The definition of the workflow - /// The name of the help file associated with the workflow - public SessionStateWorkflowEntry(string name, string definition, string helpFile) - : this(name, definition, ScopedItemOptions.None, helpFile) - { - } - - /// - /// Represents a workflow definition in an Initial session state object. - /// - /// The name of the workflow - /// The definition of the workflow - public SessionStateWorkflowEntry(string name, string definition) - : this(name, definition, ScopedItemOptions.None, null) - { - } - - /// - /// This is an internal copy constructor. - /// - internal SessionStateWorkflowEntry(string name, string definition, ScopedItemOptions options, SessionStateEntryVisibility visibility, WorkflowInfo workflow, string helpFile) - : base(name, visibility) - { - Definition = definition; - Options = options; - WorkflowInfo = workflow; - HelpFile = helpFile; - } - - /// - /// Shallow-clone this object... - /// - /// The cloned object - public override InitialSessionStateEntry Clone() - { - SessionStateWorkflowEntry entry = new SessionStateWorkflowEntry(Name, Definition, Options, Visibility, WorkflowInfo, HelpFile); - entry.SetModule(this.Module); - return entry; - } - - /// - /// Sets the name of the help file associated with the function. - /// - internal void SetHelpFile(string help) - { - HelpFile = help; - } - - /// - /// The string to use to define this function... - /// - public string Definition { get; } - - /// - /// The script block for this function. - /// - internal WorkflowInfo WorkflowInfo { get; set; } - - /// - /// Options controling scope visibility and setability for this entry. - /// - public ScopedItemOptions Options { get; } = ScopedItemOptions.None; - - /// - /// The name of the help file associated with the function. - /// - public string HelpFile { get; private set; } - } -#endif - /// /// /// @@ -1481,29 +1385,6 @@ namespace System.Management.Automation.Runspaces return CreateRestrictedForRemoteServer(); } -#if CORECLR // Workflow Not Supported On CSS - if ((sessionCapabilities & SessionCapabilities.WorkflowServer) == SessionCapabilities.WorkflowServer) - { - throw PSTraceSource.NewNotSupportedException(ParserStrings.WorkflowNotSupportedInPowerShellCore); - } -#else - // only workflow has been requested - if (SessionCapabilities.WorkflowServer == sessionCapabilities) - { - return CreateRestrictedForWorkflowServerMinimum(); - } - - // workflow server with remoting support has been requested - if (sessionCapabilities == (SessionCapabilities.WorkflowServer | SessionCapabilities.RemoteServer)) - { - return CreateRestrictedForWorkflowServer(); - } - - if (sessionCapabilities == (SessionCapabilities.WorkflowServer | SessionCapabilities.RemoteServer | SessionCapabilities.Language)) - { - return CreateRestrictedForWorkflowServerWithFullLanguage(); - } -#endif return Create(); } @@ -1610,296 +1491,6 @@ namespace System.Management.Automation.Runspaces } } -#if !CORECLR // Workflow Not Supported On CSS - private static List allowedAliases = new List - { - "compare", - "diff", - "%", - "foreach", - "exsn", - "fc", - "fl", - "ft", - "fw", - "gcm", - "gjb", - "gmo", - "gv", - "group", - "ipmo", - "measure", - "rv", - "rcjb", - "rjb", - "rmo", - "rujb", - "select", - "set", - "sv", - "sort", - "spjb", - "sujb", - "wjb", - "?", - "where" - }; - - private static InitialSessionState CreateRestrictedForWorkflowServer() - { - InitialSessionState iss = CreateDefault(); - iss.LanguageMode = PSLanguageMode.NoLanguage; - iss.ThrowOnRunspaceOpenError = true; - iss.UseFullLanguageModeInDebugger = false; - - // WIN8:551312 M3P endpoint should have NO application exposed - // - foreach (SessionStateCommandEntry entry in iss.Commands) - { - if (entry is SessionStateApplicationEntry) - { - iss.Commands.Remove(entry.Name, entry); - break; - } - } - - // - // restrict what gets exposed - // - - List allowedCommands = new List(); - allowedCommands.AddRange(JobCmdlets); - allowedCommands.AddRange(ImplicitRemotingCmdlets); - allowedCommands.AddRange(MiscCmdlets); - allowedCommands.AddRange(AutoDiscoveryCmdlets); - - // make all other commands private - MakeDisallowedEntriesPrivate( - iss.Commands, - allowedCommands, - commandEntry => commandEntry.Name); - - foreach (SessionStateCommandEntry entry in iss.Commands) - { - if (entry is SessionStateAliasEntry) - { - if (allowedAliases.Contains(entry.Name, StringComparer.OrdinalIgnoreCase)) - { - entry.Visibility = SessionStateEntryVisibility.Public; - } - else - { - entry.Visibility = SessionStateEntryVisibility.Private; - } - } - } - - // Porting note: copy so it can be modified - List allowedFormats = new List(Platform.FormatFileNames); - RemoveDisallowedEntries( - iss.Formats, - allowedFormats, - formatEntry => IO.Path.GetFileName(formatEntry.FileName)); - - // Porting note: type files were deprecated - List allowedTypes = new List(); - allowedTypes.AddRange(DefaultTypeFiles); - RemoveDisallowedEntries( - iss.Types, - allowedTypes, - typeEntry => IO.Path.GetFileName(typeEntry.FileName)); - - iss.Variables.Clear(); // no variables are needed for workflow server - remove all of them - - return iss; - } - - private static InitialSessionState CreateRestrictedForWorkflowServerWithFullLanguage() - { - InitialSessionState iss = CreateDefault(); - - iss.LanguageMode = PSLanguageMode.FullLanguage; - iss.ThrowOnRunspaceOpenError = true; - iss.UseFullLanguageModeInDebugger = false; - - // WIN8:551312 M3P endpoint should have NO application exposed - // - foreach (SessionStateCommandEntry entry in iss.Commands) - { - if (entry is SessionStateApplicationEntry) - { - iss.Commands.Remove(entry.Name, entry); - break; - } - } - - // - // restrict what gets exposed - // - - List allowedCommands = new List(); - allowedCommands.AddRange(JobCmdlets); - allowedCommands.AddRange(ImplicitRemotingCmdlets); - allowedCommands.AddRange(MiscCmdlets); - allowedCommands.AddRange(MiscCommands); - allowedCommands.AddRange(AutoDiscoveryCmdlets); - allowedCommands.AddRange(LanguageHelperCmdlets); - // Exposing Debug cmdlets in only Full language WF server - // because for debugging one needs full language capabilities - allowedCommands.AddRange(DebugCmdlets); - - // make all other commands private - MakeDisallowedEntriesPrivate( - iss.Commands, - allowedCommands, - commandEntry => commandEntry.Name); - - foreach (SessionStateCommandEntry entry in iss.Commands) - { - if (entry is SessionStateAliasEntry) - { - if (allowedAliases.Contains(entry.Name, StringComparer.OrdinalIgnoreCase)) - { - entry.Visibility = SessionStateEntryVisibility.Public; - } - else - { - entry.Visibility = SessionStateEntryVisibility.Private; - } - } - } - - // Porting note: copy so it can be modified - List allowedFormats = new List(Platform.FormatFileNames); - RemoveDisallowedEntries( - iss.Formats, - allowedFormats, - formatEntry => IO.Path.GetFileName(formatEntry.FileName)); - - // Porting note: type files were deprecated - List allowedTypes = new List(); - allowedTypes.AddRange(DefaultTypeFiles); - RemoveDisallowedEntries( - iss.Types, - allowedTypes, - typeEntry => IO.Path.GetFileName(typeEntry.FileName)); - - iss.Variables.Clear(); // no variables are needed for workflow server - remove all of them - // set a preference variable to indicate Get-Command should show - // return only loaded public commands - Hashtable parameters = new Hashtable { { "Get-Command:ListImported", true } }; - iss.Variables.Add(new SessionStateVariableEntry("PSDefaultParameterValues", parameters, "Default Get-Command Action")); - return iss; - } - - private static InitialSessionState CreateRestrictedForWorkflowServerMinimum() - { - InitialSessionState iss = CreateDefault(); - iss.LanguageMode = PSLanguageMode.NoLanguage; - iss.ThrowOnRunspaceOpenError = true; - iss.UseFullLanguageModeInDebugger = false; - - // WIN8:551312 M3P endpoint should have NO application exposed - // - foreach (SessionStateCommandEntry entry in iss.Commands) - { - if (entry.GetType() == typeof(SessionStateApplicationEntry)) - { - iss.Commands.Remove(entry.Name, entry); - break; - } - } - - // - // restrict what gets exposed - // - - // required by implicit remoting and interactive remoting - List allowedCommands = new List - { - "Get-Command" - }; - allowedCommands.AddRange(JobCmdlets); - allowedCommands.AddRange(MiscCmdlets); - - // make all other commands private - MakeDisallowedEntriesPrivate( - iss.Commands, - allowedCommands, - commandEntry => commandEntry.Name); - - iss.Formats.Clear(); - List allowedTypes = new List(); - allowedTypes.AddRange(DefaultTypeFiles); - RemoveDisallowedEntries( - iss.Types, - allowedTypes, - typeEntry => IO.Path.GetFileName(typeEntry.FileName)); - - iss.Variables.Clear(); // no variables are needed for workflow server - remove all of them - - // Disable module autodiscovery - SessionStateVariableEntry ssve = new SessionStateVariableEntry("PSDisableModuleAutoDiscovery", - true, "True if we disable module autodiscovery", ScopedItemOptions.Constant); - iss.Variables.Add(ssve); - - return iss; - } - - private static readonly string[] JobCmdlets = { - "Get-Job", "Stop-Job", "Wait-Job", "Suspend-Job", "Resume-Job", - "Remove-Job", "Receive-Job" - }; - - private static readonly string[] ImplicitRemotingCmdlets = { - "Get-Command", "Select-Object", "Measure-Object", - "Get-Help", "Get-FormatData", "Exit-PSSession", - "Out-Default" - }; - - private static readonly string[] AutoDiscoveryCmdlets = { "Get-Module" }; - - private static readonly string[] LanguageHelperCmdlets = { - "Compare-Object", - "ForEach-Object", - "Group-Object", - "Sort-Object", - "Where-Object", - "Out-File", - "Out-Null", - "Out-String", - "Format-Custom", - "Format-List", - "Format-Table", - "Format-Wide", - "Remove-Module", - "Get-Variable", - "Set-Variable", - "Remove-Variable", - "Get-Credential", - "Set-StrictMode" - }; - /// - /// Following cmdlets are needed for debugging support starting WinBlue - /// - private static readonly string[] DebugCmdlets = { - "Disable-PSBreakpoint", - "Enable-PSBreakpoint", - "Get-PSBreakpoint", - "Remove-PSBreakpoint", - "Set-PSBreakpoint" - }; - - /// - /// this cmdlets are exposed due to some bugs. Need to figure out if - /// they are still required - /// - private static readonly string[] MiscCmdlets = { "Join-Path", "Import-Module" }; - private static readonly string[] MiscCommands = { "TabExpansion2" }; - - private static readonly string[] DefaultTypeFiles = { "types.ps1xml", "typesv3.ps1xml" }; -#endif - #endregion /// @@ -2705,10 +2296,6 @@ namespace System.Management.Automation.Runspaces bool etwEnabled = RunspaceEventSource.Log.IsEnabled(); if (etwEnabled) RunspaceEventSource.Log.LoadCommandsStart(); -#if !CORECLR // Workflow Not Supported On CSS - InitialSessionState cloneForWorkflowDefinitions = null; -#endif - foreach (SessionStateCommandEntry cmd in Commands) { if (etwEnabled) RunspaceEventSource.Log.LoadCommandStart(cmd.Name); @@ -2760,25 +2347,7 @@ namespace System.Management.Automation.Runspaces } continue; } -#if !CORECLR // Workflow Not Supported On CSS - SessionStateWorkflowEntry sswe = cmd as SessionStateWorkflowEntry; - if (sswe != null) - { - if (cloneForWorkflowDefinitions == null) - { - cloneForWorkflowDefinitions = this.Clone(); - var commandsCopy = - cloneForWorkflowDefinitions.Commands.Where(e => !(e is SessionStateWorkflowEntry)) - .ToList(); - cloneForWorkflowDefinitions.Commands.Clear(); - foreach (var c in commandsCopy) - { - cloneForWorkflowDefinitions.Commands.Add(c); - } - } - ss.AddSessionStateEntry(cloneForWorkflowDefinitions, sswe); - } -#endif + if (etwEnabled) RunspaceEventSource.Log.LoadCommandStop(cmd.Name); } diff --git a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs index 94fc64bee..1269b141a 100644 --- a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs +++ b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs @@ -1228,7 +1228,7 @@ namespace Microsoft.PowerShell.Commands { if (moduleInfo.RootModuleForManifest != null) { - if (moduleInfo.RootModuleForManifest.EndsWith(StringLiterals.DependentWorkflowAssemblyExtension, StringComparison.OrdinalIgnoreCase)) + if (moduleInfo.RootModuleForManifest.EndsWith(StringLiterals.PowerShellILAssemblyExtension, StringComparison.OrdinalIgnoreCase)) { moduleInfo.SetModuleType(ModuleType.Binary); } @@ -1256,7 +1256,7 @@ namespace Microsoft.PowerShell.Commands moduleInfo.RootModule = moduleInfo.Path; } } - else if (extension.Equals(StringLiterals.DependentWorkflowAssemblyExtension, StringComparison.OrdinalIgnoreCase) || extension.Equals(StringLiterals.PowerShellNgenAssemblyExtension, StringComparison.OrdinalIgnoreCase)) + else if (extension.Equals(StringLiterals.PowerShellILAssemblyExtension, StringComparison.OrdinalIgnoreCase) || extension.Equals(StringLiterals.PowerShellNgenAssemblyExtension, StringComparison.OrdinalIgnoreCase)) { moduleInfo.SetModuleType(ModuleType.Binary); moduleInfo.RootModule = moduleInfo.Path; @@ -2203,7 +2203,7 @@ namespace Microsoft.PowerShell.Commands iss.Assemblies.Add(new SessionStateAssemblyEntry(assembly, fileName)); fixedUpAssemblyPathList.Add(fileName); - fileName = FixupFileName(moduleBase, assembly, StringLiterals.DependentWorkflowAssemblyExtension); + fileName = FixupFileName(moduleBase, assembly, StringLiterals.PowerShellILAssemblyExtension); loadMessage = StringUtil.Format(Modules.LoadingFile, "Assembly", fileName); WriteVerbose(loadMessage); diff --git a/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs b/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs index 571e55ebd..f7b2f8120 100644 --- a/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs +++ b/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs @@ -480,7 +480,7 @@ namespace System.Management.Automation StringLiterals.PowerShellCmdletizationFileExtension, StringLiterals.WorkflowFileExtension, StringLiterals.PowerShellNgenAssemblyExtension, - StringLiterals.DependentWorkflowAssemblyExtension}; + StringLiterals.PowerShellILAssemblyExtension}; // A list of the extensions to check for implicit module loading and discovery, put the ni.dll in front of .dll to have higher priority to be loaded. internal static string[] PSModuleExtensions = new string[] { @@ -489,7 +489,7 @@ namespace System.Management.Automation StringLiterals.PowerShellCmdletizationFileExtension, StringLiterals.WorkflowFileExtension, StringLiterals.PowerShellNgenAssemblyExtension, - StringLiterals.DependentWorkflowAssemblyExtension}; + StringLiterals.PowerShellILAssemblyExtension}; /// /// Returns true if the extension is one of the module extensions... diff --git a/src/System.Management.Automation/engine/Modules/TestModuleManifestCommand.cs b/src/System.Management.Automation/engine/Modules/TestModuleManifestCommand.cs index f818c9435..69188c449 100644 --- a/src/System.Management.Automation/engine/Modules/TestModuleManifestCommand.cs +++ b/src/System.Management.Automation/engine/Modules/TestModuleManifestCommand.cs @@ -160,7 +160,7 @@ namespace Microsoft.PowerShell.Commands foreach (ModuleSpecification nestedModule in nestedModules) { if (!IsValidFilePath(nestedModule.Name, module, true) - && !IsValidFilePath(nestedModule.Name + StringLiterals.DependentWorkflowAssemblyExtension, module, true) + && !IsValidFilePath(nestedModule.Name + StringLiterals.PowerShellILAssemblyExtension, module, true) && !IsValidFilePath(nestedModule.Name + StringLiterals.PowerShellNgenAssemblyExtension, module, true) && !IsValidFilePath(nestedModule.Name + StringLiterals.PowerShellModuleFileExtension, module, true) && !IsValidGacAssembly(nestedModule.Name)) @@ -350,9 +350,9 @@ namespace Microsoft.PowerShell.Commands string gacPath = System.Environment.GetEnvironmentVariable("windir") + "\\Microsoft.NET\\assembly"; string assemblyFile = assemblyName; string ngenAssemblyFile = assemblyName; - if (!assemblyName.EndsWith(StringLiterals.DependentWorkflowAssemblyExtension, StringComparison.OrdinalIgnoreCase)) + if (!assemblyName.EndsWith(StringLiterals.PowerShellILAssemblyExtension, StringComparison.OrdinalIgnoreCase)) { - assemblyFile = assemblyName + StringLiterals.DependentWorkflowAssemblyExtension; + assemblyFile = assemblyName + StringLiterals.PowerShellILAssemblyExtension; ngenAssemblyFile = assemblyName + StringLiterals.PowerShellNgenAssemblyExtension; } try diff --git a/src/System.Management.Automation/engine/SessionStateFunctionAPIs.cs b/src/System.Management.Automation/engine/SessionStateFunctionAPIs.cs index 5a284f2b1..870d6208c 100644 --- a/src/System.Management.Automation/engine/SessionStateFunctionAPIs.cs +++ b/src/System.Management.Automation/engine/SessionStateFunctionAPIs.cs @@ -32,22 +32,6 @@ namespace System.Management.Automation fn.ScriptBlock.LanguageMode = PSLanguageMode.FullLanguage; } -#if !CORECLR // Workflow Not Supported On CSS - internal void AddSessionStateEntry(InitialSessionState initialSessionState, SessionStateWorkflowEntry entry) - { - var converterInstance = Utils.GetAstToWorkflowConverterAndEnsureWorkflowModuleLoaded(null); - - var workflowInfo = entry.WorkflowInfo ?? - converterInstance.CompileWorkflow(entry.Name, entry.Definition, initialSessionState); - - WorkflowInfo wf = new WorkflowInfo(workflowInfo); - - wf = this.SetWorkflowRaw(wf, CommandOrigin.Internal); - wf.Visibility = entry.Visibility; - wf.Module = entry.Module; - } -#endif - /// /// Gets a flattened view of the functions that are visible using /// the current scope as a reference and filtering the functions in @@ -300,60 +284,6 @@ namespace System.Management.Automation return functionInfo; } // SetFunctionRaw - internal WorkflowInfo SetWorkflowRaw( - WorkflowInfo workflowInfo, - CommandOrigin origin) - { - string originalName = workflowInfo.Name; - string name = originalName; - - FunctionLookupPath path = new FunctionLookupPath(name); - name = path.UnqualifiedPath; - - if (String.IsNullOrEmpty(name)) - { - SessionStateException exception = - new SessionStateException( - originalName, - SessionStateCategory.Function, - "ScopedFunctionMustHaveName", - SessionStateStrings.ScopedFunctionMustHaveName, - ErrorCategory.InvalidArgument); - - throw exception; - } - - ScopedItemOptions options = ScopedItemOptions.None; - if (path.IsPrivate) - { - options |= ScopedItemOptions.Private; - } - - FunctionScopeItemSearcher searcher = - new FunctionScopeItemSearcher( - this, - path, - origin); - - // The script that defines a workflowInfo wrapper is fully trusted - workflowInfo.ScriptBlock.LanguageMode = PSLanguageMode.FullLanguage; - - if (workflowInfo.Module == null && this.Module != null) - { - workflowInfo.Module = this.Module; - } - - var wfInfo = (WorkflowInfo) - searcher.InitialScope.SetFunction(name, workflowInfo.ScriptBlock, null, options, false, origin, ExecutionContext, null, - (arg1, arg2, arg3, arg4, arg5, arg6) => workflowInfo); - foreach (var aliasName in GetFunctionAliases(workflowInfo.ScriptBlock.Ast as IParameterMetadataProvider)) - { - searcher.InitialScope.SetAliasValue(aliasName, name, ExecutionContext, false, origin); - } - - return wfInfo; - } // SetWorkflowRaw - /// /// Set a function in the current scope of session state. /// @@ -557,7 +487,7 @@ namespace System.Management.Automation /// /// /// - /// Set to true if it is a regular function (meaning, we do not need to check this is a workflow or if the script contains JobDefinition Attribute and then process it) + /// Set to true if it is a regular function (meaning, we do not need to check if the script contains JobDefinition Attribute and then process it) /// /// /// diff --git a/src/System.Management.Automation/engine/SessionStateStrings.cs b/src/System.Management.Automation/engine/SessionStateStrings.cs index cb93f41d4..f3b0330ee 100644 --- a/src/System.Management.Automation/engine/SessionStateStrings.cs +++ b/src/System.Management.Automation/engine/SessionStateStrings.cs @@ -138,7 +138,7 @@ namespace System.Management.Automation /// /// The file extension (including the dot) of an workflow dependent assembly /// - internal const string DependentWorkflowAssemblyExtension = ".dll"; + internal const string PowerShellILAssemblyExtension = ".dll"; /// /// The file extension (including the dot) of an workflow dependent Ngen assembly diff --git a/src/System.Management.Automation/engine/Utils.cs b/src/System.Management.Automation/engine/Utils.cs index 95a316645..b58dd476f 100644 --- a/src/System.Management.Automation/engine/Utils.cs +++ b/src/System.Management.Automation/engine/Utils.cs @@ -622,47 +622,6 @@ namespace System.Management.Automation /// internal const string ScheduledJobModuleName = "PSScheduledJob"; - internal const string WorkflowType = "Microsoft.PowerShell.Workflow.AstToWorkflowConverter, Microsoft.PowerShell.Activities, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; - internal const string WorkflowModule = "PSWorkflow"; - - internal static IAstToWorkflowConverter GetAstToWorkflowConverterAndEnsureWorkflowModuleLoaded(ExecutionContext context) - { - IAstToWorkflowConverter converterInstance = null; - Type converterType = null; - - if (Utils.IsRunningFromSysWOW64()) - { - throw new NotSupportedException(AutomationExceptions.WorkflowDoesNotSupportWOW64); - } - - // If the current language mode is ConstrainedLanguage but the system lockdown mode is not, - // then also block the conversion - since we can't validate the InlineScript, PowerShellValue, - // etc. - if ((context != null) && - (context.LanguageMode == PSLanguageMode.ConstrainedLanguage) && - (SystemPolicy.GetSystemLockdownPolicy() != SystemEnforcementMode.Enforce)) - { - throw new NotSupportedException(Modules.CannotDefineWorkflowInconsistentLanguageMode); - } - - EnsureModuleLoaded(WorkflowModule, context); - - converterType = Type.GetType(WorkflowType); - - if (converterType != null) - { - converterInstance = (IAstToWorkflowConverter)converterType.GetConstructor(PSTypeExtensions.EmptyTypes).Invoke(EmptyArray()); - } - - if (converterInstance == null) - { - string error = StringUtil.Format(AutomationExceptions.CantLoadWorkflowType, Utils.WorkflowType, Utils.WorkflowModule); - throw new NotSupportedException(error); - } - - return converterInstance; - } - internal static void EnsureModuleLoaded(string module, ExecutionContext context) { if (context != null && !context.AutoLoadingModuleInProgress.Contains(module)) @@ -1107,24 +1066,12 @@ namespace System.Management.Automation internal static readonly HashSet PowerShellAssemblies = new HashSet(StringComparer.OrdinalIgnoreCase) { - "microsoft.powershell.activities", "microsoft.powershell.commands.diagnostics", "microsoft.powershell.commands.management", "microsoft.powershell.commands.utility", "microsoft.powershell.consolehost", - "microsoft.powershell.core.activities", - "microsoft.powershell.diagnostics.activities", - "microsoft.powershell.editor", - "microsoft.powershell.gpowershell", - "microsoft.powershell.graphicalhost", - "microsoft.powershell.isecommon", - "microsoft.powershell.management.activities", "microsoft.powershell.scheduledjob", - "microsoft.powershell.security.activities", "microsoft.powershell.security", - "microsoft.powershell.utility.activities", - "microsoft.powershell.workflow.servicecore", - "microsoft.wsman.management.activities", "microsoft.wsman.management", "microsoft.wsman.runtime", "system.management.automation" diff --git a/src/System.Management.Automation/engine/parser/Compiler.cs b/src/System.Management.Automation/engine/parser/Compiler.cs index c59999963..62462ad53 100644 --- a/src/System.Management.Automation/engine/parser/Compiler.cs +++ b/src/System.Management.Automation/engine/parser/Compiler.cs @@ -206,8 +206,6 @@ namespace System.Management.Automation.Language internal static readonly MethodInfo FunctionOps_DefineFunction = typeof(FunctionOps).GetMethod(nameof(FunctionOps.DefineFunction), staticFlags); - internal static readonly MethodInfo FunctionOps_DefineWorkflows = - typeof(FunctionOps).GetMethod(nameof(FunctionOps.DefineWorkflows), staticFlags); internal static readonly ConstructorInfo Hashtable_ctor = typeof(Hashtable).GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, @@ -2893,26 +2891,8 @@ namespace System.Management.Automation.Language return this.VisitPipeline(dynamicKeywordAst.GenerateCommandCallPipelineAst()); } - private bool _generatedCallToDefineWorkflows; public object VisitFunctionDefinition(FunctionDefinitionAst functionDefinitionAst) { - if (functionDefinitionAst.IsWorkflow) - { - if (_generatedCallToDefineWorkflows) - return ExpressionCache.Empty; - - var topAst = functionDefinitionAst.Parent; - while (!(topAst is ScriptBlockAst)) - { - topAst = topAst.Parent; - } - - _generatedCallToDefineWorkflows = true; - return Expression.Call(CachedReflectionInfo.FunctionOps_DefineWorkflows, - _executionContextParameter, - Expression.Constant(topAst, typeof(ScriptBlockAst))); - } - return Expression.Call(CachedReflectionInfo.FunctionOps_DefineFunction, _executionContextParameter, Expression.Constant(functionDefinitionAst), diff --git a/src/System.Management.Automation/engine/parser/SemanticChecks.cs b/src/System.Management.Automation/engine/parser/SemanticChecks.cs index 2e81c7b3d..873b74a5b 100644 --- a/src/System.Management.Automation/engine/parser/SemanticChecks.cs +++ b/src/System.Management.Automation/engine/parser/SemanticChecks.cs @@ -400,20 +400,7 @@ namespace System.Management.Automation.Language if (functionDefinitionAst.IsWorkflow) { -#if !CORECLR // Workflow Not Supported On CSS - try - { - var converterInstance = Utils.GetAstToWorkflowConverterAndEnsureWorkflowModuleLoaded(null); - List parseErrors = converterInstance.ValidateAst(functionDefinitionAst); - foreach (ParseError error in parseErrors) - { - _parser.ReportError(error); - } - } - catch (NotSupportedException) { } -#else _parser.ReportError(functionDefinitionAst.Extent, () => ParserStrings.WorkflowNotSupportedInPowerShellCore); -#endif } return AstVisitAction.Continue; diff --git a/src/System.Management.Automation/engine/parser/ast.cs b/src/System.Management.Automation/engine/parser/ast.cs index da756953f..ff9dc636e 100644 --- a/src/System.Management.Automation/engine/parser/ast.cs +++ b/src/System.Management.Automation/engine/parser/ast.cs @@ -10057,35 +10057,3 @@ namespace System.Management.Automation.Language #endregion Help } - -namespace System.Management.Automation.Internal -{ - using Runspaces; - using Language; - - /// Internal interface used for workflow compilation. - [SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")] - public interface IAstToWorkflowConverter - { - /// - List ValidateAst(FunctionDefinitionAst ast); - - /// - List CompileWorkflows(ScriptBlockAst ast, PSModuleInfo definingModule); - - /// - List CompileWorkflows(ScriptBlockAst ast, PSModuleInfo definingModule, InitialSessionState initialSessionState, out ParseException parsingErrors); - - /// - List CompileWorkflows(ScriptBlockAst ast, PSModuleInfo definingModule, InitialSessionState initialSessionState, PSLanguageMode? languageMode, out ParseException parsingErrors); - - /// - List CompileWorkflows(ScriptBlockAst ast, PSModuleInfo definingModule, string rootWorkflowName); - - /// - List CompileWorkflows(ScriptBlockAst ast, PSModuleInfo definingModule, InitialSessionState initialSessionState, out ParseException parsingErrors, string rootWorkflowName); - - /// - WorkflowInfo CompileWorkflow(string name, string definition, InitialSessionState initialSessionState); - } -} diff --git a/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs b/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs index d5ab00d93..0cba45b8e 100644 --- a/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs +++ b/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs @@ -1211,40 +1211,6 @@ namespace System.Management.Automation throw; } } - - internal static void DefineWorkflows(ExecutionContext context, ScriptBlockAst scriptBlockAst) - { - ParseException parseErrors = null; - - try - { - var converterInstance = Utils.GetAstToWorkflowConverterAndEnsureWorkflowModuleLoaded(context); - PSLanguageMode? languageMode = (context != null) ? context.LanguageMode : (PSLanguageMode?) null; - var workflows = converterInstance.CompileWorkflows(scriptBlockAst, context.EngineSessionState.Module, null, languageMode, out parseErrors); - foreach (var workflow in workflows) - { - context.EngineSessionState.SetWorkflowRaw(workflow, - context.EngineSessionState.CurrentScope.ScopeOrigin); - } - } - catch (Exception exception) - { - var rte = exception as RuntimeException; - if (rte == null) - { - throw ExceptionHandlingOps.ConvertToRuntimeException(exception, scriptBlockAst.Extent); - } - - InterpreterError.UpdateExceptionErrorRecordPosition(rte, scriptBlockAst.Extent); - throw; - } - - if (parseErrors != null && parseErrors.Errors != null) - { - InterpreterError.UpdateExceptionErrorRecordPosition(parseErrors, scriptBlockAst.Extent); - throw parseErrors; - } - } } internal class ScriptBlockExpressionWrapper diff --git a/src/System.Management.Automation/resources/AutomationExceptions.resx b/src/System.Management.Automation/resources/AutomationExceptions.resx index eddbd1c92..d83d070b0 100644 --- a/src/System.Management.Automation/resources/AutomationExceptions.resx +++ b/src/System.Management.Automation/resources/AutomationExceptions.resx @@ -195,9 +195,6 @@ Cannot generate a PowerShell object for a ScriptBlock that starts a pipeline with an expression. - - Cannot create workflow. The type '{0}' from the '{1}' module could not be loaded. - Windows PowerShell Workflow is not supported in a Windows PowerShell x86-based console. Open a Windows PowerShell x64-based console, and then try again. diff --git a/src/System.Management.Automation/resources/Modules.resx b/src/System.Management.Automation/resources/Modules.resx index 53f87e7b9..fbbf3f2a9 100644 --- a/src/System.Management.Automation/resources/Modules.resx +++ b/src/System.Management.Automation/resources/Modules.resx @@ -592,9 +592,6 @@ A CIM provider for module discovery was not found on the CIM server. {0} {0} is a placeholder for a more detailed error message - - Cannot define the workflow. The language mode for this session is incompatible with the system-wide language mode. - Cannot load the workflow. Only signed in-box XAML-based workflows or script-based workflows are supported in the current language mode.