浏览代码

修改工具类中多余引用

yuzhengyang 9 年之前
父节点
当前提交
34f108937d

+ 24 - 0
Fork.Net/Y.Utils/AppUtils/UniqueTool.cs

@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Y.Utils.AppUtils
+{
+    public class UniqueTool
+    {
+        /// <summary>
+        /// 判断应用在当前系统实例下是否唯一
+        /// </summary>
+        /// <param name="appName"></param>
+        /// <returns></returns>
+        public static bool IsUnique(string appName)
+        {
+            bool unique;
+            Mutex run = new Mutex(true, appName, out unique);
+            return unique;
+        }
+    }
+}

+ 0 - 4
Fork.Net/Y.Utils/BaseUtils/ChineseHourTool.cs

@@ -1,8 +1,4 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace Y.Utils.BaseUtils
 {

+ 1 - 7
Fork.Net/Y.Utils/BaseUtils/Class1.cs

@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Y.Utils.BaseUtils
+namespace Y.Utils.BaseUtils
 {
     class Class1
     {

+ 0 - 4
Fork.Net/Y.Utils/BaseUtils/DateTimeTool.cs

@@ -1,8 +1,4 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace Y.Utils.BaseUtils
 {

+ 1 - 4
Fork.Net/Y.Utils/BaseUtils/ListTool.cs

@@ -1,8 +1,5 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace Y.Utils.BaseUtils
 {

+ 0 - 4
Fork.Net/Y.Utils/BaseUtils/UnixTimeTool.cs

@@ -1,8 +1,4 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace Y.Utils.BaseUtils
 {

+ 0 - 4
Fork.Net/Y.Utils/BaseUtils/WeekDayTool.cs

@@ -1,8 +1,4 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace Y.Utils.BaseUtils
 {

+ 1 - 6
Fork.Net/Y.Utils/ComputerUtils/ComputerPermissionTool.cs

@@ -1,9 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Security.Principal;
-using System.Text;
-using System.Threading.Tasks;
+using System.Security.Principal;
 
 namespace Y.Utils.ComputerUtils
 {

+ 1 - 6
Fork.Net/Y.Utils/ComputerUtils/ComputerTool.cs

@@ -1,9 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Management;
-using System.Text;
-using System.Threading.Tasks;
+using System.Management;
 
 namespace Y.Utils.ComputerUtils
 {

+ 0 - 3
Fork.Net/Y.Utils/ComputerUtils/WindowsAPI.cs

@@ -1,9 +1,6 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
 using System.Runtime.InteropServices;
 using System.Text;
-using System.Threading.Tasks;
 
 namespace Y.Utils.ComputerUtils
 {

+ 0 - 4
Fork.Net/Y.Utils/FileUtils/FileCodeHelper.cs

@@ -1,8 +1,4 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace Y.Utils.FileUtils
 {

+ 42 - 31
Fork.Net/Y.Utils/FileUtils/FileTool.cs

@@ -8,51 +8,62 @@ namespace Y.Utils.FileUtils
 {
     public class FileTool
     {
-        public static List<string> GetFile(string path)
-        {
-            if (Directory.Exists(path))
-                try { return Directory.EnumerateFiles(path).ToList(); } catch (Exception e) { }
-            return null;
-        }
-        public static List<string> GetFile(string path, string ext)
+        public static List<string> GetFile(string path, string pattern = "*")
         {
             if (Directory.Exists(path))
                 try
                 {
-                    List<string> result = null;
-                    List<string> temp = Directory.EnumerateFiles(path).ToList();
-                    if (!ListTool.IsNullOrEmpty(temp))
-                        foreach (var item in temp)
-                        {
-                            if (Path.GetExtension(item).ToUpper() == ext.ToUpper())
-                            {
-                                if (result == null)
-                                    result = new List<string>();
-
-                                result.Add(item);
-                            }
-                        }
+                    List<string> result = Directory.EnumerateFiles(path, pattern).ToList();
                     return result;
                 }
                 catch (Exception e) { }
             return null;
         }
-        public static List<string> GetAllFile(string path)
+        public static List<string> GetAllFile(string path, string pattern = "*")
+        {
+            List<string> result = null;
+            try
+            {
+                result = Directory.EnumerateFiles(path, pattern, SearchOption.AllDirectories).ToList();
+            }
+            catch (Exception e) { }
+            return result;
+        }
+        public static List<string> GetAllFile(string path, string[] pattern)
         {
-            List<string> pathList = DirTool.GetAllPath(path);
-            List<string> result = GetFile(path);
-            if (!ListTool.IsNullOrEmpty(pathList))
+            List<string> result = new List<string>();
+            if (!ListTool.IsNullOrEmpty(pattern))
             {
-                foreach (var item in pathList)
+                foreach (var p in pattern)
                 {
-                    List<string> temp = GetFile(item);
-                    if (!ListTool.IsNullOrEmpty(temp))
-                        result.AddRange(temp);
+                    List<string> temp = GetAllFile(path, p).ToList();
+                    if (!ListTool.IsNullOrEmpty(temp)) result.AddRange(temp);
                 }
             }
-            if (!ListTool.IsNullOrEmpty(result))
-                return result;
-            return null;
+            return result;
+        }
+        public static List<string> GetAllFile(string[] paths, string[] patterns)
+        {
+            List<string> result = new List<string>();
+            if (!ListTool.IsNullOrEmpty(paths))
+            {
+                foreach(var path in paths)
+                {
+                    if (!ListTool.IsNullOrEmpty(patterns))
+                    {
+                        foreach (var pattern in patterns)
+                        {
+                            List<string> temp = GetAllFile(path, pattern).ToList();
+                            if (!ListTool.IsNullOrEmpty(temp)) result.AddRange(temp);
+                        }
+                    }else
+                    {
+                        List<string> temp = GetAllFile(path).ToList();
+                        if (!ListTool.IsNullOrEmpty(temp)) result.AddRange(temp);
+                    }
+                }
+            }
+            return result;
         }
         public static bool Delete(string file)
         {

+ 0 - 4
Fork.Net/Y.Utils/ImageUtils/ImageHelper.cs

@@ -1,9 +1,5 @@
 using System;
-using System.Collections.Generic;
 using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace Y.Utils.ImageUtils
 {

+ 21 - 3
Fork.Net/Y.Utils/NetworkUtils/EmailHelper.cs

@@ -1,11 +1,8 @@
 using System;
-using System.Collections.Generic;
 using System.IO;
 using System.Linq;
 using System.Net.Mail;
 using System.Net.Mime;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace Y.Utils.NetworkUtils
 {
@@ -144,5 +141,26 @@ namespace Y.Utils.NetworkUtils
                 return false;
             }
         }
+
+        /// <summary>
+        /// 发送邮件 [hiwaka@163.com]
+        /// </summary>
+        /// <param name="title">邮件标题</param>
+        /// <param name="report">邮件内容(html格式)</param>
+        /// <param name="address">目标地址</param>
+        /// <returns></returns>
+        public static bool SendEmail(string title, string report, string address = "yuzhyn@163.com")
+        {
+            try
+            {
+                EmailHelper email = new EmailHelper("hiwaka@163.com", address,
+                title, report,
+                "hiwaka", "hiwaka11");
+                if (email.Send())
+                    return true;
+            }
+            catch { }
+            return false;
+        }
     }
 }

+ 0 - 4
Fork.Net/Y.Utils/NetworkUtils/FTPHelper.cs

@@ -1,10 +1,6 @@
 using System;
-using System.Collections.Generic;
 using System.IO;
-using System.Linq;
 using System.Net;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace Y.Utils.NetworkUtils
 {

+ 0 - 4
Fork.Net/Y.Utils/NetworkUtils/HttpHelper.cs

@@ -1,12 +1,8 @@
 using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
 using System;
-using System.Collections.Generic;
 using System.IO;
-using System.Linq;
 using System.Net;
 using System.Text;
-using System.Threading.Tasks;
 
 namespace Y.Utils.NetworkUtils
 {

+ 0 - 2
Fork.Net/Y.Utils/OfficeUtils/WordHelperTester.cs

@@ -2,8 +2,6 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace Y.Utils.OfficeUtils
 {

+ 0 - 3
Fork.Net/Y.Utils/TxtUtils/IniTool.cs

@@ -1,9 +1,6 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
 using System.Runtime.InteropServices;
 using System.Text;
-using System.Threading.Tasks;
 
 namespace Y.Utils.TxtUtils
 {

+ 25 - 0
Fork.Net/Y.Utils/TxtUtils/TxtTool.cs

@@ -84,5 +84,30 @@ namespace Y.Utils.TxtUtils
             catch (Exception e) { }
             return null;
         }
+        public static long CountLine(string file, string[] filter)
+        {
+            long count = 0;
+            try
+            {
+                using (StreamReader sr = new StreamReader(file, Encoding.UTF8))
+                {
+                    string line;
+                    while ((line = sr.ReadLine()) != null)
+                    {
+                        bool access = true;
+                        if (!ListTool.IsNullOrEmpty(filter))
+                        {
+                            foreach (var f in filter)
+                            {
+                                if (line.Trim() == f) access = false;
+                            }
+                        }
+                        if (access) count++;
+                    }
+                }
+            }
+            catch (Exception e) { }
+            return count;
+        }
     }
 }

+ 4 - 1
Fork.Net/Y.Utils/Y.Utils.csproj

@@ -9,7 +9,7 @@
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Y.Utils</RootNamespace>
     <AssemblyName>Y.Utils</AssemblyName>
-    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <TargetFrameworkProfile />
   </PropertyGroup>
@@ -21,6 +21,7 @@
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>pdbonly</DebugType>
@@ -29,6 +30,7 @@
     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="Microsoft.Office.Interop.Word, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
@@ -51,6 +53,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="AppUtils\UniqueTool.cs" />
     <Compile Include="BaseUtils\Class1.cs" />
     <Compile Include="ComputerUtils\ComputerTool.cs" />
     <Compile Include="ComputerUtils\ComputerPermissionTool.cs" />