mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Remove Workflow from PSSessionType (#9618)
Remove PSSessionType and IsWorkflowConfigurationType()
This commit is contained in:
@@ -341,26 +341,6 @@ else
|
||||
[ValidateSet("x86", "amd64")]
|
||||
public string ProcessorArchitecture { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// SessionType.
|
||||
/// </summary>
|
||||
/// Only want this on non assemblyName parameter set, since assembly decides the sessiontype.
|
||||
[Parameter(ParameterSetName = PSSessionConfigurationCommandBase.NameParameterSetName)]
|
||||
public PSSessionType SessionType
|
||||
{
|
||||
get
|
||||
{
|
||||
return sessionType;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
sessionType = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal PSSessionType sessionType = PSSessionType.DefaultRemoteShell;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@@ -648,7 +628,7 @@ else
|
||||
protected override void EndProcessing()
|
||||
{
|
||||
System.Management.Automation.Tracing.Tracer tracer = new System.Management.Automation.Tracing.Tracer();
|
||||
tracer.EndpointRegistered(this.Name, this.sessionType.ToString(), WindowsIdentity.GetCurrent().Name);
|
||||
tracer.EndpointRegistered(this.Name, WindowsIdentity.GetCurrent().Name);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -821,28 +801,6 @@ else
|
||||
StringBuilder initParameters = new StringBuilder();
|
||||
|
||||
bool assemblyAndTypeTokensSet = false;
|
||||
if (sessionType == PSSessionType.Workflow)
|
||||
{
|
||||
initParameters.Append(string.Format(CultureInfo.InvariantCulture,
|
||||
initParamFormat,
|
||||
ConfigurationDataFromXML.ENDPOINTCONFIGURATIONTYPE,
|
||||
sessionType,
|
||||
Environment.NewLine));
|
||||
|
||||
initParameters.Append(string.Format(CultureInfo.InvariantCulture,
|
||||
initParamFormat,
|
||||
ConfigurationDataFromXML.ASSEMBLYTOKEN,
|
||||
ConfigurationDataFromXML.WORKFLOWCOREASSEMBLY,
|
||||
Environment.NewLine));
|
||||
|
||||
initParameters.Append(string.Format(CultureInfo.InvariantCulture,
|
||||
initParamFormat,
|
||||
ConfigurationDataFromXML.SHELLCONFIGTYPETOKEN,
|
||||
ConfigurationDataFromXML.WORKFLOWCORETYPENAME,
|
||||
Environment.NewLine));
|
||||
|
||||
assemblyAndTypeTokensSet = true;
|
||||
}
|
||||
|
||||
// DISC endpoint
|
||||
if (Path != null)
|
||||
@@ -1169,7 +1127,7 @@ else
|
||||
tempValue);
|
||||
}
|
||||
|
||||
if (sessionType == PSSessionType.Workflow && !isUseSharedProcessSpecified)
|
||||
if (!isUseSharedProcessSpecified)
|
||||
{
|
||||
UseSharedProcess = true;
|
||||
}
|
||||
@@ -1214,13 +1172,6 @@ else
|
||||
|
||||
StringBuilder sessionConfigurationData = new StringBuilder();
|
||||
|
||||
if (sessionType == PSSessionType.Workflow)
|
||||
{
|
||||
List<object> modifiedModulePath = new List<object>(modulesToImport ?? Array.Empty<string>());
|
||||
modifiedModulePath.Insert(0, ConfigurationDataFromXML.PSWORKFLOWMODULE);
|
||||
modulesToImport = modifiedModulePath.ToArray();
|
||||
}
|
||||
|
||||
if (modulesToImport != null && modulesToImport.Length > 0)
|
||||
{
|
||||
sessionConfigurationData.Append(string.Format(CultureInfo.InvariantCulture,
|
||||
@@ -1262,7 +1213,7 @@ else
|
||||
transportOption = transportOption.Clone() as PSTransportOption;
|
||||
}
|
||||
|
||||
transportOption.LoadFromDefaults(sessionType, true);
|
||||
transportOption.LoadFromDefaults(true);
|
||||
|
||||
// If useSharedHost is set to false, we need to set hostIdleTimeout to 0 as well, else WS-Man throws error
|
||||
if (isUseSharedProcessSpecified && !UseSharedProcess)
|
||||
@@ -3783,23 +3734,20 @@ Set-PSSessionConfiguration $args[0] $args[1] $args[2] $args[3] $args[4] $args[5]
|
||||
StringBuilder sessionConfigurationData = new StringBuilder();
|
||||
|
||||
string modulePathParameter = null;
|
||||
string unsetModulePathStr = string.Empty;
|
||||
bool unsetModulePath = false;
|
||||
if (modulePathSpecified)
|
||||
{
|
||||
bool isWorkflowConfiguration = IsWorkflowConfigurationType(ps);
|
||||
if (modulesToImport == null ||
|
||||
modulesToImport.Length == 0 ||
|
||||
(modulesToImport.Length == 1 && modulesToImport[0] is string && ((string)modulesToImport[0]).Equals(string.Empty, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
unsetModulePath = true;
|
||||
unsetModulePathStr = isWorkflowConfiguration ? ConfigurationDataFromXML.PSWORKFLOWMODULE : string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
modulePathParameter = PSSessionConfigurationCommandUtilities.GetModulePathAsString(this.modulesToImport).Trim();
|
||||
// Add the built-in module path if it's a workflow config
|
||||
if (!string.IsNullOrEmpty(modulePathParameter) && isWorkflowConfiguration)
|
||||
if (!string.IsNullOrEmpty(modulePathParameter))
|
||||
{
|
||||
List<object> modifiedModulePath = new List<object>(modulesToImport);
|
||||
modifiedModulePath.Insert(0, ConfigurationDataFromXML.PSWORKFLOWMODULE);
|
||||
@@ -3825,7 +3773,7 @@ Set-PSSessionConfiguration $args[0] $args[1] $args[2] $args[3] $args[4] $args[5]
|
||||
{
|
||||
sessionConfigurationData.Append(string.Format(CultureInfo.InvariantCulture,
|
||||
initParamFormat,
|
||||
PSSessionConfigurationData.ModulesToImportToken, unsetModulePathStr));
|
||||
PSSessionConfigurationData.ModulesToImportToken, string.Empty));
|
||||
}
|
||||
// unsetModulePath is false AND modulePathParameter is not empty.
|
||||
// 1. modulePathSpecified is false. In this case, modulePathParameter will be the original module path.
|
||||
@@ -3891,30 +3839,6 @@ Set-PSSessionConfiguration $args[0] $args[1] $args[2] $args[3] $args[4] $args[5]
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Check if the current configuration is a workflow endpoint.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private bool IsWorkflowConfigurationType(System.Management.Automation.PowerShell ps)
|
||||
{
|
||||
// Get the AssemblyName
|
||||
ps.AddScript(string.Format(CultureInfo.InvariantCulture, getAssemblyNameDataFormat, CodeGeneration.EscapeSingleQuotedStringContent(Name)));
|
||||
Collection<PSObject> psObjectCollection = ps.Invoke(new object[] { Name }) as Collection<PSObject>;
|
||||
if (psObjectCollection == null || psObjectCollection.Count != 1)
|
||||
{
|
||||
Dbg.Assert(false, "This should never happen. ps.Invoke always return a Collection<PSObject>");
|
||||
}
|
||||
|
||||
if (psObjectCollection[0] == null)
|
||||
{
|
||||
// Not workflow endpoint, no assembly name
|
||||
return false;
|
||||
}
|
||||
|
||||
string assemblyNameOfCurrentConfiguration = psObjectCollection[0].BaseObject.ToString();
|
||||
return assemblyNameOfCurrentConfiguration.Equals(ConfigurationDataFromXML.WORKFLOWCOREASSEMBLY, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private PSObject ConstructPropertiesForUpdate()
|
||||
{
|
||||
PSObject result = new PSObject();
|
||||
@@ -4000,14 +3924,6 @@ Set-PSSessionConfiguration $args[0] $args[1] $args[2] $args[3] $args[4] $args[5]
|
||||
{
|
||||
using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create())
|
||||
{
|
||||
bool isWorkflowConfiguration = IsWorkflowConfigurationType(ps);
|
||||
if (!string.IsNullOrEmpty(modulePathParameter) && isWorkflowConfiguration)
|
||||
{
|
||||
List<object> modifiedModulePath = new List<object>(modulesToImport);
|
||||
modifiedModulePath.Insert(0, ConfigurationDataFromXML.PSWORKFLOWMODULE);
|
||||
modulePathParameter = PSSessionConfigurationCommandUtilities.GetModulePathAsString(modifiedModulePath.ToArray()).Trim();
|
||||
}
|
||||
|
||||
// Get the SessionConfigurationDataFormat
|
||||
ps.AddScript(string.Format(CultureInfo.InvariantCulture, getSessionConfigurationDataSbFormat, CodeGeneration.EscapeSingleQuotedStringContent(Name)));
|
||||
Collection<PSObject> psObjectCollection = ps.Invoke(new object[] { Name }) as Collection<PSObject>;
|
||||
@@ -4045,10 +3961,9 @@ Set-PSSessionConfiguration $args[0] $args[1] $args[2] $args[3] $args[4] $args[5]
|
||||
// ModulesToImport exist in the pssessionConfigurationData
|
||||
if (scd.ModulesToImportInternal != null && scd.ModulesToImportInternal.Count != 0)
|
||||
{
|
||||
string unsetModulePathStr = isWorkflowConfiguration ? ConfigurationDataFromXML.PSWORKFLOWMODULE : string.Empty;
|
||||
sessionConfigurationData.Append(string.Format(CultureInfo.InvariantCulture,
|
||||
initParamFormat,
|
||||
PSSessionConfigurationData.ModulesToImportToken, unsetModulePathStr));
|
||||
PSSessionConfigurationData.ModulesToImportToken, string.Empty));
|
||||
if (!string.IsNullOrEmpty(privateData))
|
||||
{
|
||||
sessionConfigurationData.Append(string.Format(CultureInfo.InvariantCulture, privateDataFormat, privateData));
|
||||
|
||||
+2
-7
@@ -23,7 +23,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
private const string AttribProcessIdleTimeout = "ProcessIdleTimeoutSec";
|
||||
internal static readonly int? DefaultProcessIdleTimeout_ForPSRemoting = 0; // in seconds
|
||||
internal static readonly int? DefaultProcessIdleTimeout_ForWorkflow = 1209600; // in seconds
|
||||
private int? _processIdleTimeoutSec = null;
|
||||
|
||||
internal const string AttribMaxIdleTimeout = "MaxIdleTimeoutms";
|
||||
@@ -68,9 +67,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// LoadFromDefaults.
|
||||
/// </summary>
|
||||
/// <param name="sessionType"></param>
|
||||
/// <param name="keepAssigned"></param>
|
||||
protected internal override void LoadFromDefaults(PSSessionType sessionType, bool keepAssigned)
|
||||
protected internal override void LoadFromDefaults(bool keepAssigned)
|
||||
{
|
||||
if (!keepAssigned || !_outputBufferingMode.HasValue)
|
||||
{
|
||||
@@ -79,10 +77,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (!keepAssigned || !_processIdleTimeoutSec.HasValue)
|
||||
{
|
||||
_processIdleTimeoutSec
|
||||
= sessionType == PSSessionType.Workflow
|
||||
? DefaultProcessIdleTimeout_ForWorkflow
|
||||
: DefaultProcessIdleTimeout_ForPSRemoting;
|
||||
_processIdleTimeoutSec = DefaultProcessIdleTimeout_ForPSRemoting;
|
||||
}
|
||||
|
||||
if (!keepAssigned || !_maxIdleTimeoutSec.HasValue)
|
||||
|
||||
+1
-7
@@ -81,19 +81,13 @@ namespace System.Management.Automation
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
internal void LoadFromDefaults(PSSessionType sessionType)
|
||||
{
|
||||
LoadFromDefaults(sessionType, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets all the values to default values.
|
||||
/// If keepAssigned is true only those values are set
|
||||
/// which are unassigned.
|
||||
/// </summary>
|
||||
/// <param name="sessionType"></param>
|
||||
/// <param name="keepAssigned"></param>
|
||||
protected internal virtual void LoadFromDefaults(PSSessionType sessionType, bool keepAssigned)
|
||||
protected internal virtual void LoadFromDefaults(bool keepAssigned)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -75,24 +75,6 @@ namespace System.Management.Automation.Runspaces
|
||||
Kerberos = 0x6,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the type of session configuration that
|
||||
/// should be used for creating a connection info.
|
||||
/// </summary>
|
||||
public enum PSSessionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Default PowerShell remoting
|
||||
/// endpoint.
|
||||
/// </summary>
|
||||
DefaultRemoteShell = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Default Workflow endpoint.
|
||||
/// </summary>
|
||||
Workflow = 1,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specify the type of access mode that should be
|
||||
/// used when creating a session configuration.
|
||||
@@ -1503,44 +1485,6 @@ namespace System.Management.Automation.Runspaces
|
||||
}
|
||||
|
||||
#endregion Internal members
|
||||
|
||||
#region V3 Extensions
|
||||
|
||||
private const string DefaultM3PShellName = "Microsoft.PowerShell.Workflow";
|
||||
private const string DefaultM3PEndpoint = Remoting.Client.WSManNativeApi.ResourceURIPrefix + DefaultM3PShellName;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor that constructs the configuration name from its type.
|
||||
/// </summary>
|
||||
/// <param name="configurationType">Type of configuration to construct.</param>
|
||||
public WSManConnectionInfo(PSSessionType configurationType) : this()
|
||||
{
|
||||
ComputerName = string.Empty;
|
||||
switch (configurationType)
|
||||
{
|
||||
case PSSessionType.DefaultRemoteShell:
|
||||
{
|
||||
// it is already the default
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case PSSessionType.Workflow:
|
||||
{
|
||||
ShellUri = DefaultM3PEndpoint;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
{
|
||||
Diagnostics.Assert(false, "Unknown value for PSSessionType");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion V3 Extensions
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -52,9 +52,7 @@ namespace System.Management.Automation.Remoting
|
||||
internal const string MAXPSVERSIONTOKEN = "MaxPSVersion";
|
||||
internal const string MODULESTOIMPORT = "ModulesToImport";
|
||||
internal const string HOSTMODE = "hostmode";
|
||||
internal const string ENDPOINTCONFIGURATIONTYPE = "sessiontype";
|
||||
internal const string WORKFLOWCOREASSEMBLY = "Microsoft.PowerShell.Workflow.ServiceCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL";
|
||||
internal const string WORKFLOWCORETYPENAME = "Microsoft.PowerShell.Workflow.PSWorkflowSessionConfiguration";
|
||||
internal const string PSWORKFLOWMODULE = "%windir%\\system32\\windowspowershell\\v1.0\\Modules\\PSWorkflow";
|
||||
internal const string CONFIGFILEPATH = "configfilepath";
|
||||
internal const string CONFIGFILEPATH_CamelCase = "ConfigFilePath";
|
||||
|
||||
@@ -450,9 +450,9 @@ namespace System.Management.Automation.Tracing
|
||||
/// EndpointRegistered (EventId: 0xb041/45121)
|
||||
/// </summary>
|
||||
[EtwEvent(0xb041)]
|
||||
public void EndpointRegistered(string endpointName, string endpointType, string registeredBy)
|
||||
public void EndpointRegistered(string endpointName, string registeredBy)
|
||||
{
|
||||
WriteEvent(M3PEndpointRegisteredEvent, endpointName, endpointType, registeredBy);
|
||||
WriteEvent(M3PEndpointRegisteredEvent, endpointName, registeredBy);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user