6

推荐一个Asp.Net Core工具库

 3 years ago
source link: http://mp.weixin.qq.com/s?__biz=MzAwNTMxMzg1MA%3D%3D&%3Bmid=2654079185&%3Bidx=4&%3Bsn=b9ab8bb96dd7e9bf1a30c9bcd99a5425
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

nEZZJfQ.jpg!web

Masuit.Tools

开源地址

https://github.com/XiLife-OSPC/Masuit.Tools

BNZrqyU.png!web

包含一些常用的操作类,大都是静态类,加密解密,反射操作,硬件信息,字符串扩展方法,日期时间扩展操作,大文件拷贝,图像裁剪,验证码等常用封装。

关于开源协议

除了源代码,这个开源协议也是比较有趣的一点,当然这也可能只是一个玩笑,毕竟个人开发的,精力有限

请注意:一旦使用本开源项目以及引用了本项目或包含本项目代码的公司因为违反劳动法(包括但不限定非法裁员、超时用工、雇佣童工等)在任何法律诉讼中败诉的,项目作者有权利追讨本项目的使用费,或者直接不允许使用任何包含本项目的源代码!任何性质的外包公司或996公司需要使用本类库,请联系作者进行商业授权!其他企业或个人可随意使用不受限。

特色功能示例代码

日志组件

LogManager.LogDirectory=AppDomain.CurrentDomain.BaseDirectory+"/logs";
LogManager.Event+=info =>
{
//todo:注册一些事件操作
};
LogManager.Info("记录一次消息");
LogManager.Error(new Exception("异常消息"));

检验字符串是否是Email、手机号、URL、IP地址、身份证号

bool isEmail="[email protected]".MatchEmail();
bool isInetAddress = "114.114.114.114".MatchInetAddress();
bool isUrl = "http://masuit.com".MatchUrl();
bool isPhoneNumber = "15205201520".MatchPhoneNumber();
bool isIdentifyCard = "312000199502230660".MatchIdentifyCard();// 校验中国大陆身份证号

硬件监测(仅支持Windows)

float load = SystemInfo.CpuLoad;// 获取CPU占用率
long physicalMemory = SystemInfo.PhysicalMemory;// 获取物理内存总数
long memoryAvailable = SystemInfo.MemoryAvailable;// 获取物理内存可用率
double freePhysicalMemory = SystemInfo.GetFreePhysicalMemory();// 获取可用物理内存
Dictionary<string, string> diskFree = SystemInfo.DiskFree();// 获取磁盘每个分区可用空间
Dictionary<string, string> diskTotalSpace = SystemInfo.DiskTotalSpace();// 获取磁盘每个分区总大小
Dictionary<string, double> diskUsage = SystemInfo.DiskUsage();// 获取磁盘每个分区使用率
double temperature = SystemInfo.GetCPUTemperature();// 获取CPU温度
int cpuCount = SystemInfo.GetCpuCount();// 获取CPU核心数
IList<string> ipAddress = SystemInfo.GetIPAddress();// 获取本机所有IP地址
string localUsedIp = SystemInfo.GetLocalUsedIP();// 获取本机当前正在使用的IP地址
IList<string> macAddress = SystemInfo.GetMacAddress();// 获取本机所有网卡mac地址
string osVersion = SystemInfo.GetOsVersion();// 获取操作系统版本
RamInfo ramInfo = SystemInfo.GetRamInfo();// 获取内存信息

大文件操作

FileStream fs = new FileStream(@"D:\boot.vmdk", FileMode.OpenOrCreate, FileAccess.ReadWrite);
{
//fs.CopyToFile(@"D:\1.bak");//同步复制大文件
fs.CopyToFileAsync(@"D:\1.bak");//异步复制大文件
string md5 = fs.GetFileMD5Async().Result;//异步获取文件的MD5
}

任意进制转换

NumberFormater nf = new NumberFormater(36);//内置2-62进制的转换
//NumberFormater nf = new NumberFormater("0123456789abcdefghijklmnopqrstuvwxyz");// 自定义进制字符,可用于生成验证码
string s36 = nf.ToString(12345678);
long num = nf.FromString("7clzi");
Console.WriteLine("12345678的36进制是:" + s36); // 7clzi
Console.WriteLine("36进制的7clzi是:" + num); // 12345678

多线程后台下载

var mtd = new MultiThreadDownloader("https://attachments-cdn.shimo.im/yXwC4kphjVQu06rH/KeyShot_Pro_7.3.37.7z",Environment.GetEnvironmentVariable("temp"),"E:\\Downloads\\KeyShot_Pro_7.3.37.7z",8);
mtd.Configure(req =>
{
req.Referer = "https://masuit.com";
req.Headers.Add("Origin", "https://baidu.com");
});
mtd.TotalProgressChanged+=(sender, e) =>
{
var downloader = sender as MultiThreadDownloader;
Console.WriteLine("下载进度:"+downloader.TotalProgress+"%");
Console.WriteLine("下载速度:"+downloader.TotalSpeedInBytes/1024/1024+"MBps");
};
mtd.FileMergeProgressChanged+=(sender, e) =>
{
Console.WriteLine("下载完成");
};
mtd.Start();//开始下载
//mtd.Pause(); // 暂停下载
//mtd.Resume(); // 继续下载

往期推荐

有了这个开源项目,分分钟搞定第三方授权登录!

推荐:股票走势图这个开源项目就够了!

Github这5个沙雕项目,征服了我的膝盖!

推荐:Github必装的3款插件

jiyiey6.jpg!web

回复   【关闭】 学关闭微信朋友圈广告

回复   【实战】 获取20套实战源码

回复   【福利】 获取最新微信支付有奖励

回复   【被删】 学查看你哪个好友删除了你巧

回复   【聊天记录】 学备份/恢复聊天记录

回复   【访客】 学微信查看朋友圈访客记录

回复   【卡通】 学制作微信卡通头像

回复 【python】 学微获取全套0基础Python知识手册

回复   【临时】 获取临时接收短信、邮箱验证码网址列表


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK