Skip to content

Commit 8c8b3a0

Browse files
authored
Show sign-in announcements less often (#25613)
1 parent 5cd1e81 commit 8c8b3a0

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/Accounts/Accounts/Account/ConnectAzureRmAccount.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ public override void ExecuteCmdlet()
537537
shouldPopulateContextList = false;
538538
}
539539

540-
profileClient.WarningLog = (message) => _tasks.Enqueue(new Task(() => this.WriteWarning(message)));
540+
profileClient.WarningLog = (message) => _tasks.Enqueue(new Task(() => this.WriteWarning(message)));
541541
profileClient.InteractiveInformationLog = (message) => _tasks.Enqueue(new Task(() => WriteInteractiveInformation(message)));
542542
profileClient.DebugLog = (message) => _tasks.Enqueue(new Task(() => this.WriteDebugWithTimestamp(message)));
543543
profileClient.PromptAndReadLine = (message) =>
@@ -603,8 +603,28 @@ public override void ExecuteCmdlet()
603603
}
604604
});
605605

606-
WriteInteractiveInformation($"{Resources.AnnouncementsHeader}{System.Environment.NewLine}{Resources.AnnouncementsMessage}{System.Environment.NewLine}");
607-
WriteInteractiveInformation($"{Resources.ReportIssue}{System.Environment.NewLine}");
606+
WriteAnnouncementsPeriodically();
607+
}
608+
}
609+
610+
private void WriteAnnouncementsPeriodically()
611+
{
612+
if (ParameterSetName != UserParameterSet)
613+
{
614+
// Write-Host may block automation scenarios
615+
return;
616+
}
617+
const string AnnouncementsFeatureName = "SignInAnnouncements";
618+
TimeSpan AnnouncementsInterval = TimeSpan.FromDays(7);
619+
if (AzureSession.Instance.TryGetComponent<IFrequencyService>(nameof(IFrequencyService), out var frequency))
620+
{
621+
frequency.Register(AnnouncementsFeatureName, AnnouncementsInterval);
622+
// WriteInformation can't fail, so the second parameter always returns true
623+
frequency.TryRun(AnnouncementsFeatureName, () => true, () =>
624+
{
625+
WriteInformation($"{Resources.AnnouncementsHeader}{System.Environment.NewLine}{Resources.AnnouncementsMessage}{System.Environment.NewLine}", false);
626+
WriteInformation($"{Resources.ReportIssue}{System.Environment.NewLine}", false);
627+
});
608628
}
609629
}
610630

@@ -878,7 +898,7 @@ private void AddConfigTelemetry()
878898
AzConfigReader.GetAzConfig(ConfigKeys.EnableLoginByWam, true).ToString());
879899
}
880900
}
881-
catch(Exception ex)
901+
catch (Exception ex)
882902
{
883903
WriteDebug(string.Format("Failed to add telemtry for config as {0}", ex.Message));
884904
}

src/Accounts/Accounts/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Reduced the frequency of displaying sign-in announcement messages.
2223
* Upgraded Azure.Core to 1.41.0 to include the fix for `BearerTokenAuthenticationPolicy`
2324
* Removed the informational table about selected context to avoid duplication with output table.
2425

0 commit comments

Comments
 (0)