Skip to content

Commit 7984785

Browse files
authored
check null reference cases for version upgrade notification (#401)
1 parent dae2d46 commit 7984785

File tree

4 files changed

+56
-16
lines changed

4 files changed

+56
-16
lines changed

src/Common/AzurePSCmdlet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
1717
using Microsoft.Azure.PowerShell.Common.Config;
1818
using Microsoft.Azure.PowerShell.Common.Share.Survey;
19-
using Microsoft.Azure.PowerShell.Common.Share.UpgradeNotification;
19+
using Microsoft.Azure.PowerShell.Common.UpgradeNotification;
2020
using Microsoft.Azure.ServiceManagement.Common.Models;
2121
using Microsoft.WindowsAzure.Commands.Common;
2222
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;

src/Common/Properties/Resources.Designer.cs

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Common/Properties/Resources.resx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,4 +1742,15 @@ Note : Go to {0} for steps to suppress this breaking change warning, and other i
17421742
<data name="PreviewCmdletETAMessage" xml:space="preserve">
17431743
<value> The estimated generally available date is '{0}'.</value>
17441744
</data>
1745+
<data name="BreakingChangesMessage" xml:space="preserve">
1746+
<value>There will be breaking changes from {0} to {1}. Open {2} and check the details.</value>
1747+
</data>
1748+
<data name="MigrationGuideLink" xml:space="preserve">
1749+
<value>https://go.microsoft.com/fwlink/?linkid=2241373</value>
1750+
</data>
1751+
<data name="VersionUpgradeMessage" xml:space="preserve">
1752+
<value>You're using {0} version {1}. The latest version of {0} is {2}. Upgrade your Az modules using the following commands:
1753+
{3} {4} -WhatIf -- Simulate updating your Az modules.
1754+
{3} {4} -- Update your Az modules.</value>
1755+
</data>
17451756
</root>

src/Common/UpgradeNotification/UpgradeNotificationHelper.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Microsoft.Azure.PowerShell.Common.Config;
22
using Microsoft.WindowsAzure.Commands.Common;
3+
using Microsoft.WindowsAzure.Commands.Common.Properties;
4+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
35
using Newtonsoft.Json;
46
using System;
57
using System.Collections.Generic;
@@ -8,11 +10,10 @@
810
using System.Management.Automation;
911
using System.Threading;
1012

11-
namespace Microsoft.Azure.PowerShell.Common.Share.UpgradeNotification
13+
namespace Microsoft.Azure.PowerShell.Common.UpgradeNotification
1214
{
1315
public class UpgradeNotificationHelper
1416
{
15-
private const string AZPSMigrationGuideLink = "https://go.microsoft.com/fwlink/?linkid=2241373";
1617
private const string FrequencyKeyForUpgradeNotification = "VersionUpgradeNotification";
1718
private static TimeSpan FrequencyTimeSpanForUpgradeNotification = TimeSpan.FromDays(30);
1819

@@ -55,14 +56,18 @@ public static UpgradeNotificationHelper GetInstance()
5556
return _instance;
5657
}
5758

58-
public void WriteWarningMessageForVersionUpgrade(Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet cmdlet, AzurePSQoSEvent _qosEvent, IConfigManager configManager, IFrequencyService frequencyService) {
59-
_qosEvent.HigherVersionsChecked = false;
60-
_qosEvent.UpgradeNotificationPrompted = false;
61-
59+
public void WriteWarningMessageForVersionUpgrade(AzurePSCmdlet cmdlet, AzurePSQoSEvent _qosEvent, IConfigManager configManager, IFrequencyService frequencyService) {
60+
// skip if it's the exceptional case.
61+
if (cmdlet == null || _qosEvent == null || configManager == null || frequencyService == null) {
62+
return;
63+
}
6264
try
6365
{
66+
_qosEvent.HigherVersionsChecked = false;
67+
_qosEvent.UpgradeNotificationPrompted = false;
68+
6469
//disabled by az config, skip
65-
if (configManager!=null&& configManager.GetConfigValue<bool>(ConfigKeysForCommon.CheckForUpgrade).Equals(false))
70+
if (configManager.GetConfigValue<bool>(ConfigKeysForCommon.CheckForUpgrade).Equals(false))
6671
{
6772
return;
6873
}
@@ -73,10 +78,6 @@ public void WriteWarningMessageForVersionUpgrade(Microsoft.WindowsAzure.Commands
7378
return;
7479
}
7580

76-
//register verion check and upgrade notification in frequency service
77-
if (frequencyService == null) {
78-
return;
79-
}
8081
frequencyService.Register(FrequencyKeyForUpgradeCheck, FrequencyTimeSpanForUpgradeCheck);
8182
frequencyService.Register(FrequencyKeyForUpgradeNotification, FrequencyTimeSpanForUpgradeNotification);
8283

@@ -119,12 +120,11 @@ public void WriteWarningMessageForVersionUpgrade(Microsoft.WindowsAzure.Commands
119120

120121
string latestModuleVersion = GetModuleLatestVersion(checkModuleName);
121122
string updateModuleCmdletName = GetCmdletForUpdateModule();
122-
string warningMsg = $"You're using {checkModuleName} version {checkModuleCurrentVersion}. The latest version of {checkModuleName} is {latestModuleVersion}. Upgrade your Az modules using the following commands:{Environment.NewLine}";
123-
warningMsg += $" {updateModuleCmdletName} {upgradeModuleNames} -WhatIf -- Simulate updating your Az modules.{Environment.NewLine}";
124-
warningMsg += $" {updateModuleCmdletName} {upgradeModuleNames} -- Update your Az modules.{Environment.NewLine}";
123+
string warningMsg = string.Format(Resources.VersionUpgradeMessage, checkModuleName, checkModuleCurrentVersion, latestModuleVersion, updateModuleCmdletName, upgradeModuleNames);
125124
if ("Az".Equals(checkModuleName) && GetInstance().HasHigherMajorVersion(checkModuleName, checkModuleCurrentVersion))
126125
{
127-
warningMsg += $"There will be breaking changes from {checkModuleCurrentVersion} to {latestModuleVersion}. Open {AZPSMigrationGuideLink} and check the details.{Environment.NewLine}";
126+
warningMsg += Environment.NewLine;
127+
warningMsg += string.Format(Resources.BreakingChangesMessage, checkModuleCurrentVersion, latestModuleVersion, Resources.MigrationGuideLink);
128128
}
129129
cmdlet.WriteWarning(warningMsg);
130130
});

0 commit comments

Comments
 (0)