From 615b305a767ac5246fa7755cc59e9bbd895da11f Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Wed, 9 Jun 2021 12:05:26 +0800 Subject: [PATCH] update parent class --- .../Feedback/OpenAzSurveyLinkCmdlet.cs | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/Accounts/Accounts/Feedback/OpenAzSurveyLinkCmdlet.cs b/src/Accounts/Accounts/Feedback/OpenAzSurveyLinkCmdlet.cs index b9dd26f38d43..b0af944e6c4b 100644 --- a/src/Accounts/Accounts/Feedback/OpenAzSurveyLinkCmdlet.cs +++ b/src/Accounts/Accounts/Feedback/OpenAzSurveyLinkCmdlet.cs @@ -12,25 +12,55 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.Commands.ResourceManager.Common; +using Microsoft.Azure.Commands.Common.Authentication.Abstractions; +using Microsoft.WindowsAzure.Commands.Utilities.Common; using System; -using System.Collections.Generic; using System.Diagnostics; using System.Management.Automation; -using System.Text; +using System.Runtime.InteropServices; namespace Microsoft.Azure.Commands.Profile.Survey { [Cmdlet(VerbsCommon.Open, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SurveyLink"), OutputType(typeof(void))] - public class OpenAzSurveyLinkCmdlet : AzureRMCmdlet + public class OpenAzSurveyLinkCmdlet : AzurePSCmdlet { private const string _surveyLinkFormat = "https://aka.ms/azpssurvey?Q_CHL=INTERCEPT"; + protected override IAzureContext DefaultContext => null; + + protected override string DataCollectionWarning => null; + public override void ExecuteCmdlet() { - base.ExecuteCmdlet(); WriteInformation(new HostInformationMessage() { Message = $"Opening the default browser to {_surveyLinkFormat}" }, new string[] { "PSHOST" }); - Process.Start(new ProcessStartInfo() { FileName = _surveyLinkFormat, UseShellExecute = true}); + OpenBrowser(_surveyLinkFormat); + } + + private void OpenBrowser(string url) + { + try + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + url = url.Replace("&", "^&"); + Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true }); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + Process.Start("xdg-open", url); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + Process.Start("open", url); + } + else + { + throw new PlatformNotSupportedException(RuntimeInformation.OSDescription); + } + } + catch + { + } } } }