Browse Source

整理工具类(把之前在.net2.0中的一些工具整理进来了)

yuzhengyang 8 years ago
parent
commit
f731b2053d

BIN
Fork.Net/Dlls/Control/IPAddressControlLib.dll


+ 88 - 0
Fork.Net/Y.Utils.Net20/ImageUtils/ImageTool.cs

@@ -1,5 +1,7 @@
 using System;
 using System.Drawing;
+using System.Drawing.Drawing2D;
+using System.Drawing.Imaging;
 
 namespace Y.Utils.Net20.ImageUtils
 {
@@ -83,6 +85,7 @@ namespace Y.Utils.Net20.ImageUtils
                 g.Dispose();
             }
         }
+        
         /// <summary>
         /// 逆时针旋转图像
         /// </summary>
@@ -136,5 +139,90 @@ namespace Y.Utils.Net20.ImageUtils
                 g.Dispose();
             }
         }
+
+        /// 无损压缩图片    
+        /// <param name="sFile">原图片</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)
+        {
+            Image iSource = Image.FromFile(sFile);
+            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)
+            {
+                if ((tem_size.Width * dHeight) > (tem_size.Width * dWidth))
+                {
+                    sW = dWidth;
+                    sH = (dWidth * tem_size.Height) / tem_size.Width;
+                }
+                else
+                {
+                    sH = dHeight;
+                    sW = (tem_size.Width * dHeight) / tem_size.Height;
+                }
+            }
+            else
+            {
+                sW = tem_size.Width;
+                sH = tem_size.Height;
+            }
+
+            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(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(System.Drawing.Imaging.Encoder.Quality, qy);
+            ep.Param[0] = eParam;
+            try
+            {
+                ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
+                ImageCodecInfo jpegICIinfo = null;
+                for (int x = 0; x < arrayICI.Length; x++)
+                {
+                    if (arrayICI[x].FormatDescription.Equals("JPEG"))
+                    {
+                        jpegICIinfo = arrayICI[x];
+                        break;
+                    }
+                }
+                if (jpegICIinfo != null)
+                {
+                    ob.Save(dFile, jpegICIinfo, ep);//dFile是压缩后的新路径    
+                }
+                else
+                {
+                    ob.Save(dFile, tFormat);
+                }
+                return true;
+            }
+            catch
+            {
+                return false;
+            }
+            finally
+            {
+                iSource.Dispose();
+                ob.Dispose();
+            }
+        }
     }
 }

+ 74 - 0
Fork.Net/Y.Utils.Net20/ImageUtils/ThunbnailTool.cs

@@ -0,0 +1,74 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Drawing.Drawing2D;
+using System.Text;
+
+namespace Y.Utils.Net20.ImageUtils
+{
+    public class ThumbnailTool
+    {
+        /// <summary>
+        /// 标准缩略图生成
+        /// </summary>
+        /// <param name="originalImage">原始图像</param>
+        /// <param name="width">指定宽度</param>
+        /// <param name="height">指定高度</param>
+        /// <param name="mode">缩略图模式</param>
+        /// <param name="im">差值模式</param>
+        /// <param name="sm">平滑模式</param>
+        /// <returns></returns>
+        public static Bitmap Normal(Bitmap originalImage, int width, int height, string mode,
+            InterpolationMode im = InterpolationMode.High, SmoothingMode sm = SmoothingMode.HighQuality)
+        {
+            int towidth = width;
+            int toheight = height;
+            int x = 0;
+            int y = 0;
+            int ow = originalImage.Width;
+            int oh = originalImage.Height;
+            switch (mode)
+            {
+                case "HW"://指定高宽缩放(可能变形)                 
+                    break;
+                case "W"://指定宽,高按比例                     
+                    toheight = originalImage.Height * width / originalImage.Width;
+                    break;
+                case "H"://指定高,宽按比例 
+                    towidth = originalImage.Width * height / originalImage.Height;
+                    break;
+                case "Cut"://指定高宽裁减(不变形)                 
+                    if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
+                    {
+                        oh = originalImage.Height;
+                        ow = originalImage.Height * towidth / toheight;
+                        y = 0;
+                        x = (originalImage.Width - ow) / 2;
+                    }
+                    else
+                    {
+                        ow = originalImage.Width;
+                        oh = originalImage.Width * height / towidth;
+                        x = 0;
+                        y = (originalImage.Height - oh) / 2;
+                    }
+                    break;
+                default:
+                    break;
+            }
+            //新建一个bmp图片 
+            Bitmap bitmap = new Bitmap(towidth, toheight);
+            //新建一个画板 
+            Graphics g = Graphics.FromImage(bitmap);
+            //设置高质量插值法 
+            g.InterpolationMode = im;
+            //设置高质量,低速度呈现平滑程度 
+            g.SmoothingMode = sm;
+            //清空画布并以透明背景色填充 
+            g.Clear(Color.Transparent);
+            //在指定位置并且按指定大小绘制原图片的指定部分 
+            g.DrawImage(originalImage, new Rectangle(0, 0, towidth, toheight), new Rectangle(x, y, ow, oh), GraphicsUnit.Pixel);
+            return bitmap;
+        }
+    }
+}

