CloudYxt.Base 2.0.0

dotnet add package CloudYxt.Base --version 2.0.0
                    
NuGet\Install-Package CloudYxt.Base -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CloudYxt.Base" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CloudYxt.Base" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="CloudYxt.Base" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CloudYxt.Base --version 2.0.0
                    
#r "nuget: CloudYxt.Base, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CloudYxt.Base@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CloudYxt.Base&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=CloudYxt.Base&version=2.0.0
                    
Install as a Cake Tool

CloudYxt .Net Core 数据类型模型库(DTO / 消息响应结构)

功能概览

类型 命名空间 说明
dbLoginLock CloudYxt.Base 用户重复登录锁
dbRunStat CloudYxt.Base APP 运行状态结构
messageData CloudYxt.Base 通用数据消息结构(object 数据)
messageData<T> CloudYxt.Base 通用数据消息结构(泛型数据)
messageStatus<T> CloudYxt.Base 通用状态消息结构(status + message + result)
messageStatusData<T> CloudYxt.Base 通用状态数据消息结构(status + message + data)
messageErrorCode CloudYxt.Base 通用错误码消息结构
messageInfo CloudYxt.Base 通用返回消息结构(属性为 PascalCase)
responseIp CloudYxt.Base IP 地址 / 端口信息
ApiMessageLog CloudYxt.Api Api 消息日志结构
ApiMessageLog_Ch CloudYxt.Api Api 消息日志结构(ClickHouse 批量写入辅助)

所有类型的属性均为 public get/set,除 ApiMessageLog_Ch 实现 IEnumerable 外,不实现其他接口;类均未标记 sealed。


快速开始

1. 返回标准消息结构

using CloudYxt.Base;

// 成功响应:message 构造时已默认 "success",code 默认为 0
var ok = new messageData<OrderDto>
{
    data = new OrderDto { Id = 1001, Amount = 99.5m }
};

// 失败响应
var fail = new messageErrorCode
{
    errcode = 4001,
    errmsg = "订单不存在"
};

ok 序列化(System.Text.Json / Newtonsoft.Json 默认行为):

{
  "code": 0,
  "message": "success",
  "data": { "Id": 1001, "Amount": 99.5 }
}

2. 使用状态码 + 结果

var r1 = new messageStatus<OrderDto>
{
    status = 0,
    result = order
};

var r2 = new messageStatusData<OrderDto>
{
    status = 0,
    data = order
};

3. 登录锁定信息

var lockInfo = new dbLoginLock
{
    id = "alice",
    retry = 3,
    addTime = DateTime.Now,
    lastTime = DateTime.Now
};

4. 从 IDataReader 读取日志

using System.Data.Common;
using CloudYxt.Api;

public static List<ApiMessageLog> ReadLogs(DbConnection connection)
{
    using var cmd = connection.CreateCommand();
    cmd.CommandText = """
        SELECT id, apiId, apiController, url, agent, request, code,
               message, data, info, addTime, ip, timer, userId, appId, custom
        FROM api_message_log
        """;

    using var dr = cmd.ExecuteReader();
    var list = new List<ApiMessageLog>();
    while (dr.Read())
    {
        list.Add(ApiMessageLog.LoadFromIDataReader(dr));
    }
    return list;
}

apiName 不在 LoadFromIDataReader 的读取列中,需要时请手动赋值。

5. ClickHouse 批量写入的列名与值

using System;
using System.Linq;
using CloudYxt.Api;

string[] columns = ApiMessageLog_Ch.ChBulkFields.Split(", ");
// ["id","apiName","apiId","apiController","url","agent","request","code",
//  "message","data","info","addTime","ip","timer","userId","appId","custom"]

var row = new ApiMessageLog_Ch
{
    id = Guid.NewGuid().ToString("N"),
    apiName = "GetOrder",
    // ... 其余属性
};

// GetEnumerator 按与 ChBulkFields 完全相同的顺序返回 17 个属性的值
object[] values = row.Cast<object>().ToArray();

API 参考

1. 消息响应模型

messageData

通用数据消息结构。

[Description("通用数据消息结构")]
public class messageData
{
    [Description("接口状态码,0-成功,其他状态码参照message的说明")]
    public int code { get; set; }

