11using Microsoft . Azure . PowerShell . Common . Config ;
22using Microsoft . WindowsAzure . Commands . Common ;
3+ using Microsoft . WindowsAzure . Commands . Common . Properties ;
4+ using Microsoft . WindowsAzure . Commands . Utilities . Common ;
35using Newtonsoft . Json ;
46using System ;
57using System . Collections . Generic ;
810using System . Management . Automation ;
911using 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