Skip to content

Commit 57133e1

Browse files
committed
doc: 更新注释文档
1 parent 013e063 commit 57133e1

5 files changed

Lines changed: 188 additions & 145 deletions

File tree

src/components/BootstrapBlazor.JuHeIpLocatorProvider/Extensions/ServiceCollectionExtensions.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
1+
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

@@ -7,12 +7,14 @@
77
namespace Microsoft.Extensions.DependencyInjection;
88

99
/// <summary>
10-
/// BootstrapBlazor 服务扩展类
10+
/// <para lang="zh">BootstrapBlazor 服务扩展类</para>
11+
/// <para lang="en">BootstrapBlazor service extensions</para>
1112
/// </summary>
12-
public static class BootstrapBlazoJuHeIpLocatorExtensions
13+
public static class BootstrapBlazorJuHeIpLocatorExtensions
1314
{
1415
/// <summary>
15-
/// 添加 AzureOpenAIService 服务
16+
/// <para lang="zh">添加聚合搜索引擎 IP 定位器服务</para>
17+
/// <para lang="en">Adds JuHe IP locator service</para>
1618
/// </summary>
1719
/// <param name="services"></param>
1820
public static IServiceCollection AddBootstrapBlazorJuHeIpLocatorService(this IServiceCollection services)
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
55

66
namespace BootstrapBlazor.Components;
77

88
/// <summary>
9-
/// 聚合搜索引擎 IP 定位器配置类
9+
/// <para lang="zh">聚合搜索引擎 IP 定位器配置类</para>
10+
/// <para lang="en">JuHe IP locator options</para>
1011
/// </summary>
1112
class JuHeIpLocatorOptions
1213
{
1314
/// <summary>
14-
/// 聚合搜索引擎 IP 定位器 AppKey
15+
/// <para lang="zh">获得/设置 聚合搜索引擎 IP 定位器 AppKey</para>
16+
/// <para lang="en">Gets or sets the JuHe IP locator AppKey</para>
1517
/// </summary>
16-
public string Key { get; set; } = "";
18+
public string? Key { get; set; }
1719

1820
/// <summary>
19-
/// 聚合搜索引擎 IP 定位器请求地址
21+
/// <para lang="zh">获得/设置 聚合搜索引擎 IP 定位器请求地址</para>
22+
/// <para lang="en">Gets or sets the JuHe IP locator request URL</para>
2023
/// </summary>
21-
public string Url { get; set; } = "http://apis.juhe.cn/ip/ipNew";
24+
public string? Url { get; set; }
2225

2326
/// <summary>
24-
/// 聚合搜索引擎 IP 定位器请求超时时间 默认 5 秒
27+
/// <para lang="zh">获得/设置 聚合搜索引擎 IP 定位器请求超时时间 默认 5 秒</para>
28+
/// <para lang="en">Gets or sets the JuHe IP locator request timeout, default is 5 seconds</para>
2529
/// </summary>
2630
public TimeSpan Timeout { get; set; }
2731
}
Lines changed: 9 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
1+
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

5-
using Microsoft.Extensions.Configuration;
65
using Microsoft.Extensions.Logging;
76
using Microsoft.Extensions.Options;
87
using System.Net.Http.Json;
9-
using System.Text.Json.Serialization;
108

119
namespace BootstrapBlazor.Components;
1210

1311
/// <summary>
14-
/// 聚合搜索引擎 IP 定位器
12+
/// <para lang="zh">聚合搜索引擎 IP 定位器</para>
13+
/// <para lang="en">JuHe IP locator provider</para>
1514
/// </summary>
1615
/// <param name="httpClientFactory"></param>
1716
/// <param name="options"></param>
@@ -26,6 +25,8 @@ class JuHeIpLocatorProvider(IHttpClientFactory httpClientFactory,
2625

2726
private JuHeIpLocatorOptions? _options;
2827

28+
private const string Url = "http://apis.juhe.cn/ip/ipNewV3";
29+
2930
/// <summary>
3031
/// <inheritdoc/>
3132
/// </summary>
@@ -60,7 +61,7 @@ private JuHeIpLocatorOptions GetOptions()
6061
}
6162
if (string.IsNullOrEmpty(options.Url))
6263
{
63-
options.Url = "http://apis.juhe.cn/ip/ipNewV3";
64+
options.Url = Url;
6465
}
6566
}
6667
catch (Exception ex)
@@ -71,145 +72,19 @@ private JuHeIpLocatorOptions GetOptions()
7172
}
7273

