Skip to content

Commit afa76de

Browse files
authored
Remove Workflow from PSSessionType (PowerShell#9618)
Remove PSSessionType and IsWorkflowConfigurationType()
1 parent 1d94e8c commit afa76de

File tree

6 files changed

+11
-165
lines changed

6 files changed

+11
-165
lines changed

src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs

+6-91
Original file line numberDiff line numberDiff line change
@@ -341,26 +341,6 @@ function Register-PSSessionConfiguration
341341
[ValidateSet("x86", "amd64")]
342342
public string ProcessorArchitecture { get; set; }
343343

344-
/// <summary>
345-
/// SessionType.
346-
/// </summary>
347-
/// Only want this on non assemblyName parameter set, since assembly decides the sessiontype.
348-
[Parameter(ParameterSetName = PSSessionConfigurationCommandBase.NameParameterSetName)]
349-
public PSSessionType SessionType
350-
{
351-
get
352-
{
353-
return sessionType;
354-
}
355-
356-
set
357-
{
358-
sessionType = value;
359-
}
360-
}
361-
362-
internal PSSessionType sessionType = PSSessionType.DefaultRemoteShell;
363-
364344
#endregion
365345

366346
#region Constructors
@@ -648,7 +628,7 @@ protected override void ProcessRecord()
648628
protected override void EndProcessing()
649629
{
650630
System.Management.Automation.Tracing.Tracer tracer = new System.Management.Automation.Tracing.Tracer();
651-
tracer.EndpointRegistered(this.Name, this.sessionType.ToString(), WindowsIdentity.GetCurrent().Name);
631+
tracer.EndpointRegistered(this.Name, WindowsIdentity.GetCurrent().Name);
652632
}
653633

654634
#endregion
@@ -821,28 +801,6 @@ private string ConstructPluginContent(out string srcConfigFilePath, out string d
821801
StringBuilder initParameters = new StringBuilder();
822802

823803
bool assemblyAndTypeTokensSet = false;
824-
if (sessionType == PSSessionType.Workflow)
825-
{
826-
initParameters.Append(string.Format(CultureInfo.InvariantCulture,
827-
initParamFormat,
828-
ConfigurationDataFromXML.ENDPOINTCONFIGURATIONTYPE,
829-
sessionType,
830-
Environment.NewLine));
831-
832-
initParameters.Append(string.Format(CultureInfo.InvariantCulture,
833-
initParamFormat,
834-
ConfigurationDataFromXML.ASSEMBLYTOKEN,
835-
ConfigurationDataFromXML.WORKFLOWCOREASSEMBLY,
836-
Environment.NewLine));
837-
838-
initParameters.Append(string.Format(CultureInfo.InvariantCulture,
839-
initParamFormat,
840-
ConfigurationDataFromXML.SHELLCONFIGTYPETOKEN,
841-
ConfigurationDataFromXML.WORKFLOWCORETYPENAME,
842-
Environment.NewLine));
843-
844-
assemblyAndTypeTokensSet = true;
845-
}
846804

847805
// DISC endpoint
848806
if (Path != null)
@@ -1169,7 +1127,7 @@ private string ConstructPluginContent(out string srcConfigFilePath, out string d
11691127
tempValue);
11701128
}
11711129

1172-
if (sessionType == PSSessionType.Workflow && !isUseSharedProcessSpecified)
1130+
if (!isUseSharedProcessSpecified)
11731131
{
11741132
UseSharedProcess = true;
11751133
}
@@ -1214,13 +1172,6 @@ private string ConstructPluginContent(out string srcConfigFilePath, out string d
12141172

12151173
StringBuilder sessionConfigurationData = new StringBuilder();
12161174

1217-
if (sessionType == PSSessionType.Workflow)
1218-
{
1219-
List<object> modifiedModulePath = new List<object>(modulesToImport ?? Array.Empty<string>());
1220-
modifiedModulePath.Insert(0, ConfigurationDataFromXML.PSWORKFLOWMODULE);
1221-
modulesToImport = modifiedModulePath.ToArray();
1222-
}
1223-
12241175
if (modulesToImport != null && modulesToImport.Length > 0)
12251176
{
12261177
sessionConfigurationData.Append(string.Format(CultureInfo.InvariantCulture,
@@ -1262,7 +1213,7 @@ private string ConstructPluginContent(out string srcConfigFilePath, out string d
12621213
transportOption = transportOption.Clone() as PSTransportOption;
12631214
}
12641215

1265-
transportOption.LoadFromDefaults(sessionType, true);
1216+
transportOption.LoadFromDefaults(true);
12661217

12671218
// If useSharedHost is set to false, we need to set hostIdleTimeout to 0 as well, else WS-Man throws error
12681219
if (isUseSharedProcessSpecified && !UseSharedProcess)
@@ -3783,23 +3734,20 @@ private void SetSessionConfigurationTypeOptions()
37833734
StringBuilder sessionConfigurationData = new StringBuilder();
37843735

37853736
string modulePathParameter = null;
3786-
string unsetModulePathStr = string.Empty;
37873737
bool unsetModulePath = false;
37883738
if (modulePathSpecified)
37893739
{
3790-
bool isWorkflowConfiguration = IsWorkflowConfigurationType(ps);
37913740
if (modulesToImport == null ||
37923741
modulesToImport.Length == 0 ||
37933742
(modulesToImport.Length == 1 && modulesToImport[0] is string && ((string)modulesToImport[0]).Equals(string.Empty, StringComparison.OrdinalIgnoreCase)))
37943743
{
37953744
unsetModulePath = true;
3796-
unsetModulePathStr = isWorkflowConfiguration ? ConfigurationDataFromXML.PSWORKFLOWMODULE : string.Empty;
37973745
}
37983746
else
37993747
{
38003748
modulePathParameter = PSSessionConfigurationCommandUtilities.GetModulePathAsString(this.modulesToImport).Trim();
38013749
// Add the built-in module path if it's a workflow config
3802-
if (!string.IsNullOrEmpty(modulePathParameter) && isWorkflowConfiguration)
3750+
if (!string.IsNullOrEmpty(modulePathParameter))
38033751
{
38043752
List<object> modifiedModulePath = new List<object>(modulesToImport);
38053753
modifiedModulePath.Insert(0, ConfigurationDataFromXML.PSWORKFLOWMODULE);
@@ -3825,7 +3773,7 @@ private void SetSessionConfigurationTypeOptions()
38253773
{
38263774
sessionConfigurationData.Append(string.Format(CultureInfo.InvariantCulture,
38273775
initParamFormat,
3828-
PSSessionConfigurationData.ModulesToImportToken, unsetModulePathStr));
3776+
PSSessionConfigurationData.ModulesToImportToken, string.Empty));
38293777
}
38303778
// unsetModulePath is false AND modulePathParameter is not empty.
38313779
// 1. modulePathSpecified is false. In this case, modulePathParameter will be the original module path.
@@ -3891,30 +3839,6 @@ protected override void EndProcessing()
38913839

38923840
#region Private Methods
38933841

3894-
/// <summary>
3895-
/// Check if the current configuration is a workflow endpoint.
3896-
/// </summary>
3897-
/// <returns></returns>
3898-
private bool IsWorkflowConfigurationType(System.Management.Automation.PowerShell ps)
3899-
{
3900-
// Get the AssemblyName
3901-
ps.AddScript(string.Format(CultureInfo.InvariantCulture, getAssemblyNameDataFormat, CodeGeneration.EscapeSingleQuotedStringContent(Name)));
3902-
Collection<PSObject> psObjectCollection = ps.Invoke(new object[] { Name }) as Collection<PSObject>;
3903-
if (psObjectCollection == null || psObjectCollection.Count != 1)
3904-
{
3905-
Dbg.Assert(false, "This should never happen. ps.Invoke always return a Collection<PSObject>");
3906-
}
3907-
3908-
if (psObjectCollection[0] == null)
3909-
{
3910-
// Not workflow endpoint, no assembly name
3911-
return false;
3912-
}
3913-
3914-
string assemblyNameOfCurrentConfiguration = psObjectCollection[0].BaseObject.ToString();
3915-
return assemblyNameOfCurrentConfiguration.Equals(ConfigurationDataFromXML.WORKFLOWCOREASSEMBLY, StringComparison.OrdinalIgnoreCase);
3916-
}
3917-
39183842
private PSObject ConstructPropertiesForUpdate()
39193843
{
39203844
PSObject result = new PSObject();
@@ -4000,14 +3924,6 @@ private PSObject ConstructPropertiesForUpdate()
40003924
{
40013925
using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create())
40023926
{
4003-
bool isWorkflowConfiguration = IsWorkflowConfigurationType(ps);
4004-
if (!string.IsNullOrEmpty(modulePathParameter) && isWorkflowConfiguration)
4005-
{
4006-
List<object> modifiedModulePath = new List<object>(modulesToImport);
4007-
modifiedModulePath.Insert(0, ConfigurationDataFromXML.PSWORKFLOWMODULE);
4008-
modulePathParameter = PSSessionConfigurationCommandUtilities.GetModulePathAsString(modifiedModulePath.ToArray()).Trim();
4009-
}
4010-
40113927
// Get the SessionConfigurationDataFormat
40123928
ps.AddScript(string.Format(CultureInfo.InvariantCulture, getSessionConfigurationDataSbFormat, CodeGeneration.EscapeSingleQuotedStringContent(Name)));
40133929
Collection<PSObject> psObjectCollection = ps.Invoke(new object[] { Name }) as Collection<PSObject>;
@@ -4045,10 +3961,9 @@ private PSObject ConstructPropertiesForUpdate()
40453961
// ModulesToImport exist in the pssessionConfigurationData
40463962
if (scd.ModulesToImportInternal != null && scd.ModulesToImportInternal.Count != 0)
40473963
{
4048-
string unsetModulePathStr = isWorkflowConfiguration ? ConfigurationDataFromXML.PSWORKFLOWMODULE : string.Empty;
40493964
sessionConfigurationData.Append(string.Format(CultureInfo.InvariantCulture,
40503965
initParamFormat,
4051-
PSSessionConfigurationData.ModulesToImportToken, unsetModulePathStr));
3966+
PSSessionConfigurationData.ModulesToImportToken, string.Empty));
40523967
if (!string.IsNullOrEmpty(privateData))
40533968
{
40543969
sessionConfigurationData.Append(string.Format(CultureInfo.InvariantCulture, privateDataFormat, privateData));

src/System.Management.Automation/engine/remoting/commands/NewPSSessionConfigurationOptionCommand.cs

+2-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public class WSManConfigurationOption : PSTransportOption
2323

2424
private const string AttribProcessIdleTimeout = "ProcessIdleTimeoutSec";
2525
internal static readonly int? DefaultProcessIdleTimeout_ForPSRemoting = 0; // in seconds
26-
internal static readonly int? DefaultProcessIdleTimeout_ForWorkflow = 1209600; // in seconds
2726
private int? _processIdleTimeoutSec = null;
2827

2928
internal const string AttribMaxIdleTimeout = "MaxIdleTimeoutms";
@@ -68,9 +67,8 @@ internal WSManConfigurationOption()
6867
/// <summary>
6968
/// LoadFromDefaults.
7069
/// </summary>
71-
/// <param name="sessionType"></param>
7270
/// <param name="keepAssigned"></param>
73-
protected internal override void LoadFromDefaults(PSSessionType sessionType, bool keepAssigned)
71+
protected internal override void LoadFromDefaults(bool keepAssigned)
7472
{
7573
if (!keepAssigned || !_outputBufferingMode.HasValue)
7674
{
@@ -79,10 +77,7 @@ protected internal override void LoadFromDefaults(PSSessionType sessionType, boo
7977

8078
if (!keepAssigned || !_processIdleTimeoutSec.HasValue)
8179
{
82-
_processIdleTimeoutSec
83-
= sessionType == PSSessionType.Workflow
84-
? DefaultProcessIdleTimeout_ForWorkflow
85-
: DefaultProcessIdleTimeout_ForPSRemoting;
80+
_processIdleTimeoutSec = DefaultProcessIdleTimeout_ForPSRemoting;
8681
}
8782

8883
if (!keepAssigned || !_maxIdleTimeoutSec.HasValue)

src/System.Management.Automation/engine/remoting/common/PSSessionConfigurationTypeOption.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,13 @@ internal virtual Hashtable ConstructQuotasAsHashtable()
8181
throw new NotImplementedException();
8282
}
8383

84-
internal void LoadFromDefaults(PSSessionType sessionType)
85-
{
86-
LoadFromDefaults(sessionType, false);
87-
}
88-
8984
/// <summary>
9085
/// Sets all the values to default values.
9186
/// If keepAssigned is true only those values are set
9287
/// which are unassigned.
9388
/// </summary>
94-
/// <param name="sessionType"></param>
9589
/// <param name="keepAssigned"></param>
96-
protected internal virtual void LoadFromDefaults(PSSessionType sessionType, bool keepAssigned)
90+
protected internal virtual void LoadFromDefaults(bool keepAssigned)
9791
{
9892
throw new NotImplementedException();
9993
}

src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs

-56
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,6 @@ public enum AuthenticationMechanism
7575
Kerberos = 0x6,
7676
}
7777

78-
/// <summary>
79-
/// Specifies the type of session configuration that
80-
/// should be used for creating a connection info.
81-
/// </summary>
82-
public enum PSSessionType
83-
{
84-
/// <summary>
85-
/// Default PowerShell remoting
86-
/// endpoint.
87-
/// </summary>
88-
DefaultRemoteShell = 0,
89-
90-
/// <summary>
91-
/// Default Workflow endpoint.
92-
/// </summary>
93-
Workflow = 1,
94-
}
95-
9678
/// <summary>
9779
/// Specify the type of access mode that should be
9880
/// used when creating a session configuration.
@@ -1503,44 +1485,6 @@ internal void SetDisconnectedExpiresOnToNow()
15031485
}
15041486

15051487
#endregion Internal members
1506-
1507-
#region V3 Extensions
1508-
1509-
private const string DefaultM3PShellName = "Microsoft.PowerShell.Workflow";
1510-
private const string DefaultM3PEndpoint = Remoting.Client.WSManNativeApi.ResourceURIPrefix + DefaultM3PShellName;
1511-
1512-
/// <summary>
1513-
/// Constructor that constructs the configuration name from its type.
1514-
/// </summary>
1515-
/// <param name="configurationType">Type of configuration to construct.</param>
1516-
public WSManConnectionInfo(PSSessionType configurationType) : this()
1517-
{
1518-
ComputerName = string.Empty;
1519-
switch (configurationType)
1520-
{
1521-
case PSSessionType.DefaultRemoteShell:
1522-
{
1523-
// it is already the default
1524-
}
1525-
1526-
break;
1527-
1528-
case PSSessionType.Workflow:
1529-
{
1530-
ShellUri = DefaultM3PEndpoint;
1531-
}
1532-
1533-
break;
1534-
default:
1535-
{
1536-
Diagnostics.Assert(false, "Unknown value for PSSessionType");
1537-
}
1538-
1539-
break;
1540-
}
1541-
}
1542-
1543-
#endregion V3 Extensions
15441488
}
15451489

15461490
/// <summary>

src/System.Management.Automation/engine/remoting/fanin/InitialSessionStateProvider.cs

-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ internal class ConfigurationDataFromXML
5252
internal const string MAXPSVERSIONTOKEN = "MaxPSVersion";
5353
internal const string MODULESTOIMPORT = "ModulesToImport";
5454
internal const string HOSTMODE = "hostmode";
55-
internal const string ENDPOINTCONFIGURATIONTYPE = "sessiontype";
5655
internal const string WORKFLOWCOREASSEMBLY = "Microsoft.PowerShell.Workflow.ServiceCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL";
57-
internal const string WORKFLOWCORETYPENAME = "Microsoft.PowerShell.Workflow.PSWorkflowSessionConfiguration";
5856
internal const string PSWORKFLOWMODULE = "%windir%\\system32\\windowspowershell\\v1.0\\Modules\\PSWorkflow";
5957
internal const string CONFIGFILEPATH = "configfilepath";
6058
internal const string CONFIGFILEPATH_CamelCase = "ConfigFilePath";

src/System.Management.Automation/utils/tracing/TracingGen.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,9 @@ public void EndpointModified(string endpointName, string modifiedBy)
450450
/// EndpointRegistered (EventId: 0xb041/45121)
451451
/// </summary>
452452
[EtwEvent(0xb041)]
453-
public void EndpointRegistered(string endpointName, string endpointType, string registeredBy)
453+
public void EndpointRegistered(string endpointName, string registeredBy)
454454
{
455-
WriteEvent(M3PEndpointRegisteredEvent, endpointName, endpointType, registeredBy);
455+
WriteEvent(M3PEndpointRegisteredEvent, endpointName, registeredBy);
456456
}
457457

458458
/// <summary>

0 commit comments

Comments
 (0)