Cleanup '#if !CORECLR' code (#8337)

* NewWinEventCommand.cs
* CredSSP.cs
* WsManHelper.cs
* debugger.cs
* InternalHost.cs
* InitialSessionState.cs
* BaseTransportManager.cs
* Types_Ps1Xml.cs
* FileSystemProvider.cs
* Restore XmlResolver = null
This commit is contained in:
Ilya
2018-11-30 08:11:20 +05:00
committed by GitHub
parent 8c3de33ae1
commit 4e58ee6426
11 changed files with 13 additions and 350 deletions
@@ -242,9 +242,7 @@ namespace Microsoft.PowerShell.Commands
IgnoreProcessingInstructions = true,
MaxCharactersInDocument = 0, // no limit
ConformanceLevel = ConformanceLevel.Fragment,
#if !CORECLR
XmlResolver = null,
#endif
XmlResolver = null
};
int definedParameterCount = 0;
+2 -37
View File
@@ -330,15 +330,6 @@ namespace Microsoft.WSMan.Management
/// </summary>
protected override void BeginProcessing()
{
#if !CORECLR
if (Environment.OSVersion.Version.Major < 6)
{
//OS is XP/Win2k3. Throw error.
WSManHelper helper = new WSManHelper(this);
string message = helper.FormatResourceMsgFromResourcetext("CmdletNotAvailable");
throw new InvalidOperationException(message);
}
#endif
//If not running elevated, then throw an "elevation required" error message.
WSManHelper.ThrowIfNotAdministrator();
@@ -440,14 +431,6 @@ namespace Microsoft.WSMan.Management
//If not running elevated, then throw an "elevation required" error message.
WSManHelper.ThrowIfNotAdministrator();
helper = new WSManHelper(this);
#if !CORECLR
if (Environment.OSVersion.Version.Major < 6)
{
//OS is XP/Win2k3. Throw error.
string message = helper.FormatResourceMsgFromResourcetext("CmdletNotAvailable");
throw new InvalidOperationException(message);
}
#endif
// DelegateComputer cannot be specified when Role is other than client
if ((delegatecomputer != null) && !Role.Equals(Client, StringComparison.OrdinalIgnoreCase))
@@ -671,11 +654,7 @@ namespace Microsoft.WSMan.Management
//open the registry key.If key is not present,create a new one
Credential_Delegation_Key = rootKey.OpenSubKey(Registry_Path_Credentials_Delegation, true);
if (Credential_Delegation_Key == null)
Credential_Delegation_Key = rootKey.CreateSubKey(Registry_Path_Credentials_Delegation
#if !CORECLR
, RegistryKeyPermissionCheck.ReadWriteSubTree
#endif
);
Credential_Delegation_Key = rootKey.CreateSubKey(Registry_Path_Credentials_Delegation, RegistryKeyPermissionCheck.ReadWriteSubTree);
Credential_Delegation_Key.SetValue(helper.Key_Allow_Fresh_Credentials, 1, RegistryValueKind.DWord);
Credential_Delegation_Key.SetValue(helper.Key_Concatenate_Defaults_AllowFresh, 1, RegistryValueKind.DWord);
@@ -683,11 +662,7 @@ namespace Microsoft.WSMan.Management
// add the delegate value
Allow_Fresh_Credential_Key = rootKey.OpenSubKey(Registry_Path_Credentials_Delegation + @"\" + helper.Key_Allow_Fresh_Credentials, true);
if (Allow_Fresh_Credential_Key == null)
Allow_Fresh_Credential_Key = rootKey.CreateSubKey(Registry_Path_Credentials_Delegation + @"\" + helper.Key_Allow_Fresh_Credentials
#if !CORECLR
, RegistryKeyPermissionCheck.ReadWriteSubTree
#endif
);
Allow_Fresh_Credential_Key = rootKey.CreateSubKey(Registry_Path_Credentials_Delegation + @"\" + helper.Key_Allow_Fresh_Credentials, RegistryKeyPermissionCheck.ReadWriteSubTree);
if (Allow_Fresh_Credential_Key != null)
{
@@ -833,17 +808,7 @@ namespace Microsoft.WSMan.Management
{
//If not running elevated, then throw an "elevation required" error message.
WSManHelper.ThrowIfNotAdministrator();
helper = new WSManHelper(this);
#if !CORECLR
if (Environment.OSVersion.Version.Major < 6)
{
//OS is XP/Win2k3. Throw error.
string message = helper.FormatResourceMsgFromResourcetext("CmdletNotAvailable");
throw new InvalidOperationException(message);
}
#endif
IWSManSession m_SessionObj = null;
try
{
@@ -987,17 +987,14 @@ namespace Microsoft.WSMan.Management
{
RegistryKey rGPOLocalMachineKey = Registry.LocalMachine.OpenSubKey(
Registry_Path_Credentials_Delegation + @"\CredentialsDelegation",
#if !CORECLR
RegistryKeyPermissionCheck.ReadWriteSubTree,
#endif
System.Security.AccessControl.RegistryRights.FullControl);
if (rGPOLocalMachineKey != null)
{
rGPOLocalMachineKey = rGPOLocalMachineKey.OpenSubKey(Key_Allow_Fresh_Credentials,
#if !CORECLR
rGPOLocalMachineKey = rGPOLocalMachineKey.OpenSubKey(
Key_Allow_Fresh_Credentials,
RegistryKeyPermissionCheck.ReadWriteSubTree,
#endif
System.Security.AccessControl.RegistryRights.FullControl);
if (rGPOLocalMachineKey == null)
{
@@ -33,7 +33,6 @@
<ItemGroup>
<Compile Remove="cimSupport\cmdletization\xml\cmdlets-over-objects.objectModel.autogen.cs" />
<Compile Remove="cimSupport\cmdletization\xml\cmdlets-over-objects.xmlSerializer.autogen.cs" />
<Compile Remove="engine\CodeMethods.cs" />
<Compile Remove="engine\ComInterop\ArgBuilder.cs" />
<Compile Remove="engine\ComInterop\BoolArgBuilder.cs" />
<Compile Remove="engine\ComInterop\BoundDispEvent.cs" />
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#if !UNIX
using System;
using System.Collections;
using System.Reflection;
@@ -130,3 +131,4 @@ namespace Microsoft.PowerShell
#endregion
}
}
#endif
@@ -3720,14 +3720,6 @@ namespace System.Management.Automation.Runspaces
throw e;
}
#if !CORECLR // CustomPSSnapIn Not Supported On CSS.
if (!String.IsNullOrEmpty(psSnapInInfo.CustomPSSnapInType))
{
LoadCustomPSSnapIn(psSnapInInfo);
warning = null;
return psSnapInInfo;
}
#endif
Assembly assembly = null;
string helpFile = null;
@@ -3875,137 +3867,6 @@ namespace System.Management.Automation.Runspaces
return loadedSnapins;
}
#if !CORECLR // CustomPSSnapIn Not Supported On CSS.
/// <summary>
/// This is a "proxy" snapin that loads a subset of cmdlets from another snapin...
/// </summary>
/// <remarks>
/// CustomPSSnapIn derives from System.Configuration.Install, which is not in CoreCLR.
/// So CustomPSSnapIn is not supported on CSS.
/// </remarks>
/// <param name="psSnapInInfo">The snapin to examine.</param>
private void LoadCustomPSSnapIn(PSSnapInInfo psSnapInInfo)
{
if (psSnapInInfo == null)
return;
if (String.IsNullOrEmpty(psSnapInInfo.CustomPSSnapInType))
{
return;
}
Dictionary<string, SessionStateCmdletEntry> cmdlets = null;
Dictionary<string, SessionStateProviderEntry> providers = null;
Assembly assembly = null;
s_PSSnapInTracer.WriteLine("Loading assembly for mshsnapin {0}", psSnapInInfo.Name);
assembly = PSSnapInHelpers.LoadPSSnapInAssembly(psSnapInInfo, out cmdlets, out providers);
if (assembly == null)
{
s_PSSnapInTracer.TraceError("Loading assembly for mshsnapin {0} failed", psSnapInInfo.Name);
return;
}
CustomPSSnapIn customPSSnapIn = null;
try
{
Type type = assembly.GetType(psSnapInInfo.CustomPSSnapInType, true);
if (type != null)
{
customPSSnapIn = (CustomPSSnapIn)assembly.CreateInstance(psSnapInInfo.CustomPSSnapInType);
}
s_PSSnapInTracer.WriteLine("Loading assembly for mshsnapin {0} succeeded", psSnapInInfo.Name);
}
catch (TypeLoadException tle)
{
throw new PSSnapInException(psSnapInInfo.Name, tle.Message);
}
catch (ArgumentException ae)
{
throw new PSSnapInException(psSnapInInfo.Name, ae.Message);
}
catch (MissingMethodException mme)
{
throw new PSSnapInException(psSnapInInfo.Name, mme.Message);
}
catch (InvalidCastException ice)
{
throw new PSSnapInException(psSnapInInfo.Name, ice.Message);
}
catch (TargetInvocationException tie)
{
if (tie.InnerException != null)
{
throw new PSSnapInException(psSnapInInfo.Name, tie.InnerException.Message);
}
throw new PSSnapInException(psSnapInInfo.Name, tie.Message);
}
MergeCustomPSSnapIn(psSnapInInfo, customPSSnapIn);
}
private void MergeCustomPSSnapIn(PSSnapInInfo psSnapInInfo, CustomPSSnapIn customPSSnapIn)
{
if (psSnapInInfo == null || customPSSnapIn == null)
return;
s_PSSnapInTracer.WriteLine("Merging configuration from custom mshsnapin {0}", psSnapInInfo.Name);
if (customPSSnapIn.Cmdlets != null)
{
foreach (CmdletConfigurationEntry entry in customPSSnapIn.Cmdlets)
{
SessionStateCmdletEntry cmdlet = new SessionStateCmdletEntry(entry.Name, entry.ImplementingType, entry.HelpFileName);
cmdlet.SetPSSnapIn(psSnapInInfo);
this.Commands.Add(cmdlet);
}
}
if (customPSSnapIn.Providers != null)
{
foreach (ProviderConfigurationEntry entry in customPSSnapIn.Providers)
{
SessionStateProviderEntry provider = new SessionStateProviderEntry(entry.Name, entry.ImplementingType, entry.HelpFileName);
provider.SetPSSnapIn(psSnapInInfo);
this.Providers.Add(provider);
}
}
if (customPSSnapIn.Types != null)
{
foreach (TypeConfigurationEntry entry in customPSSnapIn.Types)
{
string path = Path.Combine(psSnapInInfo.ApplicationBase, entry.FileName);
SessionStateTypeEntry typeEntry = new SessionStateTypeEntry(path);
typeEntry.SetPSSnapIn(psSnapInInfo);
this.Types.Add(typeEntry);
}
}
if (customPSSnapIn.Formats != null)
{
foreach (FormatConfigurationEntry entry in customPSSnapIn.Formats)
{
string path = Path.Combine(psSnapInInfo.ApplicationBase, entry.FileName);
SessionStateFormatEntry formatEntry = new SessionStateFormatEntry(path);
formatEntry.SetPSSnapIn(psSnapInInfo);
this.Formats.Add(formatEntry);
}
}
SessionStateAssemblyEntry assemblyEntry = new SessionStateAssemblyEntry(psSnapInInfo.AssemblyName, psSnapInInfo.AbsoluteModulePath);
this.Assemblies.Add(assemblyEntry);
}
#endif
[SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.Reflection.Assembly.LoadFrom")]
internal static Assembly LoadAssemblyFromFile(string fileName)
{
@@ -54,12 +54,12 @@ namespace System.Management.Automation.Runspaces
}"), null));
yield return td4;
#if !CORECLR
#if !UNIX
var td5 = new TypeData(@"System.DirectoryServices.PropertyValueCollection", true);
td5.Members.Add("ToString",
new CodeMethodData("ToString", GetMethodInfo(typeof(Microsoft.PowerShell.ToStringCodeMethods), @"PropertyValueCollection")));
yield return td5;
#endif // !CORECLR
#endif
var td6 = new TypeData(@"System.Drawing.Printing.PrintDocument", true);
td6.Members.Add("Name",
@@ -169,7 +169,7 @@ namespace System.Management.Automation.Runspaces
}"), null));
yield return td17;
#if !CORECLR
#if !UNIX
var td18 = new TypeData(@"System.DirectoryServices.DirectoryEntry", true);
td18.Members.Add("ConvertLargeIntegerToInt64",
new CodeMethodData("ConvertLargeIntegerToInt64", GetMethodInfo(typeof(Microsoft.PowerShell.AdapterCodeMethods), @"ConvertLargeIntegerToInt64")));
@@ -178,7 +178,7 @@ namespace System.Management.Automation.Runspaces
td18.DefaultDisplayPropertySet =
new PropertySetData(new [] { "distinguishedName", "Path" }) { Name = "DefaultDisplayPropertySet" };
yield return td18;
#endif // !CORECLR
#endif
var td19 = new TypeData(@"System.IO.DirectoryInfo", true);
td19.Members.Add("Mode",
@@ -1443,13 +1443,7 @@ namespace System.Management.Automation
_currentDebuggerAction = DebuggerResumeAction.Continue;
ResumeExecution(DebuggerResumeAction.Stop);
}
#if !CORECLR // Workflow Not Supported on OneCore PS
// Lazily subscribe to workflow start engine event for workflow debugging.
if (!_wfStartEventSubscribed && IsJobDebuggingMode())
{
SubscribeToEngineWFJobStartEvent();
}
#endif
UpdateBreakpoints(functionContext);
if (_steppingMode == SteppingMode.StepIn &&
@@ -1631,9 +1625,6 @@ namespace System.Management.Automation
private PowerShell _psDebuggerCommand;
// Job debugger integration.
#if !CORECLR // Workflow Not Supported on OneCore PS
private bool _wfStartEventSubscribed;
#endif
private bool _nestedDebuggerStop;
private bool _writeWFErrorOnce;
private Dictionary<Guid, PSJobStartEventArgs> _runningJobs;
@@ -2098,14 +2089,7 @@ namespace System.Management.Automation
ResumeExecution(DebuggerResumeAction.StepInto);
}
}
#if !CORECLR
// Workflow Not Supported on OneCore PS
// Look for any running workflow jobs and set to step mode.
if ((nestedType & EnableNestedType.NestedJob) == EnableNestedType.NestedJob)
{
EnableRunningWorkflowJobsForStepping();
}
#endif
// Look for any runspaces with debuggers and set to setp mode.
if ((nestedType & EnableNestedType.NestedRunspace) == EnableNestedType.NestedRunspace)
{
@@ -2813,62 +2797,6 @@ namespace System.Management.Automation
#region Job debugger integration
#if !CORECLR // Workflow Not Supported on OneCore PS
private void SubscribeToEngineWFJobStartEvent()
{
Diagnostics.Assert(_context.Events != null, "Event manager cannot be null.");
_context.Events.SubscribeEvent(
source: null,
eventName: null,
sourceIdentifier: PSEngineEvent.WorkflowJobStartEvent,
data: null,
handlerDelegate: HandleJobStartEvent,
supportEvent: true,
forwardEvent: false);
_wfStartEventSubscribed = true;
}
private void UnsubscribeFromEngineWFJobStartEvent()
{
PSEventManager eventManager = _context.Events;
Diagnostics.Assert(eventManager != null, "Event manager cannot be null.");
foreach (var subscriber in eventManager.GetEventSubscribers(PSEngineEvent.WorkflowJobStartEvent))
{
eventManager.UnsubscribeEvent(subscriber);
}
_wfStartEventSubscribed = false;
}
private void HandleJobStartEvent(object sender, PSEventArgs args)
{
Diagnostics.Assert(args.SourceArgs.Length == 1, "WF Job Started engine event SourceArgs should have a single element.");
PSJobStartEventArgs jobStartedArgs = args.SourceArgs[0] as PSJobStartEventArgs;
Diagnostics.Assert(jobStartedArgs != null, "WF Job Started engine event args cannot be null.");
Diagnostics.Assert(jobStartedArgs.Job != null, "WF Job to start cannot be null.");
Diagnostics.Assert(jobStartedArgs.Debugger != null, "WF Job Started Debugger object cannot be null.");
if (!(jobStartedArgs.Debugger.GetType().FullName.Equals("Microsoft.PowerShell.Workflow.PSWorkflowDebugger",
StringComparison.OrdinalIgnoreCase)))
{
// Check to ensure only PS workflow debuggers can be passed in.
throw new PSInvalidOperationException();
}
// At this point the script debugger stack frame must be the Workflow execution function which is DebuggerHidden.
// The internal debugger resume action is set to StepOut, *if* the user selected StepIn, so as to skip this frame
// since debugging the workflow execution function is turned off. We look at the previous resume action to see
// what the user intended. If it is StepIn then we start the workflow job debugger in step mode.
Diagnostics.Assert(_callStack.LastFunctionContext()._debuggerHidden, "Current stack frame must be WF function DebuggerHidden");
DebuggerResumeAction startAction = (_previousDebuggerAction == DebuggerResumeAction.StepInto) ?
DebuggerResumeAction.StepInto : DebuggerResumeAction.Continue;
AddToJobRunningList(jobStartedArgs, startAction);
}
#endif
private void AddToJobRunningList(PSJobStartEventArgs jobArgs, DebuggerResumeAction startAction)
{
bool newJob = false;
@@ -2993,9 +2921,6 @@ namespace System.Management.Automation
private void ClearRunningJobList()
{
#if !CORECLR // Workflow Not Supported on OneCore PS
UnsubscribeFromEngineWFJobStartEvent();
#endif
PSJobStartEventArgs[] runningJobs = null;
lock (_syncObject)
{
@@ -3148,12 +3073,6 @@ namespace System.Management.Automation
{
if (!IsJobDebuggingMode())
{
#if !CORECLR // Workflow Not Supported on OneCore PS
// Remove workflow job callback.
UnsubscribeFromEngineWFJobStartEvent();
// Write warning to user.
WriteWorkflowDebugNotSupportedError();
#endif
// Ignore job debugger stop.
args.ResumeAction = DebuggerResumeAction.Continue;
return;
@@ -3357,57 +3276,6 @@ namespace System.Management.Automation
}
}
#if !CORECLR // Workflow Not Supported on OneCore PS
private void EnableRunningWorkflowJobsForStepping()
{
// Make sure workflow job start callback is set to pick
// up any newly starting jobs.
if (!_wfStartEventSubscribed)
{
lock (_syncObject)
{
if (!_wfStartEventSubscribed)
{
SubscribeToEngineWFJobStartEvent();
}
}
}
// Get list of workflow jobs
Collection<Job> jobs;
using (PowerShell ps = PowerShell.Create())
{
ps.Commands.Clear();
ps.AddScript(@"Get-Job | Where-Object {$_.PSJobTypeName -eq 'PSWorkflowJob'}");
jobs = ps.Invoke<Job>();
}
// Add debuggable workflow jobs to running Job list
// and set debugger to step mode.
foreach (var parentJob in jobs)
{
if (parentJob != null)
{
foreach (var childJob in parentJob.ChildJobs)
{
IJobDebugger debuggableJob = childJob as IJobDebugger;
if (debuggableJob != null)
{
AddToJobRunningList(
new PSJobStartEventArgs(
childJob,
debuggableJob.Debugger,
debuggableJob.IsAsync),
DebuggerResumeAction.StepInto);
}
}
}
}
// Ensure existing running jobs in list are also set to step mode.
SetRunningJobListToStep(true);
}
#endif
#endregion
#region Runspace debugger integration
@@ -3845,9 +3713,6 @@ namespace System.Management.Automation
/// </summary>
public void Dispose()
{
#if !CORECLR // Workflow Not Supported on OneCore PS
UnsubscribeFromEngineWFJobStartEvent();
#endif
// Ensure all job event handlers are removed.
PSJobStartEventArgs[] runningJobs;
lock (_syncObject)
@@ -299,7 +299,6 @@ namespace System.Management.Automation.Internal.Host
commandInfoProperty.Value = callingCommand.CommandInfo;
}
#if !CORECLR //TODO:CORECLR StackTrace not in CoreCLR
stackTraceProperty = newValue.Properties["StackTrace"];
if (stackTraceProperty == null)
{
@@ -310,7 +309,6 @@ namespace System.Management.Automation.Internal.Host
oldStackTrace = stackTraceProperty.Value;
stackTraceProperty.Value = new System.Diagnostics.StackTrace();
}
#endif
Context.SetVariable(SpecialVariables.CurrentlyExecutingCommandVarPath, newValue);
}
@@ -1520,9 +1520,7 @@ namespace System.Management.Automation.Remoting.Server
readerSettings.CheckCharacters = false;
readerSettings.IgnoreComments = true;
readerSettings.IgnoreProcessingInstructions = true;
#if !CORECLR // No XmlReaderSettings.XmlResolver in CoreCLR
readerSettings.XmlResolver = null;
#endif
readerSettings.ConformanceLevel = ConformanceLevel.Fragment;
readerSettings.MaxCharactersFromEntities = 1024;
readerSettings.DtdProcessing = System.Xml.DtdProcessing.Prohibit;
@@ -7594,26 +7594,6 @@ namespace Microsoft.PowerShell.Commands
IntPtr OutBuffer, int nOutBufferSize,
out int pBytesReturned, IntPtr lpOverlapped);
#if !CORECLR
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern IntPtr FindFirstFileName(
string lpFileName,
uint flags,
ref UInt32 StringLength,
StringBuilder LinkName);
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern bool FindNextFileName(
IntPtr hFindStream,
ref UInt32 StringLength,
StringBuilder LinkName);
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern bool FindClose(IntPtr hFindFile);
#endif
[DllImport(PinvokeDllNames.GetFileInformationByHandleDllName, SetLastError = true, CharSet = CharSet.Unicode)]
private static extern bool GetFileInformationByHandle(
IntPtr hFile,