Skip to content

Commit

Permalink
Clean Up Full CLR Code From Web Cmdlets (#5376)
Browse files Browse the repository at this point in the history
  • Loading branch information
markekraus authored and iSazonov committed Nov 10, 2017
1 parent 6530b77 commit f5f3fab
Show file tree
Hide file tree
Showing 26 changed files with 17 additions and 2,250 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
using System.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
#if !CORECLR
using mshtml;
#endif
using Microsoft.Win32;

namespace Microsoft.PowerShell.Commands
Expand Down Expand Up @@ -56,10 +53,10 @@ public abstract partial class WebRequestPSCmdlet : PSCmdlet
#region URI

/// <summary>
/// gets or sets the parameter UseBasicParsing
/// Deprecated. Gets or sets UseBasicParsing. This has no affect on the operation of the Cmdlet.
/// </summary>
[Parameter]
public virtual SwitchParameter UseBasicParsing { get; set; }
[Parameter(DontShow = true)]
public virtual SwitchParameter UseBasicParsing { get; set; } = true;

/// <summary>
/// gets or sets the Uri property
Expand Down Expand Up @@ -583,81 +580,6 @@ internal bool ShouldWriteToPipeline

#region Helper Methods

/// <summary>
/// Verifies that Internet Explorer is available, and that its first-run
/// configuration is complete.
/// </summary>
/// <param name="checkComObject">True if we should try to access IE's COM object. Not
/// needed if an HtmlDocument will be created shortly.</param>
protected bool VerifyInternetExplorerAvailable(bool checkComObject)
{
// TODO: Remove this code once the dependency on mshtml has been resolved.
#if CORECLR
return false;
#else
bool isInternetExplorerConfigurationComplete = false;
// Check for IE for both PS Full and PS Core on windows.
// The registry key DisableFirstRunCustomize can exits at one of the following path.
// IE uses the same descending order (as mentioned) to check for the presence of this key.
// If the value of DisableFirstRunCustomize key is set to greater than zero then Run first
// is disabled.
string[] disableFirstRunCustomizePaths = new string[] {
@"HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Internet Explorer\Main",
@"HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Main",
@"HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main",
@"HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Main" };

foreach (string currentRegPath in disableFirstRunCustomizePaths)
{
object val = Registry.GetValue(currentRegPath, "DisableFirstRunCustomize", string.Empty);
if (val != null && !string.Empty.Equals(val) && Convert.ToInt32(val, CultureInfo.InvariantCulture) > 0)
{
isInternetExplorerConfigurationComplete = true;
break;
}
}

if (!isInternetExplorerConfigurationComplete)
{
// Verify that if IE is installed, it has been through the RunOnce check.
// Otherwise, the call will stop responding waiting for users to go through First Run
// personalization.
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\Main"))
{
if (key != null)
{
foreach (string setting in key.GetValueNames())
{
if (setting.IndexOf("RunOnce", StringComparison.OrdinalIgnoreCase) > -1)
{
isInternetExplorerConfigurationComplete = true;
break;
}
}
}
}
}

if (isInternetExplorerConfigurationComplete && checkComObject)
{
try
{
IHTMLDocument2 ieCheck = (IHTMLDocument2)new HTMLDocument();
System.Runtime.InteropServices.Marshal.ReleaseComObject(ieCheck);
}
catch (System.Runtime.InteropServices.COMException)
{
isInternetExplorerConfigurationComplete = false;
}
}

// Throw exception in PS Full only
if (!isInternetExplorerConfigurationComplete)
throw new NotSupportedException(WebCmdletStrings.IEDomNotSupported);
return isInternetExplorerConfigurationComplete;
#endif
}

private Uri PrepareUri(Uri uri)
{
uri = CheckProtocol(uri);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if CORECLR

/********************************************************************++
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/

Expand All @@ -18,7 +16,7 @@ public partial class BasicHtmlWebResponseObject : WebResponseObject
#region Constructors

/// <summary>
/// Constructor for HtmlWebResponseObject
/// Constructor for BasicHtmlWebResponseObject
/// </summary>
/// <param name="response"></param>
public BasicHtmlWebResponseObject(HttpResponseMessage response)
Expand Down Expand Up @@ -52,4 +50,3 @@ private void InitializeRawContent(HttpResponseMessage baseResponse)
#endregion Methods
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if CORECLR

/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
Expand Down Expand Up @@ -69,4 +67,3 @@ internal static StringBuilder GetRawContentHeader(HttpResponseMessage response)
}
}
}
#endif

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if CORECLR

/********************************************************************++
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/

Expand Down Expand Up @@ -108,4 +106,3 @@ internal static HashSet<string> ContentHeaders
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if CORECLR

/********************************************************************++
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/

Expand Down Expand Up @@ -131,4 +129,3 @@ private RestReturnType CheckReturnType(HttpResponseMessage response)
#endregion Helper Methods
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if CORECLR

/********************************************************************++
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/

Expand Down Expand Up @@ -36,24 +34,12 @@ internal override void ProcessResponse(HttpResponseMessage response)
{
if (null == response) { throw new ArgumentNullException("response"); }

// check for Server Core, throws exception if -UseBasicParsing is not used
if (ShouldWriteToPipeline && !UseBasicParsing)
{
// IE is not available in PS Linux, and may not available in PS Core depending on
// where it's running (desktop/nano/iot).
// For PS Linux and PS Core, if IE is not available, we always use basic parsing.
if (!VerifyInternetExplorerAvailable(true))
{
UseBasicParsing = true;
}
}

Stream responseStream = StreamHelper.GetResponseStream(response);
if (ShouldWriteToPipeline)
{
// creating a MemoryStream wrapper to response stream here to support IsStopping.
responseStream = new WebResponseContentMemoryStream(responseStream, StreamHelper.ChunkSize, this);
WebResponseObject ro = WebResponseObjectFactory.GetResponseObject(response, responseStream, this.Context, UseBasicParsing);
WebResponseObject ro = WebResponseObjectFactory.GetResponseObject(response, responseStream, this.Context);
ro.RelationLink = _relationLink;
WriteObject(ro);

Expand All @@ -73,4 +59,3 @@ internal override void ProcessResponse(HttpResponseMessage response)
#endregion Virtual Method Overrides
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if CORECLR

/********************************************************************++
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/

Expand Down Expand Up @@ -69,4 +67,3 @@ public bool IsBypassed(Uri host)
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if CORECLR

/********************************************************************++
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/

Expand Down Expand Up @@ -351,19 +349,6 @@ internal virtual void FillRequestStream(HttpRequestMessage request)
content = psBody.BaseObject;
}

/* TODO: This needs to be enable after the dependency on mshtml is resolved.
var html = content as HtmlWebResponseObject;
if (html != null)
{
// use the form if it's the only one present
if (html.Forms.Count == 1)
{
SetRequestContent(request, html.Forms[0].Fields);
}
}
else if (content is FormObject)
*/

if (content is FormObject)
{
FormObject form = content as FormObject;
Expand Down Expand Up @@ -870,4 +855,3 @@ internal void ParseLinkHeader(HttpResponseMessage response, System.Uri requestUr
#endregion Helper Methods
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if CORECLR

/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
Expand Down Expand Up @@ -68,4 +66,3 @@ internal static bool IsText(HttpResponseMessage response)
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if CORECLR

/********************************************************************++
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/

Expand Down Expand Up @@ -122,4 +120,3 @@ private void SetResponse(HttpResponseMessage response, Stream contentStream)
#endregion
}
}
#endif

0 comments on commit f5f3fab

Please sign in to comment.