Skip to content

Commit

Permalink
update parent class
Browse files Browse the repository at this point in the history
  • Loading branch information
VeryEarly committed Jun 9, 2021
1 parent 3f00150 commit 615b305
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions src/Accounts/Accounts/Feedback/OpenAzSurveyLinkCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
}
}
}

0 comments on commit 615b305

Please sign in to comment.