Skip to content

Commit 71a19a0

Browse files
Nickcandydingmeng-xuewyunchi-ms
authored
upgrade for new survey machenism (#19285)
* revise code * revise code * generate help markdown file * revise code * Revise code * revise code * revise code * test common 1.0.0-preview * revise code * add dependency on new common lib and add change log * revise change log Co-authored-by: [email protected] <[email protected]> Co-authored-by: Yunchi Wang <[email protected]>
1 parent 36c9eb1 commit 71a19a0

13 files changed

+164
-38
lines changed

src/Accounts/Accounts/Account/ConnectAzureRmAccount.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
4545
using Microsoft.WindowsAzure.Commands.Common.Utilities;
4646
using Microsoft.WindowsAzure.Commands.Utilities.Common;
47+
using Microsoft.Azure.PowerShell.Common.Share.Survey;
4748

4849
namespace Microsoft.Azure.Commands.Profile
4950
{
@@ -680,7 +681,7 @@ public void OnImport()
680681
#if DEBUG
681682
}
682683
#endif
683-
684+
SurveyHelper.GetInstance().updateSurveyHelper(AzureSession.Instance.ExtendedProperties["InstallationId"]);
684685
var autoSaveEnabled = AzureSession.Instance.ARMContextSaveMode == ContextSaveMode.CurrentUser;
685686
var autosaveVariable = System.Environment.GetEnvironmentVariable(AzureProfileConstants.AzureAutosaveVariable);
686687

src/Accounts/Accounts/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
## Upcoming Release
2222
* Supported returning all subscriptions with specified name while using `Get-AzSubscription` with parameter `SubscriptionName`. [#19295]
23+
* Fixed null reference exception when cmdlet uses AzureRestOperation [#18104]
24+
* Updated survey message and settings
2325

2426
## Version 2.9.1
2527
* Implemented `SupportsShouldProcess` for `Invoke-AzRestMethod`

src/Accounts/Accounts/Feedback/OpenAzSurveyLinkCmdlet.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,44 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
16+
using Microsoft.Azure.Commands.Common.Authentication;
17+
using Microsoft.Azure.PowerShell.Common.Share.Survey;
1618
using Microsoft.WindowsAzure.Commands.Utilities.Common;
1719
using System;
1820
using System.Diagnostics;
1921
using System.Management.Automation;
2022
using System.Runtime.InteropServices;
23+
using System.IO;
24+
using Newtonsoft.Json;
2125

2226
namespace Microsoft.Azure.Commands.Profile.Survey
2327
{
2428
[Cmdlet(VerbsCommon.Open, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SurveyLink"), OutputType(typeof(void))]
2529
public class OpenAzSurveyLinkCmdlet : AzurePSCmdlet
2630
{
27-
private const string _surveyLinkFormat = "https://aka.ms/azpssurvey?Q_CHL=INTERCEPT";
28-
2931
protected override IAzureContext DefaultContext => null;
3032

3133
protected override string DataCollectionWarning => null;
3234

3335
public override void ExecuteCmdlet()
3436
{
35-
WriteInformation(new HostInformationMessage() { Message = $"Opening the default browser to {_surveyLinkFormat}" }, new string[] { "PSHOST" });
36-
OpenBrowser(_surveyLinkFormat);
37+
DateTime today = DateTime.UtcNow;
38+
AzureSession.Instance.ExtendedProperties.TryGetValue("InstallationId", out string InstallationId);
39+
String version= AzurePSCmdlet.AzVersion;
40+
int gapDays = -1;
41+
42+
ScheduleInfo scheduleInfo = SurveyHelper.GetInstance().GetScheduleInfo();
43+
DateTime LastPromptDate = Convert.ToDateTime(scheduleInfo?.LastPromptDate);
44+
if (LastPromptDate != DateTime.MinValue){
45+
TimeSpan ts = today.Subtract(LastPromptDate);
46+
gapDays = (int) ts.TotalDays;
47+
}
48+
String svLink = $"https://go.microsoft.com/fwlink/?linkid=2201766&ID={InstallationId}&v={version}&d={gapDays}";
49+
WriteInformation(new HostInformationMessage() { Message = $"Opening the default browser to {svLink}" }, new string[] { "PSHOST" });
50+
OpenBrowser(svLink);
3751
}
3852

53+
3954
private void OpenBrowser(string url)
4055
{
4156
try

src/Accounts/Accounts/help/Clear-AzConfig.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Clear-AzConfig [-Force] [-PassThru] [-AppliesTo <String>] [-Scope <ConfigScope>]
2222
```
2323
Clear-AzConfig [-PassThru] [-AppliesTo <String>] [-Scope <ConfigScope>]
2424
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [-DefaultSubscriptionForLogin]
25-
[-DisplayBreakingChangeWarning] [-EnableDataCollection] [<CommonParameters>]
25+
[-DisplayBreakingChangeWarning] [-DisplaySurveyMessage] [-EnableDataCollection] [<CommonParameters>]
2626
```
2727

2828
## DESCRIPTION
@@ -114,6 +114,21 @@ Accept pipeline input: False
114114
Accept wildcard characters: False
115115
```
116116
117+
### -DisplaySurveyMessage
118+
When enabled, you are prompted infrequently to participate in user experience surveys for Azure PowerShell.
119+
120+
```yaml
121+
Type: System.Management.Automation.SwitchParameter
122+
Parameter Sets: ClearByKey
123+
Aliases:
124+
125+
Required: False
126+
Position: Named
127+
Default value: None
128+
Accept pipeline input: False
129+
Accept wildcard characters: False
130+
```
131+
117132
### -EnableDataCollection
118133
When enabled, Azure PowerShell cmdlets send telemetry data to Microsoft to improve the customer experience.
119134
For more information, see our privacy statement: https://aka.ms/privacy

src/Accounts/Accounts/help/Get-AzConfig.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Gets the configs of Azure PowerShell.
1414

1515
```
1616
Get-AzConfig [-AppliesTo <String>] [-Scope <ConfigScope>] [-DefaultProfile <IAzureContextContainer>]
17-
[-DefaultSubscriptionForLogin] [-DisplayBreakingChangeWarning] [-EnableDataCollection] [<CommonParameters>]
17+
[-DefaultSubscriptionForLogin] [-DisplayBreakingChangeWarning] [-DisplaySurveyMessage] [-EnableDataCollection]
18+
[<CommonParameters>]
1819
```
1920

2021
## DESCRIPTION
@@ -125,6 +126,21 @@ Accept pipeline input: False
125126
Accept wildcard characters: False
126127
```
127128
129+
### -DisplaySurveyMessage
130+
When enabled, you are prompted infrequently to participate in user experience surveys for Azure PowerShell.
131+
132+
```yaml
133+
Type: System.Management.Automation.SwitchParameter
134+
Parameter Sets: (All)
135+
Aliases:
136+
137+
Required: False
138+
Position: Named
139+
Default value: None
140+
Accept pipeline input: False
141+
Accept wildcard characters: False
142+
```
143+
128144
### -EnableDataCollection
129145
When enabled, Azure PowerShell cmdlets send telemetry data to Microsoft to improve the customer experience.
130146
For more information, see our privacy statement: https://aka.ms/privacy

src/Accounts/Accounts/help/Update-AzConfig.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Updates the configs of Azure PowerShell.
1515
```
1616
Update-AzConfig [-AppliesTo <String>] [-Scope <ConfigScope>] [-DefaultProfile <IAzureContextContainer>]
1717
[-WhatIf] [-Confirm] [-DefaultSubscriptionForLogin <String>] [-DisplayBreakingChangeWarning <Boolean>]
18-
[-EnableDataCollection <Boolean>] [<CommonParameters>]
18+
[-DisplaySurveyMessage <Boolean>] [-EnableDataCollection <Boolean>] [<CommonParameters>]
1919
```
2020

2121
## DESCRIPTION
@@ -137,6 +137,21 @@ Accept pipeline input: True (ByPropertyName)
137137
Accept wildcard characters: False
138138
```
139139
140+
### -DisplaySurveyMessage
141+
When enabled, you are prompted infrequently to participate in user experience surveys for Azure PowerShell.
142+
143+
```yaml
144+
Type: System.Boolean
145+
Parameter Sets: (All)
146+
Aliases:
147+
148+
Required: False
149+
Position: Named
150+
Default value: None
151+
Accept pipeline input: True (ByPropertyName)
152+
Accept wildcard characters: False
153+
```
154+
140155
### -EnableDataCollection
141156
When enabled, Azure PowerShell cmdlets send telemetry data to Microsoft to improve the customer experience.
142157
For more information, see our privacy statement: https://aka.ms/privacy

src/Accounts/Authentication/Authentication.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<PsModuleName>Accounts</PsModuleName>

src/Accounts/Authentication/AzureSessionInitializer.cs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
using Microsoft.Azure.Commands.Common.Authentication.Properties;
2727
using Microsoft.Azure.Commands.Common.Authentication.Config;
2828
using Newtonsoft.Json;
29+
using Microsoft.Azure.Commands.Common.Authentication.Models;
30+
2931

3032
using TraceLevel = System.Diagnostics.TraceLevel;
3133
using System.Collections.Generic;
@@ -39,6 +41,7 @@ namespace Microsoft.Azure.Commands.Common.Authentication
3941
public static class AzureSessionInitializer
4042
{
4143
private const string ContextAutosaveSettingFileName = ContextAutosaveSettings.AutoSaveSettingsFile;
44+
4245
private const string DataCollectionFileName = AzurePSDataCollectionProfile.DefaultFileName;
4346

4447
/// <summary>
@@ -173,7 +176,14 @@ static ContextAutosaveSettings InitializeSessionSettings(IDataStore store, strin
173176
result.ContextDirectory = migrated ? profileDirectory : settings.ContextDirectory ?? result.ContextDirectory;
174177
result.Mode = settings.Mode;
175178
result.ContextFile = settings.ContextFile ?? result.ContextFile;
176-
if (migrated)
179+
result.Settings = settings.Settings;
180+
bool updateSettings = false;
181+
if (!settings.Settings.ContainsKey("InstallationId"))
182+
{
183+
result.Settings.Add("InstallationId", GetAzureCLIInstallationId(store) ?? Guid.NewGuid().ToString());
184+
updateSettings = true;
185+
}
186+
if (migrated || updateSettings)
177187
{
178188
string autoSavePath = Path.Combine(profileDirectory, settingsFile);
179189
store.WriteFile(autoSavePath, JsonConvert.SerializeObject(result));
@@ -188,6 +198,7 @@ static ContextAutosaveSettings InitializeSessionSettings(IDataStore store, strin
188198
}
189199
string autoSavePath = Path.Combine(profileDirectory, settingsFile);
190200
result.Mode = ContextSaveMode.CurrentUser;
201+
result.Settings.Add("InstallationId", GetAzureCLIInstallationId(store) ?? Guid.NewGuid().ToString());
191202
store.WriteFile(autoSavePath, JsonConvert.SerializeObject(result));
192203
}
193204
}
@@ -202,6 +213,24 @@ static ContextAutosaveSettings InitializeSessionSettings(IDataStore store, strin
202213
return result;
203214
}
204215

216+
private static String GetAzureCLIInstallationId(IDataStore store){
217+
if (store.FileExists(AzCLIProfileInfo.AzCLIProfileFile))
218+
{
219+
try
220+
{
221+
AzCLIProfileInfo azInfo = JsonConvert.DeserializeObject<AzCLIProfileInfo>(store.ReadFileAsText(AzCLIProfileInfo.AzCLIProfileFile));
222+
if (!string.IsNullOrEmpty(azInfo?.installationId))
223+
{
224+
return azInfo.installationId;
225+
}
226+
}
227+
catch (Exception)
228+
{
229+
TracingAdapter.Information($"[AzureSessionInitializer]: Cannot read Azure CLI profile from {AzCLIProfileInfo.AzCLIProfileFile}");
230+
}
231+
}
232+
return null;
233+
}
205234
static void InitializeDataCollection(IAzureSession session)
206235
{
207236
session.RegisterComponent(DataCollectionController.RegistryKey, () => DataCollectionController.Create(session));
@@ -239,7 +268,8 @@ static IAzureSession CreateInstance(IDataStore dataStore = null, Action<string>
239268
session.ARMProfileFile = autoSave.ContextFile;
240269
session.TokenCacheDirectory = autoSave.CacheDirectory;
241270
session.TokenCacheFile = autoSave.CacheFile;
242-
271+
autoSave.Settings.TryGetValue("InstallationId", out string installationId);
272+
session.ExtendedProperties.Add("InstallationId", installationId);
243273
InitializeConfigs(session, profilePath, writeWarning);
244274
InitializeDataCollection(session);
245275
session.RegisterComponent(HttpClientOperationsFactory.Name, () => HttpClientOperationsFactory.Create());

src/Accounts/Authentication/Config/ConfigInitializer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ private void RegisterConfigs(IConfigManager configManager)
191191
AzurePSDataCollectionProfile.EnvironmentVariableName,
192192
new[] { AppliesTo.Az }));
193193

194-
// configs with their own types
195-
// configManager.RegisterConfig(new EnableInterceptSurveyConfig()); // todo: uncomment after improvements are made to survey
194+
configManager.RegisterConfig(new EnableInterceptSurveyConfig());
196195
configManager.RegisterConfig(new DisplayBreakingChangeWarningsConfig());
197196
}
198197
}

src/Accounts/Authentication/Config/Definitions/EnableInterceptSurveyConfig.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@ internal class EnableInterceptSurveyConfig : TypedConfig<bool>
3636

3737
public override string ParseFromEnvironmentVariables(IReadOnlyDictionary<string, string> environmentVariables)
3838
{
39-
if (environmentVariables.TryGetValue("Azure_PS_Intercept_Survey", out string configString))
39+
environmentVariables.TryGetValue("Azure_PS_Intercept_Survey", out string oldConfigString);
40+
environmentVariables.TryGetValue("AzSurveyMessage", out string configString);
41+
42+
if (string.Equals(Boolean.FalseString, oldConfigString, StringComparison.OrdinalIgnoreCase) || string.Equals(Boolean.FalseString, configString, StringComparison.OrdinalIgnoreCase))
4043
{
41-
if ("Disabled".Equals(configString, StringComparison.OrdinalIgnoreCase)
42-
|| "False".Equals(configString, StringComparison.OrdinalIgnoreCase))
43-
{
44-
return false.ToString();
45-
}
44+
return Boolean.FalseString;
4645
}
47-
return null;
46+
return string.Empty;
4847
}
4948
}
5049
}

0 commit comments

Comments
 (0)