+ 1 - 0
Fork.Net/Y.Utils.Net20/Y.Utils.Net20.csproj

@@ -53,6 +53,7 @@
     <Compile Include="HookUtils\UserActivityHook.cs" />
     <Compile Include="HttpUtils\HttpTool.cs" />
     <Compile Include="ImageUtils\ImageTool.cs" />
+    <Compile Include="ImageUtils\ThunbnailTool.cs" />
     <Compile Include="JsonUtils\JsonTool.cs" />
     <Compile Include="ListUtils\ListTool.cs" />
     <Compile Include="LogUtils\Log.cs" />

+ 44 - 0
Fork.Net/Y.Utils/EncryptUtils/AesTool.cs

@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Cryptography;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Y.Utils.EncryptUtils
+{
+    public class AesTool
+    {
+        public static string Encrypt(string s, string key)
+        {
+            //byte[] keyArray = UTF8Encoding.UTF8.GetBytes("12345678901234567890123456789012");
+            byte[] keyArray = UTF8Encoding.UTF8.GetBytes(key);
+            byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(s);
+
+            RijndaelManaged rDel = new RijndaelManaged();
+            rDel.Key = keyArray;
+            rDel.Mode = CipherMode.ECB;
+            rDel.Padding = PaddingMode.PKCS7;
+
+            ICryptoTransform cTransform = rDel.CreateEncryptor();
+            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
+
+            return Convert.ToBase64String(resultArray, 0, resultArray.Length);
+        }
+        public static string Decrypt(string s, string key)
+        {
+            byte[] keyArray = UTF8Encoding.UTF8.GetBytes(key);
+            byte[] toEncryptArray = Convert.FromBase64String(s);
+
+            RijndaelManaged rDel = new RijndaelManaged();
+            rDel.Key = keyArray;
+            rDel.Mode = CipherMode.ECB;
+            rDel.Padding = PaddingMode.PKCS7;
+
+            ICryptoTransform cTransform = rDel.CreateDecryptor();
+            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
+
+            return UTF8Encoding.UTF8.GetString(resultArray);
+        }
+    }
+}

+ 68 - 0
Fork.Net/Y.Utils/EncryptUtils/DesTool.cs

@@ -0,0 +1,68 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Security.Cryptography;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Y.Utils.EncryptUtils
+{
+    public class DesTool
+    {
+        #region DESEnCode DES加密     
+        public static string Encrypt(string pToEncrypt, string sKey)
+        {
+            // string pToEncrypt1 = HttpContext.Current.Server.UrlEncode(pToEncrypt);     
+            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
+            byte[] inputByteArray = Encoding.GetEncoding("UTF-8").GetBytes(pToEncrypt);
+
+            //建立加密对象的密钥和偏移量      
+            //原文使用ASCIIEncoding.ASCII方法的GetBytes方法      
+            //使得输入密码必须输入英文文本      
+            des.Key = Encoding.ASCII.GetBytes(sKey);
+            des.IV = Encoding.ASCII.GetBytes(sKey);
+            MemoryStream ms = new MemoryStream();
+            CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
+
+            cs.Write(inputByteArray, 0, inputByteArray.Length);
+            cs.FlushFinalBlock();
+
+            StringBuilder ret = new StringBuilder();
+            foreach (byte b in ms.ToArray())
+            {
+                ret.AppendFormat("{0:X2}", b);
+            }
+            ret.ToString();
+            return ret.ToString();
+        }
+        #endregion
+
+        #region DESDeCode DES解密     
+        public static string Decrypt(string pToDecrypt, string sKey)
+        {
+            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
+
+            byte[] inputByteArray = new byte[pToDecrypt.Length / 2];
+            for (int x = 0; x < pToDecrypt.Length / 2; x++)
+            {
+                int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
+                inputByteArray[x] = (byte)i;
+            }
+
+            des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
+            des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
+            MemoryStream ms = new MemoryStream();
+            CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
+            cs.Write(inputByteArray, 0, inputByteArray.Length);
+            cs.FlushFinalBlock();
+
+            StringBuilder ret = new StringBuilder();
+
+            return System.Text.Encoding.Default.GetString(ms.ToArray());
+        }
+        #endregion
+
+
+    }
+}

