Browse Source

Apewer-6.8.1

dev
王厅 6 months ago
parent
commit
71a0fde759
  1. 2
      Apewer/Apewer.props
  2. 4
      Apewer/CollectionUtility.cs
  3. 14
      Apewer/Network/HttpClient.cs
  4. 16
      Apewer/Network/HttpHeaders.cs
  5. 10
      Apewer/StorageUtility.cs
  6. 4
      Apewer/Web/ApiOptions.cs
  7. 1
      Apewer/Web/ApiProcessor.cs
  8. 3
      Apewer/_Extensions.cs
  9. 10
      ChangeLog.md

2
Apewer/Apewer.props

@ -9,7 +9,7 @@
<Description></Description>
<RootNamespace>Apewer</RootNamespace>
<Product>Apewer Libraries</Product>
<Version>6.8.0</Version>
<Version>6.8.1</Version>
</PropertyGroup>
<!-- 生成 -->

4
Apewer/CollectionUtility.cs

@ -309,9 +309,9 @@ namespace Apewer
}
/// <summary>对元素去重,且去除 NULL 值。</summary>
public static T[] Distinct<T>(IEnumerable<T> items)
public static T[] Distinct<T>(this IEnumerable<T> items)
{
if (items != null) throw new ArgumentNullException(nameof(items));
if (items == null) throw new ArgumentNullException(nameof(items));
var count = Count(items);
var added = 0;
var array = new T[count];

14
Apewer/Network/HttpClient.cs

@ -111,6 +111,15 @@ namespace Apewer.Network
HttpWebRequest _request = null;
HttpWebResponse _response = null;
Nullable<DateTime> _request_time = null;
Nullable<DateTime> _response_time = null;
/// <summary>发送请求的时间。</summary>
public Nullable<DateTime> RequestTime { get => _request_time; }
/// <summary>接收响应的时间。</summary>
public Nullable<DateTime> ResponseTime { get => _response_time; }
/// <summary>获取最近发生的异常。</summary>
public Exception Exception { get { return _exception; } }
@ -155,11 +164,14 @@ namespace Apewer.Network
try
{
_request = Prepare(url, method);
_request_time = DateTime.Now;
_response = _request.GetResponse() as HttpWebResponse;
_response_time = DateTime.Now;
Parse(_response);
}
catch (Exception ex)
{
_response_time = DateTime.Now;
_exception = ex;
if (ex is WebException webEx) Parse((HttpWebResponse)webEx.Response);
return ex;
@ -168,7 +180,9 @@ namespace Apewer.Network
else
{
_request = Prepare(url, method);
_request_time = DateTime.Now;
_response = _request.GetResponse() as HttpWebResponse;
_response_time = DateTime.Now;
Parse(_response);
}
}

16
Apewer/Network/HttpHeaders.cs

@ -214,6 +214,22 @@ namespace Apewer.Network
#region operation
/// <summary>获取所有名称。</summary>
public string[] GetNames()
{
var names = new List<string>();
var count = _list.Count;
for (var i = 0; i < count; i++)
{
var name = _list[i].Name;
if (string.IsNullOrEmpty(name)) continue;
if (names.Contains(name)) continue;
names.Add(name);
}
names.Sort();
return names.ToArray();
}
/// <summary>获取匹配 Name 的 Value。不存在 Name 时返回 NULL 值。</summary>
/// <exception cref="ArgumentNullException" />
public string GetValue(string name)

10
Apewer/StorageUtility.cs

@ -490,16 +490,6 @@ namespace Apewer
}
}
/// <summary>将数据写入新文件,若文件已存在则覆盖。</summary>
public static bool WriteFile(string path, Json json, bool bom = false)
{
if (string.IsNullOrEmpty(path)) return false;
if (json == null || json.IsNull || json.IsNone) return false;
var text = json.ToString(true);
var bytes = TextUtility.Bytes(text);
return WriteFile(path, bom, bytes);
}
/// <summary>读取文件,获取文件内容。当文件为 UTF-8 文本文件时,可去除 BOM 头。</summary>
/// <remarks>注:<br />字节数组最大为 2GB;<br />此方法不抛出异常,读取失时返回空字节数组。</remarks>
public static byte[] ReadFile(string path, bool wipeBom = false)

4
Apewer/Web/ApiOptions.cs

@ -54,8 +54,8 @@ namespace Apewer.Web
public ApiPreOutput PreOutput { get; set; }
/// <summary>默认的结果渲染器。</summary>
/// <remarks>默认值:<see cref="ApiUtility.Error(ApiContext, string)"/></remarks>
public Action<ApiContext, string> TextRenderer { get; set; } = ApiUtility.Error;
/// <remarks>默认值:NULL(返回值不为空时视为错误信息)</remarks>
public Action<ApiContext, string> TextRenderer { get; set; }
/// <summary>在响应头中设置 Content-Security-Policy,要求浏览器升级资源链接,使用 HTTPS。</summary>
/// <remarks>默认值:不要求。在 HTTPS 页面中,不自动升级 HTTP 资源。</remarks>

1
Apewer/Web/ApiProcessor.cs

@ -131,6 +131,7 @@ namespace Apewer.Web
var action = _context.Entries.GetAction(path);
if (action != null)
{
_context.ApiAction = action;
Invoke(action);
_context.Response.Duration = Duration(_context.Beginning);
return;

3
Apewer/_Extensions.cs

@ -447,9 +447,6 @@ public static class Extensions
/// <summary>获取集合中元素的数量。</summary>
public static int Count<T>(this IEnumerable<T> @this) => CollectionUtility.Count(@this);
/// <summary>对元素去重,且去除 NULL 值。</summary>
public static T[] Distinct<T>(this IEnumerable<T> @this) => CollectionUtility.Distinct(@this);
/// <summary>获取可枚举集合的部分元素。</summary>
public static T[] Slice<T>(this IEnumerable<T> @this, int start = 0, int count = -1, Func<T> stuffer = null) => CollectionUtility.Slice<T>(@this, start, count, stuffer);

10
ChangeLog.md

@ -1,6 +1,16 @@

### 最新提交
### 6.8.1
- 新特性
- HttpClient:增加 RequestTime 和 ResponseTime 属性,记录发起请求和接收响应的时间;
- HttpHeaders:增加 GetNames 方法,用于获取所有名称。
- 问题修正
- CollectionUtility:修正 Distinct 判断参数为 NULL 时会抛出异常的问题;
- TextUtility:删除 Write(path, json) 方法,以避免传递错误参数导致写文件失败;
- Web:修正 ApiContext.Action 无值的问题;
- Web:修正 ApiOptions.TextRendrer 的默认值,正确的默认值应该是 NULL。
### 6.8.0
- 新特性
- ClockUtility:增加 CustomToStamp 和 CustomFromStamp,支持自定义时间戳的转换方法;

Loading…
Cancel
Save