TJC.Cyclops.Common 2026.2.4.1

dotnet add package TJC.Cyclops.Common --version 2026.2.4.1
                    
NuGet\Install-Package TJC.Cyclops.Common -Version 2026.2.4.1
                    
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="TJC.Cyclops.Common" Version="2026.2.4.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TJC.Cyclops.Common" Version="2026.2.4.1" />
                    
Directory.Packages.props
<PackageReference Include="TJC.Cyclops.Common" />
                    
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 TJC.Cyclops.Common --version 2026.2.4.1
                    
#r "nuget: TJC.Cyclops.Common, 2026.2.4.1"
                    
#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 TJC.Cyclops.Common@2026.2.4.1
                    
#: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=TJC.Cyclops.Common&version=2026.2.4.1
                    
Install as a Cake Addin
#tool nuget:?package=TJC.Cyclops.Common&version=2026.2.4.1
                    
Install as a Cake Tool

Cyclops.Common

项目概述

Cyclops.Common是企服版框架中的核心工具类库,提供了丰富的实用功能模块,为框架中的其他组件提供基础支持。该项目集成了大量常用工具类,包括数据处理、加密解密、缓存管理、日志处理、文件操作、HTTP通信等多方面功能,极大地简化了企业级应用的开发工作。

核心功能模块

1. 数据处理工具

1.1 Excel与CSV处理
  • ExcelUtil:提供Excel文件的读取、写入和格式化功能
  • CsvUtil:支持CSV文件的解析和生成
  • DataTableUtil:DataTable操作的辅助工具类
1.2 数据结构与集合
  • PagedList:分页列表实现,支持高效的分页数据展示
  • ThreadSafeList:线程安全的列表实现
  • PagedDictionary:分页字典,结合了字典和分页功能
  • DataSplitter:大数据集合的分割处理工具

2. 加密与安全

2.1 加密解密
  • Base64Util:Base64编码解码工具
  • CalcUtil:包含各种计算相关的工具方法
2.2 安全防护
  • AntiReplayAttacks:防重放攻击相关功能实现
  • AraReplayAttacksUtil:防重放攻击工具类

3. 缓存管理

  • BaseCache:缓存基类,定义了缓存的基本操作接口
  • MemoryCache:内存缓存实现
  • IServiceCache:服务缓存接口
  • LocalCacheUtil:本地缓存工具类

4. 事件总线

提供了轻量级的事件总线实现,支持事件发布订阅模式:

  • BusBuilder:事件总线构建器
  • Publisher:事件发布者
  • Subscriber:事件订阅者
  • EventQueue:事件队列
  • IEventData:事件数据接口

5. 错误处理

提供了友好的错误处理机制:

  • FriendlyException:友好异常类
  • FriendlyError:友好错误信息类
  • EnumErrorCode:错误代码枚举

6. HTTP通信

6.1 HTTP客户端
  • HttpClientProxy:HTTP客户端代理,简化HTTP请求
  • HttpExtension:HTTP扩展方法
6.2 表单上传
  • FormUpload:表单上传功能
  • FileParameter:文件参数定义

7. 文件操作

  • FileUtil:文件操作工具类
  • PathUtil:路径处理工具
  • FileTypeUtil:文件类型判断工具
  • TempFile:临时文件管理

8. 日志处理

  • Logger:日志记录器,基于log4net的封装
  • LogInfo:日志信息类
  • ApiLogInfo:API日志信息类

9. 时间与日期

  • DateTimeUtil:日期时间处理工具
  • ChineseCalendar:中国农历日历工具

10. 系统工具

10.1 反射与动态
  • ReflectionUtil:反射操作工具
  • DynamicUtil:动态类型操作工具
  • FastILUtil:基于IL的快速反射工具
10.2 枚举与配置
  • EnumUtil:枚举操作工具类
  • ConfigUtil:配置文件操作工具
  • NacosConfigUtil:Nacos配置中心工具类
10.3 系统信息
  • ComputerUtil:计算机系统信息获取工具
  • ProcessUtil:进程管理工具

11. 网络工具

  • IPUtil:IP地址处理工具
  • IPToRegion:IP地址到地理位置的映射
  • LANUtil:局域网相关工具

12. 图片与二维码

  • ImageUtil:图片处理工具类,基于SkiaSharp
  • ZXing:二维码生成与识别功能

13. 短信服务

  • SmsSender:短信发送服务
  • SmsOption:短信服务配置选项

技术栈

  • 开发框架:.NET 8.0
  • 项目类型:类库(Class Library)
  • 核心依赖
    • Encrypt.Library (2025.4.28.1) - 加密库
    • HtmlAgilityPack (1.12.4) - HTML解析
    • log4net (3.2.0) - 日志框架
    • Newtonsoft.Json (13.0.4) - JSON处理
    • NPOI (2.7.5) - Excel处理
    • SharpZipLib (1.4.2) - 压缩解压
    • SkiaSharp (3.119.1) - 图像处理
    • ZXing.Net (0.16.11) - 二维码处理
    • Cyclops.Threading - 线程处理相关

环境依赖要求

  • .NET 8.0 SDK 或更高版本
  • 引用的Cyclops.Threading项目

安装与配置

安装方式

可以通过以下方式安装Cyclops.Common包:

  1. NuGet包管理器

    Install-Package TJC.Cyclops.Common
    
  2. .NET CLI

    dotnet add package TJC.Cyclops.Common
    

基本配置

使用Cyclops.Common通常不需要特殊配置,但某些功能可能需要额外设置:

  1. 日志配置:使用log4net时,需要在应用程序中配置log4net.config
  2. 缓存配置:使用缓存功能时,可根据需要配置缓存策略
  3. 事件总线配置:使用事件总线时,需要通过BusBuilder进行初始化配置

