From ab39905346b599d245d25fa3c14e84961cdec3e3 Mon Sep 17 00:00:00 2001 From: iSazonov Date: Mon, 26 Nov 2018 09:32:53 +0500 Subject: [PATCH 1/6] Remove WebClient code --- .../help/UpdatableHelpSystem.cs | 119 +----------------- 1 file changed, 2 insertions(+), 117 deletions(-) diff --git a/src/System.Management.Automation/help/UpdatableHelpSystem.cs b/src/System.Management.Automation/help/UpdatableHelpSystem.cs index f190f7bc8f5..9cf438d77fe 100644 --- a/src/System.Management.Automation/help/UpdatableHelpSystem.cs +++ b/src/System.Management.Automation/help/UpdatableHelpSystem.cs @@ -235,12 +235,7 @@ internal UpdatableHelpProgressEventArgs(string moduleName, UpdatableHelpCommandT /// internal class UpdatableHelpSystem : IDisposable { -#if CORECLR private TimeSpan _defaultTimeout; -#else - private AutoResetEvent _completionEvent; - private bool _completed; -#endif private Collection _progressEvents; private bool _stopping; private object _syncObject; @@ -257,12 +252,7 @@ internal class UpdatableHelpSystem : IDisposable internal UpdatableHelpSystem(UpdatableHelpCommandBase cmdlet, bool useDefaultCredentials) { WebClient = new WebClient(); -#if CORECLR _defaultTimeout = new TimeSpan(0, 0, 30); -#else - _completionEvent = new AutoResetEvent(false); - _completed = false; -#endif _progressEvents = new Collection(); Errors = new Collection(); _stopping = false; @@ -348,7 +338,6 @@ internal UpdatableHelpInfo GetHelpInfo(UpdatableHelpCommandType commandType, str OnProgressChanged(this, new UpdatableHelpProgressEventArgs(CurrentModule, commandType, StringUtil.Format( HelpDisplayStrings.UpdateProgressLocating), 0)); -#if CORECLR string xml; using (HttpClientHandler handler = new HttpClientHandler()) { @@ -364,9 +353,7 @@ internal UpdatableHelpInfo GetHelpInfo(UpdatableHelpCommandType commandType, str } } } -#else - string xml = WebClient.DownloadString(uri); -#endif + UpdatableHelpInfo helpInfo = CreateHelpInfo(xml, moduleName, moduleGuid, currentCulture: culture, pathOverride: null, verbose: true, shouldResolveUri: true, ignoreValidationException: false); @@ -432,7 +419,6 @@ private string ResolveUri(string baseUri, bool verbose) return uri; } -#if CORECLR using (HttpClientHandler handler = new HttpClientHandler()) { handler.AllowAutoRedirect = false; @@ -487,64 +473,6 @@ private string ResolveUri(string baseUri, bool verbose) } } } -#else - HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri); - - request.AllowAutoRedirect = false; - request.Timeout = 30000; - - HttpWebResponse response = (HttpWebResponse)request.GetResponse(); - - WebHeaderCollection headers = response.Headers; - - try - { - if (response.StatusCode == HttpStatusCode.Found || - response.StatusCode == HttpStatusCode.Redirect || - response.StatusCode == HttpStatusCode.Moved || - response.StatusCode == HttpStatusCode.MovedPermanently) - { - Uri responseUri = new Uri(headers["Location"], UriKind.RelativeOrAbsolute); - - if (responseUri.IsAbsoluteUri) - { - uri = responseUri.ToString(); - } - else - { - uri = uri.Replace(request.Address.AbsolutePath, responseUri.ToString()); - } - - uri = uri.Trim(); - - if (verbose) - { - _cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.URIRedirectWarningToHost, uri)); - } - - if (uri.EndsWith("/", StringComparison.OrdinalIgnoreCase)) - { - return uri; - } - } - else if (response.StatusCode == HttpStatusCode.OK) - { - if (uri.EndsWith("/", StringComparison.OrdinalIgnoreCase)) - { - return uri; - } - else - { - throw new UpdatableHelpSystemException("InvalidHelpInfoUri", StringUtil.Format(HelpDisplayStrings.InvalidHelpInfoUri, uri), - ErrorCategory.InvalidOperation, null, null); - } - } - } - finally - { - response.Close(); - } -#endif } } catch (UriFormatException e) @@ -817,16 +745,7 @@ private void HelpContentValidationHandler(object sender, ValidationEventArgs arg /// internal void CancelDownload() { -#if CORECLR _cancelTokenSource.Cancel(); -#else - if (WebClient.IsBusy) - { - WebClient.CancelAsync(); - _completed = true; - _completionEvent.Set(); - } -#endif _stopping = true; } @@ -890,17 +809,11 @@ internal bool DownloadHelpContent(UpdatableHelpCommandType commandType, string p string uri = helpContentUri + fileName; -#if CORECLR return DownloadHelpContentHttpClient(uri, Path.Combine(path, fileName), commandType); -#else - return DownloadHelpContentWebClient(uri, Path.Combine(path, fileName), culture, commandType); -#endif } -#if CORECLR /// - /// Downloads the help content and saves it to a directory. The goal is to achieve - /// functional parity with WebClient.DownloadFileAsync() using CoreCLR-compatible APIs. + /// Downloads the help content and saves it to a directory. /// /// /// @@ -981,34 +894,6 @@ private void WriteResponseToFile(HttpResponseMessage response, string fileName) } } -#else - - /// - /// Downloads help content and saves it in the specified file. - /// - /// - /// - /// - /// - /// - private bool DownloadHelpContentWebClient(string uri, string fileName, string culture, UpdatableHelpCommandType commandType) - { - WebClient.DownloadFileAsync(new Uri(uri), fileName, culture); - - OnProgressChanged(this, new UpdatableHelpProgressEventArgs(CurrentModule, commandType, StringUtil.Format( - HelpDisplayStrings.UpdateProgressConnecting), 100)); - - while (!_completed || WebClient.IsBusy) - { - _completionEvent.WaitOne(); - - SendProgressEvents(commandType); - } - - return (Errors.Count == 0); - } -#endif - private void SendProgressEvents(UpdatableHelpCommandType commandType) { // Send progress events From 4ad09b3f5143c96ea33cf1bffd71ac97961db07b Mon Sep 17 00:00:00 2001 From: iSazonov Date: Mon, 26 Nov 2018 09:40:03 +0500 Subject: [PATCH 2/6] CoreFX now supports XML Schemas --- .../help/UpdatableHelpSystem.cs | 53 ------------------- 1 file changed, 53 deletions(-) diff --git a/src/System.Management.Automation/help/UpdatableHelpSystem.cs b/src/System.Management.Automation/help/UpdatableHelpSystem.cs index 9cf438d77fe..080f47991a8 100644 --- a/src/System.Management.Automation/help/UpdatableHelpSystem.cs +++ b/src/System.Management.Automation/help/UpdatableHelpSystem.cs @@ -17,13 +17,10 @@ using Microsoft.PowerShell.Commands; using Microsoft.Win32; using System.Security; -#if CORECLR using System.IO.Compression; using System.Net.Http; using System.Threading.Tasks; -#else using System.Xml.Schema; -#endif namespace System.Management.Automation.Help { @@ -537,9 +534,7 @@ internal UpdatableHelpInfo CreateHelpInfo(string xml, string moduleName, Guid mo try { document = CreateValidXmlDocument(xml, HelpInfoXmlNamespace, HelpInfoXmlSchema, -#if !CORECLR new ValidationEventHandler(HelpInfoValidationHandler), -#endif true); } catch (UpdatableHelpSystemException e) @@ -612,46 +607,6 @@ internal UpdatableHelpInfo CreateHelpInfo(string xml, string moduleName, Guid mo return helpInfo; } -#if CORECLR - - /// - /// Creates a valid xml document - /// - /// input xml - /// schema namespace - /// xml schema - /// HelpInfo or HelpContent? - private XmlDocument CreateValidXmlDocument(string xml, string ns, string schema, bool helpInfo) - { - XmlReaderSettings settings = new XmlReaderSettings(); - - XmlReader reader = XmlReader.Create(new StringReader(xml), settings); - XmlDocument document = new XmlDocument(); - - try - { - document.Load(reader); - } - catch (XmlException e) - { - if (helpInfo) - { - throw new UpdatableHelpSystemException(HelpInfoXmlValidationFailure, - StringUtil.Format(HelpDisplayStrings.HelpInfoXmlValidationFailure, e.Message), - ErrorCategory.InvalidData, null, e); - } - else - { - throw new UpdatableHelpSystemException("HelpContentXmlValidationFailure", - StringUtil.Format(HelpDisplayStrings.HelpContentXmlValidationFailure, e.Message), - ErrorCategory.InvalidData, null, e); - } - } - return document; - } - -#else - /// /// Creates a valid xml document /// @@ -734,8 +689,6 @@ private void HelpContentValidationHandler(object sender, ValidationEventArgs arg } } -#endif - #endregion #region Help Content Retrieval @@ -1269,11 +1222,7 @@ private void ValidateAndCopyHelpContent(string sourcePath, Collection de { installed = new Collection(); -#if CORECLR // TODO:CORECLR Disabling this because XML Schemas are not supported for CoreCLR - string xsd = "Remove this when adding schema support"; -#else string xsd = LoadStringFromPath(_cmdlet, xsdPath, null); -#endif // We only accept txt files and xml files foreach (string file in Directory.GetFiles(sourcePath)) @@ -1383,9 +1332,7 @@ private void ValidateAndCopyHelpContent(string sourcePath, Collection de } CreateValidXmlDocument(node.OuterXml, targetNamespace, xsd, -#if !CORECLR new ValidationEventHandler(HelpContentValidationHandler), -#endif false); } } From 5362f5840035c243e343eeabb0bd9f34d441b4b2 Mon Sep 17 00:00:00 2001 From: iSazonov Date: Mon, 26 Nov 2018 09:42:41 +0500 Subject: [PATCH 3/6] Reorder using-s --- .../help/UpdatableHelpSystem.cs | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/System.Management.Automation/help/UpdatableHelpSystem.cs b/src/System.Management.Automation/help/UpdatableHelpSystem.cs index 080f47991a8..63b4d1336af 100644 --- a/src/System.Management.Automation/help/UpdatableHelpSystem.cs +++ b/src/System.Management.Automation/help/UpdatableHelpSystem.cs @@ -1,27 +1,28 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System.Globalization; +using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Net; using System.ComponentModel; -using System.Management.Automation.Configuration; -using System.Management.Automation.Internal; using System.Diagnostics; -using System.Threading; +using System.Globalization; using System.IO; -using System.Xml; -using System.Collections.Generic; -using System.Runtime.Serialization; -using System.Text; -using Microsoft.PowerShell.Commands; -using Microsoft.Win32; -using System.Security; using System.IO.Compression; +using System.Management.Automation.Configuration; +using System.Management.Automation.Internal; +using System.Net; using System.Net.Http; +using System.Runtime.Serialization; +using System.Security; +using System.Text; +using System.Threading; using System.Threading.Tasks; +using System.Xml; using System.Xml.Schema; +using Microsoft.PowerShell.Commands; +using Microsoft.Win32; + namespace System.Management.Automation.Help { /// From 2bf264c42231dd69756b7aa50ad0422b1b011798 Mon Sep 17 00:00:00 2001 From: iSazonov Date: Thu, 29 Nov 2018 18:52:43 +0500 Subject: [PATCH 4/6] Publish Schemas --- src/powershell-win-core/powershell-win-core.csproj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/powershell-win-core/powershell-win-core.csproj b/src/powershell-win-core/powershell-win-core.csproj index 49e815b2e21..63486744e9a 100644 --- a/src/powershell-win-core/powershell-win-core.csproj +++ b/src/powershell-win-core/powershell-win-core.csproj @@ -20,6 +20,11 @@ PreserveNewest PreserveNewest + + Schemas\PSMaml\%(FileName)%(Extension) + PreserveNewest + PreserveNewest + PreserveNewest PreserveNewest From 33072dc5da2616956748370d2ac8e2c37ad0fe36 Mon Sep 17 00:00:00 2001 From: iSazonov Date: Thu, 29 Nov 2018 19:28:17 +0500 Subject: [PATCH 5/6] Publish Schemas on Unix --- src/powershell-unix/powershell-unix.csproj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/powershell-unix/powershell-unix.csproj b/src/powershell-unix/powershell-unix.csproj index f6b16e80d70..f9ccc3451d6 100644 --- a/src/powershell-unix/powershell-unix.csproj +++ b/src/powershell-unix/powershell-unix.csproj @@ -16,6 +16,11 @@ PreserveNewest PreserveNewest + + Schemas\PSMaml\%(FileName)%(Extension) + PreserveNewest + PreserveNewest + PreserveNewest PreserveNewest From c1efed6637eab886b7e2d6db8499f49ee5654fa2 Mon Sep 17 00:00:00 2001 From: iSazonov Date: Thu, 29 Nov 2018 19:31:27 +0500 Subject: [PATCH 6/6] Upadate files.wxs --- assets/files.wxs | 216 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 216 insertions(+) diff --git a/assets/files.wxs b/assets/files.wxs index dc3496021a8..dee0720a3d0 100644 --- a/assets/files.wxs +++ b/assets/files.wxs @@ -2023,6 +2023,169 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2672,6 +2835,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +