ソースを参照

添加工具类验证有效期方法(积极查找更灵活的方式)

yuzhengyang 8 年 前
コミット
afc6ed5bd4

+ 14 - 0
Fork.Net/Test/Y.Test/Views/MainForm.Designer.cs

@@ -35,6 +35,7 @@
             this.TestIconGroupForm = new System.Windows.Forms.Button();
             this.TestIconGroupForm = new System.Windows.Forms.Button();
             this.TestShadowForm = new System.Windows.Forms.Button();
             this.TestShadowForm = new System.Windows.Forms.Button();
             this.TestIrrForm = new System.Windows.Forms.Button();
             this.TestIrrForm = new System.Windows.Forms.Button();
+            this.BTCheckYUtils = new System.Windows.Forms.Button();
             this.SuspendLayout();
             this.SuspendLayout();
             // 
             // 
             // ChineseCalendarForm
             // ChineseCalendarForm
@@ -107,11 +108,22 @@
             this.TestIrrForm.UseVisualStyleBackColor = true;
             this.TestIrrForm.UseVisualStyleBackColor = true;
             this.TestIrrForm.Click += new System.EventHandler(this.TestIrrForm_Click);
             this.TestIrrForm.Click += new System.EventHandler(this.TestIrrForm_Click);
             // 
             // 
+            // BTCheckYUtils
+            // 
+            this.BTCheckYUtils.Location = new System.Drawing.Point(465, 12);
+            this.BTCheckYUtils.Name = "BTCheckYUtils";
+            this.BTCheckYUtils.Size = new System.Drawing.Size(75, 23);
+            this.BTCheckYUtils.TabIndex = 7;
+            this.BTCheckYUtils.Text = "检查工具类";
+            this.BTCheckYUtils.UseVisualStyleBackColor = true;
+            this.BTCheckYUtils.Click += new System.EventHandler(this.BTCheckYUtils_Click);
+            // 
             // MainForm
             // MainForm
             // 
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(564, 427);
             this.ClientSize = new System.Drawing.Size(564, 427);
+            this.Controls.Add(this.BTCheckYUtils);
             this.Controls.Add(this.TestIrrForm);
             this.Controls.Add(this.TestIrrForm);
             this.Controls.Add(this.TestShadowForm);
             this.Controls.Add(this.TestShadowForm);
             this.Controls.Add(this.TestIconGroupForm);
             this.Controls.Add(this.TestIconGroupForm);
@@ -120,6 +132,7 @@
             this.Controls.Add(this.TestComputerInfoForm);
             this.Controls.Add(this.TestComputerInfoForm);
             this.Controls.Add(this.ChineseCalendarForm);
             this.Controls.Add(this.ChineseCalendarForm);
             this.Name = "MainForm";
             this.Name = "MainForm";
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
             this.Text = "MainForm";
             this.Text = "MainForm";
             this.Load += new System.EventHandler(this.MainForm_Load);
             this.Load += new System.EventHandler(this.MainForm_Load);
             this.ResumeLayout(false);
             this.ResumeLayout(false);
@@ -135,5 +148,6 @@
         private System.Windows.Forms.Button TestIconGroupForm;
         private System.Windows.Forms.Button TestIconGroupForm;
         private System.Windows.Forms.Button TestShadowForm;
         private System.Windows.Forms.Button TestShadowForm;
         private System.Windows.Forms.Button TestIrrForm;
         private System.Windows.Forms.Button TestIrrForm;
+        private System.Windows.Forms.Button BTCheckYUtils;
     }
     }
 }
 }

+ 12 - 3
Fork.Net/Test/Y.Test/Views/MainForm.cs

@@ -7,6 +7,7 @@ using System.Linq;
 using System.Text;
 using System.Text;
 using System.Windows.Forms;
 using System.Windows.Forms;
 using Y.Test.Commons;
 using Y.Test.Commons;
+using Y.Utils.DataUtils.Collections;
 
 
 namespace Y.Test.Views
 namespace Y.Test.Views
 {
 {
@@ -16,7 +17,10 @@ namespace Y.Test.Views
         {
         {
             InitializeComponent();
             InitializeComponent();
         }
         }
+        private void MainForm_Load(object sender, EventArgs e)
+        {
 
 
+        }
         private void ChineseCalendarForm_Click(object sender, EventArgs e)
         private void ChineseCalendarForm_Click(object sender, EventArgs e)
         {
         {
             R.Forms.GetUnique<ChineseCalendarForm>().Show();
             R.Forms.GetUnique<ChineseCalendarForm>().Show();
@@ -47,13 +51,18 @@ namespace Y.Test.Views
             R.Forms.GetUnique<TestShadowForm>().Show();
             R.Forms.GetUnique<TestShadowForm>().Show();
         }
         }
 
 
-        private void MainForm_Load(object sender, EventArgs e)
+        private void TestIrrForm_Click(object sender, EventArgs e)
         {
         {
+            R.Forms.GetUnique<TestIrrForm>().Show();
         }
         }
 
 
-        private void TestIrrForm_Click(object sender, EventArgs e)
+        private void BTCheckYUtils_Click(object sender, EventArgs e)
         {
         {
-            R.Forms.GetUnique<TestIrrForm>().Show();
+            List<string> a = new List<string>();
+            for (int i = 0; i < 5; i++)
+            {
+                ListTool.HasElements(a);
+            }
         }
         }
     }
     }
 }
 }

+ 17 - 30
Fork.Net/Y.Utils/DataUtils/Collections/ListTool.cs

@@ -1,45 +1,32 @@
-//############################################################
+//************************************************************************
 //      https://github.com/yuzhengyang
 //      https://github.com/yuzhengyang
-//      author:yuzhengyang
-//############################################################
+//      author:     yuzhengyang
+//      date:       2017.3.29 - 2017.9.12
+//      desc:       元素列表工具类
+//      Copyright (c) yuzhengyang. All rights reserved.
+//************************************************************************
+using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
+using Y.Utils.YUtils;
 
 
 namespace Y.Utils.DataUtils.Collections
 namespace Y.Utils.DataUtils.Collections
 {
 {
+    /// <summary>
+    /// 元素列表工具类
+    /// </summary>
     public sealed class ListTool
     public sealed class ListTool
     {
     {
         /// <summary>
         /// <summary>
         /// 列表为空(null 或 count 等于 0)
         /// 列表为空(null 或 count 等于 0)
         /// </summary>
         /// </summary>
-        /// <param name="list"></param>
-        /// <returns></returns>
-        public static bool IsNullOrEmpty(List<string> list)
-        {
-            if (list != null && list.Count() > 0)
-                return false;
-            return true;
-        }
-        /// <summary>
-        /// 列表为空(null 或 count 等于 0)
-        /// </summary>
-        /// <typeparam name="T"></typeparam>
-        /// <param name="list"></param>
-        /// <returns></returns>
-        public static bool IsNullOrEmpty<T>(List<T> list)
-        {
-            if (list != null && list.Count() > 0)
-                return false;
-            return true;
-        }
-        /// <summary>
-        /// 列表为空(null 或 count 等于 0)
-        /// </summary>
-        /// <typeparam name="T"></typeparam>
-        /// <param name="list"></param>
+        /// <typeparam name="T">元素类型</typeparam>
+        /// <param name="list">元素列表</param>
         /// <returns></returns>
         /// <returns></returns>
+        [Obsolete("Please Use HasElements(list)", false)]
         public static bool IsNullOrEmpty<T>(IEnumerable<T> list)
         public static bool IsNullOrEmpty<T>(IEnumerable<T> list)
         {
         {
+            YUtilsAuth.Start();
             if (list != null && list.Count() > 0)
             if (list != null && list.Count() > 0)
                 return false;
                 return false;
             return true;
             return true;
@@ -47,8 +34,8 @@ namespace Y.Utils.DataUtils.Collections
         /// <summary>
         /// <summary>
         /// 列表至少有一个元素
         /// 列表至少有一个元素
         /// </summary>
         /// </summary>
-        /// <typeparam name="T"></typeparam>
-        /// <param name="list"></param>
+        /// <typeparam name="T">元素类型</typeparam>
+        /// <param name="list">元素列表</param>
         /// <returns></returns>
         /// <returns></returns>
         public static bool HasElements<T>(IEnumerable<T> list)
         public static bool HasElements<T>(IEnumerable<T> list)
         {
         {

+ 1 - 1
Fork.Net/Y.Utils/IOUtils/FileUtils/FileTool.cs

@@ -96,7 +96,7 @@ namespace Y.Utils.IOUtils.FileUtils
                         foreach (var pattern in patterns)
                         foreach (var pattern in patterns)
                         {
                         {
                             List<string> temp = GetFile(path, pattern);
                             List<string> temp = GetFile(path, pattern);
-                            if (!ListTool.IsNullOrEmpty(temp)) result.AddRange(temp);
+                            if (ListTool.HasElements(temp)) result.AddRange(temp);
                         }
                         }
                     }
                     }
                     else
                     else

+ 2 - 2
Fork.Net/Y.Utils/Properties/AssemblyInfo.cs

@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
 [assembly: AssemblyConfiguration("")]
 [assembly: AssemblyConfiguration("")]
 [assembly: AssemblyCompany("")]
 [assembly: AssemblyCompany("")]
 [assembly: AssemblyProduct("Y.Utils")]
 [assembly: AssemblyProduct("Y.Utils")]
-[assembly: AssemblyCopyright("Copyright ©  2016")]
+[assembly: AssemblyCopyright("Copyright ©  2017")]
 [assembly: AssemblyTrademark("")]
 [assembly: AssemblyTrademark("")]
 [assembly: AssemblyCulture("")]
 [assembly: AssemblyCulture("")]
 
 
@@ -33,4 +33,4 @@ using System.Runtime.InteropServices;
 // 方法是按如下所示使用“*”: :
 // 方法是按如下所示使用“*”: :
 // [assembly: AssemblyVersion("1.0.*")]
 // [assembly: AssemblyVersion("1.0.*")]
 [assembly: AssemblyVersion("1.0.0.0")]
 [assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.1.0.0")]
+[assembly: AssemblyFileVersion("1.1.0.0")]

+ 3 - 3
Fork.Net/Y.Utils/WindowsUtils/InfoUtils/RegisterTool.cs

@@ -15,7 +15,7 @@ namespace Y.Utils.WindowsUtils.InfoUtils
     /// </summary>
     /// </summary>
     public class RegisterTool
     public class RegisterTool
     {
     {
-        [Obsolete]
+        [Obsolete("SetValue",true)]
         public static bool Write(string key, string name, string value)
         public static bool Write(string key, string name, string value)
         {
         {
             try
             try
@@ -31,7 +31,7 @@ namespace Y.Utils.WindowsUtils.InfoUtils
                 return false;
                 return false;
             }
             }
         }
         }
-        [Obsolete]
+        [Obsolete("GetValue", true)]
         public static string Read(string key, string name)
         public static string Read(string key, string name)
         {
         {
             try
             try
@@ -45,7 +45,7 @@ namespace Y.Utils.WindowsUtils.InfoUtils
             catch (Exception e) { }
             catch (Exception e) { }
             return null;
             return null;
         }
         }
-        [Obsolete]
+        [Obsolete("DeleteValue", true)]
         public static bool Delete(string key, string name)
         public static bool Delete(string key, string name)
         {
         {
             try
             try

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

@@ -150,6 +150,7 @@
     <Compile Include="WindowsUtils\InfoUtils\TaskSchedulerTool.cs" />
     <Compile Include="WindowsUtils\InfoUtils\TaskSchedulerTool.cs" />
     <Compile Include="WindowsUtils\ProcessUtils\ProcessInfoTool.cs" />
     <Compile Include="WindowsUtils\ProcessUtils\ProcessInfoTool.cs" />
     <Compile Include="WindowsUtils\ProcessUtils\ProcessTool.cs" />
     <Compile Include="WindowsUtils\ProcessUtils\ProcessTool.cs" />
+    <Compile Include="YUtils\YUtilsAuth.cs" />
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <COMReference Include="IWshRuntimeLibrary">
     <COMReference Include="IWshRuntimeLibrary">

+ 50 - 0
Fork.Net/Y.Utils/YUtils/YUtilsAuth.cs

@@ -0,0 +1,50 @@
+//************************************************************************
+//      https://github.com/yuzhengyang
+//      author:     yuzhengyang
+//      date:       2017.9.12 - 2017.9.12
+//      desc:       工具类验证
+//      Copyright (c) yuzhengyang. All rights reserved.
+//************************************************************************
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace Y.Utils.YUtils
+{
+    public class YUtilsAuth
+    {
+        private static bool IsStart = false;
+        private static DateTime StartTime = DateTime.Now;
+        /// <summary>
+        /// 工具类验证
+        /// </summary>
+        public static void Start()
+        {
+            if (!IsStart)
+            {
+                IsStart = true;
+                if (IsStart)
+                {
+                    StartTime = DateTime.Now;
+                    Task.Factory.StartNew(() =>
+                    {
+                        CheckObsolete();
+                    });
+                }
+            }
+            if ((DateTime.Now - StartTime).TotalHours > 1) IsStart = false;
+        }
+        /// <summary>
+        /// 验证有效期
+        /// </summary>
+        private static void CheckObsolete()
+        {
+            if (DateTime.Now > new DateTime(2018, 12, 2, 0, 0, 0))
+                MessageBox.Show("工具组件超出有效期,请更新工具组件。(https://github.com/yuzhengyang)", "超出有效期");
+        }
+    }
+}