|
8 | 8 | using System.Globalization; |
9 | 9 | using System.Linq; |
10 | 10 | using System.Net; |
| 11 | +using System.Text.Json; |
11 | 12 | using System.Threading; |
12 | 13 | using System.Threading.Tasks; |
13 | | -using Newtonsoft.Json.Linq; |
14 | 14 | using NuGet.Protocol.Core.Types; |
| 15 | +using NuGet.Protocol.Model; |
| 16 | +using NuGet.Protocol.Utility; |
15 | 17 | using NuGet.Versioning; |
16 | 18 |
|
17 | 19 | namespace NuGet.Protocol |
@@ -55,32 +57,29 @@ public override async Task<IEnumerable<string>> IdStartsWith( |
55 | 57 | Common.ILogger logger = log ?? Common.NullLogger.Instance; |
56 | 58 |
|
57 | 59 | var queryUri = queryUrl.Uri; |
58 | | - var results = await _client.GetJObjectAsync( |
| 60 | + AutoCompleteModel results = await _client.ProcessStreamAsync( |
59 | 61 | new HttpSourceRequest(queryUri, logger), |
| 62 | + async stream => |
| 63 | + { |
| 64 | + if (stream == null) |
| 65 | + { |
| 66 | + return null; |
| 67 | + } |
| 68 | + |
| 69 | + return await JsonSerializer.DeserializeAsync(stream, JsonContext.Default.AutoCompleteModel, token); |
| 70 | + }, |
60 | 71 | logger, |
61 | 72 | token); |
| 73 | + |
62 | 74 | token.ThrowIfCancellationRequested(); |
63 | | - if (results == null) |
64 | | - { |
65 | | - return Enumerable.Empty<string>(); |
66 | | - } |
67 | | - var data = results.Value<JArray>("data"); |
68 | | - if (data == null) |
69 | | - { |
70 | | - return Enumerable.Empty<string>(); |
71 | | - } |
72 | 75 |
|
73 | | - // Resolve all the objects |
74 | | - var outputs = new List<string>(); |
75 | | - foreach (var result in data) |
| 76 | + if (results?.Data == null) |
76 | 77 | { |
77 | | - if (result != null) |
78 | | - { |
79 | | - outputs.Add(result.ToString()); |
80 | | - } |
| 78 | + return Enumerable.Empty<string>(); |
81 | 79 | } |
82 | 80 |
|
83 | | - return outputs.Where(item => item.StartsWith(packageIdPrefix, StringComparison.OrdinalIgnoreCase)); |
| 81 | + return results.Data |
| 82 | + .Where(item => item != null && item.StartsWith(packageIdPrefix, StringComparison.OrdinalIgnoreCase)); |
84 | 83 | } |
85 | 84 |
|
86 | 85 | public override async Task<IEnumerable<NuGetVersion>> VersionStartsWith( |
|
0 commit comments