Browse Source

API调整

懒得勤快 8 years ago
parent
commit
270817e4b3

+ 2 - 4
Masuit.Tools/Database/DataTableHelper.cs

@@ -224,11 +224,9 @@ namespace Masuit.Tools.Database
         /// </summary>
         /// <param name="nameString">字符列表</param>
         /// <returns>内存表</returns>
-        public static DataTable CreateTable(string nameString)
+        public static DataTable CreateTable(this DataTable dt, string nameString)
         {
-            string[] nameArray = nameString.Split(new char[] { ',', ';' });
-            List<string> nameList = new List<string>();
-            DataTable dt = new DataTable();
+            string[] nameArray = nameString.Split(',', ';');
             foreach (string item in nameArray)
             {
                 if (!string.IsNullOrEmpty(item))

+ 10 - 10
Masuit.Tools/DateTimeExt/CNCalendar.cs

@@ -8,7 +8,7 @@ namespace Masuit.Tools.DateTimeExt
     /// <summary>
     /// 日历操作
     /// </summary>
-    public class CNCalendar
+    public static class CNCalendar
     {
         /// <summary>
         /// 格式化日期
@@ -425,7 +425,7 @@ namespace Masuit.Tools.DateTimeExt
         /// 传回农历y年的生肖
         /// </summary>
         /// <param name="y">公元年</param>
-        private string AnimalsYear(int y)
+        private static string AnimalsYear(int y)
         {
             return animals[(y - 4) % 12];
         }
@@ -434,7 +434,7 @@ namespace Masuit.Tools.DateTimeExt
         ///传入月日的offset 传回天干地支, 0=甲子
         /// </summary>
         /// <param name="num">月日的偏差</param>
-        private string Cyclical(int num)
+        private static string Cyclical(int num)
         {
             return gan[num % 10] + zhi[num % 12];
         }
@@ -443,7 +443,7 @@ namespace Masuit.Tools.DateTimeExt
         /// 传入offset 传回干支, 0=甲子
         /// </summary>
         /// <param name="y">公元年</param>
-        private string cyclical(int y)
+        private static string cyclical(int y)
         {
             int num = y - 1900 + 36;
             return Cyclical(num);
@@ -546,7 +546,7 @@ namespace Masuit.Tools.DateTimeExt
         /// <param name="y">年</param>
         /// <param name="m">月</param>
         /// <param name="d">日</param>
-        private long[] calElement(int y, int m, int d)
+        private static long[] calElement(int y, int m, int d)
         {
             long[] nongDate = new long[7];
 
@@ -633,7 +633,7 @@ namespace Masuit.Tools.DateTimeExt
         /// </summary>
         /// <param name="d">农历日</param>
         /// <returns>中文表示</returns>
-        private string GetCDay(int d)
+        private static string GetCDay(int d)
         {
             string s = "";
 
@@ -663,7 +663,7 @@ namespace Masuit.Tools.DateTimeExt
         /// <param name="y">年</param>
         /// <param name="n">节气</param>
         /// <returns>日期时间</returns>
-        private DateTime GetSolarTermDay(int y, int n)
+        private static DateTime GetSolarTermDay(int y, int n)
         {
             //按分钟起计算
             double minutes = (525948.766245 * (y - 1900)) + solarTermInfo[n - 1];
@@ -690,7 +690,7 @@ namespace Masuit.Tools.DateTimeExt
         /// </summary>
         /// <param name="d">待检查的日子</param>
         /// <returns>日期信息</returns>
-        public StructDateFullInfo GetDateTidyInfo(DateTime d)
+        public static StructDateFullInfo GetDateTidyInfo(this DateTime d)
         {
             StructDateFullInfo dayinfo = new StructDateFullInfo();
             structDate day = GetLunar(d);
@@ -783,7 +783,7 @@ namespace Masuit.Tools.DateTimeExt
         /// </summary>
         /// <param name="d">待检查的日子</param>
         /// <returns>日期信息</returns>
-        public StructDateFullInfo GetDateInfo(DateTime d)
+        public static StructDateFullInfo GetDateInfo(this DateTime d)
         {
             // xml文件属性-生成操作-嵌入的资源
             string calendarXmlData = ReadFileFromEmbedded("Core.Common" + "CCalendarData.xml");
@@ -921,7 +921,7 @@ namespace Masuit.Tools.DateTimeExt
         /// 获取农历
         /// </summary>
         /// <param name="dt">阳历日期</param>
-        public StructDateFullInfo getChinaDate(DateTime dt)
+        public static StructDateFullInfo getChinaDate(this DateTime dt)
         {
             StructDateFullInfo cd = new StructDateFullInfo();
             int year = dt.Year;

+ 3 - 4
Masuit.Tools/DateTimeExt/ChineseCalendar.cs

@@ -17,9 +17,9 @@ namespace Masuit.Tools.DateTimeExt
         /// 获取农历当前日期
         /// </summary>
         /// <returns>当前农历日期</returns>
-        public static string GetChineseDateTimeNow()
+        public static string GetChineseDateTimeNow(this DateTime dt)
         {
-            return GetChineseDateTime(DateTime.Now);
+            return GetChineseDateTime(dt);
         }
 
         /// <summary>
@@ -57,7 +57,7 @@ namespace Masuit.Tools.DateTimeExt
         /// <summary>
         /// 返回农历日期
         /// </summary>
-        public static string Now => GetChineseDateTimeNow();
+        public static string Now => DateTime.Now.GetChineseDateTimeNow();
 
         /// <summary>
         /// 最大支持日期
@@ -108,7 +108,6 @@ namespace Masuit.Tools.DateTimeExt
             {
                 int tgIndex = (year - 4) % 10;
                 int dzIndex = (year - 4) % 12;
-
                 return string.Concat(tiangan[tgIndex], dizhi[dzIndex], "[", shengxiao[dzIndex], "]");
             }
 

+ 3 - 3
Masuit.Tools/DateTimeExt/DateTimeHelper.cs

@@ -14,7 +14,7 @@ namespace Masuit.Tools.DateTimeExt
         /// </summary>
         /// <param name="year">年份</param>
         /// <returns>该年周数</returns>
-        public static int GetWeekAmount(int year)
+        public static int GetWeekAmount(this DateTime _, int year)
         {
             var end = new System.DateTime(year, 12, 31); //该年最后一天
             var gc = new GregorianCalendar();
@@ -55,7 +55,7 @@ namespace Masuit.Tools.DateTimeExt
         /// <param name="nNumWeek">第几周</param>
         /// <param name="dtWeekStart">开始日期</param>
         /// <param name="dtWeekeEnd">结束日期</param>
-        public static void GetWeekTime(int nYear, int nNumWeek, out DateTime dtWeekStart, out DateTime dtWeekeEnd)
+        public static void GetWeekTime(this DateTime _, int nYear, int nNumWeek, out DateTime dtWeekStart, out DateTime dtWeekeEnd)
         {
             var dt = new DateTime(nYear, 1, 1);
             dt += new TimeSpan((nNumWeek - 1) * 7, 0, 0, 0);
@@ -70,7 +70,7 @@ namespace Masuit.Tools.DateTimeExt
         /// <param name="nNumWeek">第几周</param>
         /// <param name="dtWeekStart">开始日期</param>
         /// <param name="dtWeekeEnd">结束日期</param>
-        public static void GetWeekWorkTime(int nYear, int nNumWeek, out System.DateTime dtWeekStart, out System.DateTime dtWeekeEnd)
+        public static void GetWeekWorkTime(this DateTime _, int nYear, int nNumWeek, out System.DateTime dtWeekStart, out System.DateTime dtWeekeEnd)
         {
             var dt = new DateTime(nYear, 1, 1);
             dt += new TimeSpan((nNumWeek - 1) * 7, 0, 0, 0);

+ 49 - 21
Masuit.Tools/DateTimeExt/DateUtil.cs

@@ -1,5 +1,4 @@
-
-using System;
+using System;
 
 namespace Masuit.Tools.DateTimeExt
 {
@@ -11,26 +10,24 @@ namespace Masuit.Tools.DateTimeExt
         /// <summary>
         /// 返回相对于当前时间的相对天数
         /// </summary>
+        /// <param name="dt"></param>
         /// <param name="relativeday">相对天数</param>
-        public static string GetDateTime(int relativeday)
+        public static string GetDateTime(this DateTime dt, int relativeday)
         {
-            return DateTime.Now.AddDays(relativeday).ToString("yyyy-MM-dd HH:mm:ss");
+            return dt.AddDays(relativeday).ToString("yyyy-MM-dd HH:mm:ss");
         }
 
         /// <summary>
         /// 返回标准时间格式string
         /// </summary>
-        public static string GetDateTimeF()
-        {
-            return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fffffff");
-        }
+        public static string GetDateTimeF(this DateTime dt) => dt.ToString("yyyy-MM-dd HH:mm:ss:fffffff");
 
         /// <summary>
         /// 返回标准时间 
         /// </summary>
         /// <param name="fDateTime">日期时间字符串</param>
         /// <param name="formatStr">格式</param>
-        public static string GetStandardDateTime(string fDateTime, string formatStr)
+        public static string GetStandardDateTime(this string fDateTime, string formatStr)
         {
             if (fDateTime == "0000-0-0 0:00:00")
             {
@@ -44,17 +41,52 @@ namespace Masuit.Tools.DateTimeExt
         /// 返回标准时间 yyyy-MM-dd HH:mm:ss
         /// </summary>
         /// <param name="fDateTime">日期时间字符串</param>
-        public static string GetStandardDateTime(string fDateTime)
+        public static string GetStandardDateTime(this string fDateTime)
         {
             return GetStandardDateTime(fDateTime, "yyyy-MM-dd HH:mm:ss");
         }
 
+        /// <summary>
+        /// 获取该时间相对于1970-01-01 00:00:00的秒数
+        /// </summary>
+        /// <param name="dt"></param>
+        /// <returns></returns>
+        public static double GetTotalSeconds(this DateTime dt) => (dt - DateTime.Parse("1970-01-01 00:00:00")).TotalSeconds;
+
+        /// <summary>
+        /// 获取该时间相对于1970-01-01 00:00:00的毫秒数
+        /// </summary>
+        /// <param name="dt"></param>
+        /// <returns></returns>
+        public static double GetTotalMilliseconds(this DateTime dt) => (dt - DateTime.Parse("1970-01-01 00:00:00")).TotalMilliseconds;
+
+        /// <summary>
+        /// 获取该时间相对于1970-01-01 00:00:00的分钟数
+        /// </summary>
+        /// <param name="dt"></param>
+        /// <returns></returns>
+        public static double GetTotalMinutes(this DateTime dt) => (dt - DateTime.Parse("1970-01-01 00:00:00")).TotalMinutes;
+
+        /// <summary>
+        /// 获取该时间相对于1970-01-01 00:00:00的小时数
+        /// </summary>
+        /// <param name="dt"></param>
+        /// <returns></returns>
+        public static double GetTotalHours(this DateTime dt) => (dt - DateTime.Parse("1970-01-01 00:00:00")).TotalHours;
+
+        /// <summary>
+        /// 获取该时间相对于1970-01-01 00:00:00的天数
+        /// </summary>
+        /// <param name="dt"></param>
+        /// <returns></returns>
+        public static double GetTotalDays(this DateTime dt) => (dt - DateTime.Parse("1970-01-01 00:00:00")).TotalDays;
+
         /// <summary>
         /// 返回本年有多少天
         /// </summary>
         /// <param name="iYear">年份</param>
         /// <returns>本年的天数</returns>
-        public static int GetDaysOfYear(int iYear)
+        public static int GetDaysOfYear(this DateTime _, int iYear)
         {
             int cnt = 0;
             if (IsRuYear(iYear))
@@ -64,7 +96,7 @@ namespace Masuit.Tools.DateTimeExt
             }
             else
             {
-                //--非闰年少1天 即:2 月为 28 天
+                //非闰年少1天 即:2 月为 28 天
                 cnt = 365;
             }
             return cnt;
@@ -93,7 +125,7 @@ namespace Masuit.Tools.DateTimeExt
         /// <param name="iYear">年</param>
         /// <param name="month">月</param>
         /// <returns>天数</returns>
-        public static int GetDaysOfMonth(int iYear, int month)
+        public static int GetDaysOfMonth(this DateTime _, int iYear, int month)
         {
             int days = 0;
             switch (month)
@@ -127,8 +159,6 @@ namespace Masuit.Tools.DateTimeExt
                     days = 30;
                     break;
                 case 7:
-                    days = 31;
-                    break;
                 case 8:
                     days = 31;
                     break;
@@ -327,7 +357,7 @@ namespace Masuit.Tools.DateTimeExt
         /// </summary>
         /// <param name="strInput">输入字符串</param>
         /// <returns>日期对象</returns>
-        public static System.DateTime ConvertStringToDate(string strInput)
+        public static System.DateTime ConvertStringToDate(this string strInput)
         {
             System.DateTime oDateTime;
 
@@ -386,13 +416,12 @@ namespace Masuit.Tools.DateTimeExt
         /// </summary>
         /// <param name="strDate">输入日期字符串</param>
         /// <returns>True/False</returns>
-        public static bool IsDateTime(string strDate)
+        public static bool IsDateTime(this string strDate)
         {
             try
             {
                 DateTime oDate = DateTime.Parse(strDate);
-                if (oDate.CompareTo(DateTime.Parse("1800-1-1")) > 0)
-                    return true;
+                if (oDate.CompareTo(DateTime.Parse("1800-1-1")) > 0) return true;
                 return false;
             }
             catch (Exception)
@@ -401,5 +430,4 @@ namespace Masuit.Tools.DateTimeExt
             }
         }
     }
-}
-
+}

+ 6 - 6
Masuit.Tools/DateTimeExt/TimeHelper.cs

@@ -41,7 +41,7 @@ namespace Masuit.Tools.DateTimeExt
         /// <param name="month">月份</param>
         /// <param name="firstDay">第一天</param>
         /// <param name="lastDay">最后一天</param>
-        public static void ReturnDateFormat(int month, out string firstDay, out string lastDay)
+        public static void ReturnDateFormat(this DateTime _, int month, out string firstDay, out string lastDay)
         {
             int year = DateTime.Now.Year + (month / 12);
             if (month != 12)
@@ -155,9 +155,9 @@ namespace Masuit.Tools.DateTimeExt
         /// </summary>
         /// <param name="Second">秒数</param>
         /// <returns>分钟数</returns>
-        public static int SecondToMinute(int Second)
+        public static int SecondToMinute(this DateTime _, int Second)
         {
-            decimal mm = (decimal)((decimal)Second / (decimal)60);
+            decimal mm = Second / (decimal)60;
             return Convert.ToInt32(Math.Ceiling(mm));
         }
         #endregion
@@ -169,7 +169,7 @@ namespace Masuit.Tools.DateTimeExt
         /// <param name="year">年份</param>
         /// <param name="month">月份</param>
         /// <returns>日</returns>
-        public static int GetMonthLastDate(int year, int month)
+        public static int GetMonthLastDate(this DateTime _, int year, int month)
         {
             System.DateTime lastDay = new System.DateTime(year, month, new System.Globalization.GregorianCalendar().GetDaysInMonth(year, month));
             int Day = lastDay.Day;
@@ -419,7 +419,7 @@ namespace Masuit.Tools.DateTimeExt
         /// </summary>
         /// <param name="time">php的时间</param>
         /// <returns>C#的时间</returns>
-        public static System.DateTime PhpTime2CsharpTime(long time)
+        public static System.DateTime PhpTime2CsharpTime(this DateTime _, long time)
         {
             System.DateTime timeStamp = new System.DateTime(1970, 1, 1);  //得到1970年的时间戳
             long t = (time + 8 * 60 * 60) * 10000000 + timeStamp.Ticks;
@@ -446,7 +446,7 @@ namespace Masuit.Tools.DateTimeExt
         /// </summary> 
         /// <param name="strDateTime">Rss中读取的时间</param> 
         /// <returns>处理后的标准时间格式</returns> 
-        public static string DateConvert(string strDateTime)
+        public static string DateConvert(this string strDateTime)
         {
             strDateTime = strDateTime.Replace("+0000", "GMT");
             strDateTime = strDateTime.Replace("+0100", "GMT");

+ 306 - 0
Masuit.Tools/Extensions.cs

@@ -1,6 +1,13 @@
 using System;
 using System.Collections.Generic;
+using System.Drawing;
+using System.IO;
+using System.Runtime.Serialization;
+using System.Runtime.Serialization.Formatters.Binary;
+using System.Security;
 using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using Newtonsoft.Json;
 
 namespace Masuit.Tools
 {
@@ -9,6 +16,8 @@ namespace Masuit.Tools
     /// </summary>
     public static class Extensions
     {
+        #region Sync
+
         /// <summary>
         /// 遍历数组
         /// </summary>
@@ -180,6 +189,111 @@ namespace Masuit.Tools
             }
         }
 
+        #endregion
+
+        #region Async
+
+        /// <summary>
+        /// 遍历数组
+        /// </summary>
+        /// <param name="objs"></param>
+        /// <param name="action">回调方法</param>
+        public static async void ForEachAsync(this object[] objs, Action<object> action)
+        {
+            await Task.Run(() =>
+            {
+                foreach (var o in objs)
+                {
+                    action(o);
+                }
+            });
+        }
+
+        /// <summary>
+        /// 遍历IEnumerable
+        /// </summary>
+        /// <param name="objs"></param>
+        /// <param name="action">回调方法</param>
+        public static async void ForEachAsync(this IEnumerable<dynamic> objs, Action<object> action)
+        {
+            await Task.Run(() =>
+            {
+                foreach (var o in objs)
+                {
+                    action(o);
+                }
+            });
+        }
+
+        /// <summary>
+        /// 遍历集合
+        /// </summary>
+        /// <param name="objs"></param>
+        /// <param name="action">回调方法</param>
+        public static async void ForEachAsync(this IList<dynamic> objs, Action<object> action)
+        {
+            await Task.Run(() =>
+            {
+                foreach (var o in objs)
+                {
+                    action(o);
+                }
+            });
+        }
+
+        /// <summary>
+        /// 遍历数组
+        /// </summary>
+        /// <param name="objs"></param>
+        /// <param name="action">回调方法</param>
+        /// <typeparam name="T"></typeparam>
+        public static async void ForEachAsync<T>(this T[] objs, Action<T> action)
+        {
+            await Task.Run(() =>
+            {
+                foreach (var o in objs)
+                {
+                    action(o);
+                }
+            });
+        }
+
+        /// <summary>
+        /// 遍历IEnumerable
+        /// </summary>
+        /// <param name="objs"></param>
+        /// <param name="action">回调方法</param>
+        /// <typeparam name="T"></typeparam>
+        public static async void ForEachAsync<T>(this IEnumerable<T> objs, Action<T> action)
+        {
+            await Task.Run(() =>
+            {
+                foreach (var o in objs)
+                {
+                    action(o);
+                }
+            });
+        }
+
+        /// <summary>
+        /// 遍历List
+        /// </summary>
+        /// <param name="objs"></param>
+        /// <param name="action">回调方法</param>
+        /// <typeparam name="T"></typeparam>
+        public static async void ForEachAsync<T>(this IList<T> objs, Action<T> action)
+        {
+            await Task.Run(() =>
+            {
+                foreach (var o in objs)
+                {
+                    action(o);
+                }
+            });
+        }
+
+        #endregion
+
         /// <summary>
         /// 映射到目标类型(浅克隆)
         /// </summary>
@@ -192,6 +306,67 @@ namespace Masuit.Tools
             dest.GetType().GetProperties().ForEach(p => { p.SetValue(dest, source.GetType().GetProperty(p.Name)?.GetValue(source)); });
             return dest;
         }
+        /// <summary>
+        /// 映射到目标类型(浅克隆)
+        /// </summary>
+        /// <param name="source">源</param>
+        /// <typeparam name="TDestination">目标类型</typeparam>
+        /// <returns>目标类型</returns>
+        public static async Task<TDestination> MapToAsync<TDestination>(this object source) where TDestination : new()
+        {
+            return await Task.Run(() =>
+            {
+                TDestination dest = new TDestination();
+                dest.GetType().GetProperties().ForEach(p => { p.SetValue(dest, source.GetType().GetProperty(p.Name)?.GetValue(source)); });
+                return dest;
+            });
+        }
+
+        /// <summary>
+        /// 映射到目标类型(深克隆)
+        /// </summary>
+        /// <param name="source">源</param>
+        /// <typeparam name="TDestination">目标类型</typeparam>
+        /// <returns>目标类型</returns>
+        public static TDestination Map<TDestination>(this object source) where TDestination : new() => JsonConvert.DeserializeObject<TDestination>(JsonConvert.SerializeObject(source));
+        /// <summary>
+        /// 映射到目标类型(深克隆)
+        /// </summary>
+        /// <param name="source">源</param>
+        /// <typeparam name="TDestination">目标类型</typeparam>
+        /// <returns>目标类型</returns>
+        public static async Task<TDestination> MapAsync<TDestination>(this object source) where TDestination : new()
+        {
+            return await Task.Run(() => JsonConvert.DeserializeObject<TDestination>(JsonConvert.SerializeObject(source)));
+        }
+
+        /// <summary>
+        /// 复制一个新的对象
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="source"></param>
+        /// <returns></returns>
+        public static T Copy<T>(this T source) where T : new()
+        {
+            T dest = new T();
+            dest.GetType().GetProperties().ForEach(p => { p.SetValue(dest, source.GetType().GetProperty(p.Name)?.GetValue(source)); });
+            return dest;
+        }
+        /// <summary>
+        /// 复制一个新的对象
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="source"></param>
+        /// <returns></returns>
+        public static async Task<T> CopyAsync<T>(this T source) where T : new()
+        {
+            return await Task.Run(() =>
+            {
+                T dest = new T();
+                dest.GetType().GetProperties().ForEach(p => { p.SetValue(dest, source.GetType().GetProperty(p.Name)?.GetValue(source)); });
+                return dest;
+            });
+        }
 
         /// <summary>
         /// 映射到目标类型的集合
@@ -208,6 +383,26 @@ namespace Masuit.Tools
                 yield return dest;
             }
         }
+        /// <summary>
+        /// 映射到目标类型的集合
+        /// </summary>
+        /// <param name="source">源</param>
+        /// <typeparam name="TDestination">目标类型</typeparam>
+        /// <returns>目标类型集合</returns>
+        public static async Task<IEnumerable<TDestination>> ToListAsync<TDestination>(this object[] source) where TDestination : new()
+        {
+            return await Task.Run(() =>
+            {
+                IList<TDestination> list = new List<TDestination>();
+                foreach (var o in source)
+                {
+                    var dest = new TDestination();
+                    dest.GetType().GetProperties().ForEach(p => { p.SetValue(dest, source.GetType().GetProperty(p.Name)?.GetValue(o)); });
+                    list.Add(dest);
+                }
+                return list;
+            });
+        }
 
         /// <summary>
         /// 映射到目标类型的集合
@@ -224,6 +419,26 @@ namespace Masuit.Tools
                 yield return dest;
             }
         }
+        /// <summary>
+        /// 映射到目标类型的集合
+        /// </summary>
+        /// <param name="source">源</param>
+        /// <typeparam name="TDestination">目标类型</typeparam>
+        /// <returns>目标类型集合</returns>
+        public static async Task<IEnumerable<TDestination>> ToListAsync<TDestination>(this IList<dynamic> source) where TDestination : new()
+        {
+            return await Task.Run(() =>
+            {
+                IList<TDestination> list = new List<TDestination>();
+                foreach (var o in source)
+                {
+                    var dest = new TDestination();
+                    dest.GetType().GetProperties().ForEach(p => { p.SetValue(dest, source.GetType().GetProperty(p.Name)?.GetValue(o)); });
+                    list.Add(dest);
+                }
+                return list;
+            });
+        }
 
         /// <summary>
         /// 映射到目标类型的集合
@@ -240,6 +455,39 @@ namespace Masuit.Tools
                 yield return dest;
             }
         }
+        /// <summary>
+        /// 映射到目标类型的集合
+        /// </summary>
+        /// <param name="source">源</param>
+        /// <typeparam name="TDestination">目标类型</typeparam>
+        /// <returns>目标类型集合</returns>
+        public static async Task<IEnumerable<TDestination>> ToListAsync<TDestination>(this IEnumerable<dynamic> source) where TDestination : new()
+        {
+            return await Task.Run(() =>
+            {
+                IList<TDestination> list = new List<TDestination>();
+                foreach (var o in source)
+                {
+                    var dest = new TDestination();
+                    dest.GetType().GetProperties().ForEach(p => { p.SetValue(dest, source.GetType().GetProperty(p.Name)?.GetValue(o)); });
+                    list.Add(dest);
+                }
+                return list;
+            });
+        }
+
+        /// <summary>
+        /// 转换成json字符串
+        /// </summary>
+        /// <param name="source"></param>
+        /// <returns></returns>
+        public static string ToJsonString(this object source) => JsonConvert.SerializeObject(source);
+        /// <summary>
+        /// 转换成json字符串
+        /// </summary>
+        /// <param name="source"></param>
+        /// <returns></returns>
+        public static async Task<string> ToJsonStringAsync(this object source) => await Task.Run(() => JsonConvert.SerializeObject(source));
 
         #region UBB转HTML
 
@@ -597,6 +845,13 @@ namespace Masuit.Tools
             return ubbStr;
         }
 
+        /// <summary>
+        /// UBB代码处理函数
+        /// </summary>
+        /// <param name="ubbStr">输入UBB字符串</param>
+        /// <returns>输出html字符串</returns>
+        public static async Task<string> UbbToHtmlAsync(this string ubbStr) => await Task.Run(() => UbbToHtml(ubbStr));
+
         #endregion
 
         #region UBB转HTML方式2
@@ -750,6 +1005,13 @@ namespace Masuit.Tools
             return ubbStr;
         }
 
+        /// <summary>
+        /// UBB转HTML方式2
+        /// </summary>
+        /// <param name="ubbStr">UBB 代码</param>
+        /// <returns>HTML代码</returns>
+        public static async Task<string> UbbToHtml2Async(this string ubbStr) => await Task.Run(() => UbbToHtml2(ubbStr));
+
         #endregion
 
         #region Html转UBB
@@ -793,6 +1055,12 @@ namespace Masuit.Tools
             chr = Regex.Replace(chr, @"<center>—— 以下是引用 ——<table border='1' width='80%' cellpadding='10' cellspacing='0' ><tr><td>$1</td></tr></table></center>", @"[quote](?<x>.*)[/quote]", RegexOptions.IgnoreCase);
             return chr;
         }
+        /// <summary>
+        /// Html转UBB
+        /// </summary>
+        /// <param name="chr">HTML代码</param>
+        /// <returns>UBB代码</returns>
+        public static async Task<string> HtmltoUBBAsync(this string chr) => await Task.Run(() => HtmltoUBB(chr));
 
         #endregion
 
@@ -1054,5 +1322,43 @@ namespace Masuit.Tools
         }
 
         #endregion
+
+        /// <summary>
+        /// 将dataUri保存为图片
+        /// </summary>
+        /// <param name="source">dataUri数据源</param>
+        /// <returns></returns>
+        /// <exception cref="Exception">操作失败。</exception>
+        public static Bitmap SaveDataUriAsImageFile(string source)
+        {
+            string strbase64 = source.Substring(source.IndexOf(',') + 1);
+            strbase64 = strbase64.Trim('\0');
+            Bitmap bmp2;
+            byte[] arr = Convert.FromBase64String(strbase64);
+            using (var ms = new MemoryStream(arr))
+            {
+                var bmp = new Bitmap(ms);
+                //新建第二个bitmap类型的bmp2变量。
+                bmp2 = new Bitmap(bmp, bmp.Width, bmp.Height);
+                //将第一个bmp拷贝到bmp2中
+                Graphics draw = Graphics.FromImage(bmp2);
+                using (draw)
+                {
+                    draw.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height);
+                }
+            }
+            return bmp2;
+        }
+
+        /// <summary>
+        /// 严格比较两个对象是否是同一对象
+        /// </summary>
+        /// <param name="_this">自己</param>
+        /// <param name="o">需要比较的对象</param>
+        /// <returns>是否同一对象</returns>
+        public new static bool ReferenceEquals(this object _this, object o)
+        {
+            return object.ReferenceEquals(_this, o);
+        }
     }
 }

+ 34 - 72
Masuit.Tools/Html/HtmlHelper.cs

@@ -115,11 +115,11 @@ namespace Masuit.Tools.Html
         /// <param name="postData">post 提交的字符串</param>
         /// <param name="isPost">是否以post方式发送请求</param>
         /// <param name="cookieContainer">Cookie集合</param>
-        public static string GetHtml(string url, string postData, bool isPost, CookieContainer cookieContainer)
+        public static string GetHtml(this HttpWebRequest _, string url, string postData, bool isPost, CookieContainer cookieContainer)
         {
             if (string.IsNullOrEmpty(postData))
             {
-                return GetHtml(url, cookieContainer);
+                return GetHtml(null, url, cookieContainer);
             }
             Thread.Sleep(NetworkDelay);
             currentTry++;
@@ -129,7 +129,7 @@ namespace Masuit.Tools.Html
             {
                 byte[] byteRequest = Encoding.Default.GetBytes(postData);
 
-                httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
+                httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                 httpWebRequest.CookieContainer = cookieContainer;
                 httpWebRequest.ContentType = contentType;
                 httpWebRequest.ServicePoint.ConnectionLimit = MaxTry;
@@ -170,7 +170,7 @@ namespace Masuit.Tools.Html
             {
                 if (currentTry <= MaxTry)
                 {
-                    GetHtml(url, postData, isPost, cookieContainer);
+                    GetHtml(null, url, postData, isPost, cookieContainer);
                 }
                 currentTry--;
                 if (httpWebRequest != null) httpWebRequest.Abort();
@@ -184,7 +184,7 @@ namespace Masuit.Tools.Html
         /// </summary>
         /// <param name="url">地址</param>
         /// <param name="cookieContainer">Cookie集合</param>
-        public static string GetHtml(string url, CookieContainer cookieContainer)
+        public static string GetHtml(this HttpWebRequest _, string url, CookieContainer cookieContainer)
         {
             Thread.Sleep(NetworkDelay);
             currentTry++;
@@ -192,7 +192,7 @@ namespace Masuit.Tools.Html
             HttpWebResponse httpWebResponse = null;
             try
             {
-                httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
+                httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                 httpWebRequest.CookieContainer = cookieContainer;
                 httpWebRequest.ContentType = contentType;
                 httpWebRequest.ServicePoint.ConnectionLimit = MaxTry;
@@ -213,7 +213,7 @@ namespace Masuit.Tools.Html
             }
             catch (Exception)
             {
-                if (currentTry <= MaxTry) GetHtml(url, cookieContainer);
+                if (currentTry <= MaxTry) GetHtml(null, url, cookieContainer);
                 currentTry--;
                 if (httpWebRequest != null) httpWebRequest.Abort();
                 if (httpWebResponse != null) httpWebResponse.Close();
@@ -234,7 +234,7 @@ namespace Masuit.Tools.Html
         ///---------------------------------------------------------------------------------------------------------------
         /// <param name="url">地址</param>
         /// <param name="cookieContainer">cookieContainer</param>
-        public static Stream GetStream(string url, CookieContainer cookieContainer)
+        public static Stream GetStream(this HttpWebRequest _, string url, CookieContainer cookieContainer)
         {
             currentTry++;
 
@@ -243,7 +243,7 @@ namespace Masuit.Tools.Html
 
             try
             {
-                httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
+                httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                 httpWebRequest.CookieContainer = cookieContainer;
                 httpWebRequest.ContentType = contentType;
                 httpWebRequest.ServicePoint.ConnectionLimit = MaxTry;
@@ -261,7 +261,7 @@ namespace Masuit.Tools.Html
             {
                 if (currentTry <= MaxTry)
                 {
-                    GetHtml(url, cookieContainer);
+                    GetHtml(null, url, cookieContainer);
                 }
 
                 currentTry--;
@@ -300,7 +300,7 @@ namespace Masuit.Tools.Html
         ///</summary>   
         ///<param name="Htmlstring">包括HTML的源码</param>   
         ///<returns>已经去除后的文字</returns>   
-        public static string RemoveHTML(string Htmlstring)
+        public static string RemoveHTML(this string Htmlstring)
         {
             //删除脚本   
             Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
@@ -339,7 +339,7 @@ namespace Masuit.Tools.Html
         /// 4.1获取页面的链接正则
         /// </summary>
         /// <param name="HtmlCode">html代码</param>
-        public static string GetHref(string HtmlCode)
+        public static string GetHref(this string HtmlCode)
         {
             string MatchVale = "";
             string Reg = @"(h|H)(r|R)(e|E)(f|F) *= *('|"")?((\w|\\|\/|\.|:|-|_)+)[\S]*";
@@ -357,7 +357,7 @@ namespace Masuit.Tools.Html
         /// </summary>
         /// <param name="html">html代码</param>
         /// <returns>提取到的url</returns>
-        public static string GetAllURL(string html)
+        public static string GetAllURL(this string html)
         {
             StringBuilder sb = new StringBuilder();
             Match m = Regex.Match(html.ToLower(), "<a href=(.*?)>.*?</a>");
@@ -378,7 +378,7 @@ namespace Masuit.Tools.Html
         /// </summary>
         /// <param name="html">html代码</param>
         /// <returns>所有的带链接的a标签</returns>
-        public static string GetAllLinkText(string html)
+        public static string GetAllLinkText(this string html)
         {
             StringBuilder sb = new StringBuilder();
             Match m = Regex.Match(html.ToLower(), "<a href=.*?>(1,100})</a>");
@@ -409,7 +409,7 @@ namespace Masuit.Tools.Html
         /// </summary>
         /// <param name="HtmlCode">html代码</param>
         /// <param name="imgHttp">要补充的http://路径信息</param>
-        public static string GetImgSrc(string HtmlCode, string imgHttp)
+        public static string GetImgSrc(this string HtmlCode, string imgHttp)
         {
             string MatchVale = "";
             string Reg = @"<img.+?>";
@@ -467,7 +467,7 @@ namespace Masuit.Tools.Html
         /// </summary>
         /// <param name="ImgString"><img src="" />字符串</param>
         /// <param name="imgHttp">图片路径</param>
-        public static string GetImg(string ImgString, string imgHttp)
+        public static string GetImg(this string ImgString, string imgHttp)
         {
             string MatchVale = "";
             string Reg = @"src=.+\.(bmp|jpg|gif|png|)";
@@ -487,12 +487,12 @@ namespace Masuit.Tools.Html
         /// 6.1以GET方式抓取远程页面内容
         /// </summary>
         /// <param name="tUrl">URL</param>
-        public static string Get_Http(string tUrl)
+        public static string Get_Http(this HttpWebRequest _, string tUrl)
         {
             string strResult;
             try
             {
-                HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create(tUrl);
+                HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(tUrl);
                 hwr.Timeout = 19600;
                 HttpWebResponse hwrs = (HttpWebResponse)hwr.GetResponse();
                 Stream myStream = hwrs.GetResponseStream();
@@ -518,7 +518,7 @@ namespace Masuit.Tools.Html
         /// <param name="url">URL</param>
         /// <param name="postData">参数列表</param>
         /// <param name="encodeType">编码类型</param>
-        public static string Post_Http(string url, string postData, string encodeType)
+        public static string Post_Http(this HttpWebRequest _, string url, string postData, string encodeType)
         {
             string strResult = null;
             try
@@ -549,7 +549,7 @@ namespace Masuit.Tools.Html
         /// 7.1压缩HTML输出
         /// </summary>
         /// <param name="Html">html</param>
-        public static string ZipHtml(string Html)
+        public static string ZipHtml(this string Html)
         {
             Html = Regex.Replace(Html, @">\s+?<", "><");//去除HTML中的空白字符
             Html = Regex.Replace(Html, @"\r\n\s*", "");
@@ -566,7 +566,7 @@ namespace Masuit.Tools.Html
         /// </summary>
         /// <param name="s_TextStr">要过滤的字符</param>
         /// <param name="html_Str">a img p div</param>
-        public static string DelHtml(string s_TextStr, string html_Str)
+        public static string DelHtml(this string s_TextStr, string html_Str)
         {
             string rStr = "";
             if (!string.IsNullOrEmpty(s_TextStr))
@@ -584,7 +584,7 @@ namespace Masuit.Tools.Html
         /// </summary>
         /// <param name="content">html代码</param>
         /// <returns>过滤后的安全内容</returns>
-        public static string RemoveUnsafeHtml(string content)
+        public static string RemoveUnsafeHtml(this string content)
         {
             content = Regex.Replace(content, @"(\<|\s+)o([a-z]+\s?=)", "$1$2", RegexOptions.IgnoreCase);
             content = Regex.Replace(content, @"(script|frame|form|meta|behavior|style)([\s|:|>])+", "$1.$2", RegexOptions.IgnoreCase);
@@ -601,7 +601,7 @@ namespace Masuit.Tools.Html
         /// </summary>
         /// <param name="strHtml">html代码</param>
         /// <returns>普通文本</returns>
-        public static string HtmlToTxt(string strHtml)
+        public static string HtmlToTxt(this string strHtml)
         {
             string[] aryReg ={
             @"<script[^>]*?>.*?</script>",
@@ -621,7 +621,6 @@ namespace Masuit.Tools.Html
             @"<!--.*\n"
             };
 
-            string newReg = aryReg[0];
             string strOutput = strHtml;
             for (int i = 0; i < aryReg.Length; i++)
             {
@@ -641,7 +640,7 @@ namespace Masuit.Tools.Html
         /// </summary>
         /// <param name="str">字符串</param>
         /// <returns>html标签</returns>
-        public static string StringToHtml(string str)
+        public static string StringToHtml(this string str)
         {
             str = str.Replace("&", "&amp;");
             str = str.Replace(" ", "&nbsp;");
@@ -662,7 +661,7 @@ namespace Masuit.Tools.Html
         /// </summary>
         /// <param name="strHtml">html代码</param>
         /// <returns>安全的字符串</returns>
-        public static string HtmlToString(string strHtml)
+        public static string HtmlToString(this string strHtml)
         {
             strHtml = strHtml.Replace("<br>", "\r\n");
             strHtml = strHtml.Replace(@"<br />", "\r\n");
@@ -683,7 +682,7 @@ namespace Masuit.Tools.Html
         /// </summary>
         /// <param name="url">URL</param>
         /// <returns>编码类型</returns>
-        public static string GetEncoding(string url)
+        public static string GetEncoding(this HttpWebRequest _, string url)
         {
             HttpWebRequest request = null;
             HttpWebResponse response = null;
@@ -747,7 +746,7 @@ namespace Masuit.Tools.Html
         /// </summary>
         /// <param name="url">待判断的URL,可以是网页以及图片链接等</param>
         /// <returns>200为正确,其余为大致网页错误代码</returns>
-        public static int GetUrlError(string url)
+        public static int GetUrlError(this HttpWebRequest _, string url)
         {
             int num = 200;
             try
@@ -805,59 +804,22 @@ namespace Masuit.Tools.Html
         }
         #endregion
 
-        #region 加载文件块
-        /// <summary>
-        /// 加载文件块
-        /// </summary>
-        /// <param name="Path">文件路径</param>
-        /// <param name="p">Page页</param>
-        public static string File(string Path, System.Web.UI.Page p)
-        {
-            return @p.ResolveUrl(Path);
-        }
-        #endregion
-
-        #region 加载CSS样式文件
-        /// <summary>
-        /// 加载CSS样式文件
-        /// </summary>
-        /// <param name="cssPath">css路径</param>
-        /// <param name="p">Page页</param>
-        public static string CSS(string cssPath, System.Web.UI.Page p)
-        {
-            return @"<link href=""" + p.ResolveUrl(cssPath) + @""" rel=""stylesheet"" type=""text/css"" />" + "\r\n";
-        }
-        #endregion
-
-        #region 加载JavaScript脚本文件
-        /// <summary>
-        /// 加载javascript脚本文件
-        /// </summary>
-        /// <param name="jsPath">js路径</param>
-        /// <param name="p">web页面</param>
-        public static string Javascript(string jsPath, System.Web.UI.Page p)
-        {
-            return @"<script type=""text/javascript"" src=""" + p.ResolveUrl(jsPath) + @"""> </script>" + "\r\n";
-        }
-        #endregion
-
         /// <summary>
         /// 获取Cookie集合
         /// </summary>
         /// <param name="cookieString">Cookie的键</param>
         /// <returns>Cookie键值集合</returns>
-        public static CookieCollection GetCookieCollection(string cookieString)
+        public static CookieCollection GetCookieCollection(this CookieCollection cookie, string cookieString)
         {
-            CookieCollection ccc = new CookieCollection();
             //string cookieString = "SID=ARRGy4M1QVBtTU-ymi8bL6X8mVkctYbSbyDgdH8inu48rh_7FFxHE6MKYwqBFAJqlplUxq7hnBK5eqoh3E54jqk=;Domain=.google.com;Path=/,LSID=AaMBTixN1MqutGovVSOejyb8mVkctYbSbyDgdH8inu48rh_7FFxHE6MKYwqBFAJqlhCe_QqxLg00W5OZejb_UeQ=;Domain=www.google.com;Path=/accounts";
             Regex re = new Regex("([^;,]+)=([^;,]+);Domain=([^;,]+);Path=([^;,]+)", RegexOptions.IgnoreCase);
             foreach (Match m in re.Matches(cookieString))
             {
                 //name,   value,   path,   domain   
                 Cookie c = new Cookie(m.Groups[1].Value, m.Groups[2].Value, m.Groups[3].Value, m.Groups[3].Value);
-                ccc.Add(c);
+                cookie.Add(c);
             }
-            return ccc;
+            return cookie;
         }
 
         #region 从HTML中获取文本,保留br,p,img
@@ -867,7 +829,7 @@ namespace Masuit.Tools.Html
         /// </summary>
         /// <param name="HTML">html代码</param>
         /// <returns>保留br,p,img的文本</returns>
-        public static string GetTextFromHTML(string HTML)
+        public static string GetTextFromHTML(this string HTML)
         {
             Regex regEx = new Regex(@"</?(?!br|/?p|img)[^>]*>", RegexOptions.IgnoreCase);
 
@@ -883,7 +845,7 @@ namespace Masuit.Tools.Html
         /// <param name="html">html源代码</param>
         /// <param name="key">键</param>
         /// <returns>获取到的值</returns>
-        public static string GetHiddenKeyValue(string html, string key)
+        public static string GetHiddenKeyValue(this string html, string key)
         {
             string result = "";
             string sRegex = string.Format("<input\\s*type=\"hidden\".*?name=\"{0}\".*?\\s*value=[\"|'](?<value>.*?)[\"|'^/]", key);
@@ -901,7 +863,7 @@ namespace Masuit.Tools.Html
         /// 替换回车换行符为html换行符
         /// </summary>
         /// <param name="str">html</param>
-        public static string StrFormat(string str)
+        public static string StrFormat(this string str)
         {
             string str2;
             if (str == null)
@@ -920,7 +882,7 @@ namespace Masuit.Tools.Html
         /// 替换html字符
         /// </summary>
         /// <param name="strHtml">html</param>
-        public static string EncodeHtml(string strHtml)
+        public static string EncodeHtml(this string strHtml)
         {
             if (strHtml != "")
             {

+ 0 - 432
Masuit.Tools/Html/HtmlPager.cs

@@ -1,432 +0,0 @@
-using System;
-using System.Text;
-
-namespace Masuit.Tools.Html
-{
-    /// <summary>
-    /// HTMl 分页
-    /// </summary>
-    public static class HtmlPager
-    {
-        /// <summary>
-        /// 写出分页
-        /// </summary>
-        /// <param name="pageCount">页数</param>
-        /// <param name="currentPage">当前页</param>
-        public static string GetPager(int pageCount, int currentPage)
-        {
-            return GetPager(pageCount, currentPage, new string[] { }, new string[] { });
-        }
-
-        /// <summary>
-        /// 写出分页
-        /// </summary>
-        /// <param name="pageCount">页数</param>
-        /// <param name="currentPage">当前页</param>
-        /// <param name="FieldName">地址栏参数</param>
-        /// <param name="FieldValue">地址栏参数值</param>
-        /// <returns>分页栏</returns>
-        public static string GetPager(int pageCount, int currentPage, string[] FieldName, string[] FieldValue)
-        {
-            string pString = "";
-            for (int i = 0; i < FieldName.Length; i++)
-            {
-                pString += "&" + FieldName[i] + "=" + FieldValue[i];
-            }
-            int stepNum = 4;
-            int pageRoot = 1;
-            pageCount = pageCount == 0 ? 1 : pageCount;
-            currentPage = currentPage == 0 ? 1 : currentPage;
-
-            StringBuilder sb = new StringBuilder();
-            sb.Append("<table cellpadding=0 cellspacing=1 class=\"pager\">\r<tr>\r");
-            sb.Append("<td class=pagerTitle>&nbsp;分页&nbsp;</td>\r");
-            sb.Append("<td class=pagerTitle>&nbsp;" + currentPage + "/" + pageCount + "&nbsp;</td>\r");
-            if (currentPage - stepNum < 2)
-                pageRoot = 1;
-            else
-                pageRoot = currentPage - stepNum;
-            int pageFoot = pageCount;
-            if (currentPage + stepNum >= pageCount)
-                pageFoot = pageCount;
-            else
-                pageFoot = currentPage + stepNum;
-            if (pageRoot == 1)
-            {
-                if (currentPage > 1)
-                {
-                    sb.Append("<td>&nbsp;<a href='?page=1" + pString + "' title='首页'>首页</a>&nbsp;</td>\r");
-                    sb.Append("<td>&nbsp;<a href='?page=" + Convert.ToString(currentPage - 1) + pString + "' title='上页'>上页</a>&nbsp;</td>\r");
-                }
-            }
-            else
-            {
-                sb.Append("<td>&nbsp;<a href='?page=1" + pString + "' title='首页'>首页</a>&nbsp;</td>");
-                sb.Append("<td>&nbsp;<a href='?page=" + Convert.ToString(currentPage - 1) + pString + "' title='上页'>上页</a>&nbsp;</td>\r");
-            }
-            for (int i = pageRoot; i <= pageFoot; i++)
-            {
-                if (i == currentPage)
-                {
-                    sb.Append("<td class='current'>&nbsp;" + i.ToString() + "&nbsp;</td>\r");
-                }
-                else
-                {
-                    sb.Append("<td>&nbsp;<a href='?page=" + i.ToString() + pString + "' title='第" + i.ToString() + "页'>" + i.ToString() + "</a>&nbsp;</td>\r");
-                }
-                if (i == pageCount)
-                    break;
-            }
-            if (pageFoot == pageCount)
-            {
-                if (pageCount > currentPage)
-                {
-                    sb.Append("<td>&nbsp;<a href='?page=" + Convert.ToString(currentPage + 1) + pString + "' title='下页'>下页</a>&nbsp;</td>\r");
-                    sb.Append("<td>&nbsp;<a href='?page=" + pageCount.ToString() + pString + "' title='尾页'>尾页</a>&nbsp;</td>\r");
-                }
-            }
-            else
-            {
-                sb.Append("<td>&nbsp;<a href='?page=" + Convert.ToString(currentPage + 1) + pString + "' title='下页'>下页</a>&nbsp;</td>\r");
-                sb.Append("<td>&nbsp;<a href='?page=" + pageCount.ToString() + pString + "' title='尾页'>尾页</a>&nbsp;</td>\r");
-            }
-            sb.Append("</tr>\r</table>");
-            return sb.ToString();
-        }
-
-        /// <summary>
-        /// 写出分页
-        /// </summary>
-        /// <param name="pageCount">总页数</param>
-        /// <param name="currentPage">当前页</param>
-        /// <param name="prefix">上一页</param>
-        /// <param name="suffix">下一页</param>
-        /// <returns>分页栏</returns>
-        public static string GetHtmlPager(int pageCount, int currentPage, string prefix, string suffix)
-        {
-            int stepNum = 4;
-            int pageRoot = 1;
-            pageCount = pageCount == 0 ? 1 : pageCount;
-            currentPage = currentPage == 0 ? 1 : currentPage;
-            StringBuilder sb = new StringBuilder();
-            sb.Append("<table cellpadding=0 cellspacing=1 class=\"pager\">\r<tr>\r");
-            sb.Append("<td class=pagerTitle>&nbsp;分页&nbsp;</td>\r");
-            sb.Append("<td class=pagerTitle>&nbsp;" + currentPage.ToString() + "/" + pageCount.ToString() + "&nbsp;</td>\r");
-            if (currentPage - stepNum < 2)
-                pageRoot = 1;
-            else
-                pageRoot = currentPage - stepNum;
-            int pageFoot = pageCount;
-            if (currentPage + stepNum >= pageCount)
-                pageFoot = pageCount;
-            else
-                pageFoot = currentPage + stepNum;
-            if (pageRoot == 1)
-            {
-                if (currentPage > 1)
-                {
-                    sb.Append("<td>&nbsp;<a href='" + prefix + "1" + suffix + "' title='首页'>首页</a>&nbsp;</td>\r");
-                    sb.Append("<td>&nbsp;<a href='" + prefix + Convert.ToString(currentPage - 1) + suffix + "' title='上页'>上页</a>&nbsp;</td>\r");
-                }
-            }
-            else
-            {
-                sb.Append("<td>&nbsp;<a href='" + prefix + "1" + suffix + "' title='首页'>首页</a>&nbsp;</td>");
-                sb.Append("<td>&nbsp;<a href='" + prefix + Convert.ToString(currentPage - 1) + suffix + "' title='上页'>上页</a>&nbsp;</td>\r");
-            }
-            for (int i = pageRoot; i <= pageFoot; i++)
-            {
-                if (i == currentPage)
-                {
-                    sb.Append("<td class='current'>&nbsp;" + i.ToString() + "&nbsp;</td>\r");
-                }
-                else
-                {
-                    sb.Append("<td>&nbsp;<a href='" + prefix + i.ToString() + suffix + "' title='第" + i.ToString() + "页'>" + i.ToString() + "</a>&nbsp;</td>\r");
-                }
-                if (i == pageCount)
-                    break;
-            }
-            if (pageFoot == pageCount)
-            {
-                if (pageCount > currentPage)
-                {
-                    sb.Append("<td>&nbsp;<a href='" + prefix + Convert.ToString(currentPage + 1) + suffix + "' title='下页'>下页</a>&nbsp;</td>\r");
-                    sb.Append("<td>&nbsp;<a href='" + prefix + pageCount.ToString() + suffix + "' title='尾页'>尾页</a>&nbsp;</td>\r");
-                }
-            }
-            else
-            {
-                sb.Append("<td>&nbsp;<a href='" + prefix + Convert.ToString(currentPage + 1) + suffix + "' title='下页'>下页</a>&nbsp;</td>\r");
-                sb.Append("<td>&nbsp;<a href='" + prefix + pageCount.ToString() + suffix + "' title='尾页'>尾页</a>&nbsp;</td>\r");
-            }
-            sb.Append("</tr>\r</table>");
-            return sb.ToString();
-        }
-
-        #region 分页
-
-        /// <summary>
-        /// 分页
-        /// </summary>
-        /// <param name="url">URL</param>
-        /// <param name="para">参数</param>
-        /// <param name="sumpage">总页数</param>
-        /// <param name="page">当前页</param>
-        /// <returns>当前页的内容</returns>
-        public static string Paging(string url, string para, int sumpage, int page)
-        {
-            string result = string.Empty;
-            if (sumpage == 1)
-            {
-                return result;
-            }
-            if (sumpage > 500)
-            {
-                sumpage = 500;
-            }
-            if (page > sumpage)
-            {
-                page = 1;
-            }
-            StringBuilder sb = new StringBuilder();
-            if (sumpage > 0)
-            {
-                switch (page)
-                {
-                    case 1:
-                        sb.Append(string.Format("<p class=\"next\"><a href=\"{0}?page={1}{2}\">{3}</a> ", new object[] { url, page + 1, para, "下一页" }));
-                        break;
-                    default:
-                        if (sumpage == page)
-                        {
-                            sb.Append(string.Format("<p class=\"next\"><a href=\"{0}?page={1}{2}\">{3}</a> ", new object[] { url, page - 1, para, "上一页" }));
-                        }
-                        else
-                        {
-                            sb.Append(string.Format("<p class=\"next\"><a href=\"{0}?page={1}{2}\">{3}</a> <a href=\"{4}?page={5}{6}\">{7}</a> ",
-                                new object[] { url, page + 1, para, "下一页", url, page - 1, para, "上一页" }));
-                        }
-                        break;
-                }
-                sb.Append(string.Format("第{0}/{1}页</p>", new object[] { page, sumpage }));
-            }
-            return sb.ToString();
-        }
-
-        /// <summary>
-        /// 分页控件
-        /// </summary>
-        /// <param name="url">URL</param>
-        /// <param name="para">参数</param>
-        /// <param name="sumpage">总页数</param>
-        /// <param name="page">当前页</param>
-        /// <param name="myPaging">分页控件</param>
-        /// <returns>当前页的内容</returns>
-        public static string Paging(string url, string para, int sumpage, int page, System.Web.UI.UserControl myPaging)
-        {
-            myPaging.Visible = false;
-            string result = string.Empty;
-            if (sumpage == 1)
-            {
-                return result;
-            }
-            if (sumpage > 500)
-            {
-                sumpage = 500;
-            }
-            if (page > sumpage)
-            {
-                page = 1;
-            }
-            StringBuilder sb = new StringBuilder();
-            if (sumpage > 0)
-            {
-                myPaging.Visible = true;
-                switch (page)
-                {
-                    case 1:
-                        sb.Append(string.Format("<a href=\"{0}?page={1}{2}\">{3}</a> ", new object[] { url, page + 1, para, "下一页" }));
-                        break;
-                    default:
-                        if (sumpage == page)
-                        {
-                            sb.Append(string.Format("<a href=\"{0}?page={1}{2}\">{3}</a> ", new object[] { url, page - 1, para, "上一页" }));
-                        }
-                        else
-                        {
-                            sb.Append(string.Format("<a href=\"{0}?page={1}{2}\">{3}</a> <a href=\"{4}?page={5}{6}\">{7}</a> ",
-                                new object[] { url, page + 1, para, "下一页", url, page - 1, para, "上一页" }));
-                        }
-                        break;
-                }
-                sb.Append(string.Format("第{0}/{1}页", new object[] { page, sumpage }));
-            }
-            return sb.ToString();
-        }
-
-        /// <summary>
-        /// 分页
-        /// </summary>
-        /// <param name="para">参数</param>
-        /// <param name="sumpage">总页数</param>
-        /// <param name="page">当前页</param>
-        /// <param name="count">总条数</param>
-        /// <returns>当前页的内容</returns>
-        public static string Paging(string para, int sumpage, int page, int count)
-        {
-            string result = string.Empty;
-            if (page > sumpage)
-            {
-                page = 1;
-            }
-            StringBuilder sb = new StringBuilder();
-            if (sumpage > 0)
-            {
-                if (sumpage != 1)
-                {
-                    switch (page)
-                    {
-                        case 1:
-                            sb.Append(string.Format("<a href=\"?page={0}{1}\">{2}</a> ", new object[] { page + 1, para, "下一页" }));
-                            break;
-                        default:
-                            if (sumpage == page)
-                            {
-                                sb.Append(string.Format("<a href=\"?page={0}{1}\">{2}</a> ", new object[] { page - 1, para, "上一页" }));
-                            }
-                            else
-                            {
-                                sb.Append(string.Format("<a href=\"?page={0}{1}\">{2}</a> <a href=\"?page={3}{4}\">{5}</a> ",
-                                    new object[] { page - 1, para, "上一页", page + 1, para, "下一页" }));
-                            }
-                            break;
-                    }
-                }
-                sb.Append(string.Format("第{0}/{1}页 共{2}条", new object[] { page, sumpage, count }));
-            }
-            return sb.ToString();
-        }
-
-        /// <summary>
-        /// 带第一页和最后一页
-        /// </summary>
-        /// <param name="para">参数</param>
-        /// <param name="sumpage">总页数</param>
-        /// <param name="page">当前页</param>
-        /// <param name="count">总条数</param>
-        /// <returns>当前页的内容</returns>
-        public static string paging2(string para, int sumpage, int page, int count)
-        {
-            string result = string.Empty;
-            if (page > sumpage)
-            {
-                page = 1;
-            }
-            StringBuilder sb = new StringBuilder();
-            if (sumpage > 0)
-            {
-                if (sumpage != 1)
-                {
-                    //第一页
-                    sb.Append(string.Format("<a href=\"?page={0}{1}\"><img src=\"images/first-icon.gif\" border=\"0\"/></a>&nbsp;&nbsp;", new object[] { 1, para }));
-                    switch (page)
-                    {
-                        case 1:
-                            //前一页图片
-                            sb.Append(string.Format("<a>{0}</a>", new object[] { "<img src=\"images/left-icon.gif\" border=\"0\"/>" }));
-                            sb.Append(string.Format("<a>上一页</a><a href=\"?page={0}{1}\">{2}</a> ", new object[] { page + 1, para, "下一页" }));
-                            //后一页图片
-                            sb.Append(string.Format("<a href=\"?page={0}{1}\">{2}</a>", new object[] { page + 1, para, "<img src=\"images/right-icon.gif\" border=\"0\"/>" }));
-                            break;
-                        default:
-                            if (sumpage == page)
-                            {
-                                //前一页图片
-                                sb.Append(string.Format("<a href=\"?page={0}{1}\">{2}</a>", new object[] { page - 1, para, "<img src=\"images/left-icon.gif\" border=\"0\"/>" }));
-                                sb.Append(string.Format("<a href=\"?page={0}{1}\">{2}</a><a>下一页</a> ", new object[] { page - 1, para, "上一页" }));
-                                //后一页图片
-                                sb.Append(string.Format("<a>{0}</a>", new object[] { "<img src=\"images/right-icon.gif\" />" }));
-                            }
-                            else
-                            {
-                                //前一页图片
-                                sb.Append(string.Format("<a href=\"?page={0}{1}\">{2}</a>", new object[] { page - 1, para, "<img src=\"images/left-icon.gif\" border=\"0\"/>" }));
-                                sb.Append(string.Format("<a href=\"?page={0}{1}\">{2}</a> <a href=\"?page={3}{4}\">{5}</a> ",
-                                    new object[] { page - 1, para, "上一页", page + 1, para, "下一页" }));
-                                //后一页图片
-                                sb.Append(string.Format("<a href=\"?page={0}{1}\">{2}</a>", new object[] { page + 1, para, "<img src=\"images/right-icon.gif\" border=\"0\"/>" }));
-                            }
-                            break;
-                    }
-                    //最后一页图片
-                    sb.Append(string.Format("&nbsp;&nbsp;<a href=\"?page={0}{1}\"><img src=\"images/last-icon.gif\" border=\"0\"/></a>&nbsp;&nbsp;", new object[] { sumpage, para }));
-                }
-                sb.Append(string.Format("第{0}页/共{1}页 共{2}条", new object[] { page, sumpage, count }));
-            }
-            return sb.ToString();
-        }
-
-        /// <summary>
-        /// 分页
-        /// </summary>
-        /// <param name="url">URL</param>
-        /// <param name="para">参数</param>
-        /// <param name="sumpage">总页数</param>
-        /// <param name="page">当前页</param>
-        /// <param name="count">总条数</param>
-        /// <returns>当前页的内容</returns>
-        public static string Paging(string url, string para, int sumpage, int page, int count)
-        {
-            string result = string.Empty;
-            if (page > sumpage)
-            {
-                page = 1;
-            }
-            StringBuilder sb = new StringBuilder();
-            if (sumpage > 0)
-            {
-                if (sumpage != 1)
-                {
-                    //第一页
-                    sb.Append(string.Format("<a href=\"{2}?page={0}{1}\">首页</a>", new object[] { 1, para, url }));
-                    switch (page)
-                    {
-                        case 1:
-                            //前一页图片
-                            // sb.Append(string.Format("<a>{0}</a>", new object[] { "<img src=\"images/left-icon.gif\" border=\"0\"/>" }));
-                            sb.Append(string.Format("<a>上一页</a><a href=\"{3}?page={0}{1}\">{2}</a> ", new object[] { page + 1, para, "下一页", url }));
-                            //后一页图片
-                            // sb.Append(string.Format("<a href=\"?page={0}{1}\">{2}</a>", new object[] { page + 1, para, "<img src=\"images/right-icon.gif\" border=\"0\"/>" }));
-                            break;
-                        default:
-                            if (sumpage == page)
-                            {
-                                //前一页图片
-                                //sb.Append(string.Format("<a href=\"?page={0}{1}\">{2}</a>", new object[] { page - 1, para, "<img src=\"images/left-icon.gif\" border=\"0\"/>" }));
-                                sb.Append(string.Format("<a href=\"{3}?page={0}{1}\">{2}</a><a>下一页</a> ", new object[] { page - 1, para, "上一页", url }));
-                                //后一页图片
-                                //sb.Append(string.Format("<a>{0}</a>", new object[] { "<img src=\"images/right-icon.gif\" />" }));
-                            }
-                            else
-                            {
-                                //前一页图片
-                                //sb.Append(string.Format("<a href=\"?page={0}{1}\">{2}</a>", new object[] { page - 1, para, "<img src=\"images/left-icon.gif\" border=\"0\"/>" }));
-                                sb.Append(string.Format("<a href=\"{6}?page={0}{1}\">{2}</a> <a href=\"{6}?page={3}{4}\">{5}</a> ",
-                                    new object[] { page - 1, para, "上一页", page + 1, para, "下一页", url }));
-                                //后一页图片
-                                //sb.Append(string.Format("<a href=\"?page={0}{1}\">{2}</a>", new object[] { page + 1, para, "<img src=\"images/right-icon.gif\" border=\"0\"/>" }));
-                            }
-                            break;
-                    }
-                    //最后一页图片
-                    sb.Append(string.Format("<a href=\"{2}?page={0}{1}\">末页</a>&nbsp;&nbsp;", new object[] { sumpage, para, url }));
-                }
-                sb.Append(string.Format("第{0}页/共{1}页 共{2}条", new object[] { page, sumpage, count }));
-            }
-            return sb.ToString();
-        }
-        #endregion
-
-    }
-}

+ 2 - 43
Masuit.Tools/Html/HtmlTools.cs

@@ -18,47 +18,6 @@ namespace Masuit.Tools.Html
     /// </summary>
     public static partial class HtmlTools
     {
-        #region 获得发表日期、编码
-        /// <summary>
-        /// 获得发表日期、编码
-        /// </summary>
-        /// <param name="sContent">内容</param>
-        /// <param name="sRegex">正则表达式</param>
-        /// <returns>日期</returns>
-        public static DateTime GetCreateDate(string sContent, string sRegex)
-        {
-            DateTime dt = System.DateTime.Now;
-
-            Regex re = new Regex(sRegex, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline);
-            Match mc = re.Match(sContent);
-            if (mc.Success)
-            {
-                try
-                {
-                    int iYear = int.Parse(mc.Groups["Year"].Value);
-                    int iMonth = int.Parse(mc.Groups["Month"].Value);
-                    int iDay = int.Parse(mc.Groups["Day"].Value);
-                    int iHour = dt.Hour;
-                    int iMinute = dt.Minute;
-
-                    string sHour = mc.Groups["Hour"].Value;
-                    string sMintue = mc.Groups["Mintue"].Value;
-
-                    if (sHour != "")
-                        iHour = int.Parse(sHour);
-                    if (sMintue != "")
-                        iMinute = int.Parse(sMintue);
-
-                    dt = new DateTime(iYear, iMonth, iDay, iHour, iMinute, 0);
-                }
-                catch
-                {
-                }
-            }
-            return dt;
-        }
-        #endregion 获得发表日期
-
         #region 防止html的xss净化器
         /// <summary>
         /// 标准的防止html的xss净化器
@@ -1192,7 +1151,7 @@ namespace Masuit.Tools.Html
         /// </summary>
         /// <param name="sHtml">html</param>
         /// <returns>纯文本</returns>
-        public static string GetTxtFromHtml(string sHtml)
+        public static string GetTxtFromHtml(this string sHtml)
         {
             string del = @"<head[^>]*>[\s\S]*?</head>";
             string content = RemoveByReg(sHtml, del);
@@ -1221,7 +1180,7 @@ namespace Masuit.Tools.Html
         /// </summary>
         /// <param name="sHtml">html源代码</param>
         /// <returns>从html中过滤出文本,不过保留换行符号</returns>
-        public static string GetTxtFromHtml2(string sHtml)
+        public static string GetTxtFromHtml2(this string sHtml)
         {
             string del = @"<head[^>]*>[\s\S]*?</head>";
             string content = RemoveByReg(sHtml, del);

+ 0 - 233
Masuit.Tools/Html/ListBuilder.cs

@@ -1,233 +0,0 @@
-using System.Data;
-using System.Text;
-using System.Text.RegularExpressions;
-
-namespace Masuit.Tools.Html
-{
-    /// <summary>
-    /// 无序列表生成器<br/>
-    /// 使用方式:<br/>
-    /// ListBuilder lb1=new ListBuilder("ul");<br/>
-    /// lb1.SetTemplate("&lt;a href="{#url}" target="_blank">&lt;strong>{#sortName}&lt;/strong> &lt;/a>\r\n{#lb2}");<br/>
-    /// ListBuilder lb2 = new ListBuilder("ul");<br/>
-    /// lb2.SetTemplate("&lt;a href=url?tid={#id}" target=\"_blank\">{#title}&lt;/a> &lt;span class='date'>[{#date}]&lt;/span>");<br/>
-    /// lb2.BindData(dt2);<br/>
-    /// 或者<br/>
-    /// lb1.AddTemplateData("sortName", dr["sortName"].ToString());<br/>
-    /// lb1.AddTemplateData("url",url+"#sid."+dr["id"].ToString()+"/page.1/");<br/>
-    /// lb1.AddTemplateData("lb2",lb2.ToString());<br/>
-    /// lb1.EndTemplateData();<br/>
-    /// lSitemap.Text=lb1.ToString();<br/>
-    /// </summary>
-    public class ListBuilder
-    {
-        private string type = "dl";
-        private StringBuilder sb = new StringBuilder();
-        private string template = string.Empty;
-        private System.Collections.Specialized.NameValueCollection nvc = new System.Collections.Specialized.NameValueCollection();
-
-        /// <summary>
-        /// 构造函数
-        /// </summary>
-        /// <param name="_type">列表类型,可选"ul","dl",默认"ul"</param>
-        /// <param name="className">类名</param>
-        public ListBuilder(string _type, string className)
-        {
-            if (_type != string.Empty) type = _type;
-            if (className != string.Empty) className = " class='" + className + "'";
-            sb.Append("<" + type + className + ">");
-        }
-        /// <summary>
-        /// 以ul构造列表
-        /// </summary>
-        public ListBuilder()
-        {
-            sb.Append("<dl>");
-        }
-        /// <summary>
-        /// 构造函数
-        /// </summary>
-        /// <param name="_type">列表类型,可选"ul","dl",默认"ul"</param>
-        public ListBuilder(string _type)
-        {
-            type = _type;
-            sb.Append("<" + type + ">");
-        }
-
-        /// <summary>
-        /// 设置模版
-        /// </summary>
-        /// <param name="_template">模版,以{#name}作为参数,name来自数据源datatable或者执行设置</param>
-        public void SetTemplate(string _template)
-        {
-            template = _template;
-        }
-
-        /// <summary>
-        /// 添加模版数据
-        /// </summary>
-        /// <param name="name">名称</param>
-        /// <param name="value">值</param>
-        public void AddTemplateData(string name, string value)
-        {
-            nvc.Add(name, value);
-        }
-
-        /// <summary>
-        /// 模版数据添加完成后需调用此方法
-        /// </summary>
-        /// <param name="className">列表项(li或者dd)的css类名</param>
-        public void EndTemplateData(string className)
-        {
-            string itemName = "dd";
-            if (type != "dl")
-            {
-                itemName = "li";
-            }
-            if (className != string.Empty) className = " class='" + className + "'";
-            sb.Append("<" + itemName + className + ">");
-            sb.Append(GenerateString());
-            sb.Append("</" + itemName + ">");
-            nvc.Clear();
-        }
-
-        /// <summary>
-        /// 模版数据添加完成后需调用此方法
-        /// </summary>
-        public void EndTemplateData()
-        {
-            EndTemplateData("");
-        }
-
-        /// <summary>
-        /// 生成字符串返回
-        /// </summary>
-        /// <returns>生成后的内容</returns>
-        protected string GenerateString()
-        {
-            Regex regex = new Regex(@"{#(\w+)}", RegexOptions.IgnoreCase);
-            return regex.Replace(template, new MatchEvaluator(this.MatchEvaluator));
-        }
-
-        /// <summary>
-        /// 正则匹配中的委托定义
-        /// </summary>
-        /// <param name="m">匹配对象</param>
-        /// <returns>正则匹配中的委托定义</returns>
-        protected string MatchEvaluator(Match m)
-        {
-            string name = m.Groups[1].Captures[0].Value;
-            return nvc[name];
-        }
-
-        /// <summary>
-        /// 设置标题
-        /// </summary>
-        /// <param name="text">文本</param>
-        /// <param name="url">链接</param>
-        /// <param name="target">目标窗口,可选"_blank","_self"等,默认"_self"</param>
-        public void SetTitle(string text, string url, string target)
-        {
-            this.SetTitle(text, url, target, "");
-        }
-        /// <summary>
-        /// 设置标题
-        /// </summary>
-        /// <param name="text">文本</param>
-        /// <param name="url">链接</param>
-        public void SetTitle(string text, string url)
-        {
-            this.SetTitle(text, url, "", "");
-        }
-        /// <summary>
-        /// 设置纯文本标题
-        /// </summary>
-        /// <param name="text">文本</param>
-        public void SetTitle(string text)
-        {
-            this.SetTitle(text, "", "", "");
-        }
-        /// <summary>
-        /// 设置标题
-        /// </summary>
-        /// <param name="text">文本</param>
-        /// <param name="url">链接</param>
-        /// <param name="target">目标窗口,可选"_blank","_self"等,默认"_self"</param>
-        /// <param name="className">CSS类名</param>
-        public void SetTitle(string text, string url, string target, string className)
-        {
-            string itemName = "dt";
-            if (type != "dl")
-            {
-                itemName = "li";
-                className += " title ";
-            }
-            if (className != string.Empty) className = " class='" + className + "'";
-            sb.Append("<" + itemName + className + ">");
-            if (url?.Length == 0)
-            {
-                sb.Append(text);
-            }
-            else
-            {
-                if (target != string.Empty) target = " target='" + target + "'";
-                sb.Append("<a href='" + url + "'" + target + ">");
-                sb.Append(text);
-                sb.Append("</a>");
-            }
-            sb.Append("</" + itemName + ">");
-        }
-        /// <summary>
-        /// 添加一项
-        /// </summary>
-        /// <param name="text">文本</param>
-        /// <param name="url">链接</param>
-        /// <param name="target">目标窗口,可选"_blank","_self"等,默认"_self"</param>
-        /// <param name="className">CSS类名</param>
-        public void AddItem(string text, string url, string target, string className)
-        {
-            string itemName = "dd";
-            if (type != "dl") itemName = "li";
-            if (className != string.Empty) className = " class='" + className + "'";
-            sb.Append("<" + itemName + className + ">");
-            if (url?.Length == 0)
-            {
-                sb.Append(text);
-            }
-            else
-            {
-                if (target != string.Empty) target = " target='" + target + "'";
-                sb.Append("<a href='" + url + "'" + target + ">");
-                sb.Append(text);
-                sb.Append("</a>");
-            }
-            sb.Append("</" + itemName + ">");
-        }
-
-        /// <summary>
-        /// 返回列表的HTML
-        /// </summary>
-        /// <returns>列表的HTML</returns>
-        public override string ToString()
-        {
-            sb.Append("</" + type + ">");
-            return sb.ToString();
-        }
-
-        /// <summary>
-        /// 根据模板绑定一个dataTable,使用datatable中的值来填充模板
-        /// </summary>
-        /// <param name="dataTable">内存表对象</param>
-        public void BindData(System.Data.DataTable dataTable)
-        {
-            foreach (System.Data.DataRow dr in dataTable.Rows)
-            {
-                foreach (DataColumn column in dataTable.Columns)
-                {
-                    AddTemplateData(column.ColumnName, dr[column.ColumnName].ToString());
-                }
-                EndTemplateData();
-            }
-        }
-    }
-}

+ 43 - 1
Masuit.Tools/Logging/LogManager.cs

@@ -41,7 +41,7 @@ namespace Masuit.Tools.Logging
                             logArr = new[] { logPath, logMergeContent };
                             temp.Add(logArr);
                         }
-                        LogQueue.TryDequeue(out Tuple<string, string> val);
+                        LogQueue.TryDequeue(out Tuple<string, string> _);
                     }
                     foreach (string[] item in temp)
                     {
@@ -70,6 +70,27 @@ namespace Masuit.Tools.Logging
             string logContent = $"{Now}   [{Thread.CurrentThread.ManagedThreadId}]   {nameof(info).ToUpper()}   {source}  {info}";
             LogQueue.Enqueue(new Tuple<string, string>(logPath, logContent));
         }
+        /// <summary>
+        /// 写入Info级别的日志
+        /// </summary>
+        /// <param name="source"></param>
+        /// <param name="info"></param>
+        public static void Info(Type source, string info)
+        {
+            string logPath = GetLogPath();
+            string logContent = $"{Now}   [{Thread.CurrentThread.ManagedThreadId}]   {nameof(info).ToUpper()}   {source.FullName}  {info}";
+            LogQueue.Enqueue(new Tuple<string, string>(logPath, logContent));
+        }
+        /// <summary>
+        /// 写入Info级别的日志
+        /// </summary>
+        /// <param name="info"></param>
+        public static void Info(string info)
+        {
+            string logPath = GetLogPath();
+            string logContent = $"{Now}   [{Thread.CurrentThread.ManagedThreadId}]   {nameof(info).ToUpper()}  {info}";
+            LogQueue.Enqueue(new Tuple<string, string>(logPath, logContent));
+        }
 
         /// <summary>
         /// 写入error级别日志
@@ -117,6 +138,27 @@ namespace Masuit.Tools.Logging
             string logContent = $"{Now}   [{Thread.CurrentThread.ManagedThreadId}]   {nameof(debug).ToUpper()}   {source}  {debug}";
             LogQueue.Enqueue(new Tuple<string, string>(logPath, logContent));
         }
+        /// <summary>
+        /// 写入debug级别日志
+        /// </summary>
+        /// <param name="source">异常源的类型</param>
+        /// <param name="debug">异常对象</param>
+        public static void Debug(Type source, string debug)
+        {
+            string logPath = GetLogPath();
+            string logContent = $"{Now}   [{Thread.CurrentThread.ManagedThreadId}]   {nameof(debug).ToUpper()}   {source.FullName}  {debug}";
+            LogQueue.Enqueue(new Tuple<string, string>(logPath, logContent));
+        }
+        /// <summary>
+        /// 写入debug级别日志
+        /// </summary>
+        /// <param name="debug">异常对象</param>
+        public static void Debug(string debug)
+        {
+            string logPath = GetLogPath();
+            string logContent = $"{Now}   [{Thread.CurrentThread.ManagedThreadId}]   {nameof(debug).ToUpper()}   {debug}";
+            LogQueue.Enqueue(new Tuple<string, string>(logPath, logContent));
+        }
 
         /// <summary>
         /// 写入fatal级别日志

+ 7 - 3
Masuit.Tools/Masuit.Tools.csproj

@@ -40,6 +40,12 @@
       <HintPath>..\packages\AngleSharp.0.9.9\lib\net45\AngleSharp.dll</HintPath>
       <Private>True</Private>
     </Reference>
+    <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+      <HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
+    </Reference>
+    <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+      <HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
+    </Reference>
     <Reference Include="HtmlSanitizer, Version=3.0.0.0, Culture=neutral, PublicKeyToken=61c49a1a9e79cc28, processorArchitecture=MSIL">
       <HintPath>..\packages\HtmlSanitizer.3.4.156\lib\net45\HtmlSanitizer.dll</HintPath>
       <Private>True</Private>
@@ -82,9 +88,7 @@
     <Compile Include="Files\FileTree.cs" />
     <Compile Include="Files\INIFile.cs" />
     <Compile Include="Html\HtmlHelper.cs" />
-    <Compile Include="Html\HtmlPager.cs" />
     <Compile Include="Html\HtmlTools.cs" />
-    <Compile Include="Html\ListBuilder.cs" />
     <Compile Include="Logging\LogManager.cs" />
     <Compile Include="Net\CacheHelper.cs" />
     <Compile Include="Net\CookieHelper.cs" />
@@ -104,7 +108,6 @@
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Security\HashEncode.cs" />
     <Compile Include="Security\RSACryption.cs" />
-    <Compile Include="Objects\ObjectExt.cs" />
     <Compile Include="Strings\ValidateCode.cs" />
     <Compile Include="Net\WebExtension.cs" />
     <Compile Include="Win32\Windows.cs" />
@@ -112,6 +115,7 @@
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
+    <None Include="package.nuspec" />
     <None Include="packages.config" />
   </ItemGroup>
   <ItemGroup>

+ 52 - 265
Masuit.Tools/Media/ImageUtilities.cs

@@ -551,70 +551,65 @@ namespace Masuit.Tools.Media
         /// <summary>
         /// 无损压缩图片
         /// </summary>
-        /// <param name="sFile">原图片</param>
+        /// <param name="image">原图片</param>
         /// <param name="dFile">压缩后保存位置</param>
         /// <param name="dHeight">高度</param>
         /// <param name="dWidth">宽度</param>
         /// <param name="flag">压缩质量 1-100</param>
         /// <returns>处理结果</returns>
-        public static bool GetPicThumbnail(string sFile, string dFile, int dHeight, int dWidth, int flag = 100)
+        public static bool GetPicThumbnail(this Image image, string dFile, int dHeight, int dWidth, int flag = 100)
         {
-            using (Image iSource = Image.FromFile(sFile))
+            ImageFormat tFormat = image.RawFormat;
+            int sW = 0, sH = 0;
+            //按比例缩放
+            Size temSize = new Size(image.Width, image.Height);
+            if ((temSize.Width > dHeight) || (temSize.Width > dWidth)) //将**改成c#中的或者操作符号
             {
-                ImageFormat tFormat = iSource.RawFormat;
-                int sW = 0, sH = 0;
-                //按比例缩放
-                Size tem_size = new Size(iSource.Width, iSource.Height);
-                if ((tem_size.Width > dHeight) || (tem_size.Width > dWidth)) //将**改成c#中的或者操作符号
+                if (temSize.Width * dHeight > temSize.Height * dWidth)
                 {
-                    if (tem_size.Width * dHeight > tem_size.Height * dWidth)
-                    {
-                        sW = dWidth;
-                        sH = dWidth * tem_size.Height / tem_size.Width;
-                    }
-                    else
-                    {
-                        sH = dHeight;
-                        sW = tem_size.Width * dHeight / tem_size.Height;
-                    }
+                    sW = dWidth;
+                    sH = dWidth * temSize.Height / temSize.Width;
                 }
                 else
                 {
-                    sW = tem_size.Width;
-                    sH = tem_size.Height;
+                    sH = dHeight;
+                    sW = temSize.Width * dHeight / temSize.Height;
                 }
-                using (Bitmap ob = new Bitmap(dWidth, dHeight))
+            }
+            else
+            {
+                sW = temSize.Width;
+                sH = temSize.Height;
+            }
+            using (Bitmap ob = new Bitmap(dWidth, dHeight))
+            {
+                Graphics g = Graphics.FromImage(ob);
+                g.Clear(Color.WhiteSmoke);
+                g.CompositingQuality = CompositingQuality.HighQuality;
+                g.SmoothingMode = SmoothingMode.HighQuality;
+                g.InterpolationMode = InterpolationMode.HighQualityBicubic;
+                g.DrawImage(image, new Rectangle((dWidth - sW) / 2, (dHeight - sH) / 2, sW, sH), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
+                g.Dispose();
+                //以下代码为保存图片时,设置压缩质量
+                EncoderParameters ep = new EncoderParameters();
+                long[] qy = new long[1];
+                qy[0] = flag; //设置压缩的比例1-100
+                EncoderParameter eParam = new EncoderParameter(Encoder.Quality, qy);
+                ep.Param[0] = eParam;
+                ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
+                ImageCodecInfo jpegICIinfo = null;
+                for (int x = 0; x < arrayICI.Length; x++)
                 {
-                    Graphics g = Graphics.FromImage(ob);
-                    g.Clear(Color.WhiteSmoke);
-                    g.CompositingQuality = CompositingQuality.HighQuality;
-                    g.SmoothingMode = SmoothingMode.HighQuality;
-                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
-                    g.DrawImage(iSource, new Rectangle((dWidth - sW) / 2, (dHeight - sH) / 2, sW, sH), 0, 0, iSource.Width, iSource.Height, GraphicsUnit.Pixel);
-                    g.Dispose();
-                    //以下代码为保存图片时,设置压缩质量
-                    EncoderParameters ep = new EncoderParameters();
-                    long[] qy = new long[1];
-                    qy[0] = flag; //设置压缩的比例1-100
-                    EncoderParameter eParam = new EncoderParameter(Encoder.Quality, qy);
-                    ep.Param[0] = eParam;
-                    ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
-                    ImageCodecInfo jpegICIinfo = null;
-                    for (int x = 0; x < arrayICI.Length; x++)
+                    if (arrayICI[x].FormatDescription.Equals("JPEG"))
                     {
-                        if (arrayICI[x].FormatDescription.Equals("JPEG"))
-                        {
-                            jpegICIinfo = arrayICI[x];
-                            break;
-                        }
+                        jpegICIinfo = arrayICI[x];
+                        break;
                     }
-
-                    if (jpegICIinfo != null)
-                        ob.Save(dFile, jpegICIinfo, ep); //dFile是压缩后的新路径
-                    else
-                        ob.Save(dFile, tFormat);
-                    return true;
                 }
+
+                if (jpegICIinfo != null) ob.Save(dFile, jpegICIinfo, ep); //dFile是压缩后的新路径
+                else ob.Save(dFile, tFormat);
+                return true;
             }
         }
 
@@ -625,15 +620,13 @@ namespace Masuit.Tools.Media
         /// <summary>
         /// 生成缩略图
         /// </summary>
-        /// <param name="originalImagePath">源图路径(物理路径)</param>
+        /// <param name="originalImage">原图</param>
         /// <param name="thumbnailPath">缩略图路径(物理路径)</param>
         /// <param name="width">缩略图宽度</param>
         /// <param name="height">缩略图高度</param>
         /// <param name="mode">生成缩略图的方式</param>    
-        public static void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, string mode)
+        public static void MakeThumbnail(this Image originalImage, string thumbnailPath, int width, int height, string mode)
         {
-            Image originalImage = Image.FromFile(originalImagePath);
-
             int towidth = width;
             int toheight = height;
 
@@ -934,12 +927,10 @@ namespace Masuit.Tools.Media
         /// </summary>
         /// <param name="oldfile">原文件</param>
         /// <param name="newfile">新文件</param>
-        public static bool Compress(string oldfile, string newfile)
+        public static bool Compress(this Image img, string newfile)
         {
             try
             {
-                Image img = Image.FromFile(oldfile);
-                ImageFormat thisFormat = img.RawFormat;
                 Size newSize = new Size(100, 125);
                 Bitmap outBmp = new Bitmap(newSize.Width, newSize.Height);
                 Graphics g = Graphics.FromImage(outBmp);
@@ -948,11 +939,10 @@ namespace Masuit.Tools.Media
                 g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                 g.DrawImage(img, new Rectangle(0, 0, newSize.Width, newSize.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel);
                 g.Dispose();
-                EncoderParameters encoderParams = new EncoderParameters();
-                long[] quality = new long[1];
+                var encoderParams = new EncoderParameters();
+                var quality = new long[1];
                 quality[0] = 100;
-                EncoderParameter encoderParam = new EncoderParameter(Encoder.Quality, quality);
-                encoderParams.Param[0] = encoderParam;
+                encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, quality);
                 ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
                 ImageCodecInfo jpegICI = null;
                 for (int x = 0; x < arrayICI.Length; x++)
@@ -964,7 +954,6 @@ namespace Masuit.Tools.Media
                     }
                 }
 
-                img.Dispose();
                 if (jpegICI != null) outBmp.Save(newfile, ImageFormat.Jpeg);
                 outBmp.Dispose();
                 return true;
@@ -984,7 +973,7 @@ namespace Masuit.Tools.Media
         /// </summary>
         /// <param name="c">输入颜色</param>
         /// <returns>输出颜色</returns>
-        public static Color Gray(Color c)
+        public static Color Gray(this Color c)
         {
             int rgb = Convert.ToInt32(0.3 * c.R + 0.59 * c.G + 0.11 * c.B);
             return Color.FromArgb(rgb, rgb, rgb);
@@ -1028,11 +1017,10 @@ namespace Masuit.Tools.Media
         /// <summary>
         /// 获取图片中的各帧
         /// </summary>
-        /// <param name="pPath">图片路径</param>
+        /// <param name="gif">源gif</param>
         /// <param name="pSavedPath">保存路径</param>
-        public static void GetFrames(string pPath, string pSavedPath)
+        public static void GetFrames(this Image gif, string pSavedPath)
         {
-            Image gif = Image.FromFile(pPath);
             using (gif)
             {
                 FrameDimension fd = new FrameDimension(gif.FrameDimensionsList[0]);
@@ -1046,206 +1034,5 @@ namespace Masuit.Tools.Media
         }
 
         #endregion
-
-        #region 图片水印
-
-        /// <summary>
-        /// 图片水印处理方法
-        /// </summary>
-        /// <param name="path">需要加载水印的图片路径(绝对路径)</param>
-        /// <param name="waterpath">水印图片(绝对路径)</param>
-        /// <param name="location">水印位置(传送正确的代码)</param>
-        public static string ImageWatermark(string path, string waterpath, string location)
-        {
-            string kz_name = Path.GetExtension(path);
-            if ((kz_name == ".jpg") || (kz_name == ".bmp") || (kz_name == ".jpeg"))
-            {
-                DateTime time = DateTime.Now;
-                string filename = "" + time.Year + time.Month + time.Day + time.Hour + time.Minute + time.Second + time.Millisecond;
-                Image img = Image.FromFile(path);
-                Image waterimg = Image.FromFile(waterpath);
-                Graphics g = Graphics.FromImage(img);
-                ArrayList loca = GetLocation(location, img, waterimg);
-                g.DrawImage(waterimg, new Rectangle(int.Parse(loca[0].ToString()), int.Parse(loca[1].ToString()), waterimg.Width, waterimg.Height));
-                waterimg.Dispose();
-                g.Dispose();
-                string newpath = Path.GetDirectoryName(path) + filename + kz_name;
-                img.Save(newpath);
-                img.Dispose();
-                File.Copy(newpath, path, true);
-                if (File.Exists(newpath))
-                    File.Delete(newpath);
-            }
-            return path;
-        }
-
-        /// <summary>
-        /// 图片水印位置处理方法
-        /// </summary>
-        /// <param name="location">水印位置</param>
-        /// <param name="img">需要添加水印的图片</param>
-        /// <param name="waterimg">水印图片</param>
-        private static ArrayList GetLocation(string location, Image img, Image waterimg)
-        {
-            ArrayList loca = new ArrayList();
-            int x = 0;
-            int y = 0;
-
-            if (location == "LT")
-            {
-                x = 10;
-                y = 10;
-            }
-            else if (location == "T")
-            {
-                x = img.Width / 2 - waterimg.Width / 2;
-                y = img.Height - waterimg.Height;
-            }
-            else if (location == "RT")
-            {
-                x = img.Width - waterimg.Width;
-                y = 10;
-            }
-            else if (location == "LC")
-            {
-                x = 10;
-                y = img.Height / 2 - waterimg.Height / 2;
-            }
-            else if (location == "C")
-            {
-                x = img.Width / 2 - waterimg.Width / 2;
-                y = img.Height / 2 - waterimg.Height / 2;
-            }
-            else if (location == "RC")
-            {
-                x = img.Width - waterimg.Width;
-                y = img.Height / 2 - waterimg.Height / 2;
-            }
-            else if (location == "LB")
-            {
-                x = 10;
-                y = img.Height - waterimg.Height;
-            }
-            else if (location == "B")
-            {
-                x = img.Width / 2 - waterimg.Width / 2;
-                y = img.Height - waterimg.Height;
-            }
-            else
-            {
-                x = img.Width - waterimg.Width;
-                y = img.Height - waterimg.Height;
-            }
-            loca.Add(x);
-            loca.Add(y);
-            return loca;
-        }
-
-        #endregion
-
-        #region 文字水印
-
-        /// <summary>
-        /// 文字水印处理方法
-        /// </summary>
-        /// <param name="path">图片路径(绝对路径)</param>
-        /// <param name="size">字体大小</param>
-        /// <param name="letter">水印文字</param>
-        /// <param name="color">颜色</param>
-        /// <param name="location">水印位置</param>
-        public static string LetterWatermark(string path, int size, string letter, Color color, string location)
-        {
-            #region
-
-            string kz_name = Path.GetExtension(path);
-            if ((kz_name == ".jpg") || (kz_name == ".bmp") || (kz_name == ".jpeg"))
-            {
-                DateTime time = DateTime.Now;
-                string filename = "" + time.Year + time.Month + time.Day + time.Hour + time.Minute + time.Second + time.Millisecond;
-                Image img = Image.FromFile(path);
-                Graphics gs = Graphics.FromImage(img);
-                ArrayList loca = GetLocation(location, img, size, letter.Length);
-                Font font = new Font("宋体", size);
-                Brush br = new SolidBrush(color);
-                gs.DrawString(letter, font, br, float.Parse(loca[0].ToString()), float.Parse(loca[1].ToString()));
-                gs.Dispose();
-                string newpath = Path.GetDirectoryName(path) + filename + kz_name;
-                img.Save(newpath);
-                img.Dispose();
-                File.Copy(newpath, path, true);
-                if (File.Exists(newpath))
-                    File.Delete(newpath);
-            }
-            return path;
-
-            #endregion
-        }
-
-        /// <summary>
-        /// 文字水印位置的方法
-        /// </summary>
-        /// <param name="location">位置代码</param>
-        /// <param name="img">图片对象</param>
-        /// <param name="width">宽(当水印类型为文字时,传过来的就是字体的大小)</param>
-        /// <param name="height">高(当水印类型为文字时,传过来的就是字符的长度)</param>
-        private static ArrayList GetLocation(string location, Image img, int width, int height)
-        {
-            #region
-
-            ArrayList loca = new ArrayList(); //定义数组存储位置
-            float x = 10;
-            float y = 10;
-
-            if (location == "LT")
-            {
-                loca.Add(x);
-                loca.Add(y);
-            }
-            else if (location == "T")
-            {
-                x = img.Width / 2 - width * height / 2;
-                loca.Add(x);
-                loca.Add(y);
-            }
-            else if (location == "RT")
-            {
-                x = img.Width - width * height;
-            }
-            else if (location == "LC")
-            {
-                y = img.Height / 2;
-            }
-            else if (location == "C")
-            {
-                x = img.Width / 2 - width * height / 2;
-                y = img.Height / 2;
-            }
-            else if (location == "RC")
-            {
-                x = img.Width - height;
-                y = img.Height / 2;
-            }
-            else if (location == "LB")
-            {
-                y = img.Height - width - 5;
-            }
-            else if (location == "B")
-            {
-                x = img.Width / 2 - width * height / 2;
-                y = img.Height - width - 5;
-            }
-            else
-            {
-                x = img.Width - (width * height);
-                y = img.Height - width - 5;
-            }
-            loca.Add(x);
-            loca.Add(y);
-            return loca;
-
-            #endregion
-        }
-
-        #endregion
     } //end class
 }

+ 12 - 21
Masuit.Tools/Net/CacheHelper.cs

@@ -18,10 +18,9 @@ namespace Masuit.Tools.Net
         /// </summary>
         /// <typeparam name="T">返回的类型</typeparam>
         /// <param name="CacheKey">键</param>
-        public static T GetCache<T>(string CacheKey)
+        public static T GetCache<T>(this Cache cache, string CacheKey)
         {
-            System.Web.Caching.Cache objCache = HttpRuntime.Cache;
-            return (T)objCache[CacheKey];
+            return (T)cache[CacheKey];
         }
         #endregion
 
@@ -32,10 +31,9 @@ namespace Masuit.Tools.Net
         /// </summary>
         /// <param name="CacheKey">键</param>
         /// <param name="objObject">值</param>
-        public static void SetCache(string CacheKey, object objObject)
+        public static void SetCache(this Cache cache, string CacheKey, object objObject)
         {
-            System.Web.Caching.Cache objCache = HttpRuntime.Cache;
-            objCache.Insert(CacheKey, objObject);
+            cache.Insert(CacheKey, objObject);
         }
 
         /// <summary>
@@ -45,11 +43,10 @@ namespace Masuit.Tools.Net
         /// <param name="objObject">值</param>
         /// <param name="Timeout">过期时间</param>
         /// <exception cref="ArgumentNullException"><paramref name="cacheKey"/>"/> is <c>null</c>.</exception>
-        public static void SetCache(string cacheKey, object objObject, TimeSpan Timeout)
+        public static void SetCache(this Cache cache, string cacheKey, object objObject, TimeSpan Timeout)
         {
             if (cacheKey == null) throw new ArgumentNullException(nameof(cacheKey));
-            System.Web.Caching.Cache objCache = HttpRuntime.Cache;
-            objCache.Insert(cacheKey, objObject, null, DateTime.MaxValue, Timeout, System.Web.Caching.CacheItemPriority.NotRemovable, null);
+            cache.Insert(cacheKey, objObject, null, DateTime.MaxValue, Timeout, CacheItemPriority.NotRemovable, null);
         }
 
         /// <summary>
@@ -59,10 +56,9 @@ namespace Masuit.Tools.Net
         /// <param name="objObject">值</param>
         /// <param name="absoluteExpiration">绝对过期时间</param>
         /// <param name="slidingExpiration">滑动过期时间</param>
-        public static void SetCache(string CacheKey, object objObject, DateTime absoluteExpiration, TimeSpan slidingExpiration)
+        public static void SetCache(this Cache cache, string CacheKey, object objObject, DateTime absoluteExpiration, TimeSpan slidingExpiration)
         {
-            System.Web.Caching.Cache objCache = HttpRuntime.Cache;
-            objCache.Insert(CacheKey, objObject, null, absoluteExpiration, slidingExpiration);
+            cache.Insert(CacheKey, objObject, null, absoluteExpiration, slidingExpiration);
         }
         #endregion
 
@@ -71,22 +67,17 @@ namespace Masuit.Tools.Net
         /// 移除指定数据缓存
         /// </summary>
         /// <param name="CacheKey">键</param>
-        public static void RemoveAllCache(string CacheKey)
-        {
-            System.Web.Caching.Cache _cache = HttpRuntime.Cache;
-            _cache.Remove(CacheKey);
-        }
+        public static void RemoveAllCache(this Cache cache, string CacheKey) => cache.Remove(CacheKey);
 
         /// <summary>
         /// 移除全部缓存
         /// </summary>
-        public static void RemoveAllCache()
+        public static void RemoveAllCache(this Cache cache)
         {
-            System.Web.Caching.Cache _cache = HttpRuntime.Cache;
-            IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();
+            IDictionaryEnumerator CacheEnum = cache.GetEnumerator();
             while (CacheEnum.MoveNext())
             {
-                _cache.Remove(CacheEnum.Key.ToString());
+                cache.Remove(CacheEnum.Key.ToString());
             }
         }
         #endregion

+ 1 - 1
Masuit.Tools/Net/CookieHelper.cs

@@ -182,7 +182,7 @@ namespace Masuit.Tools.Net
         public static List<CookieItem> GetCookieList(string cookie)
         {
             List<CookieItem> cookielist = new List<CookieItem>();
-            foreach (string item in cookie.Split(new string[] { ";", "," }, StringSplitOptions.RemoveEmptyEntries))
+            foreach (string item in cookie.Split(new[] { ";", "," }, StringSplitOptions.RemoveEmptyEntries))
             {
                 if (Regex.IsMatch(item, @"([\s\S]*?)=([\s\S]*?)$"))
                 {

+ 0 - 12
Masuit.Tools/Net/SocketClient.cs

@@ -545,17 +545,5 @@ namespace Masuit.Tools.Net
         }
 
         #endregion
-
-        #region NetworkStream接收数据
-
-        //没写
-
-        #endregion
-
-        #region NetworkStream发送数据
-
-        //没写
-
-        #endregion
     }
 }

+ 5 - 3
Masuit.Tools/Net/WebExtension.cs

@@ -1,9 +1,11 @@
 using System;
+using System.Data.Entity;
 using System.Net.Http;
 using System.Runtime.Remoting.Messaging;
 using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using System.Web;
+using System.Web.SessionState;
 using Masuit.Tools.Models;
 using Masuit.Tools.Strings;
 using Newtonsoft.Json;
@@ -22,7 +24,7 @@ namespace Masuit.Tools.Net
         /// </summary>
         /// <typeparam name="T">EF上下文容器对象</typeparam>
         /// <returns>EF上下文容器对象</returns>
-        public static T GetDbContext<T>() where T : new()
+        public static T GetDbContext<T>(this DbContext _) where T : DbContext, new()
         {
             T db;
             if (CallContext.GetData("db") == null) //由于CallContext比HttpContext先存在,所以首选CallContext为线程内唯一对象
@@ -42,7 +44,7 @@ namespace Masuit.Tools.Net
         /// </summary>
         /// <param name="key">键</param>
         /// <param name="value">值</param>
-        public static void SetSession(string key, dynamic value) => HttpContext.Current.Session[key] = value;
+        public static void SetSession(this HttpSessionState session, string key, dynamic value) => session.Add(key, value);
 
         #endregion
 
@@ -54,7 +56,7 @@ namespace Masuit.Tools.Net
         /// <typeparam name="T">对象</typeparam>
         /// <param name="key">键</param>
         /// <returns>对象</returns>
-        public static T GetSession<T>(string key) => (T)HttpContext.Current.Session[key];
+        public static T GetSession<T>(this HttpSessionState session, string key) => (T)session[key];
 
         #endregion
 

+ 0 - 19
Masuit.Tools/Objects/ObjectExt.cs

@@ -1,19 +0,0 @@
-namespace Masuit.Tools.Objects
-{
-    /// <summary>
-    /// Object扩展类
-    /// </summary>
-    public static class ObjectExt
-    {
-        /// <summary>
-        /// 严格比较两个对象是否是同一对象
-        /// </summary>
-        /// <param name="_this">自己</param>
-        /// <param name="o">需要比较的对象</param>
-        /// <returns>是否同一对象</returns>
-        public new static bool ReferenceEquals(this object _this, object o)
-        {
-            return object.ReferenceEquals(_this, o);
-        }
-    }
-}

+ 4 - 4
Masuit.Tools/Properties/AssemblyInfo.cs

@@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
 // 控制。更改这些特性值可修改
 // 与程序集关联的信息。
 
-[assembly: AssemblyTitle("Masuit.Utilities")]
-[assembly: AssemblyDescription("")]
+[assembly: AssemblyTitle("Masuit.Tools")]
+[assembly: AssemblyDescription("懒得勤快")]
 [assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("Masuit.Utilities")]
+[assembly: AssemblyCompany("懒得勤快")]
+[assembly: AssemblyProduct("Masuit.Tools")]
 [assembly: AssemblyCopyright("Copyright ©  2017")]
 [assembly: AssemblyTrademark("")]
 [assembly: AssemblyCulture("")]

+ 1 - 1
Masuit.Tools/Reflection/ReflectionUtil.cs

@@ -329,7 +329,7 @@ namespace Masuit.Tools.Reflection
         /// </summary>
         /// <param name="resourceName">资源的名称</param>
         /// <returns>数据流</returns>
-        public static Stream GetImageResource(string resourceName)
+        public static Stream GetImageResource(this Assembly _, string resourceName)
         {
             Assembly asm = Assembly.GetExecutingAssembly();
             return asm.GetManifestResourceStream(resourceName);

+ 5 - 26
Masuit.Tools/Security/HashEncode.cs

@@ -1,48 +1,27 @@
 using System;
 using System.Security.Cryptography;
 using System.Text;
+using Masuit.Tools.Win32;
 
 namespace Masuit.Tools.Security
 {
     /// <summary>
     /// 得到随机安全码(哈希加密)。
     /// </summary>
-    public class HashEncode
+    public static class HashEncode
     {
-        /// <summary>
-        /// 哈希加密
-        /// </summary>
-        public HashEncode()
-        {
-            //
-            // TODO: 在此处添加构造函数逻辑
-            //
-        }
         /// <summary>
         /// 得到随机哈希加密字符串
         /// </summary>
         /// <returns>随机哈希加密字符串</returns>
-        public static string GetSecurity()
-        {
-            string Security = HashEncoding(GetRandomValue());
-            return Security;
-        }
-        /// <summary>
-        /// 得到一个随机数值
-        /// </summary>
-        /// <returns>随机数值</returns>
-        public static string GetRandomValue()
-        {
-            Random Seed = new Random();
-            string RandomVaule = Seed.Next(1, int.MaxValue).ToString();
-            return RandomVaule;
-        }
+        public static string GetSecurity(this Random r) => HashEncoding(r.StrictNext().ToString());
+
         /// <summary>
         /// 哈希加密一个字符串
         /// </summary>
         /// <param name="Security">需要加密的字符串</param>
         /// <returns>加密后的数据</returns>
-        public static string HashEncoding(string Security)
+        public static string HashEncoding(this string Security)
         {
             byte[] Value;
             UnicodeEncoding Code = new UnicodeEncoding();

+ 1 - 1
Masuit.Tools/Security/RSACryption.cs

@@ -27,7 +27,7 @@ namespace Masuit.Tools.Security
         /// <param name="xmlPublicKey">公钥</param>
         public void RSAKey(out string xmlKeys, out string xmlPublicKey)
         {
-            System.Security.Cryptography.RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
+            var rsa = new RSACryptoServiceProvider();
             xmlKeys = rsa.ToXmlString(true);
             xmlPublicKey = rsa.ToXmlString(false);
         }

+ 1 - 1
Masuit.Tools/app.config

@@ -2,7 +2,7 @@
 <configuration>
   <configSections>
     <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
-  </configSections>
+  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
   <runtime>
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
       <dependentAssembly>

+ 36 - 0
Masuit.Tools/package.nuspec

@@ -0,0 +1,36 @@
+<?xml version="1.0"?>
+<package>
+  <metadata>
+    <!--*-->
+    <id>$id$</id>
+    <!--*-->
+    <version>$version$</version>
+    <title></title>
+    <!--*-->
+    <authors>$author$</authors>
+    <owners>$author$</owners>
+<!--
+    <licenseUrl></licenseUrl>
+    <projectUrl></projectUrl>
+    <iconUrl></iconUrl>
+-->
+    <requireLicenseAcceptance>false</requireLicenseAcceptance>
+    <!--*-->
+    <description>$description$</description>
+    <!--*-->
+    <releaseNotes> </releaseNotes>
+    <copyright>$copyright$</copyright>
+    <tags> </tags>
+    <dependencies>
+         <group targetFramework="net45">
+            <dependency id="AngleSharp" version="0.9.9" />
+            <dependency id="EntityFramework" version="6.1.3" />
+            <dependency id="EntityFramework.zh-Hans" version="6.1.3" />
+            <dependency id="HtmlSanitizer" version="3.4.156" />
+            <dependency id="Newtonsoft.Json" version="10.0.3" />
+            <dependency id="SharpZipLib" version="0.86.0" />
+            <dependency id="StackExchange.Redis" version="1.2.4" />
+         </group>
+      </dependencies>
+  </metadata>
+</package>

+ 2 - 0
Masuit.Tools/packages.config

@@ -1,6 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
   <package id="AngleSharp" version="0.9.9" targetFramework="net45" />
+  <package id="EntityFramework" version="6.1.3" targetFramework="net45" />
+  <package id="EntityFramework.zh-Hans" version="6.1.3" targetFramework="net45" />
   <package id="HtmlSanitizer" version="3.4.156" targetFramework="net45" />
   <package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" />
   <package id="SharpZipLib" version="0.86.0" targetFramework="net45" />

+ 2 - 3
Masuit.Tools帮助文档/Masuit.Tools帮助文档.shfbproj

@@ -27,9 +27,8 @@
       <Argument Key="maxVersionParts" Value="" xmlns="" />
     </TransformComponentArguments>
     <DocumentationSources>
-      <DocumentationSource sourceFile="..\Masuit.Tools\bin\Debug\Masuit.Tools.XML" />
-      <DocumentationSource sourceFile="..\Masuit.Tools\bin\Debug\Masuit.Tools.dll" />
-    </DocumentationSources>
+      <DocumentationSource sourceFile="..\Masuit.Tools\bin\Release\Masuit.Tools.dll" />
+<DocumentationSource sourceFile="..\Masuit.Tools\bin\Release\Masuit.Tools.XML" /></DocumentationSources>
     <MaximumGroupParts>2</MaximumGroupParts>
     <NamespaceGrouping>False</NamespaceGrouping>
     <SyntaxFilters>C#</SyntaxFilters>

+ 5 - 0
Test/Program.cs

@@ -1,4 +1,9 @@
 using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+using System.Xml.Serialization;
+using Masuit.Tools;
 using Masuit.Tools.Win32;
 
 namespace Test