7374
/// <summary>
74-
/// 请求获得地理位置接口方法
75+
/// <para lang="zh">请求获得地理位置接口方法</para>
76+
/// <para lang="en">Fetches the geolocation data</para>
7577
/// </summary>
7678
/// <param name="url"></param>
7779
/// <param name="client"></param>
7880
/// <param name="token"></param>
79-
/// <returns></returns>
8081
protected virtual async Task<string?> Fetch(string url, HttpClient client, CancellationToken token)
8182
{
82-
var result = await client.GetFromJsonAsync<LocationResult>(url, token);
83+
var result = await client.GetFromJsonAsync<JuHeLocationResult>(url, token);
8384
if (result != null && result.ErrorCode != 0)
8485
{
8586
logger.LogError("ErrorCode: {ErrorCode} Reason: {Reason}", result.ErrorCode, result.Reason);
8687
}
8788
return result?.ToString();
8889
}
89-
90-
/// <summary>
91-
/// LocationResult 结构体
92-
/// </summary>
93-
class LocationResult
94-
{
95-
/// <summary>
96-
/// 获得/设置 结果状态返回码 为 查询成功 时通讯正常
97-
/// </summary>
98-
public string? Reason { get; set; }
99-
100-
/// <summary>
101-
/// 获得/设置 错误码
102-
/// </summary>
103-
[JsonPropertyName("error_code")]
104-
public int ErrorCode { get; set; }
105-
106-
/// <summary>
107-
/// 获得/设置 定位信息
108-
/// </summary>
109-
public LocationData? Result { get; set; }
110-
111-
/// <summary>
112-
/// <inheritdoc/>
113-
/// </summary>
114-
/// <returns></returns>
115-
public override string? ToString()
116-
{
117-
string? ret = null;
118-
if (ErrorCode == 0)
119-
{
120-
ret = Result?.Country == "中国"
121-
? $"{Result?.Prov}{Result?.City}{Result?.District} {Result?.Isp}"
122-
: $"{Result?.Continent} {Result?.Country} {Result?.City}";
123-
}
124-
return ret;
125-
}
126-
}
127-
128-
class LocationData
129-
{
130-
/// <summary>
131-
/// 获得/设置 州
132-
/// </summary>
133-
public string? Continent { get; set; }
134-
135-
/// <summary>
136-
/// 获得/设置 国家
137-
/// </summary>
138-
public string? Country { get; set; }
139-
140-
/// <summary>
141-
/// 获得/设置 邮编
142-
/// </summary>
143-
public string? ZipCode { get; set; }
144-
145-
/// <summary>
146-
/// 获得/设置 时区
147-
/// </summary>
148-
public string? TimeZone { get; set; }
149-
150-
/// <summary>
151-
/// 获得/设置 精度
152-
/// </summary>
153-
public string? Accuracy { get; set; }
154-
155-
/// <summary>
156-
/// 获得/设置 所属
157-
/// </summary>
158-
public string? Owner { get; set; }
159-
160-
/// <summary>
161-
/// 获得/设置 运营商
162-
/// </summary>
163-
public string? Isp { get; set; }
164-
165-
/// <summary>
166-
/// 获得/设置 来源
167-
/// </summary>
168-
public string? Source { get; set; }
169-
170-
/// <summary>
171-
/// 获得/设置 区号
172-
/// </summary>
173-
public string? AreaCode { get; set; }
174-
175-
/// <summary>
176-
/// 获得/设置 行政区划代码
177-
/// </summary>
178-
public string? AdCode { get; set; }
179-
180-
/// <summary>
181-
/// 获得/设置 国家代码
182-
/// </summary>
183-
public string? AsNumber { get; set; }
184-
185-
/// <summary>
186-
/// 获得/设置 经度
187-
/// </summary>
188-
public string? Lat { get; set; }
189-
190-
/// <summary>
191-
/// 获得/设置 纬度
192-
/// </summary>
193-
public string? Lng { get; set; }
194-
195-
/// <summary>
196-
/// 获得/设置 半径
197-
/// </summary>
198-
public string? Radius { get; set; }
199-
200-
/// <summary>
201-
/// 获得/设置 省份
202-
/// </summary>
203-
public string? Prov { get; set; }
204-
205-
/// <summary>
206-
/// 获得/设置 城市
207-
/// </summary>
208-
public string? City { get; set; }
209-
210-
/// <summary>
211-
/// 获得/设置 区县
212-
/// </summary>
213-
public string? District { get; set; }
214-
}
21590
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
// Website: https://www.blazor.zone
4+
5+
namespace BootstrapBlazor.Components;
6+
7+
/// <summary>
8+
/// <para lang="zh">聚合定位数据类</para>
9+
/// <para lang="en">JuHe location data class</para>
10+
/// </summary>
11+
class JuHeLocationData
12+
{
13+
/// <summary>
14+
/// <para lang="zh">获得/设置 州</para>
15+
/// <para lang="en">Gets or sets the continent</para>
16+
/// </summary>
17+
public string? Continent { get; set; }
18+
19+
/// <summary>
20+
/// <para lang="zh">获得/设置 国家</para>
21+
/// <para lang="en">Gets or sets the country</para>
22+
/// </summary>
23+
public string? Country { get; set; }
24+
25+
/// <summary>
26+
/// <para lang="zh">获得/设置 邮编</para>
27+
/// <para lang="en">Gets or sets the zip code</para>
28+
/// </summary>
29+
public string? ZipCode { get; set; }
30+
31+
/// <summary>
32+
/// <para lang="zh">获得/设置 时区</para>
33+
/// <para lang="en">Gets or sets the time zone</para>
34+
/// </summary>
35+
public string? TimeZone { get; set; }
36+
37+
/// <summary>
38+
/// <para lang="zh">获得/设置 精度</para>
39+
/// <para lang="en">Gets or sets the accuracy</para>
40+
/// </summary>
41+
public string? Accuracy { get; set; }
42+
43+
/// <summary>
44+
/// <para lang="zh">获得/设置 所属</para>
45+
/// <para lang="en">Gets or sets the owner</para>
46+
/// </summary>
47+
public string? Owner { get; set; }
48+
49+
/// <summary>
50+
/// <para lang="zh">获得/设置 运营商</para>
51+
/// <para lang="en">Gets or sets the ISP</para>
52+
/// </summary>
53+
public string? Isp { get; set; }
54+
55+
/// <summary>
56+
/// <para lang="zh">获得/设置 来源</para>
57+
/// <para lang="en">Gets or sets the source</para>
58+
/// </summary>
59+
public string? Source { get; set; }
60+
61+
/// <summary>
62+
/// <para lang="zh">获得/设置 区号</para>
63+
/// <para lang="en">Gets or sets the area code</para>
64+
/// </summary>
65+
public string? AreaCode { get; set; }
66+
67+
/// <summary>
68+
/// <para lang="zh">获得/设置 行政区划代码</para>
69+
/// <para lang="en">Gets or sets the administrative division code</para>
70+
/// </summary>
71+
public string? AdCode { get; set; }
72+
73+
/// <summary>
74+
/// <para lang="zh">获得/设置 国家代码</para>
75+
/// <para lang="en">Gets or sets the AS number</para>
76+
/// </summary>
77+
public string? AsNumber { get; set; }
78+
79+
/// <summary>
80+
/// <para lang="zh">获得/设置 经度</para>
81+
/// <para lang="en">Gets or sets the latitude</para>
82+
/// </summary>
83+
public string? Lat { get; set; }
84+
85+
/// <summary>
86+
/// <para lang="zh">获得/设置 纬度</para>
87+
/// <para lang="en">Gets or sets the longitude</para>
88+
/// </summary>
89+
public string? Lng { get; set; }
90+
91+
/// <summary>
92+
/// <para lang="zh">获得/设置 半径</para>
93+
/// <para lang="en">Gets or sets the radius</para>
94+
/// </summary>
95+
public string? Radius { get; set; }
96+
97+
/// <summary>
98+
/// <para lang="zh">获得/设置 省份</para>
99+
/// <para lang="en">Gets or sets the province</para>
100+
/// </summary>
101+
public string? Prov { get; set; }
102+
103+
/// <summary>
104+
/// <para lang="zh">获得/设置 城市</para>
105+
/// <para lang="en">Gets or sets the city</para>
106+
/// </summary>
107+
public string? City { get; set; }
108+
109+
/// <summary>
110+
/// <para lang="zh">获得/设置 区县</para>
111+
/// <para lang="en">Gets or sets the district</para>
112+
/// </summary>
113+
public string? District { get; set; }
114+
}

0 commit comments

Comments
 (0)