推薦一個Asp.Net Core工具庫
Masuit.Tools
開源地址
https://github.com/XiLife-OSPC/Masuit.Tools

包含一些常用的操作類,大都是靜態(tài)類,加密解密,反射操作,硬件信息,字符串?dāng)U展方法,日期時間擴(kuò)展操作,大文件拷貝,圖像裁剪,驗(yàn)證碼等常用封裝。
關(guān)于開源協(xié)議
除了源代碼,這個開源協(xié)議也是比較有趣的一點(diǎn),當(dāng)然這也可能只是一個玩笑,畢竟個人開發(fā)的,精力有限
請注意:一旦使用本開源項(xiàng)目以及引用了本項(xiàng)目或包含本項(xiàng)目代碼的公司因?yàn)檫`反勞動法(包括但不限定非法裁員、超時用工、雇傭童工等)在任何法律訴訟中敗訴的,項(xiàng)目作者有權(quán)利追討本項(xiàng)目的使用費(fèi),或者直接不允許使用任何包含本項(xiàng)目的源代碼!任何性質(zhì)的外包公司或996公司需要使用本類庫,請聯(lián)系作者進(jìn)行商業(yè)授權(quán)!其他企業(yè)或個人可隨意使用不受限。
特色功能示例代碼
日志組件
LogManager.LogDirectory=AppDomain.CurrentDomain.BaseDirectory+"/logs";
LogManager.Event+=info?=>
{
????//todo:注冊一些事件操作
};
LogManager.Info("記錄一次消息");
LogManager.Error(new?Exception("異常消息"));
檢驗(yàn)字符串是否是Email、手機(jī)號、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();//?校驗(yàn)中國大陸身份證號
硬件監(jiān)測(僅支持Windows)
float?load?=?SystemInfo.CpuLoad;//?獲取CPU占用率
long?physicalMemory?=?SystemInfo.PhysicalMemory;//?獲取物理內(nèi)存總數(shù)
long?memoryAvailable?=?SystemInfo.MemoryAvailable;//?獲取物理內(nèi)存可用率
double?freePhysicalMemory?=?SystemInfo.GetFreePhysicalMemory();//?獲取可用物理內(nèi)存
Dictionary<string,?string>?diskFree?=?SystemInfo.DiskFree();//?獲取磁盤每個分區(qū)可用空間
Dictionary<string,?string>?diskTotalSpace?=?SystemInfo.DiskTotalSpace();//?獲取磁盤每個分區(qū)總大小
Dictionary<string,?double>?diskUsage?=?SystemInfo.DiskUsage();//?獲取磁盤每個分區(qū)使用率
double?temperature?=?SystemInfo.GetCPUTemperature();//?獲取CPU溫度
int?cpuCount?=?SystemInfo.GetCpuCount();//?獲取CPU核心數(shù)
IList<string>?ipAddress?=?SystemInfo.GetIPAddress();//?獲取本機(jī)所有IP地址
string?localUsedIp?=?SystemInfo.GetLocalUsedIP();//?獲取本機(jī)當(dāng)前正在使用的IP地址
IList<string>?macAddress?=?SystemInfo.GetMacAddress();//?獲取本機(jī)所有網(wǎng)卡mac地址
string?osVersion?=?SystemInfo.GetOsVersion();//?獲取操作系統(tǒng)版本
RamInfo?ramInfo?=?SystemInfo.GetRamInfo();//?獲取內(nèi)存信息
大文件操作
FileStream?fs?=?new?FileStream(@"D:\boot.vmdk",?FileMode.OpenOrCreate,?FileAccess.ReadWrite);
{
????????//fs.CopyToFile(@"D:\1.bak");//同步復(fù)制大文件
????????fs.CopyToFileAsync(@"D:\1.bak");//異步復(fù)制大文件
????????string?md5?=?fs.GetFileMD5Async().Result;//異步獲取文件的MD5
}
任意進(jìn)制轉(zhuǎn)換
NumberFormater?nf?=?new?NumberFormater(36);//內(nèi)置2-62進(jìn)制的轉(zhuǎn)換
//NumberFormater?nf?=?new?NumberFormater("0123456789abcdefghijklmnopqrstuvwxyz");//?自定義進(jìn)制字符,可用于生成驗(yàn)證碼
string?s36?=?nf.ToString(12345678);
long?num?=?nf.FromString("7clzi");
Console.WriteLine("12345678的36進(jìn)制是:"?+?s36);?//?7clzi
Console.WriteLine("36進(jìn)制的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("下載進(jìn)度:"+downloader.TotalProgress+"%");
????Console.WriteLine("下載速度:"+downloader.TotalSpeedInBytes/1024/1024+"MBps");
};
mtd.FileMergeProgressChanged+=(sender,?e)?=>
{
????Console.WriteLine("下載完成");
};
mtd.Start();//開始下載
//mtd.Pause();?//?暫停下載
//mtd.Resume();?//?繼續(xù)下載
評論
圖片
表情