+ 45 - 0
Fork.Net/Y.Utils/EnumUtils/FlagsEnumTool.cs

@@ -0,0 +1,45 @@
+using System;
+
+namespace Y.Utils.EnumUtils
+{
+    /// <summary>
+    /// 标志枚举修改工具
+    /// 弃用:效率太低
+    /// sa = sa | StatusAttributes.Join;//添加属性
+    /// sa = (sa | StatusAttributes.Share) ^ StatusAttributes.Share;//删除属性
+    /// </summary>
+    [Obsolete]
+    public sealed class FlagsEnumTool
+    {
+        public static int AddAttribute(int en, int att)
+        {
+            return en ^ att;
+        }
+        public static int AddAttribute<T>(T en, T att)
+        {
+            try
+            {
+                int intEn = (int)Convert.ChangeType(en, typeof(int));
+                int intAtt = (int)Convert.ChangeType(att, typeof(int));
+                return intEn ^ intAtt;
+            }
+            catch (Exception e) { }
+            return 0;
+        }
+        public static int RemoveAttribute(int en, int att)
+        {
+            return (en | att) ^ att;
+        }
+        public static int RemoveAttribute<T>(T en, T att)
+        {
+            try
+            {
+                int intEn = (int)Convert.ChangeType(en, typeof(int));
+                int intAtt = (int)Convert.ChangeType(att, typeof(int));
+                return (intEn | intAtt) ^ intAtt;
+            }
+            catch (Exception e) { }
+            return 0;
+        }
+    }
+}

+ 66 - 0
Fork.Net/Y.Utils/ImageUtils/AffineTool.cs

@@ -0,0 +1,66 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Y.Utils.ImageUtils
+{
+    public class AffineTool
+    {
+        /// <summary>
+        /// 逆时针旋转图像
+        /// </summary>
+        /// <param name="originalImagePath">原始图像路径</param>
+        /// <param name="saveImagePath">保存图像的路径</param>
+        /// <param name = "angle" > 旋转角度[0, 360](前台给的) </ param >
+        /// <returns></returns>
+        public static bool RotateImg(string originalImagePath, string saveImagePath, int angle)
+        {
+            Image originalImage = Image.FromFile(originalImagePath);
+            angle = angle % 360;
+            //弧度转换  
+            double radian = angle * Math.PI / 180.0;
+            double cos = Math.Cos(radian);
+            double sin = Math.Sin(radian);
+            //原图的宽和高  
+            int w = originalImage.Width;
+            int h = originalImage.Height;
+            int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
+            int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));
+            //目标位图  
+            Bitmap saveImage = new Bitmap(W, H);
+            Graphics g = Graphics.FromImage(saveImage);
+            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
+            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
+            //计算偏移量  
+            Point Offset = new Point((W - w) / 2, (H - h) / 2);
+            //构造图像显示区域:让图像的中心与窗口的中心点一致  
+            Rectangle rect = new Rectangle(Offset.X, Offset.Y, w, h);
+            Point center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
+            g.TranslateTransform(center.X, center.Y);
+            g.RotateTransform(360 - angle);
+            //恢复图像在水平和垂直方向的平移  
+            g.TranslateTransform(-center.X, -center.Y);
+            g.DrawImage(originalImage, rect);
+            //重至绘图的所有变换  
+            g.ResetTransform();
+            g.Save();
+            //保存旋转后的图片  
+            originalImage.Dispose();
+            try
+            {
+                saveImage.Save(saveImagePath, System.Drawing.Imaging.ImageFormat.Jpeg);
+                return true;
+            }
+            catch (Exception e) { return false; }
+            finally
+            {
+                originalImage.Dispose();
+                saveImage.Dispose();
+                g.Dispose();
+            }
+        }
+    }
+}