    [Description("数据说明")]
    public string message { get; set; }

    [Description("接口返回数据")]
    public object data { get; set; }

    public messageData(); // message 默认 "success",code 默认 0,data 默认 null
}
属性 类型 说明 默认值
code int 接口状态码,0 成功 0
message string 数据说明 "success"
data object 接口返回数据 null
messageData<T>

messageData 的泛型版本,data 为强类型。

[Description("通用数据消息结构")]
public class messageData<T>
{
    public int code { get; set; }
    public string message { get; set; }
    public T data { get; set; }

    public messageData(); // message 默认 "success"
}
messageStatus<T>

通用状态消息结构,结果字段名为 result。

[Description("通用数据消息结构")]
public class messageStatus<T>
{
    [Description("接口状态码,0-成功,其他状态码参照message的说明")]
    public int status { get; set; }

    [Description("数据说明")]
    public string message { get; set; }

    [Description("接口返回数据")]
    public T result { get; set; }

    public messageStatus(); // message 默认 "success",status 默认 0
}
messageStatusData<T>

与 messageStatus<T> 类似,但结果字段名为 data。

[Description("通用数据消息结构")]
public class messageStatusData<T>
{
    [Description("接口状态码,0-成功,其他状态码参照message的说明")]
    public int status { get; set; }

    [Description("数据说明")]
    public string message { get; set; }

    [Description("接口返回数据")]
    public T data { get; set; }

    public messageStatusData(); // message 默认 "success",status 默认 0
}
messageErrorCode

通用错误码消息结构,用于只表达错误信息的场景。

[Description("通用错误码消息结构")]
public class messageErrorCode
{
    [Description("错误码,0-成功,其他参照errmsg信息")]
    public int errcode { get; set; }

    [Description("错误说明")]
    public string errmsg { get; set; }

    public messageErrorCode(); // 全部为 CLR 默认值(0 / null)
}
messageInfo

通用返回消息结构。注意:该类型的属性使用 PascalCase 命名,与其他消息模型的 camelCase 不一致。

[Description("通用返回消息结构")]
public class messageInfo
{
    [Description("消息说明")]
    public string Message { get; set; }

    [Description("消息说明详细信息")]
    public string MessageDetail { get; set; }

    [Description("消息响应码")]
    public int MessageCode { get; set; }

    public messageInfo(); // 全部为 CLR 默认值
}

2. 业务数据模型

dbLoginLock

用户重复登录锁,用于记录某账号的登录尝试次数与时间窗口。

[Description("用户重复登录锁")]
public class dbLoginLock
{
    [Description("用户名/登录名")]
    public string id { get; set; }

    [Description("尝试次数")]
    public int retry { get; set; }

    [Description("首次尝试时间")]
    public DateTime addTime { get; set; }

    [Description("最后尝试时间")]
    public DateTime lastTime { get; set; }

    public dbLoginLock();
}
dbRunStat

APP 运行状态结构。

[Description("APP运行状态结构")]
public class dbRunStat
{
    [Description("ID")]
    public string id { get; set; }

    [Description("状态数值")]
    public int? num { get; set; }

    [Description("状态说明")]
    public string text { get; set; }

    [Description("最后更新时间")]
    public DateTime? time { get; set; }

    public dbRunStat();
}
responseIp

IP 地址 / 端口信息。该类型在元数据中没有 [Description] 标注,以下说明依据属性名推断。

public class responseIp
{
    public string type { get; set; }   // 地址类型
    public string ip { get; set; }     // IP 地址
    public int? port { get; set; }     // 端口,可为 null

    public responseIp();
}

3. API 日志模型(CloudYxt.Api)

ApiMessageLog

Api 消息日志实体,共 17 个属性。属性带中文 [Description],可作为日志表映射或序列化模型。

