Files
lightsetup/LightSetupBase/Md5Config.cs
2023-05-22 09:29:58 +08:00

152 lines
6.2 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json.Serialization;
using System.Text.Json;
using System.Text.Unicode;
using System.Threading.Tasks;
namespace LightSetupBase
{
/// <summary>
/// MD5打包文件配置
/// </summary>
public class Md5Config
{
/// <summary>
/// Json配置参数
/// </summary>
/// <returns>返回值</returns>
public static JsonSerializerOptions getOption()
{
JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions()
{
// 整齐打印
WriteIndented = true,
// 忽略值为Null的属性
// IgnoreNullValues = true,
// 设置Json字符串支持的编码默认情况下序列化程序会转义所有非 ASCII 字符。 即,会将它们替换为 \uxxxx其中 xxxx 为字符的 Unicode
// 代码。 可以通过设置Encoder来让生成的josn字符串不转义指定的字符集而进行序列化 下面指定了基础拉丁字母和中日韩统一表意文字的基础Unicode 块
// (U+4E00-U+9FCC)。 基本涵盖了除使用西里尔字母以外所有西方国家的文字和亚洲中日韩越的文字
Encoder = JavaScriptEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.CjkUnifiedIdeographs),
// 反序列化不区分大小写
PropertyNameCaseInsensitive = true,
// 驼峰命名
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
// 对字典的键进行驼峰命名
DictionaryKeyPolicy = JsonNamingPolicy.CamelCase,
// 序列化的时候忽略null值属性
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
// 忽略只读属性因为只读属性只能序列化而不能反序列化所以在以json为储存数据的介质的时候序列化只读属性意义不大
IgnoreReadOnlyFields = true,
// 不允许结尾有逗号的不标准json
AllowTrailingCommas = false,
// 不允许有注释的不标准json
ReadCommentHandling = JsonCommentHandling.Disallow,
// 允许在反序列化的时候原本应为数字的字符串(带引号的数字)转为数字
NumberHandling = JsonNumberHandling.AllowReadingFromString,
// 处理循环引用类型比如Book类里面有一个属性也是Book类
ReferenceHandler = ReferenceHandler.Preserve
};
return jsonSerializerOptions;
}
public Md5Config()
{
this.Filter = String.Empty;
this.Contain = String.Empty;
this.FileName = String.Empty;
this.FileFormat = String.Empty;
this.GetHttpUrl = String.Empty;
this.GetHttpFormat = String.Empty;
this.PostHttpUrl = String.Empty;
this.PostHttpFormat = String.Empty;
}
/// <summary>
/// 过滤文件,请用换行符分割,支持正则表示、普通文本
/// </summary>
[Md5ConfigAttribute("过滤文件","请用换行符分割,支持正则表示、普通文本")]
public string Filter
{
get;
set;
}
/// <summary>
/// 包含文件,请用换行符分割,支持正则表示、普通文本
/// </summary>
[Md5ConfigAttribute("包含文件", "请用换行符分割,支持正则表示、普通文本")]
public string Contain
{
get;
set;
}
/// <summary>
/// 配置文件路径,默认为UTF-8格式
/// </summary>
[Md5ConfigAttribute("配置文件路径", "默认为UTF-8格式")]
public string FileName
{
get;
set;
}
/// <summary>
/// 可支持 {md5}、{其他扩展参数}其他扩展参数请通过GetHttpUrl来请求获取.返回的为Json并只支持包含1级
/// </summary>
[Md5ConfigAttribute("配置文件内容", "可支持 {md5}、{ip}、{computerName}、{其他扩展参数},其他扩展参数请通过‘获取扩展参数’来请求获取.")]
public string FileFormat
{
get;
set;
}
/// <summary>
/// 获取扩展参数Http地址请求方式为UTF-8的Application/json返回的内容为Json并只支持包含1级。
/// 包含的字段用于对配置文件格式提交Http请求的内容进行扩展。
/// </summary>
[Md5ConfigAttribute("获取扩展参数Http地址", "请求方式为UTF-8的Application/json返回的内容为Json并只支持包含1级。" +
"包含的字段用于对配置文件格式提交Http请求的内容进行扩展。")]
public string GetHttpUrl
{
get;
set;
}
/// <summary>
/// 获取扩展参数Http格式,可支持 {md5}.
/// </summary>
[Md5ConfigAttribute("获取扩展参数Http内容", "可支持 {md5}、{ip}、{computerName}.")]
public string GetHttpFormat
{
get;
set;
}
/// <summary>
/// 提交结果Http地址请求方式为UTF-8的Application/json。
/// </summary>
[Md5ConfigAttribute("提交结果Http地址", "请求方式为UTF-8的Application/json。")]
public string PostHttpUrl
{
get;
set;
}
/// <summary>
/// 提交结果Http内容,可支持 {md5}、{其他扩展参数},其他扩展参数请通过‘获取扩展参数’来请求获取.
/// </summary>
[Md5ConfigAttribute("提交结果Http内容", "可支持 {md5}、{ip}、{computerName}、{其他扩展参数},其他扩展参数请通过‘获取扩展参数’来请求获取.")]
public string PostHttpFormat
{
get;
set;
}
}
}