|
1 | 1 | @page "/"
|
2 |
| -@using Microsoft.Extensions.Http |
| 2 | +@using System.Net |
| 3 | +@using System.Text.RegularExpressions |
3 | 4 | @inject IHttpClientFactory ClientFactory
|
4 | 5 |
|
5 |
| -<div> |
| 6 | +<div style="margin-bottom:15px"> |
6 | 7 | <h1>Namespace/Member</h1>
|
7 |
| - |
8 |
| - <label for="searchText"></label> |
9 |
| - <input id="searchText" style="width:300px" @bind="searchText" class="form-control" /> |
10 |
| - <button type="button" @onclick="GetSearchResults" class="btn btn-default">Search</button> |
11 |
| - <button type="button" class="btn btn-default" onclick="document.getElementById('searchText').value=''">Clear</button> |
| 8 | + <input id="searchText" @bind="searchText" class="form-control" aria-label="Search Text" /> |
| 9 | + <button type="button" @onclick="GetSearchResults" class="btn btn-primary">Search</button> |
| 10 | + <button type="button" class="btn btn-secondary" onclick="document.getElementById('searchText').value=''">Clear</button> |
12 | 11 | </div>
|
13 | 12 |
|
14 |
| - |
15 | 13 | <h1>Links</h1>
|
16 | 14 |
|
17 | 15 | @if (SearchResultItems?.Results?.Count() > 0)
|
|
21 | 19 | {
|
22 | 20 | <li style="margin-bottom:5px">
|
23 | 21 | <div style="font-size:1.4em;color:green;font-weight:bold">@result.Data.DisplayName</div>
|
24 |
| - <div><b>Item Type:</b> @result.Data.ItemType <b>Item Kind:</b> @result.Data.ItemKind</div> |
| 22 | + <div><b>Item Type:</b> @result.Data.ItemType</div> |
25 | 23 | <div><b>Description:</b> @result.Data.Description</div>
|
26 |
| - |
27 |
| - @if (result.Data.ItemKind == "Constructor") |
28 |
| - { |
29 |
| - |
30 |
| - <div><input style="margin-bottom:3px;width:100%" id="m@(result.Index)0" value="[LINK_TEXT](@result.Data.Link)"></div> |
31 |
| - <div><input style="margin-bottom:3px;width:100%" id="m@(result.Index)1" value="@result.Data.Link"></div> |
32 |
| - <div> |
33 |
| - <button type="button" class="btn" onclick=@("copyToClipboard('m" + result.Index + "')0")>Copy (Custom Link Text)</button> |
34 |
| - <button type="button" class="btn" onclick=@($"copyToClipboard('m" + result.Index + "')1")>Copy (Member Only)</button> |
35 |
| - </div> |
36 |
| - } |
37 |
| - else |
38 |
| - { |
39 |
| - <div><input style="margin-bottom:3px;width:100%" id="m@(result.Index)0" value="<xref:@result.Data.Link>"></div> |
40 |
| - <div><input style="margin-bottom:3px;width:100%" id="m@(result.Index)1" value="<xref:@result.Data.Link?displayProperty=fullName>"></div> |
41 |
| - <div><input style="margin-bottom:3px;width:100%" id="m@(result.Index)2" value="[LINK_TEXT](xref:@result.Data.Link)"></div> |
42 |
| - <div><input style="margin-bottom:3px;width:100%" id="m@(result.Index)3" value="xref:@result.Data.Link"></div> |
43 |
| - <div> |
44 |
| - <button type="button" class="btn" onclick=@($"copyToClipboard('m" + result.Index + "0')")>Copy</button> |
45 |
| - <button type="button" class="btn" onclick=@($"copyToClipboard('m" + result.Index + "1')")>Copy (Full Name)</button> |
46 |
| - <button type="button" class="btn" onclick=@($"copyToClipboard('m" + result.Index + "2')")>Copy (Custom Link Text)</button> |
47 |
| - <button type="button" class="btn" onclick=@($"copyToClipboard('m" + result.Index + "3')")>Copy (Member Only)</button> |
48 |
| - </div> |
49 |
| - } |
| 24 | + <div><input id="m@(result.Index)0" value="<xref:@result.Data.Link>"></div> |
| 25 | + <div><input id="m@(result.Index)1" value="<xref:@result.Data.Link?displayProperty=fullName>"></div> |
| 26 | + <div><input id="m@(result.Index)2" value="<xref:@result.Data.Link?displayProperty=nameWithType>"></div> |
| 27 | + <div><input id="m@(result.Index)3" value="[LINK_TEXT](xref:@result.Data.Link)"></div> |
| 28 | + <div><input id="m@(result.Index)4" value="xref:@result.Data.Link"></div> |
| 29 | + <div> |
| 30 | + <button type="button" class="btn btn-primary" onclick=@($"copyToClipboard('m{result.Index}0')")>Copy</button> |
| 31 | + <button type="button" class="btn btn-secondary" onclick=@($"copyToClipboard('m{result.Index}1')")>Copy (Full Name)</button> |
| 32 | + <button type="button" class="btn btn-secondary" onclick=@($"copyToClipboard('m{result.Index}2')")>Copy (Name with Type)</button> |
| 33 | + <button type="button" class="btn btn-secondary" onclick=@($"copyToClipboard('m{result.Index}3')")>Copy (Custom Link Text)</button> |
| 34 | + <button type="button" class="btn btn-secondary" onclick=@($"copyToClipboard('m{result.Index}4')")>Copy (Member Only)</button> |
| 35 | + </div> |
50 | 36 | </li>
|
51 | 37 | }
|
52 | 38 | </ol>
|
|
56 | 42 |
|
57 | 43 | @code {
|
58 | 44 | private string? searchText;
|
59 |
| - |
60 | 45 | private SearchResults? SearchResultItems { get; set; }
|
61 |
| - |
62 | 46 | public string? message;
|
63 | 47 |
|
64 | 48 | public async Task GetSearchResults()
|
65 | 49 | {
|
66 |
| - var client = ClientFactory.CreateClient("APIClient"); |
| 50 | + message = string.Empty; |
| 51 | + var apiClient = ClientFactory.CreateClient("APIClient"); |
67 | 52 |
|
68 |
| - if (searchText == null) |
| 53 | + if (string.IsNullOrEmpty(searchText) || apiClient == null) |
69 | 54 | {
|
70 | 55 | return;
|
71 | 56 | }
|
72 | 57 |
|
73 |
| - SearchResultItems = await client.GetFromJsonAsync<SearchResults>($"api/apibrowser/dotnet/search?api-version=0.2&search={searchText}"); |
74 |
| - |
75 |
| - Console.WriteLine("HERE 1 !!!!!!!!!!!!"); |
| 58 | + SearchResultItems = await apiClient.GetFromJsonAsync<SearchResults>($"api/apibrowser/dotnet/search?api-version=0.2&search={searchText}"); |
76 | 59 |
|
77 | 60 | if (SearchResultItems?.Results != null)
|
78 | 61 | {
|
79 | 62 | foreach (var result in SearchResultItems.Results)
|
80 | 63 | {
|
81 |
| - if (result.ItemType == "Constructor") |
82 |
| - { |
83 |
| - result.Link = "/dotnet/api/" + result?.DisplayName?.Substring(0, result.DisplayName.Length - 2).ToLowerInvariant() + ".-ctor"; |
84 |
| - } |
85 |
| - else if (result.ItemType == "Method") |
86 |
| - { |
87 |
| - message = $"DisplayName: {result.DisplayName} Length: {result.DisplayName?.Length}"; |
88 |
| - |
89 |
| - result.Link = result?.DisplayName?.Substring(0, result.DisplayName.Length - 2) + "%2A"; |
90 |
| - } |
91 |
| - else |
92 |
| - { |
93 |
| - result.Link = result.DisplayName; |
94 |
| - } |
| 64 | + var client = ClientFactory.CreateClient(); |
| 65 | + |
| 66 | + var urlEncodedRequestUrl = WebUtility.UrlEncode($"https://learn.microsoft.com/en-us{result.Url}?view=aspnetcore-9.0"); |
| 67 | + var request = new HttpRequestMessage(HttpMethod.Get, $"https://corsproxy.io/?{urlEncodedRequestUrl}"); |
| 68 | + |
| 69 | + var apiBrowserPage = await client.SendAsync(request); |
| 70 | + |
| 71 | + var metaTag = new Regex("<meta name=\"ms.assetid\" content=\"(.+?)\" />"); |
| 72 | + var match = metaTag.Match(await apiBrowserPage.Content.ReadAsStringAsync()).Groups[1].Value; |
| 73 | + |
| 74 | + result.Link = match.Replace("*", "%2A").Replace("`", "%60"); |
95 | 75 | }
|
96 | 76 | }
|
97 | 77 | else
|
98 | 78 | {
|
99 | 79 | message = "Request failed.";
|
100 | 80 | }
|
101 | 81 |
|
102 |
| - Console.WriteLine("HERE 2 !!!!!!!!!!!!"); |
103 |
| - |
104 | 82 | searchText = string.Empty;
|
105 |
| - message = string.Empty; |
106 | 83 |
|
107 | 84 | StateHasChanged();
|
108 |
| - |
109 |
| - Console.WriteLine("HERE 3 !!!!!!!!!!!!"); |
110 |
| - |
111 |
| - |
112 | 85 | }
|
113 | 86 |
|
114 | 87 | public class SearchResults
|
|
119 | 92 | public class Result
|
120 | 93 | {
|
121 | 94 | public string? DisplayName { get; set; }
|
| 95 | + public string? Url { get; set; } |
122 | 96 | public string? ItemType { get; set; }
|
123 |
| - public string? ItemKind { get; set; } |
124 | 97 | public string? Description { get; set; }
|
125 | 98 | public string? Link { get; set; }
|
126 |
| - public string? Id1 { get; set; } |
127 |
| - public string? Id2 { get; set; } |
128 |
| - public string? Id3 { get; set; } |
129 | 99 | }
|
130 | 100 | }
|
0 commit comments