10000 Clean up '#if CORE' in PSPrincipal.cs (#4433) · PowerShell/PowerShell@0150f65 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0150f65

Browse files
iSazonovadityapatwardhan
authored andcommitted
Clean up '#if CORE' in PSPrincipal.cs (#4433)
* Use TimeZoneInfo in PSPrincipal.cs * Use TimeZoneInfo in serverremotesession.cs * Use TimeZoneInfo in RemoteSessionCapability.cs * Use TimeZoneInfo in serialization.cs * Remove private fiield 'clientTimeZone' * Remove extra line
1 parent 984b85f commit 0150f65

File tree

4 files changed

+9
-32
lines changed

4 files changed

+9
-32
lines changed

src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteSessionCapability.cs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
using System.IO;
77
using System.Management.Automation.Host;
88
using System.Management.Automation.Internal.Host;
9-
10-
#if !CORECLR
11-
using BinaryFormatter = System.Runtime.Serialization.Formatters.Binary.BinaryFormatter;
12-
#endif
13-
9+
using System.Runtime.Serialization.Formatters.Binary;
1410
using Dbg = System.Management.Automation.Diagnostics;
1511

1612
namespace System.Management.Automation.Remoting
@@ -28,10 +24,6 @@ internal class RemoteSessionCapability
2824
internal Version PSVersion { get; }
2925
internal Version SerializationVersion { get; }
3026
internal RemotingDestination RemotingDestination { get; }
31-
32-
#if !CORECLR // TimeZone Not In CoreCLR
33-
#endif
34-
3527
private static byte[] s_timeZoneInByteFormat;
3628

3729
/// <summary>
@@ -86,16 +78,13 @@ internal static byte[] GetCurrentTimeZoneInByteFormat()
8678
{
8779
if (null == s_timeZoneInByteFormat)
8880
{
89-
#if CORECLR //TODO:CORECLR 'BinaryFormatter' is not in CORE CLR. Since this is TimeZone related and TimeZone is not available on CORE CLR so wait until we solve TimeZone issue.
90-
s_timeZoneInByteFormat = Utils.EmptyArray<byte>();
91-
#else
9281
Exception e = null;
9382
try
9483
{
9584
BinaryFormatter formatter = new BinaryFormatter();
9685
using (MemoryStream stream = new MemoryStream())
9786
{
98-
formatter.Serialize(stream, TimeZone.CurrentTimeZone);
87+
formatter.Serialize(stream, TimeZoneInfo.Local);
9988
stream.Seek(0, SeekOrigin.Begin);
10089
byte[] result = new byte[stream.Length];
10190
stream.Read(result, 0, (int)stream.Length);
@@ -121,19 +110,15 @@ internal static byte[] GetCurrentTimeZoneInByteFormat()
121110
{
122111
s_timeZoneInByteFormat = Utils.EmptyArray<byte>();
123112
}
124-
#endif
125113
}
126114

127115
return s_timeZoneInByteFormat;
128116
}
129117

130-
#if !CORECLR // TimeZone Not In CoreCLR
131118
/// <summary>
132119
/// Gets the TimeZone of the destination machine. This may be null
133120
/// </summary>
134-
internal TimeZone TimeZone { get; set; }
135-
#endif
136-
121+
internal TimeZoneInfo TimeZone { get; set; }
137122
}
138123

139124
/// <summary>

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* like Exchange.
99
*/
1010

11+
using System;
1112
using System.Security.Principal;
1213
using System.Diagnostics.CodeAnalysis;
1314
using System.Runtime.Serialization;
@@ -82,9 +83,7 @@ private PSSenderInfo(SerializationInfo info, StreamingContext context)
8283
ConnectionString = senderInfo.ConnectionString;
8384
_applicationArguments = senderInfo._applicationArguments;
8485

85-
#if !CORECLR // TimeZone Not In CoreCLR
86-
this.clientTimeZone = senderInfo.ClientTimeZone;
87-
#endif
86+
ClientTimeZone = senderInfo.ClientTimeZone;
8887
}
8988
catch (Exception)
9089
{
@@ -126,17 +125,14 @@ public PSSenderInfo(PSPrincipal userPrincipal, string httpUrl)
126125
// cmdlets/scripts a chance to modify these.
127126
}
128127

129-
#if !CORECLR // TimeZone Not In CoreCLR
130128
/// <summary>
131129
/// Contains the TimeZone information from the client machine.
132130
/// </summary>
133-
public TimeZone ClientTimeZone
131+
public TimeZoneInfo ClientTimeZone
134132
{
135-
get { return clientTimeZone; }
136-
internal set { clientTimeZone = value; }
133+
get;
134+
internal set;
137135
}
138-
private TimeZone clientTimeZone;
139-
#endif
140136

141137
/// <summary>
142138
/// Connection string used by the client to connect to the server. This is

src/System.Management.Automation/engine/remoting/server/serverremotesession.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,9 +743,7 @@ private void HandleCreateRunspacePool(object sender, RemoteDataEventArgs createR
743743
// This is used by the initial session state configuration providers like Exchange.
744744
if (Context != null)
745745
{
746-
#if !CORECLR // TimeZone Not In CoreCLR
747746
_senderInfo.ClientTimeZone = Context.ClientCapability.TimeZone;
748-
#endif
749747
}
750748

751749
_senderInfo.ApplicationArguments = RemotingDecoder.GetApplicationArguments(rcvdData.Data);

src/System.Management.Automation/engine/serialization.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7135,9 +7135,7 @@ internal static PSSenderInfo RehydratePSSenderInfo(PSObject pso)
71357135

71367136
PSSenderInfo senderInfo = new PSSenderInfo(psPrincipal, GetPropertyValue<string>(pso, "ConnectionString"));
71377137

7138-
#if !CORECLR // TimeZone Not In CoreCLR
7139-
senderInfo.ClientTimeZone = TimeZone.CurrentTimeZone;
7140-
#endif
7138+
senderInfo.ClientTimeZone = TimeZoneInfo.Local;
71417139
senderInfo.ApplicationArguments = GetPropertyValue<PSPrimitiveDictionary>(pso, "ApplicationArguments");
71427140

71437141
return senderInfo;

0 commit comments

Comments
 (0)
0