Skip to content

Commit

Permalink
Seal classes in RemotingProtocol2 (PowerShell#21164)
Browse files Browse the repository at this point in the history
  • Loading branch information
xtqqczze authored Dec 24, 2024
1 parent 617dbda commit b0fbfb7
Showing 1 changed file with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace System.Management.Automation.Internal
/// Handles all PowerShell data structure handler communication with the
/// server side RunspacePool.
/// </summary>
internal class ClientRunspacePoolDataStructureHandler : IDisposable
internal sealed class ClientRunspacePoolDataStructureHandler : IDisposable
{
private bool _reconnecting = false;

Expand Down Expand Up @@ -823,7 +823,7 @@ private void StartDisconnectAsync(object state)
{
remoteSession?.DisconnectAsync();
}
catch
catch
{
// remoteSession may have already been disposed resulting in unexpected exceptions.
}
Expand Down Expand Up @@ -981,7 +981,7 @@ public void Dispose(bool disposing)
/// Base class for ClientPowerShellDataStructureHandler to handle all
/// references.
/// </summary>
internal class ClientPowerShellDataStructureHandler
internal sealed class ClientPowerShellDataStructureHandler
{
#region Data Structure Handler events

Expand Down Expand Up @@ -1152,8 +1152,8 @@ internal void SendHostResponseToServer(RemoteHostResponse hostResponse)
RemoteDataObject<PSObject> dataToBeSent =
RemoteDataObject<PSObject>.CreateFrom(RemotingDestination.Server,
RemotingDataType.RemotePowerShellHostResponseData,
clientRunspacePoolId,
clientPowerShellId,
_clientRunspacePoolId,
_clientPowerShellId,
hostResponse.Encode());

TransportManager.DataToBeSentCollection.Add<PSObject>(dataToBeSent,
Expand All @@ -1175,7 +1175,7 @@ internal void SendInput(ObjectStreamBase inputstream)
{
// send input closed information to server
SendDataAsync(RemotingEncoder.GeneratePowerShellInputEnd(
clientRunspacePoolId, clientPowerShellId));
_clientRunspacePoolId, _clientPowerShellId));
}
}
else
Expand Down Expand Up @@ -1204,10 +1204,10 @@ internal void SendInput(ObjectStreamBase inputstream)
internal void ProcessReceivedData(RemoteDataObject<PSObject> receivedData)
{
// verify if this data structure handler is the intended recipient
if (receivedData.PowerShellId != clientPowerShellId)
if (receivedData.PowerShellId != _clientPowerShellId)
{
throw new PSRemotingDataStructureException(RemotingErrorIdStrings.PipelineIdsDoNotMatch,
receivedData.PowerShellId, clientPowerShellId);
receivedData.PowerShellId, _clientPowerShellId);
}

// decode the message and take appropriate action
Expand Down Expand Up @@ -1470,13 +1470,6 @@ internal void ProcessRobustConnectionNotification(

#endregion Data Structure Handler Methods

#region Protected Members

protected Guid clientRunspacePoolId;
protected Guid clientPowerShellId;

#endregion Protected Members

#region Constructors

/// <summary>
Expand All @@ -1493,8 +1486,8 @@ internal ClientPowerShellDataStructureHandler(BaseClientCommandTransportManager
Guid clientRunspacePoolId, Guid clientPowerShellId)
{
TransportManager = transportManager;
this.clientRunspacePoolId = clientRunspacePoolId;
this.clientPowerShellId = clientPowerShellId;
_clientRunspacePoolId = clientRunspacePoolId;
_clientPowerShellId = clientPowerShellId;
transportManager.SignalCompleted += OnSignalCompleted;
}

Expand All @@ -1510,7 +1503,7 @@ internal Guid PowerShellId
{
get
{
return clientPowerShellId;
return _clientPowerShellId;
}
}

Expand Down Expand Up @@ -1563,7 +1556,7 @@ private void WriteInput(ObjectStreamBase inputstream)
foreach (object inputObject in inputObjects)
{
SendDataAsync(RemotingEncoder.GeneratePowerShellInput(inputObject,
clientRunspacePoolId, clientPowerShellId));
_clientRunspacePoolId, _clientPowerShellId));
}

if (!inputstream.IsOpen)
Expand All @@ -1574,7 +1567,7 @@ private void WriteInput(ObjectStreamBase inputstream)
foreach (object inputObject in inputObjects)
{
SendDataAsync(RemotingEncoder.GeneratePowerShellInput(inputObject,
clientRunspacePoolId, clientPowerShellId));
_clientRunspacePoolId, _clientPowerShellId));
}

// we are sending input end to the server. Ignore the future
Expand All @@ -1583,7 +1576,7 @@ private void WriteInput(ObjectStreamBase inputstream)
inputstream.DataReady -= HandleInputDataReady;
// stream close: send end of input
SendDataAsync(RemotingEncoder.GeneratePowerShellInputEnd(
clientRunspacePoolId, clientPowerShellId));
_clientRunspacePoolId, _clientPowerShellId));
}
}

Expand All @@ -1605,6 +1598,9 @@ private void SetupTransportManager(bool inDisconnectMode)

#region Private Members

private readonly Guid _clientRunspacePoolId;
private readonly Guid _clientPowerShellId;

// object for synchronizing input to be sent
// to server powershell
private readonly object _inputSyncObject = new object();
Expand All @@ -1623,7 +1619,7 @@ private enum connectionStates
#endregion Private Members
}

internal class InformationalMessage
internal sealed class InformationalMessage
{
internal object Message { get; }

Expand Down

0 comments on commit b0fbfb7

Please sign in to comment.