+ 76 - 0
Fork.Net/Y.Utils/ImageUtils/ThunbnailTool.cs

@@ -0,0 +1,76 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Drawing.Drawing2D;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Y.Utils.ImageUtils
+{
+    public class ThunbnailTool
+    {
+        /// <summary>
+        /// 标准缩略图生成
+        /// </summary>
+        /// <param name="originalImage">原始图像</param>
+        /// <param name="width">指定宽度</param>
+        /// <param name="height">指定高度</param>
+        /// <param name="mode">缩略图模式</param>
+        /// <param name="im">差值模式</param>
+        /// <param name="sm">平滑模式</param>
+        /// <returns></returns>
+        public static Bitmap Normal(Bitmap originalImage, int width, int height, string mode,
+            InterpolationMode im = InterpolationMode.High, SmoothingMode sm = SmoothingMode.HighQuality)
+        {
+            int towidth = width;
+            int toheight = height;
+            int x = 0;
+            int y = 0;
+            int ow = originalImage.Width;
+            int oh = originalImage.Height;
+            switch (mode)
+            {
+                case "HW"://指定高宽缩放(可能变形)                 
+                    break;
+                case "W"://指定宽,高按比例                     
+                    toheight = originalImage.Height * width / originalImage.Width;
+                    break;
+                case "H"://指定高,宽按比例 
+                    towidth = originalImage.Width * height / originalImage.Height;
+                    break;
+                case "Cut"://指定高宽裁减(不变形)                 
+                    if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
+                    {
+                        oh = originalImage.Height;
+                        ow = originalImage.Height * towidth / toheight;
+                        y = 0;
+                        x = (originalImage.Width - ow) / 2;
+                    }
+                    else
+                    {
+                        ow = originalImage.Width;
+                        oh = originalImage.Width * height / towidth;
+                        x = 0;
+                        y = (originalImage.Height - oh) / 2;
+                    }
+                    break;
+                default:
+                    break;
+            }
+            //新建一个bmp图片 
+            Bitmap bitmap = new Bitmap(towidth, toheight);
+            //新建一个画板 
+            Graphics g = Graphics.FromImage(bitmap);
+            //设置高质量插值法 
+            g.InterpolationMode = im;
+            //设置高质量,低速度呈现平滑程度 
+            g.SmoothingMode = sm;
+            //清空画布并以透明背景色填充 
+            g.Clear(Color.Transparent);
+            //在指定位置并且按指定大小绘制原图片的指定部分 
+            g.DrawImage(originalImage, new Rectangle(0, 0, towidth, toheight), new Rectangle(x, y, ow, oh), GraphicsUnit.Pixel);
+            return bitmap;
+        }
+    }
+}

+ 46 - 39
Fork.Net/Y.Utils/LogUtils/Log.cs

@@ -4,6 +4,8 @@ using System.Linq;
 using System.Runtime.InteropServices;
 using System.Text;
 using System.Threading.Tasks;
+using Y.Utils.FileUtils;
+using Y.Utils.TxtUtils;
 
 namespace Y.Utils.LogUtils
 {
@@ -18,61 +20,67 @@ namespace Y.Utils.LogUtils
     public class Log
     {
         //输出的 Log 格式
-        const string LogFormat = "{0}   {1}   {2}";
-        const string TimeFormat = "MM-dd HH:mm:ss.fff";
+        const string LogFormat = "{0}  {1}  {2}";
+        const string TimeFormat = "HH:mm:ss.fff";
+
+        public static bool IsWriteFile = true;
+
+        private static object LogFileLock = new object();
 
-        #region 输出类型
-        /// <summary>
-        /// 输出类型
-        /// </summary>
-        enum PrintType
-        {
-            v,//verbose 啰嗦的意思
-            d,//debug 调试的信息
-            i,//information 一般提示性的消息
-            w,//warning 警告
-            e,//error 错误信息
-        }
-        #endregion
         #region Console 开启/关闭 API
         [DllImport("kernel32.dll")]
         public static extern Boolean AllocConsole();
         [DllImport("kernel32.dll")]
         public static extern Boolean FreeConsole();
         #endregion
-        #region 输出颜色
+
         /// <summary>
         /// 获取输出颜色
         /// </summary>
         /// <param name="type">输出类型</param>
         /// <returns></returns>
-        private static ConsoleColor GetColor(PrintType type)
+        private static ConsoleColor GetColor(LogType type)
         {
             switch (type)
             {
-                case PrintType.v: return ConsoleColor.Gray;
-                case PrintType.d: return ConsoleColor.Blue;
-                case PrintType.i: return ConsoleColor.Green;
-                case PrintType.w: return ConsoleColor.Yellow;
-                case PrintType.e: return ConsoleColor.Red;
+                case LogType.v: return ConsoleColor.Gray;
+                case LogType.d: return ConsoleColor.Blue;
+                case LogType.i: return ConsoleColor.Green;
+                case LogType.w: return ConsoleColor.Yellow;
+                case LogType.e: return ConsoleColor.Red;
                 default: return ConsoleColor.Gray;
             }
         }
-        #endregion
-        #region 写出 Log
+
         /// <summary>
         /// 写出到控制台
         /// </summary>
         /// <param name="type">类型</param>
         /// <param name="tag">标记</param>
         /// <param name="message">消息</param>
-        private static void Write(PrintType type, string message)
+        private static void Write(LogType type, string message)
         {
-            DateTime now = DateTime.Now;
             Console.ForegroundColor = GetColor(type);
-            Console.WriteLine(LogFormat, now.ToString(TimeFormat), type.ToString(), message);
+            Console.WriteLine(LogFormat, DateTime.Now.ToString(TimeFormat), type.ToString(), message);
+            if (IsWriteFile) WriteFile(type, message);
+        }
+
+        private static void WriteFile(LogType type, string message)
+        {
+            if (IsWriteFile)
+            {
+                lock (LogFileLock)
+                {
+                    //设置日志目录
+                    string logPath = AppDomain.CurrentDomain.BaseDirectory + "Log";
+                    string file = string.Format(@"{0}\{1}.txt", logPath, DateTime.Now.ToString("yyyy-MM-dd"));
+                    //创建日志目录
+                    DirTool.Create(logPath);
+                    //写出日志
+                    TxtTool.Append(file, string.Format(LogFormat, DateTime.Now.ToString(TimeFormat), type.ToString(), message));
+                }
+            }
         }
-        #endregion
 
         #region 分类详细输出
         /// <summary>
@@ -80,47 +88,46 @@ namespace Y.Utils.LogUtils
         /// </summary>
         /// <param name="message">消息</param>
         /// <param name="tag">可选:标记</param>
-        public static void v(string message)
+        public static void v<T>(T msg)
         {
-            Write(PrintType.v, message);
+            Write(LogType.v, msg.ToString());
         }
         /// <summary>
         /// 输出 Debug (调试信息)
         /// </summary>
         /// <param name="message">消息</param>
         /// <param name="tag">可选:标记</param>
-        public static void d(string message)
+        public static void d<T>(T msg)
         {
-            Write(PrintType.d, message);
+            Write(LogType.d, msg.ToString());
         }
         /// <summary>
         /// 输出 Information (重要信息)
         /// </summary>
         /// <param name="message">消息</param>
         /// <param name="tag">可选:标记</param>
-        public static void i(string message)
+        public static void i<T>(T msg)
         {
-            Write(PrintType.i, message);
+            Write(LogType.i, msg.ToString());
         }
         /// <summary>
         /// 输出 Warning (警告信息)
         /// </summary>
         /// <param name="message">消息</param>
         /// <param name="tag">可选:标记</param>
-        public static void w(string message)
+        public static void w<T>(T msg)
         {
-            Write(PrintType.w, message);
+            Write(LogType.w, msg.ToString());
         }
         /// <summary>
         /// 输出 Error (错误信息)
         /// </summary>
         /// <param name="message">消息</param>
         /// <param name="tag">可选:标记</param>
-        public static void e(string message)
+        public static void e<T>(T msg)
         {
-            Write(PrintType.e, message);
+            Write(LogType.e, msg.ToString());
         }
         #endregion
     }
-
 }

+ 17 - 0
Fork.Net/Y.Utils/LogUtils/LogType.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Y.Utils.LogUtils
+{
+    public enum LogType
+    {
+        v,//verbose 啰嗦的意思
+        d,//debug 调试的信息
+        i,//information 一般提示性的消息
+        w,//warning 警告
+        e,//error 错误信息
+    }
+}

+ 14 - 0
Fork.Net/Y.Utils/StringUtils/SimilarString.cs

@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Y.Utils.StringUtils
+{
+    public static class SimilarString
+    {
+        public static int Simple()
+        {
+            return 100;
+        }
+    }
+}

+ 19 - 0
Fork.Net/Y.Utils/StringUtils/StringTool.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Y.Utils.StringUtils
+{
+    public class StringTool
+    {
+        public static bool IsNullOrWhiteSpace(string str)
+        {
+            if (str == null)
+                return true;
+            if (str.Trim().Length == 0)
+                return true;
+
+            return false;
+        }
+    }
+}

+ 28 - 0
Fork.Net/Y.Utils/TimeUtils/DateTimeTool.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Y.Utils.TimeUtils
+{
+    public sealed class DateTimeTool
+    {
+        public static DateTime TodayDate()
+        {
+            DateTime today = DateTime.Now;
+            DateTime result = new DateTime(today.Year, today.Month, today.Day);
+            return result;
+        }
+        public static DateTime TodayDate(DateTime today)
+        {
+            DateTime result = new DateTime(today.Year, today.Month, today.Day);
+            return result;
+        }
+        public static TimeSpan TimeSpan(DateTime dt1, DateTime dt2)
+        {
+            if (dt1 > dt2)
+                return dt1 - dt2;
+            else
+                return dt2 - dt1;
+        }
+    }
+}

+ 1 - 1
Fork.Net/Y.Utils/TxtUtils/LogTool.cs