[Description("Api消息日志结构")]
public class ApiMessageLog
{
    [Description("ID")]                            public string id { get; set; }
    [Description("Api名称")]                        public string apiName { get; set; }
    [Description("ApiId:ActionDescriptor.Id")]     public string apiId { get; set; }
    [Description("所属控制器")]                      public string apiController { get; set; }
    [Description("URL")]                            public string url { get; set; }
    [Description("浏览器AGENT")]                     public string agent { get; set; }
    [Description("请求参数")]                        public string request { get; set; }
    [Description("返回code")]                        public int code { get; set; }
    [Description("返回message")]                     public string message { get; set; }
    [Description("返回data")]                        public string data { get; set; }
    [Description("调试信息")]                        public string info { get; set; }
    [Description("入库时间")]                        public DateTime addTime { get; set; }
    [Description("IP")]                             public string ip { get; set; }
    [Description("执行耗时")]                        public long timer { get; set; }
    [Description("通用扩展日志用户ID")]               public string userId { get; set; }
    [Description("通用扩展日志应用ID")]               public string appId { get; set; }
    [Description("通用扩展日志自定义数据")]           public string custom { get; set; }

    public ApiMessageLog();

    public static ApiMessageLog LoadFromIDataReader(IDataReader dr);
}

LoadFromIDataReader 行为说明

  • 静态方法,从当前 IDataReader 行创建 ApiMessageLog 实例。

  • 按列名取值,列顺序无关,但以下 16 个列必须存在: id、apiId、apiController、url、agent、request、code、message、data、info、addTime、ip、timer、userId、appId、custom。

  • 不会读取 apiName,该属性保持默认值 null。

  • 使用直接强制转换(拆箱),具体要求:

    列 转换方式 数据库返回值必须为
    code (int) Int32
    addTime (DateTime) DateTime
    timer (long) Int64
    其余 13 列 (string) String
  • 若列值为 DBNull,或提供程序返回的类型与上表不一致(例如 SQLite 把整数返回为 Int64、数据库 NULL 值),会抛出 InvalidCastException。请在 SQL 层或视图层保证非空且类型匹配。

ApiMessageLog_Ch

ApiMessageLog 的 ClickHouse 批量写入辅助类型。

[Description("Api消息日志结构(ClickHouse)")]
public class ApiMessageLog_Ch : ApiMessageLog, IEnumerable
{
    // 17 个列名,顺序与 GetEnumerator 返回值顺序一致
    public static readonly string ChBulkFields =
        "id, apiName, apiId, apiController, url, agent, request, code, " +
        "message, data, info, addTime, ip, timer, userId, appId, custom";

    // 编译器生成的迭代器:依次返回 ApiMessageLog 的 17 个属性值(装箱为 object)
    public IEnumerator GetEnumerator();
}

行为要点:

  • ChBulkFields 为 public static readonly string,列顺序固定为: id, apiName, apiId, apiController, url, agent, request, code, message, data, info, addTime, ip, timer, userId, appId, custom。
  • GetEnumerator() 返回的序列与 ChBulkFields 一一对应,依次是上述 17 个属性的当前值(object,装箱)。
  • 典型用途:ClickHouse 批量插入时,用 ChBulkFields 作为列清单,用枚举结果作为按序参数。
  • 该类型不提供额外的赋值方法,属性继承自 ApiMessageLog;apiName 需自行赋值(LoadFromIDataReader 不会填充)。
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages (8)

Showing the top 5 NuGet packages that depend on CloudYxt.Base:

Package Downloads
CloudYxt.Models

CloudYxt .Net Core常用WEBAPI数据类型及MongoDB扩展库,如:MongoDB常用方法、基于MongoDB的对象存储OSS方法,MongoDB索引自维护等。

CloudYxt.Api

云享通.Net Core针对WEBAPI常规操作库。

CloudYxt.Redis

云享通.Net Core针对Redis扩展操作库

CloudYxt.MinimalApi

CloudYxt .Net Core针对MinimalApi常规操作库,支持AOT编译。

CloudYxt.Models.WeiXin

云享通.Net Corec微信开发SDK数据结构,注意:当前仅包含核心数据结构SDK,未包含全部开发SDK。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 0 11/16/2026
1.0.3 483 4/15/2026
1.0.2 933 4/24/2025
1.0.1 2,122 5/6/2023
1.0.0 7,660 9/30/2021

CloudYxt .Net Core数据类型模型库

2.0.0
升级为.net10依赖

1.0.3
更改基础信息

1.0.2
增加messageStatusData数据模型

1.0.1
增加CloudYxt.Api使用的ApiMessageLog

1.0.0
如常见的code\message数据模型、APP运行状态模型、用户重复登录尝试模型等