12
12
// limitations under the License.
13
13
// ----------------------------------------------------------------------------------
14
14
15
- using Microsoft . Azure . Commands . ResourceManager . Common ;
15
+ using Microsoft . Azure . Commands . Common . Authentication . Abstractions ;
16
+ using Microsoft . WindowsAzure . Commands . Utilities . Common ;
16
17
using System ;
17
- using System . Collections . Generic ;
18
18
using System . Diagnostics ;
19
19
using System . Management . Automation ;
20
- using System . Text ;
20
+ using System . Runtime . InteropServices ;
21
21
22
22
namespace Microsoft . Azure . Commands . Profile . Survey
23
23
{
24
24
[ Cmdlet ( VerbsCommon . Open , ResourceManager . Common . AzureRMConstants . AzureRMPrefix + "SurveyLink" ) , OutputType ( typeof ( void ) ) ]
25
- public class OpenAzSurveyLinkCmdlet : AzureRMCmdlet
25
+ public class OpenAzSurveyLinkCmdlet : AzurePSCmdlet
26
26
{
27
27
private const string _surveyLinkFormat = "https://aka.ms/azpssurvey?Q_CHL=INTERCEPT" ;
28
28
29
+ protected override IAzureContext DefaultContext => null ;
30
+
31
+ protected override string DataCollectionWarning => null ;
32
+
29
33
public override void ExecuteCmdlet ( )
30
34
{
31
- base . ExecuteCmdlet ( ) ;
32
35
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
+ }
34
64
}
35
65
}
36
- }
66
+ }
0 commit comments