@@ -3,7 +3,7 @@ using Y.Utils.FileUtils;
 
 namespace Y.Utils.TxtUtils
 {
-    public class LogTool
+    class LogTool
     {
         public static void Normal(string tag, string info)
         {

+ 41 - 0
Fork.Net/Y.Utils/WindowsAPI/ComputerAFK.cs

@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace Y.Utils.WindowsAPI
+{
+    public class ComputerAFK
+    {
+        #region 系统空闲时间
+        #region 捕获时间结构体
+        [StructLayout(LayoutKind.Sequential)]
+        struct LASTINPUTINFO
+        {
+            // 设置结构体块容量  
+            [MarshalAs(UnmanagedType.U4)]
+            public int cbSize;
+            // 捕获的时间  
+            [MarshalAs(UnmanagedType.U4)]
+            public uint dwTime;
+        }
+        #endregion
+        [DllImport("user32.dll")]
+        private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
+        /// <summary>
+        /// 获取计算机无操作时间
+        /// </summary>
+        /// <returns></returns>
+        public static long GetLastInputTime()
+        {
+            LASTINPUTINFO vLastInputInfo = new LASTINPUTINFO();
+            vLastInputInfo.cbSize = Marshal.SizeOf(vLastInputInfo);
+            // 捕获时间  
+            if (!GetLastInputInfo(ref vLastInputInfo))
+                return 0;
+            else
+                return Environment.TickCount - (long)vLastInputInfo.dwTime;
+        }
+        #endregion
+    }
+}

+ 106 - 0
Fork.Net/Y.Utils/WindowsAPI/ScreenCapture.cs

@@ -0,0 +1,106 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace Y.Utils.WindowsAPI
+{
+    /// <summary>
+    /// 屏幕捕获类
+    /// </summary>
+    public class ScreenCapture
+    {
+        /// <summary>
+        /// 把当前屏幕捕获到位图对象中
+        /// </summary>
+        /// <param name="hdcDest">目标设备的句柄</param>
+        /// <param name="nXDest">目标对象的左上角的X坐标</param>
+        /// <param name="nYDest">目标对象的左上角的X坐标</param>
+        /// <param name="nWidth">目标对象的矩形的宽度</param>
+        /// <param name="nHeight">目标对象的矩形的长度</param>
+        /// <param name="hdcSrc">源设备的句柄</param>
+        /// <param name="nXSrc">源对象的左上角的X坐标</param>
+        /// <param name="nYSrc">源对象的左上角的X坐标</param>
+        /// <param name="dwRop">光栅的操作值</param>
+        /// <returns></returns>
+        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
+        private static extern bool BitBlt(
+        IntPtr hdcDest,
+        int nXDest,
+        int nYDest,
+        int nWidth,
+        int nHeight,
+        IntPtr hdcSrc,
+        int nXSrc,
+        int nYSrc,
+        int dwRop
+        );
+
+        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
+        private static extern IntPtr CreateDC(
+        string lpszDriver, // 驱动名称
+        string lpszDevice, // 设备名称
+        string lpszOutput, // 无用,可以设定位"NULL"
+        IntPtr lpInitData // 任意的打印机数据
+        );
+
+        /// <summary>
+        /// 屏幕捕获到位图对象中
+        /// </summary>
+        /// <returns></returns>
+        public static Bitmap Capture()
+        {
+            //创建显示器的DC
+            IntPtr dc1 = CreateDC("DISPLAY", null, null, (IntPtr)null);
+            //由一个指定设备的句柄创建一个新的Graphics对象
+            Graphics g1 = Graphics.FromHdc(dc1);
+            //根据屏幕大小创建一个与之相同大小的Bitmap对象
+            Bitmap ScreenImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, g1);
+
+            Graphics g2 = Graphics.FromImage(ScreenImage);
+            //获得屏幕的句柄
+            IntPtr dc3 = g1.GetHdc();
+            //获得位图的句柄
+            IntPtr dc2 = g2.GetHdc();
+            //把当前屏幕捕获到位图对象中
+            BitBlt(dc2, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc3, 0, 0, 13369376);
+            //释放屏幕句柄
+            g1.ReleaseHdc(dc3);
+            //释放位图句柄
+            g2.ReleaseHdc(dc2);
+            g1.Dispose();
+            g2.Dispose();
+            return ScreenImage;
+        }
+
+        /// <summary>
+        /// 压缩图片
+        /// </summary>
+        /// <param name="originalImage"></param>
+        public static Bitmap MakeThumbnail(Image originalImage, int towidth, int toheight)
+        {
+            int x = 0;
+            int y = 0;
+            int ow = originalImage.Width;
+            int oh = originalImage.Height;
+
+            //新建一个bmp图片
+            Bitmap bitmap = new Bitmap(towidth, toheight);
+            //新建一个画板
+            Graphics g = Graphics.FromImage(bitmap);
+            //设置高质量插值法
+            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
+            //设置低质量,高速度呈现平滑程度
+            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
+            //清空画布并以透明背景色填充
+            g.Clear(System.Drawing.Color.Transparent);
+
+            //在指定位置并且按指定大小绘制原图片的指定部分
+            g.DrawImage(originalImage, new System.Drawing.Rectangle(0, 0, towidth, toheight), new System.Drawing.Rectangle(x, y, ow, oh), System.Drawing.GraphicsUnit.Pixel);
+            return bitmap;
+        }
+    }
+}

+ 88 - 0
Fork.Net/Y.Utils/WindowsAPI/WindowInfo.cs

@@ -0,0 +1,88 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace Y.Utils.WindowsAPI
+{
+    public class WindowInfo
+    {
+        #region Windows 窗口操作
+        /// <summary>
+        /// 获取当前窗口句柄
+        /// </summary>
+        /// <returns></returns>
+        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
+        public static extern IntPtr GetForegroundWindow();
+        /// <summary>
+        /// 显示窗口
+        /// </summary>
+        /// <param name="hwnd"></param>
+        /// <param name="nCmdShow">0关闭 1正常显示 2最小化 3最大化</param>
+        /// <returns></returns>
+        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
+        public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
+        /// <summary>
+        /// 获取窗口大小
+        /// </summary>
+        /// <param name="hWnd"></param>
+        /// <param name="lpRect"></param>
+        /// <returns></returns>
+        [DllImport("user32.dll")]
+        [return: MarshalAs(UnmanagedType.Bool)]
+        static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
+        #region 窗口大小结构体
+        [StructLayout(LayoutKind.Sequential)]
+        public struct RECT
+        {
+            public int Left; //最左坐标
+            public int Top; //最上坐标
+            public int Right; //最右坐标
+            public int Bottom; //最下坐标
+        }
+        #endregion
+        /// <summary>
+        /// 获取窗口所在进程ID
+        /// </summary>
+        /// <param name="hwnd"></param>
+        /// <param name="pid"></param>
+        /// <returns></returns>
+        [DllImport("user32", EntryPoint = "GetWindowThreadProcessId")]
+        public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int pid);
+        /// <summary>
+        /// 获取窗体标题
+        /// </summary>
+        /// <param name="hWnd"></param>
+        /// <param name="lpString"></param>
+        /// <param name="nMaxCount"></param>
+        /// <returns></returns>
+        [DllImport("user32.dll")]
+        public extern static int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
+        [DllImport("user32.dll")]
+        public static extern int GetWindowTextLength(IntPtr hWnd);
+        #endregion
+
+        /// <summary>
+        /// 当前窗口标题
+        /// </summary>
+        /// <returns></returns>
+        public static string GetNowWindowName()
+        {
+            StringBuilder windowName = new StringBuilder(GetWindowTextLength(GetForegroundWindow()) + 1);
+            GetWindowText(GetForegroundWindow(), windowName, windowName.Capacity);
+            return windowName.ToString() ?? "";
+        }
+        /// <summary>
+        /// 当前窗口进程名
+        /// </summary>
+        /// <returns></returns>
+        public static string GetNowProcessName()
+        {
+            int windowPid = 0;
+            GetWindowThreadProcessId(GetForegroundWindow(), out windowPid);
+            string processName = Process.GetProcessById(windowPid).ProcessName;
+            return processName ?? "";
+        }
+    }
+}

+ 12 - 0
Fork.Net/Y.Utils/Y.Utils.csproj

@@ -58,7 +58,12 @@
     <Compile Include="AttributeUtils\CustomAttributeHelper.cs" />
     <Compile Include="AttributeUtils\ControlAttribute.cs" />
     <Compile Include="AttributeUtils\ControlAttributeEvent.cs" />
+    <Compile Include="EncryptUtils\AesTool.cs" />
+    <Compile Include="EncryptUtils\DesTool.cs" />
+    <Compile Include="EnumUtils\FlagsEnumTool.cs" />
     <Compile Include="HookUtils\UserActivityHook.cs" />
+    <Compile Include="ImageUtils\AffineTool.cs" />
+    <Compile Include="ImageUtils\ThunbnailTool.cs" />
     <Compile Include="LogUtils\Log.cs" />
     <Compile Include="ComputerUtils\ComputerInfoTool.cs" />
     <Compile Include="ComputerUtils\ComputerPermissionTool.cs" />
@@ -66,6 +71,7 @@
     <Compile Include="ImageUtils\BarCodeToHTML.cs" />
     <Compile Include="ComputerUtils\IPHelper.cs" />
     <Compile Include="FileUtils\FileCodeHelper.cs" />
+    <Compile Include="LogUtils\LogType.cs" />
     <Compile Include="NetworkUtils\FTPHelper.cs" />
     <Compile Include="NetworkUtils\HttpHelper.cs" />
     <Compile Include="NetworkUtils\EmailHelper.cs" />
@@ -87,12 +93,18 @@
     <Compile Include="JsonUtils\JsonTool.cs" />
     <Compile Include="ReflectionUtils\DomainTool.cs" />
     <Compile Include="ReflectionUtils\SimpleReflection.cs" />
+    <Compile Include="StringUtils\SimilarString.cs" />
+    <Compile Include="StringUtils\StringTool.cs" />
     <Compile Include="TestTest\OperatorTest.cs" />
     <Compile Include="TimeUtils\DateTimeConvert.cs" />
+    <Compile Include="TimeUtils\DateTimeTool.cs" />
     <Compile Include="TxtUtils\IniTool.cs" />
     <Compile Include="TxtUtils\LogTool.cs" />
     <Compile Include="TxtUtils\TxtTool.cs" />
     <Compile Include="BaseUtils\UnixTimeTool.cs" />
+    <Compile Include="WindowsAPI\ComputerAFK.cs" />
+    <Compile Include="WindowsAPI\ScreenCapture.cs" />
+    <Compile Include="WindowsAPI\WindowInfo.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="packages.config" />