核心功能代码示例

1. Excel文件处理

// 读取Excel文件
var dataTable = ExcelUtil.ReadExcelToDataTable("path/to/excel.xlsx");

// 写入Excel文件
ExcelUtil.DataTableToExcel(dataTable, "path/to/output.xlsx");

2. 内存缓存使用

// 创建内存缓存实例
var cache = new MemoryCache();

// 添加缓存项
cache.Set("key", "value", TimeSpan.FromMinutes(10));

// 获取缓存项
if (cache.TryGetValue("key", out string? value))
{
    // 使用缓存值
    Console.WriteLine(value);
}

// 移除缓存项
cache.Remove("key");

3. HTTP请求发送

// 使用HttpClientProxy发送GET请求
var client = new HttpClientProxy();
var result = await client.GetAsync("https://api.example.com/data");

// 发送POST请求
var postData = new { name = "test", value = 123 };
var postResult = await client.PostAsync("https://api.example.com/submit", postData);

4. 事件总线使用

// 定义事件数据类
public class UserCreatedEvent : BaseEventData
{
    public string UserId { get; set; }
    public string UserName { get; set; }
}

// 配置和初始化事件总线
var bus = BusBuilder.Create()
    .WithConfig(new BusConfig { QueueCapacity = 1000 })
    .Build();

// 订阅事件
bus.Subscribe<UserCreatedEvent>(e =>
{
    Console.WriteLine($"用户创建事件: {e.UserName} (ID: {e.UserId})");
});

// 发布事件
await bus.PublishAsync(new UserCreatedEvent
{
    UserId = "123",
    UserName = "张三"
});

5. 日期时间处理

// 格式化日期时间
string formattedDate = DateTimeUtil.ToString(DateTime.Now, "yyyy-MM-dd HH:mm:ss");

// 获取中文星期
string chineseWeekday = DateTimeUtil.GetChineseWeekDay(DateTime.Now);

// 计算两个日期之间的工作日数量
int workDays = DateTimeUtil.GetWorkDays(DateTime.Now, DateTime.Now.AddDays(10));

6. 错误处理

// 抛出友好异常
try
{
    if (someCondition)
    {
        throw new FriendlyException(EnumErrorCode.InvalidParameter, "参数无效");
    }
}
catch (FriendlyException ex)
{
    // 处理友好异常
    Console.WriteLine($"错误码: {ex.ErrorCode}, 错误信息: {ex.Message}");
}

7. 文件操作

// 读取文件内容
string content = FileUtil.ReadFileContent("path/to/file.txt");

// 写入文件
FileUtil.WriteFileContent("path/to/output.txt", "Hello, World!");

// 复制文件
FileUtil.CopyFile("source.txt", "destination.txt");

// 检查文件是否存在
bool exists = FileUtil.Exists("path/to/file.txt");

使用注意事项

  1. 日志配置:使用Logger前,请确保已正确配置log4net

  2. 线程安全:在多线程环境下使用集合类时,优先选择ThreadSafeList等线程安全实现

  3. 资源释放:使用文件操作和流操作时,请确保正确释放资源,避免资源泄漏

  4. 异常处理:在生产环境中,建议使用FriendlyException进行异常处理,提供友好的错误提示

  5. 缓存管理:使用缓存时,注意设置合理的过期时间,避免内存占用过大

  6. 配置管理:对于需要频繁变更的配置,建议使用NacosConfigUtil从配置中心读取

  7. 性能考虑:对于性能敏感的操作,可以使用FastILUtil等高性能工具类

  8. 版本兼容性:使用第三方库时,注意版本兼容性问题,特别是Newtonsoft.Json等常用库

贡献者

  • yswenli

许可证

保留所有权利

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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.

NuGet packages (23)

Showing the top 5 NuGet packages that depend on TJC.Cyclops.Common:

Package Downloads
TJC.Cyclops.Orm

企服版框架中ORM核心,基于YitIdHelper、Mapster、SqlSugar封装

TJC.Cyclops.LogLib

企服版框架集成日志核心

TJC.Cyclops.Web.Core

企服版框架中api核心功能项目,基于aspnetcore集成di、jwt、swagger、codefirtst、支持多种常见数据库、nacos配置中心、统一接口回复参数、全局异常捕获、全局接口日志、防重放攻击、图形验证码、快捷上下文对象、上传下载、数据导入导出等功能

TJC.Cyclops.Speech

语音转换工具类

TJC.Cyclops.Redis

企服版框架redis sdk

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2026.2.4.1 413 2/4/2026
2026.1.15.1 418 1/15/2026
2026.1.14.2 395 1/14/2026
2026.1.14.1 400 1/14/2026
2026.1.13.2 401 1/13/2026
2026.1.13.1 413 1/13/2026
2026.1.7.1 439 1/7/2026
2025.12.23.1 512 12/23/2025
2025.12.16.1 586 12/16/2025
2025.12.15.2 556 12/15/2025
2025.12.15.1 564 12/15/2025
2025.12.12.1 447 12/12/2025
2025.12.11.1 749 12/11/2025
2025.12.4.1 504 12/4/2025
2025.12.3.3 995 12/3/2025
2025.12.3.2 970 12/3/2025
2025.12.3.1 988 12/3/2025
2025.12.2.1 996 12/2/2025
2025.11.28.1 499 11/28/2025
2025.11.25.1 521 11/25/2025
Loading failed

企服版框架工具类项目,三方引用包主要有:Encrypt.Library、HtmlAgilityPack、ICSharpCode.SharpZipLib、log4net、Newtonsoft.Json、NPOI、SkiaSharp、ZXing等