Skip to content

Commit 4b75617

Browse files
Made PromptAsync public
1 parent c01290f commit 4b75617

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

demo/VSSDK.TestExtension/ToolWindows/RunnerWindowControl.xaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ private void btnHide_Click(object sender, RoutedEventArgs e)
3737

3838
private async Task ShowMessageAsync()
3939
{
40+
var rating = new RatingPrompt("SteveCadwallader.CodeMaidVS2022", Vsix.Name);
41+
await rating.PromptAsync();
42+
4043
await VS.StatusBar.ShowMessageAsync("Test");
41-
string text = await VS.StatusBar.GetMessageAsync();
44+
string? text = await VS.StatusBar.GetMessageAsync();
4245
await VS.StatusBar.ShowMessageAsync(text + " OK");
4346

4447
Exception ex = new Exception(nameof(TestExtension));

demo/VSSDK.TestExtension/VSSDK.TestExtension.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565
<Compile Include="Options\General.cs" />
6666
<Compile Include="Properties\AssemblyInfo.cs" />
6767
<Compile Include="SolutionExplorer\VsixManifestFilterProvider.cs" />
68+
<Compile Include="source.extension.cs">
69+
<AutoGen>True</AutoGen>
70+
<DesignTime>True</DesignTime>
71+
<DependentUpon>source.extension.vsixmanifest</DependentUpon>
72+
</Compile>
6873
<Compile Include="ToolWindows\MultiInstanceWindow.cs" />
6974
<Compile Include="ToolWindows\MultiInstanceWindowControl.xaml.cs">
7075
<DependentUpon>MultiInstanceWindowControl.xaml</DependentUpon>
@@ -97,6 +102,8 @@
97102
<ItemGroup>
98103
<None Include="source.extension.vsixmanifest">
99104
<SubType>Designer</SubType>
105+
<Generator>VsixManifestGenerator</Generator>
106+
<LastGenOutput>source.extension.cs</LastGenOutput>
100107
</None>
101108
</ItemGroup>
102109
<ItemGroup>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// ------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This file was generated by VSIX Synchronizer
4+
// </auto-generated>
5+
// ------------------------------------------------------------------------------
6+
namespace TestExtension
7+
{
8+
internal sealed partial class Vsix
9+
{
10+
public const string Id = "VSSDK.TestExtension.5a9a059d-5738-41dc-9075-250890b4ef6f";
11+
public const string Name = "VSSDK.TestExtension";
12+
public const string Description = @"Empty VSIX Project.";
13+
public const string Language = "en-US";
14+
public const string Version = "1.0";
15+
public const string Author = "Mads Kristensen";
16+
public const string Tags = "";
17+
}
18+
}

src/toolkit/Community.VisualStudio.Toolkit.Shared/Notifications/RatingPrompt.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public class RatingPrompt
2929
/// <param name="requestsBeforePrompt">Indicates how many successful requests it takes before the user is prompted to rate.</param>
3030
/// <exception cref="ArgumentNullException">None of the parameters passed in can be null.</exception>
3131
/// <exception cref="ArgumentException">The Marketplace ID has to be valid so an absolute URI can be constructed.</exception>
32-
public RatingPrompt(string marketplaceId, string extensionName, IRatingConfig config, int requestsBeforePrompt = 5)
32+
public RatingPrompt(string marketplaceId, string extensionName, IRatingConfig? config = null, int requestsBeforePrompt = 5)
3333
{
3434
MarketplaceId = marketplaceId ?? throw new ArgumentNullException(nameof(marketplaceId));
3535
ExtensionName = extensionName ?? throw new ArgumentNullException(nameof(extensionName));
36-
Config = config ?? throw new ArgumentNullException(nameof(config));
36+
Config = config;
3737
RequestsBeforePrompt = requestsBeforePrompt;
3838

3939
string ratingUrl = string.Format(CultureInfo.InvariantCulture, _urlFormat, MarketplaceId);
@@ -59,7 +59,7 @@ public RatingPrompt(string marketplaceId, string extensionName, IRatingConfig co
5959
/// <summary>
6060
/// The configuration/options object used to store the information related to the rating prompt.
6161
/// </summary>
62-
public virtual IRatingConfig Config { get; }
62+
public virtual IRatingConfig? Config { get; }
6363

6464
/// <summary>
6565
/// The Marketplace URL the users are taken to when prompted.
@@ -77,6 +77,11 @@ public RatingPrompt(string marketplaceId, string extensionName, IRatingConfig co
7777
/// </summary>
7878
public virtual void RegisterSuccessfulUsage()
7979
{
80+
if (Config == null)
81+
{
82+
throw new NullReferenceException("The Config property has not been set.");
83+
}
84+
8085
if (_hasAlreadyRequested.TryAdd(MarketplaceId, true) && Config.RatingRequests < RequestsBeforePrompt)
8186
{
8287
IncrementAsync().FireAndForget();
@@ -89,15 +94,19 @@ public virtual void RegisterSuccessfulUsage()
8994
public virtual async Task ResetAsync()
9095
{
9196
_hasAlreadyRequested.TryRemove(MarketplaceId, out _);
92-
Config.RatingRequests = 0;
93-
await Config.SaveAsync();
97+
98+
if (Config != null)
99+
{
100+
Config.RatingRequests = 0;
101+
await Config.SaveAsync();
102+
}
94103
}
95104

96105
private async Task IncrementAsync()
97106
{
98107
await Task.Yield(); // Yield to allow any shutdown procedure to continue
99108

100-
if (VsShellUtilities.ShellIsShuttingDown)
109+
if (VsShellUtilities.ShellIsShuttingDown || Config == null)
101110
{
102111
return;
103112
}
@@ -111,7 +120,10 @@ private async Task IncrementAsync()
111120
}
112121
}
113122

114-
private async Task PromptAsync()
123+
/// <summary>
124+
/// Prompts the user to rate the extension.
125+
/// </summary>
126+
public async Task PromptAsync()
115127
{
116128
InfoBar? infoBar = await CreateInfoBarAsync();
117129

0 commit comments

Comments
 (0)