Skip to content

Commit b2459b5

Browse files
committed
update parent class
1 parent 8ffcc8f commit b2459b5

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

src/Accounts/Accounts/Feedback/OpenAzSurveyLinkCmdlet.cs

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,55 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.ResourceManager.Common;
15+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
16+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
1617
using System;
17-
using System.Collections.Generic;
1818
using System.Diagnostics;
1919
using System.Management.Automation;
20-
using System.Text;
20+
using System.Runtime.InteropServices;
2121

2222
namespace Microsoft.Azure.Commands.Profile.Survey
2323
{
2424
[Cmdlet(VerbsCommon.Open, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SurveyLink"), OutputType(typeof(void))]
25-
public class OpenAzSurveyLinkCmdlet : AzureRMCmdlet
25+
public class OpenAzSurveyLinkCmdlet : AzurePSCmdlet
2626
{
2727
private const string _surveyLinkFormat = "https://aka.ms/azpssurvey?Q_CHL=INTERCEPT";
2828

29+
protected override IAzureContext DefaultContext => null;
30+
31+
protected override string DataCollectionWarning => null;
32+
2933
public override void ExecuteCmdlet()
3034
{
31-
base.ExecuteCmdlet();
3235
WriteInformation(new HostInformationMessage() { Message = $"Opening the default browser to {_surveyLinkFormat}" }, new string[] { "PSHOST" });
33-
Process.Start(new ProcessStartInfo() { FileName = _surveyLinkFormat, UseShellExecute = true});
36+
OpenBrowser(_surveyLinkFormat);
37+
}
38+
39+
private void OpenBrowser(string url)
40+
{
41+
try
42+
{
43+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
44+
{
45+
url = url.Replace("&", "^&");
46+
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true });
47+
}
48+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
49+
{
50+
Process.Start("xdg-open", url);
51+
}
52+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
53+
{
54+
Process.Start("open", url);
55+
}
56+
else
57+
{
58+
throw new PlatformNotSupportedException(RuntimeInformation.OSDescription);
59+
}
60+
}
61+
catch
62+
{
63+
}
3464
}
3565
}
36-
}
66+
}

0 commit comments

Comments
 (0)