Explorar o código

.NET Core项目增加取线程内唯一对象

懒得勤快 %!s(int64=7) %!d(string=hai) anos
pai
achega
20e13c1a9b

+ 0 - 417
Masuit.Tools.Core/DateTimeExt/CCalendarData.xml

@@ -1,417 +0,0 @@
-<?xml version="1.0" encoding="gb2312" ?>
-<HELLO>
-
-  <!-- 公历节日开始 -->
-  <AD>
-    <feast day="0101" name="元旦" sayhello="yes">
-      <hello>新年好!祝您在新的一年里身体健康,事业进步!</hello>
-      <!-- 从网站根目录算起 -->
-      <img>./img/theme/0101.gif</img>
-    </feast>
-    <feast day="0202" name="世界湿地日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0210" name="国际气象节" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0214" name="情人节" sayhello="yes">
-      <hello>祝天下有情人终成眷属!</hello>
-      <img></img>
-    </feast>
-    <feast day="0301" name="世界图书日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0303" name="全国爱耳日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0305" name="学雷锋纪念日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0308" name="妇女节" sayhello="yes">
-      <hello>妇女能顶半边天,谁说女子不如男!</hello>
-      <img></img>
-    </feast>
-    <feast day="0312" name="植树节" sayhello="yes">
-      <hello>植树造林,功德无量。</hello>
-      <img>./img/theme/0312.gif</img>
-    </feast>
-    <feast day="0314" name="国际警察日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0315" name="消费者权益日" sayhello="no">
-      <img>./img/theme/temp.gif</img>
-      <hello></hello>
-    </feast>
-    <feast day="0316" name="手拉手情系贫困地区全国行动日" sayhello="no">
-      <img>./img/theme/temp.gif</img>
-      <hello></hello>
-    </feast>
-    <feast day="0317" name="国际航海日" sayhello="no">
-      <img>./img/theme/temp.gif</img>
-      <hello></hello>
-    </feast>
-    <feast day="0318" name="全国科技人才活动日" sayhello="no">
-      <img>./img/theme/temp.gif</img>
-      <hello></hello>
-    </feast>
-    <feast day="0321" name="世界睡眠日 世界森林日 世界儿歌日 消除种族歧视国际日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0322" name="世界水日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0323" name="世界气象日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0324" name="世界防治结核病日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0401" name="愚人节" sayhello="no">
-      <img>./img/theme/temp.gif</img>
-      <hello></hello>
-    </feast>
-    <feast day="0407" name="世界卫生日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0422" name="世界地球日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0425" name="国际秘书节" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0501" name="劳动节" sayhello="yes">
-      <hello>今天是劳动节,怎么,您还在劳动吗?</hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0504" name="青年节" sayhello="yes">
-      <hello>美哉,我少年中国,与天不老!壮哉,我中国少年,与国无疆!</hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0505" name="全国碘缺乏病日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0508" name="世界红十字日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0512" name="护士节" sayhello="no">
-      <hello></hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0515" name="国际家庭日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0517" name="世界电信日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0518" name="国际博物馆日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0519" name="全国助残日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0520" name="全国学生营养日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0522" name="国际生物多样性日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0523" name="国际牛奶日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0531" name="世界无烟日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0601" name="儿童节" sayhello="yes">
-      <hello>祝您儿童节快乐!</hello>
-      <img>./img/theme/0601.gif</img>
-    </feast>
-    <feast day="0605" name="世界环境日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0606" name="全国爱眼日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0617" name="防治荒漠化和干旱日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0623" name="国际奥林匹克日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0625" name="全国土地日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0626" name="国际禁毒日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0701" name="建党节 香港回归纪念" sayhello="yes">
-      <hello>庆祝中国共产党成立_YEARS_周年!</hello>
-      <startyear>1921</startyear>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0707" name="七七卢沟桥事变" sayhello="yes">
-      <hello>1937年7月7日,卢沟桥事变,全面抗战开始。</hello>
-      <startyear>1937</startyear>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0711" name="世界人口日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0801" name="建军节" sayhello="no">
-      <hello></hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0908" name="国际扫盲日 国际新闻工作者团体日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0909" name="毛泽东逝世纪念" sayhello="yes">
-      <hello>伟大领袖毛泽东主席逝世_YEARS_周年。</hello>
-      <startyear>1976</startyear>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0910" name="中国教师节" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0916" name="国际臭氧层保护日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0918" name="九一八事变" sayhello="yes">
-      <img></img>
-      <hello>1931年9月18日,日本帝国主义对我国沈阳北大营的中国驻军发动武装进攻,接着对我国东北地区进行大规模武装侵略。</hello>
-    </feast>
-    <feast day="0920" name="全国爱牙日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0921" name="国际和平日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0927" name="世界旅游日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0928" name="国际聋人日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="1001" name="国庆节" sayhello="yes">
-      <hello>热烈庆祝中华人民共和国成立_YEARS_周年!</hello>
-      <startyear>1949</startyear>
-      <img>./img/theme/1001.gif</img>
-    </feast>
-    <feast day="1001" name="老人节" sayhello="no">
-      <hello></hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="1001" name="国际音乐日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1004" name="世界动物日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1008" name="全国高血压日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1009" name="世界邮政日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="1010" name="世界精神卫生日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1014" name="世界标准日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="1015" name="国际盲人节" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1016" name="世界粮食日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="1017" name="世界消除贫困日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1022" name="世界传统医药日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1024" name="联合国日" sayhello="no">
-      <hello></hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="1031" name="万圣节" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="1108" name="中国记者日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1109" name="消防宣传日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1112" name="孙中山诞辰纪念" sayhello="no">
-      <hello></hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="1114" name="世界糖尿病日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1117" name="国际大学生节" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="1201" name="世界艾滋病日" sayhello="no">
-      <hello></hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="1203" name="世界残疾人日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1209" name="世界足球日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1213" name="南京大屠杀纪念日" sayhello="yes">
-      <hello>南京大屠杀_YEARS_周年。1937年12月13日,日军占领南京,进行长达6周的血腥大屠杀,杀害我军民30余万人。</hello>
-      <startyear>1937</startyear>
-      <img></img>
-    </feast>
-    <feast day="1220" name="澳门回归纪念" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1224" name="圣诞节平安夜" sayhello="yes">
-      <hello>We wish you a merry christmas。</hello>
-      <img>./img/theme/1225.gif</img>
-    </feast>
-    <feast day="1225" name="圣诞节" sayhello="yes">
-      <hello>圣诞快乐。</hello>
-      <img>./img/theme/1225.gif</img>
-    </feast>
-  </AD>
-  <!-- 公历节日结束 -->
-
-  <!-- 农历节日开始 -->
-  <LUNAR>
-    <feast day="0101" name="春节" sayhello="yes">
-      <hello>恭喜发财!新年进步!万事如意!</hello>
-      <img>./img/theme/spring.gif</img>
-    </feast>
-    <feast day="0115" name="元宵节" sayhello="yes">
-      <hello>年年元夜时,花市灯如昼。月上柳梢头,人约黄昏后。</hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0505" name="端午节" sayhello="no">
-      <hello></hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0707" name="七夕情人节" sayhello="no">
-      <hello></hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0715" name="中元节" sayhello="no">
-      <hello></hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0815" name="中秋节" sayhello="yes">
-      <hello>海上升明月 天涯共此时</hello>
-      <img>./img/theme/c815.gif</img>
-    </feast>
-    <feast day="0909" name="重阳节" sayhello="yes">
-      <hello>人生易老天难老,岁岁重阳。今又重阳,战地黄花分外香。</hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="1208" name="腊八节" sayhello="yes">
-      <hello>谁愿意跟我去侠客岛喝腊八粥?</hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0100" name="除夕" sayhello="yes">
-      <hello>炮竹声中一岁除,春风送暖入屠苏。千家万户瞳瞳日,总把新桃换旧符。</hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-  </LUNAR>
-  <!-- 农历节日结束 -->
-
-  <!-- 普通日子开始 -->
-  <NORMAL>
-    <day time1="2301" time2="2359" sayhello="yes">
-      <hello>深夜了!您应该休息了。</hello>
-      <img>./img/theme/latenight.gif</img>
-    </day>
-    <day time1="1901" time2="2300" sayhello="yes">
-      <hello>晚上好!还在工作吗?</hello>
-      <img>./img/theme/night.gif</img>
-    </day>
-    <day time1="1801" time2="1900" sayhello="yes">
-      <hello>傍晚好!是时候吃晚饭了。</hello>
-      <img>./img/theme/dusk.gif</img>
-    </day>
-    <day time1="1301" time2="1800" sayhello="yes">
-      <hello>下午好!要振作精神哦!</hello>
-      <img>./img/theme/afternoon.gif</img>
-    </day>
-    <day time1="1201" time2="1300" sayhello="yes">
-      <hello>中午好!吃过午饭了吗?</hello>
-      <img>./img/theme/midday.gif</img>
-    </day>
-    <day time1="0901" time2="1200" sayhello="yes">
-      <hello>上午好!努力工作哦!</hello>
-      <img>./img/theme/ackemma.gif</img>
-    </day>
-    <day time1="0601" time2="0900" sayhello="yes">
-      <hello>早上好!休息得好吗?</hello>
-      <img>./img/theme/morning.gif</img>
-    </day>
-    <day time1="0000" time2="0600" sayhello="yes">
-      <hello>深夜了!您应该休息了。</hello>
-      <img>./img/theme/latenight.gif</img>
-    </day>
-  </NORMAL>
-  <!-- 普通日子结束 -->
-
-</HELLO>

+ 3 - 7
Masuit.Tools.Core/DateTimeExt/DateUtil.cs

@@ -1,7 +1,6 @@
 using System;
-using Masuit.Tools.Logging;
 
-namespace Masuit.Tools.DateTimeExt
+namespace Masuit.Tools.Core.DateTimeExt
 {
     /// <summary>
     /// 日期操作工具类
@@ -330,10 +329,7 @@ namespace Masuit.Tools.DateTimeExt
             {
                 return true;
             }
-            else
-            {
-                return false;
-            }
+            return false;
         }
 
         /// <summary>
@@ -349,7 +345,7 @@ namespace Masuit.Tools.DateTimeExt
                 if (oDate.CompareTo(DateTime.Parse("1800-1-1")) > 0) return true;
                 return false;
             }
-            catch (Exception e)
+            catch
             {
                 return false;
             }

+ 6 - 8
Masuit.Tools.Core/Masuit.Tools.Core.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <TargetFramework>netstandard2.0</TargetFramework>
-    <Version>1.8.0</Version>
+    <Version>1.8.1</Version>
     <Authors>懒得勤快</Authors>
     <Company>masuit.com</Company>
     <Description>包含一些常用的操作类,大都是静态类,加密解密,反射操作,硬件信息,字符串扩展方法,日期时间扩展操作,大文件拷贝,图像裁剪,html处理,验证码、NoSql等常用封装。
@@ -73,15 +73,13 @@ Windows.ClearMemorySilent();
   </PropertyGroup>
 
   <ItemGroup>
-    <Content Include="DateTimeExt\CCalendarData.xml" />
-  </ItemGroup>
-
-  <ItemGroup>
-    <PackageReference Include="AngleSharp" Version="0.9.9" />
-    <PackageReference Include="HtmlSanitizer" Version="4.0.181" />
+    <PackageReference Include="AngleSharp" Version="0.9.9.1" />
+    <PackageReference Include="HtmlSanitizer" Version="4.0.183" />
+    <PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0" />
+    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
     <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
     <PackageReference Include="StackExchange.Redis" Version="1.2.6" />
-    <PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
+    <PackageReference Include="System.Data.SqlClient" Version="4.4.2" />
   </ItemGroup>
 
 </Project>

+ 18 - 0
Masuit.Tools.Core/Net/CallContext.cs

@@ -0,0 +1,18 @@
+using System.Collections.Concurrent;
+using System.Threading;
+
+namespace Masuit.Tools.Net
+{
+    /// <summary>
+    /// 取线程内唯一对象
+    /// </summary>
+    /// <typeparam name="T"></typeparam>
+    public static class CallContext<T>
+    {
+        static ConcurrentDictionary<string, AsyncLocal<T>> state = new ConcurrentDictionary<string, AsyncLocal<T>>();
+
+        public static void SetData(string name, T data) => state.GetOrAdd(name, _ => new AsyncLocal<T>()).Value = data;
+
+        public static T GetData(string name) => state.TryGetValue(name, out AsyncLocal<T> data) ? data.Value : default(T);
+    }
+}

+ 8 - 10
Masuit.Tools.Core/Net/SocketClient.cs

@@ -6,9 +6,8 @@ using System.Runtime.Serialization;
 using System.Runtime.Serialization.Formatters.Binary;
 using System.Text;
 using System.Threading;
-using Masuit.Tools.Logging;
 
-namespace Masuit.Tools.Net
+namespace Masuit.Tools.Core.Net
 {
     /// <summary>
     /// Socket客户端操作类
@@ -37,7 +36,7 @@ namespace Masuit.Tools.Net
                 Socket socket = listener.AcceptSocket();
                 return socket;
             }
-            catch (Exception e)
+            catch
             {
                 return null;
             }
@@ -55,7 +54,7 @@ namespace Masuit.Tools.Net
                 TcpClient client = listener.AcceptTcpClient();
                 return client.GetStream();
             }
-            catch (Exception e)
+            catch
             {
                 return null;
             }
@@ -78,7 +77,7 @@ namespace Masuit.Tools.Net
                 tcpclient.Connect(ipendpoint);
                 return tcpclient.Client;
             }
-            catch (Exception e)
+            catch
             {
                 return null;
             }
@@ -98,7 +97,7 @@ namespace Masuit.Tools.Net
                 tcpclient.Connect(ipadd, port);
                 return tcpclient.Client;
             }
-            catch (Exception e)
+            catch
             {
                 return null;
             }
@@ -117,7 +116,7 @@ namespace Masuit.Tools.Net
                 tcpclient.Connect(ipendpoint);
                 return tcpclient.GetStream();
             }
-            catch (Exception e)
+            catch
             {
                 return null;
             }
@@ -137,7 +136,7 @@ namespace Masuit.Tools.Net
                 tcpclient.Connect(ipadd, port);
                 return tcpclient.GetStream();
             }
-            catch (Exception e)
+            catch
             {
                 return null;
             }
@@ -156,12 +155,11 @@ namespace Masuit.Tools.Net
         public static byte[] ReceiveFixData(this Socket socket, int size)
         {
             int offset = 0;
-            int recv = 0;
             int dataleft = size;
             byte[] msg = new byte[size];
             while (dataleft > 0)
             {
-                recv = socket.Receive(msg, offset, dataleft, 0);
+                var recv = socket.Receive(msg, offset, dataleft, 0);
                 if (recv == 0)
                     break;
                 offset += recv;

+ 183 - 0
Masuit.Tools.Core/Net/WebExtension.cs

@@ -0,0 +1,183 @@
+using System;
+using System.Collections.Generic;
+using System.Net.Http;
+using Masuit.Tools.Logging;
+using Masuit.Tools.Models;
+using Masuit.Tools.Net;
+using Microsoft.Extensions.Configuration;
+using Newtonsoft.Json;
+
+namespace Masuit.Tools.Core.Net
+{
+    /// <summary>
+    /// Web操作扩展
+    /// </summary>
+    public static class WebExtension
+    {
+        #region 获取线程内唯一的EF上下文对象
+
+        /// <summary>
+        /// 获取线程内唯一的EF上下文对象
+        /// </summary>
+        /// <typeparam name="T">EF上下文容器对象</typeparam>
+        /// <returns>EF上下文容器对象</returns>
+        public static T GetDbContext<T>() where T : new()
+        {
+            T db;
+            if (CallContext<T>.GetData("db") == null)
+            {
+                db = new T();
+                CallContext<T>.SetData("db", db);
+            }
+            db = CallContext<T>.GetData("db");
+            return db;
+        }
+
+        #endregion
+
+        #region 获取客户端IP地址信息
+
+        private static IConfigurationRoot config = new ConfigurationBuilder().AddJsonFile("appsettings.json", true).Build();
+        /// <summary>
+        /// 根据IP地址获取详细地理信息
+        /// </summary>
+        /// <param name="ip"></param>
+        /// <returns></returns>
+        public static Tuple<string, List<string>> GetIPAddressInfo(this string ip)
+        {
+            ip.MatchInetAddress(out var isIpAddress);
+            if (isIpAddress)
+            {
+                string ak = config["AppSettings:BaiduAK"];
+                if (string.IsNullOrEmpty(ak))
+                {
+                    throw new Exception("未配置BaiduAK,请先在您的应用程序appsettings.json中的AppSettings节点下添加BaiduAK配置节(注意大小写)");
+                }
+                using (HttpClient client = new HttpClient() { BaseAddress = new Uri("http://api.map.baidu.com") })
+                {
+                    try
+                    {
+                        string ipJson = client.GetStringAsync($"/location/ip?ak={ak}&ip={ip}&coor=bd09ll").Result;
+                        var ipAddress = JsonConvert.DeserializeObject<BaiduIP>(ipJson);
+                        if (ipAddress.Status == 0)
+                        {
+                            LatiLongitude point = ipAddress.AddressInfo.LatiLongitude;
+                            string result = client.GetStringAsync($"/geocoder/v2/?location={point.Y},{point.X}&output=json&pois=1&radius=1000&latest_admin=1&coordtype=bd09ll&ak={ak}").Result;
+                            PhysicsAddress address = JsonConvert.DeserializeObject<PhysicsAddress>(result);
+                            if (address.Status == 0)
+                            {
+                                string detail = $"{address.AddressResult.FormattedAddress} {address.AddressResult.AddressComponent.Direction}{address.AddressResult.AddressComponent.Distance ?? "0"}米";
+                                List<string> pois = new List<string>();
+                                address.AddressResult.Pois.ForEach(p => { pois.Add($"{p.AddressDetail}{p.Name} {p.Direction}{p.Distance ?? "0"}米"); });
+                                return new Tuple<string, List<string>>(detail, pois);
+                            }
+                        }
+                        else
+                        {
+                            using (var client2 = new HttpClient { BaseAddress = new Uri("http://ip.taobao.com") })
+                            {
+                                var result = client2.GetStringAsync($"/service/getIpInfo.php?ip={ip}").Result;
+                                TaobaoIP taobaoIp = JsonConvert.DeserializeObject<TaobaoIP>(result);
+                                if (taobaoIp.Code == 0)
+                                {
+                                    return new Tuple<string, List<string>>(taobaoIp.IpData.Country + taobaoIp.IpData.Region + taobaoIp.IpData.City, new List<string>());
+                                }
+                            }
+                        }
+                    }
+                    catch (Exception e)
+                    {
+                        LogManager.Error(e);
+                    }
+                }
+                return new Tuple<string, List<string>>("IP地址不正确", new List<string>());
+            }
+            return new Tuple<string, List<string>>($"{ip}不是一个合法的IP地址", new List<string>());
+        }
+
+        /// <summary>
+        /// 根据IP地址获取详细地理信息对象
+        /// </summary>
+        /// <param name="ip"></param>
+        /// <returns></returns>
+        public static PhysicsAddress GetPhysicsAddressInfo(this string ip)
+        {
+            ip.MatchInetAddress(out var isIpAddress);
+            if (isIpAddress)
+            {
+                string ak = config["AppSettings:BaiduAK"];
+                if (string.IsNullOrEmpty(ak))
+                {
+                    throw new Exception("未配置BaiduAK,请先在您的应用程序appsettings.json中的AppSettings节点下添加BaiduAK配置节(注意大小写)");
+                }
+                using (HttpClient client = new HttpClient() { BaseAddress = new Uri("http://api.map.baidu.com") })
+                {
+                    try
+                    {
+                        string ipJson = client.GetStringAsync($"/location/ip?ak={ak}&ip={ip}&coor=bd09ll").Result;
+                        var ipAddress = JsonConvert.DeserializeObject<BaiduIP>(ipJson);
+                        if (ipAddress.Status == 0)
+                        {
+                            LatiLongitude point = ipAddress.AddressInfo.LatiLongitude;
+                            string result = client.GetStringAsync($"/geocoder/v2/?location={point.Y},{point.X}&output=json&pois=1&radius=1000&latest_admin=1&coordtype=bd09ll&ak={ak}").Result;
+                            PhysicsAddress address = JsonConvert.DeserializeObject<PhysicsAddress>(result);
+                            if (address.Status == 0)
+                            {
+                                return address;
+                            }
+                        }
+                        else
+                        {
+                            using (var client2 = new HttpClient { BaseAddress = new Uri("http://ip.taobao.com") })
+                            {
+                                var result = client2.GetStringAsync($"/service/getIpInfo.php?ip={ip}").Result;
+                                TaobaoIP taobaoIp = JsonConvert.DeserializeObject<TaobaoIP>(result);
+                                if (taobaoIp.Code == 0)
+                                {
+                                    return new PhysicsAddress() { Status = 0, AddressResult = new AddressResult() { FormattedAddress = taobaoIp.IpData.Country + taobaoIp.IpData.Region + taobaoIp.IpData.City, AddressComponent = new AddressComponent() { Province = taobaoIp.IpData.Region }, Pois = new List<Pois>() } };
+                                }
+                            }
+                        }
+                    }
+                    catch (Exception e)
+                    {
+                        LogManager.Error(e);
+                    }
+                }
+            }
+            return null;
+        }
+
+        /// <summary>
+        /// 根据IP地址获取ISP
+        /// </summary>
+        /// <param name="ip"></param>
+        /// <returns></returns>
+        public static string GetISP(this string ip)
+        {
+            if (ip.MatchInetAddress())
+            {
+                using (var client = new HttpClient { BaseAddress = new Uri("http://ip.taobao.com") })
+                {
+                    try
+                    {
+                        var result = client.GetStringAsync($"/service/getIpInfo.php?ip={ip}").Result;
+                        TaobaoIP taobaoIp = JsonConvert.DeserializeObject<TaobaoIP>(result);
+                        if (taobaoIp.Code == 0)
+                        {
+                            return taobaoIp.IpData.Isp;
+                        }
+                    }
+                    catch
+                    {
+                        // ignored
+                    }
+                }
+                return $"未能找到{ip}的ISP信息";
+            }
+            return $"{ip}不是一个合法的IP";
+        }
+
+        #endregion
+    }
+}

+ 5 - 4
Masuit.Tools.NoSQL.MongoDBClient.Core/Masuit.Tools.NoSQL.MongoDBClient.Core.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <TargetFramework>netstandard2.0</TargetFramework>
-    <Version>1.7.7</Version>
+    <Version>1.8.1</Version>
     <Authors>懒得勤快</Authors>
     <Company>masuit.com</Company>
     <Description>包含MongoDB的所有的增删查改。
@@ -12,12 +12,13 @@
     <PackageProjectUrl>https://github.com/ldqk/Masuit.Tools</PackageProjectUrl>
     <PackageTags>Masuit.Tools</PackageTags>
     <PackageReleaseNotes>如有问题请联系QQ:1170397736,或者到项目的github反馈问题。</PackageReleaseNotes>
+    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="MongoDB.Bson" Version="2.4.4" />
-    <PackageReference Include="MongoDB.Driver" Version="2.4.4" />
-    <PackageReference Include="MongoDB.Driver.Core" Version="2.4.4" />
+    <PackageReference Include="MongoDB.Bson" Version="2.5.0" />
+    <PackageReference Include="MongoDB.Driver" Version="2.5.0" />
+    <PackageReference Include="MongoDB.Driver.Core" Version="2.5.0" />
   </ItemGroup>
 
 </Project>

+ 12 - 6
Masuit.Tools.NoSQL.MongoDBClient/Masuit.Tools.NoSQL.MongoDBClient.csproj

@@ -31,16 +31,22 @@
     <DocumentationFile>bin\Release\Masuit.Tools.NoSQL.MongoDBClient.xml</DocumentationFile>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="MongoDB.Bson, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL">
-      <HintPath>..\packages\MongoDB.Bson.2.4.4\lib\net45\MongoDB.Bson.dll</HintPath>
+    <Reference Include="DnsClient, Version=1.0.7.0, Culture=neutral, PublicKeyToken=4574bb5573c51424, processorArchitecture=MSIL">
+      <HintPath>..\packages\DnsClient.1.0.7\lib\net45\DnsClient.dll</HintPath>
     </Reference>
-    <Reference Include="MongoDB.Driver, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL">
-      <HintPath>..\packages\MongoDB.Driver.2.4.4\lib\net45\MongoDB.Driver.dll</HintPath>
+    <Reference Include="MongoDB.Bson, Version=2.5.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <HintPath>..\packages\MongoDB.Bson.2.5.0\lib\net45\MongoDB.Bson.dll</HintPath>
     </Reference>
-    <Reference Include="MongoDB.Driver.Core, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL">
-      <HintPath>..\packages\MongoDB.Driver.Core.2.4.4\lib\net45\MongoDB.Driver.Core.dll</HintPath>
+    <Reference Include="MongoDB.Driver, Version=2.5.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <HintPath>..\packages\MongoDB.Driver.2.5.0\lib\net45\MongoDB.Driver.dll</HintPath>
+    </Reference>
+    <Reference Include="MongoDB.Driver.Core, Version=2.5.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <HintPath>..\packages\MongoDB.Driver.Core.2.5.0\lib\net45\MongoDB.Driver.Core.dll</HintPath>
     </Reference>
     <Reference Include="System" />
+    <Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+      <HintPath>..\packages\System.Buffers.4.4.0\lib\netstandard1.1\System.Buffers.dll</HintPath>
+    </Reference>
     <Reference Include="System.Core" />
     <Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
       <HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>

+ 2 - 2
Masuit.Tools.NoSQL.MongoDBClient/Properties/AssemblyInfo.cs

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
 // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
 //通过使用 "*",如下所示:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.7.7.0")]
-[assembly: AssemblyFileVersion("1.7.7.0")]
+[assembly: AssemblyVersion("1.8.1.0")]
+[assembly: AssemblyFileVersion("1.8.1.0")]

+ 4 - 0
Masuit.Tools.NoSQL.MongoDBClient/app.config

@@ -6,6 +6,10 @@
         <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
         <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
       </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
+      </dependentAssembly>
     </assemblyBinding>
   </runtime>
 </configuration>

+ 5 - 3
Masuit.Tools.NoSQL.MongoDBClient/packages.config

@@ -1,7 +1,9 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
-  <package id="MongoDB.Bson" version="2.4.4" targetFramework="net45" />
-  <package id="MongoDB.Driver" version="2.4.4" targetFramework="net45" />
-  <package id="MongoDB.Driver.Core" version="2.4.4" targetFramework="net45" />
+  <package id="DnsClient" version="1.0.7" targetFramework="net45" />
+  <package id="MongoDB.Bson" version="2.5.0" targetFramework="net45" />
+  <package id="MongoDB.Driver" version="2.5.0" targetFramework="net45" />
+  <package id="MongoDB.Driver.Core" version="2.5.0" targetFramework="net45" />
+  <package id="System.Buffers" version="4.4.0" targetFramework="net45" />
   <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net45" />
 </packages>

+ 0 - 417
Masuit.Tools/DateTimeExt/CCalendarData.xml

@@ -1,417 +0,0 @@
-<?xml version="1.0" encoding="gb2312" ?>
-<HELLO>
-
-  <!-- 公历节日开始 -->
-  <AD>
-    <feast day="0101" name="元旦" sayhello="yes">
-      <hello>新年好!祝您在新的一年里身体健康,事业进步!</hello>
-      <!-- 从网站根目录算起 -->
-      <img>./img/theme/0101.gif</img>
-    </feast>
-    <feast day="0202" name="世界湿地日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0210" name="国际气象节" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0214" name="情人节" sayhello="yes">
-      <hello>祝天下有情人终成眷属!</hello>
-      <img></img>
-    </feast>
-    <feast day="0301" name="世界图书日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0303" name="全国爱耳日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0305" name="学雷锋纪念日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0308" name="妇女节" sayhello="yes">
-      <hello>妇女能顶半边天,谁说女子不如男!</hello>
-      <img></img>
-    </feast>
-    <feast day="0312" name="植树节" sayhello="yes">
-      <hello>植树造林,功德无量。</hello>
-      <img>./img/theme/0312.gif</img>
-    </feast>
-    <feast day="0314" name="国际警察日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0315" name="消费者权益日" sayhello="no">
-      <img>./img/theme/temp.gif</img>
-      <hello></hello>
-    </feast>
-    <feast day="0316" name="手拉手情系贫困地区全国行动日" sayhello="no">
-      <img>./img/theme/temp.gif</img>
-      <hello></hello>
-    </feast>
-    <feast day="0317" name="国际航海日" sayhello="no">
-      <img>./img/theme/temp.gif</img>
-      <hello></hello>
-    </feast>
-    <feast day="0318" name="全国科技人才活动日" sayhello="no">
-      <img>./img/theme/temp.gif</img>
-      <hello></hello>
-    </feast>
-    <feast day="0321" name="世界睡眠日 世界森林日 世界儿歌日 消除种族歧视国际日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0322" name="世界水日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0323" name="世界气象日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0324" name="世界防治结核病日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0401" name="愚人节" sayhello="no">
-      <img>./img/theme/temp.gif</img>
-      <hello></hello>
-    </feast>
-    <feast day="0407" name="世界卫生日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0422" name="世界地球日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0425" name="国际秘书节" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0501" name="劳动节" sayhello="yes">
-      <hello>今天是劳动节,怎么,您还在劳动吗?</hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0504" name="青年节" sayhello="yes">
-      <hello>美哉,我少年中国,与天不老!壮哉,我中国少年,与国无疆!</hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0505" name="全国碘缺乏病日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0508" name="世界红十字日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0512" name="护士节" sayhello="no">
-      <hello></hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0515" name="国际家庭日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0517" name="世界电信日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0518" name="国际博物馆日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0519" name="全国助残日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0520" name="全国学生营养日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0522" name="国际生物多样性日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0523" name="国际牛奶日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0531" name="世界无烟日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0601" name="儿童节" sayhello="yes">
-      <hello>祝您儿童节快乐!</hello>
-      <img>./img/theme/0601.gif</img>
-    </feast>
-    <feast day="0605" name="世界环境日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0606" name="全国爱眼日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0617" name="防治荒漠化和干旱日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0623" name="国际奥林匹克日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0625" name="全国土地日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0626" name="国际禁毒日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0701" name="建党节 香港回归纪念" sayhello="yes">
-      <hello>庆祝中国共产党成立_YEARS_周年!</hello>
-      <startyear>1921</startyear>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0707" name="七七卢沟桥事变" sayhello="yes">
-      <hello>1937年7月7日,卢沟桥事变,全面抗战开始。</hello>
-      <startyear>1937</startyear>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0711" name="世界人口日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0801" name="建军节" sayhello="no">
-      <hello></hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0908" name="国际扫盲日 国际新闻工作者团体日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0909" name="毛泽东逝世纪念" sayhello="yes">
-      <hello>伟大领袖毛泽东主席逝世_YEARS_周年。</hello>
-      <startyear>1976</startyear>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0910" name="中国教师节" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0916" name="国际臭氧层保护日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0918" name="九一八事变" sayhello="yes">
-      <img></img>
-      <hello>1931年9月18日,日本帝国主义对我国沈阳北大营的中国驻军发动武装进攻,接着对我国东北地区进行大规模武装侵略。</hello>
-    </feast>
-    <feast day="0920" name="全国爱牙日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0921" name="国际和平日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0927" name="世界旅游日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="0928" name="国际聋人日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="1001" name="国庆节" sayhello="yes">
-      <hello>热烈庆祝中华人民共和国成立_YEARS_周年!</hello>
-      <startyear>1949</startyear>
-      <img>./img/theme/1001.gif</img>
-    </feast>
-    <feast day="1001" name="老人节" sayhello="no">
-      <hello></hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="1001" name="国际音乐日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1004" name="世界动物日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1008" name="全国高血压日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1009" name="世界邮政日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="1010" name="世界精神卫生日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1014" name="世界标准日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="1015" name="国际盲人节" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1016" name="世界粮食日" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="1017" name="世界消除贫困日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1022" name="世界传统医药日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1024" name="联合国日" sayhello="no">
-      <hello></hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="1031" name="万圣节" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="1108" name="中国记者日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1109" name="消防宣传日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1112" name="孙中山诞辰纪念" sayhello="no">
-      <hello></hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="1114" name="世界糖尿病日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1117" name="国际大学生节" sayhello="no">
-      <img></img>
-      <hello></hello>
-    </feast>
-    <feast day="1201" name="世界艾滋病日" sayhello="no">
-      <hello></hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="1203" name="世界残疾人日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1209" name="世界足球日" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1213" name="南京大屠杀纪念日" sayhello="yes">
-      <hello>南京大屠杀_YEARS_周年。1937年12月13日,日军占领南京,进行长达6周的血腥大屠杀,杀害我军民30余万人。</hello>
-      <startyear>1937</startyear>
-      <img></img>
-    </feast>
-    <feast day="1220" name="澳门回归纪念" sayhello="no">
-      <hello></hello>
-      <img></img>
-    </feast>
-    <feast day="1224" name="圣诞节平安夜" sayhello="yes">
-      <hello>We wish you a merry christmas。</hello>
-      <img>./img/theme/1225.gif</img>
-    </feast>
-    <feast day="1225" name="圣诞节" sayhello="yes">
-      <hello>圣诞快乐。</hello>
-      <img>./img/theme/1225.gif</img>
-    </feast>
-  </AD>
-  <!-- 公历节日结束 -->
-
-  <!-- 农历节日开始 -->
-  <LUNAR>
-    <feast day="0101" name="春节" sayhello="yes">
-      <hello>恭喜发财!新年进步!万事如意!</hello>
-      <img>./img/theme/spring.gif</img>
-    </feast>
-    <feast day="0115" name="元宵节" sayhello="yes">
-      <hello>年年元夜时,花市灯如昼。月上柳梢头,人约黄昏后。</hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0505" name="端午节" sayhello="no">
-      <hello></hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0707" name="七夕情人节" sayhello="no">
-      <hello></hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0715" name="中元节" sayhello="no">
-      <hello></hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0815" name="中秋节" sayhello="yes">
-      <hello>海上升明月 天涯共此时</hello>
-      <img>./img/theme/c815.gif</img>
-    </feast>
-    <feast day="0909" name="重阳节" sayhello="yes">
-      <hello>人生易老天难老,岁岁重阳。今又重阳,战地黄花分外香。</hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="1208" name="腊八节" sayhello="yes">
-      <hello>谁愿意跟我去侠客岛喝腊八粥?</hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-    <feast day="0100" name="除夕" sayhello="yes">
-      <hello>炮竹声中一岁除,春风送暖入屠苏。千家万户瞳瞳日,总把新桃换旧符。</hello>
-      <img>./img/theme/temp.gif</img>
-    </feast>
-  </LUNAR>
-  <!-- 农历节日结束 -->
-
-  <!-- 普通日子开始 -->
-  <NORMAL>
-    <day time1="2301" time2="2359" sayhello="yes">
-      <hello>深夜了!您应该休息了。</hello>
-      <img>./img/theme/latenight.gif</img>
-    </day>
-    <day time1="1901" time2="2300" sayhello="yes">
-      <hello>晚上好!还在工作吗?</hello>
-      <img>./img/theme/night.gif</img>
-    </day>
-    <day time1="1801" time2="1900" sayhello="yes">
-      <hello>傍晚好!是时候吃晚饭了。</hello>
-      <img>./img/theme/dusk.gif</img>
-    </day>
-    <day time1="1301" time2="1800" sayhello="yes">
-      <hello>下午好!要振作精神哦!</hello>
-      <img>./img/theme/afternoon.gif</img>
-    </day>
-    <day time1="1201" time2="1300" sayhello="yes">
-      <hello>中午好!吃过午饭了吗?</hello>
-      <img>./img/theme/midday.gif</img>
-    </day>
-    <day time1="0901" time2="1200" sayhello="yes">
-      <hello>上午好!努力工作哦!</hello>
-      <img>./img/theme/ackemma.gif</img>
-    </day>
-    <day time1="0601" time2="0900" sayhello="yes">
-      <hello>早上好!休息得好吗?</hello>
-      <img>./img/theme/morning.gif</img>
-    </day>
-    <day time1="0000" time2="0600" sayhello="yes">
-      <hello>深夜了!您应该休息了。</hello>
-      <img>./img/theme/latenight.gif</img>
-    </day>
-  </NORMAL>
-  <!-- 普通日子结束 -->
-
-</HELLO>

+ 1 - 2
Masuit.Tools/DateTimeExt/DateUtil.cs

@@ -1,5 +1,4 @@
 using System;
-using Masuit.Tools.Logging;
 
 namespace Masuit.Tools.DateTimeExt
 {
@@ -349,7 +348,7 @@ namespace Masuit.Tools.DateTimeExt
                 if (oDate.CompareTo(DateTime.Parse("1800-1-1")) > 0) return true;
                 return false;
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return false;
             }

+ 4 - 0
Masuit.Tools/Hardware/OnLogicalDiskProc.cs

@@ -0,0 +1,4 @@
+namespace Masuit.Tools.Hardware
+{
+    public delegate void OnLogicalDiskProc(string s);
+}

+ 12 - 21
Masuit.Tools/Hardware/SystemInfo.cs

@@ -10,12 +10,6 @@ using Microsoft.Win32;
 
 namespace Masuit.Tools.Hardware
 {
-    /// <summary>
-    /// 
-    /// </summary>
-    /// <param name="s"></param>
-    public delegate void OnLogicalDiskProc(string s);
-
     /// <summary>
     /// 硬件信息,部分功能需要C++支持
     /// </summary>
@@ -87,9 +81,6 @@ namespace Masuit.Tools.Hardware
 
         #endregion
 
-        /// <summary>
-        /// 
-        /// </summary>
         public static bool CompactFormat { get; set; }
 
         #region CPU核心 
@@ -130,7 +121,7 @@ namespace Masuit.Tools.Hardware
                     }
                     return availablebytes;
                 }
-                catch (Exception e)
+                catch (Exception)
                 {
                     return 0;
                 }
@@ -196,7 +187,7 @@ namespace Masuit.Tools.Hardware
                 ManagementObjectCollection mn = m.GetInstances();
                 return mn.Count;
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return 0;
             }
@@ -236,7 +227,7 @@ namespace Masuit.Tools.Hardware
 
                 return list;
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return new List<CpuInfo>();
             }
@@ -282,7 +273,7 @@ namespace Masuit.Tools.Hardware
                 double temp = (double.Parse(str) - 2732) / 10;
                 return Math.Round(temp, 2);
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return 0;
             }
@@ -458,7 +449,7 @@ namespace Masuit.Tools.Hardware
                 }
                 return list;
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return new List<string>();
             }
@@ -495,7 +486,7 @@ namespace Masuit.Tools.Hardware
                     }
                 }
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return new List<string>() { "未能获取到操作系统版本,可能是当前程序无管理员权限,如果是web应用程序,请将应用程序池的高级设置中的进程模型下的标识设置为:LocalSystem;如果是普通桌面应用程序,请提升管理员权限后再操作。" };
             }
@@ -510,7 +501,7 @@ namespace Masuit.Tools.Hardware
             {
                 return Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion")?.GetValue("ProductName").ToString();
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return "未能获取到操作系统版本,可能是当前程序无管理员权限,如果是web应用程序,请将应用程序池的高级设置中的进程模型下的标识设置为:LocalSystem;如果是普通桌面应用程序,请提升管理员权限后再操作。";
             }
@@ -568,7 +559,7 @@ namespace Masuit.Tools.Hardware
                 foreach (ManagementObject objMgmt in objCS.Get()) str = objMgmt[type].ToString();
                 return str;
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return "未能获取到操作系统版本,可能是当前程序无管理员权限,如果是web应用程序,请将应用程序池的高级设置中的进程模型下的标识设置为:LocalSystem;如果是普通桌面应用程序,请提升管理员权限后再操作。";
             }
@@ -613,7 +604,7 @@ namespace Masuit.Tools.Hardware
                 }
                 return dic;
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return new Dictionary<string, string>() { { "null", "未能获取到操作系统版本,可能是当前程序无管理员权限,如果是web应用程序,请将应用程序池的高级设置中的进程模型下的标识设置为:LocalSystem;如果是普通桌面应用程序,请提升管理员权限后再操作。" } };
             }
@@ -643,7 +634,7 @@ namespace Masuit.Tools.Hardware
                 }
                 return dic;
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return new Dictionary<string, string>();
             }
@@ -675,7 +666,7 @@ namespace Masuit.Tools.Hardware
                 }
                 return dic;
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return new Dictionary<string, string>() { { "null", "未能获取到操作系统版本,可能是当前程序无管理员权限,如果是web应用程序,请将应用程序池的高级设置中的进程模型下的标识设置为:LocalSystem;如果是普通桌面应用程序,请提升管理员权限后再操作。" } };
             }
@@ -706,7 +697,7 @@ namespace Masuit.Tools.Hardware
                 }
                 return dic;
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return new Dictionary<string, double>() { { "未能获取到操作系统版本,可能是当前程序无管理员权限,如果是web应用程序,请将应用程序池的高级设置中的进程模型下的标识设置为:LocalSystem;如果是普通桌面应用程序,请提升管理员权限后再操作。", 0 } };
             }

+ 4 - 6
Masuit.Tools/Masuit.Tools.csproj

@@ -24,6 +24,7 @@
     <WarningLevel>4</WarningLevel>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <DocumentationFile>bin\Debug\Masuit.Tools.XML</DocumentationFile>
+    <NoWarn>1591;</NoWarn>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>pdbonly</DebugType>
@@ -37,11 +38,10 @@
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="AngleSharp, Version=0.9.9.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea, processorArchitecture=MSIL">
-      <HintPath>..\packages\AngleSharp.0.9.9\lib\net45\AngleSharp.dll</HintPath>
-      <Private>True</Private>
+      <HintPath>..\..\MyBlogs\packages\AngleSharp.0.9.9.1\lib\net45\AngleSharp.dll</HintPath>
     </Reference>
     <Reference Include="HtmlSanitizer, Version=3.0.0.0, Culture=neutral, PublicKeyToken=61c49a1a9e79cc28, processorArchitecture=MSIL">
-      <HintPath>..\packages\HtmlSanitizer.4.0.181\lib\net45\HtmlSanitizer.dll</HintPath>
+      <HintPath>..\packages\HtmlSanitizer.4.0.183\lib\net45\HtmlSanitizer.dll</HintPath>
     </Reference>
     <Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
       <HintPath>..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath>
@@ -84,6 +84,7 @@
     <Compile Include="Hardware\DiskData.cs" />
     <Compile Include="Hardware\MemoryInfo.cs" />
     <Compile Include="Hardware\NetData.cs" />
+    <Compile Include="Hardware\OnLogicalDiskProc.cs" />
     <Compile Include="Hardware\RamInfo.cs" />
     <Compile Include="Hardware\SystemtimeInfo.cs" />
     <Compile Include="Hardware\Unit.cs" />
@@ -123,9 +124,6 @@
       <SubType>Designer</SubType>
     </None>
   </ItemGroup>
-  <ItemGroup>
-    <Content Include="DateTimeExt\CCalendarData.xml" />
-  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.

+ 4 - 5
Masuit.Tools/Media/ImageUtilities.cs

@@ -5,7 +5,6 @@ using System.Drawing.Imaging;
 using System.IO;
 using System.Linq;
 using System.Threading.Tasks;
-using Masuit.Tools.Logging;
 
 namespace Masuit.Tools.Media
 {
@@ -498,7 +497,7 @@ namespace Masuit.Tools.Media
                 g.Dispose();
                 return bmpOut;
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return null;
             }
@@ -527,7 +526,7 @@ namespace Masuit.Tools.Media
                 g.Dispose();
                 return b;
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return null;
             }
@@ -813,7 +812,7 @@ namespace Masuit.Tools.Media
                     }).ConfigureAwait(false);
                 }
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return null;
             }
@@ -947,7 +946,7 @@ namespace Masuit.Tools.Media
                 outBmp.Dispose();
                 return true;
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return false;
             }

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

@@ -368,7 +368,7 @@ namespace Masuit.Tools.Net
                     return false;
                 }).ConfigureAwait(false);
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return false;
             }

+ 6 - 7
Masuit.Tools/Net/SocketClient.cs

@@ -6,7 +6,6 @@ using System.Runtime.Serialization;
 using System.Runtime.Serialization.Formatters.Binary;
 using System.Text;
 using System.Threading;
-using Masuit.Tools.Logging;
 
 namespace Masuit.Tools.Net
 {
@@ -37,7 +36,7 @@ namespace Masuit.Tools.Net
                 Socket socket = listener.AcceptSocket();
                 return socket;
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return null;
             }
@@ -55,7 +54,7 @@ namespace Masuit.Tools.Net
                 TcpClient client = listener.AcceptTcpClient();
                 return client.GetStream();
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return null;
             }
@@ -78,7 +77,7 @@ namespace Masuit.Tools.Net
                 tcpclient.Connect(ipendpoint);
                 return tcpclient.Client;
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return null;
             }
@@ -98,7 +97,7 @@ namespace Masuit.Tools.Net
                 tcpclient.Connect(ipadd, port);
                 return tcpclient.Client;
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return null;
             }
@@ -117,7 +116,7 @@ namespace Masuit.Tools.Net
                 tcpclient.Connect(ipendpoint);
                 return tcpclient.GetStream();
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return null;
             }
@@ -137,7 +136,7 @@ namespace Masuit.Tools.Net
                 tcpclient.Connect(ipadd, port);
                 return tcpclient.GetStream();
             }
-            catch (Exception e)
+            catch (Exception)
             {
                 return null;
             }

+ 2 - 2
Masuit.Tools/Net/WebExtension.cs

@@ -392,9 +392,9 @@ namespace Masuit.Tools.Net
                             return taobaoIp.IpData.Isp;
                         }
                     }
-                    catch (Exception e)
+                    catch
                     {
-
+                        // ignored
                     }
                 }
                 return $"未能找到{ip}的ISP信息";

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

@@ -36,7 +36,7 @@ using System.Runtime.InteropServices;
 // 方法是按如下所示使用“*”: :
 // [assembly: AssemblyVersion("1.0.*")]
 
-[assembly: AssemblyVersion("1.7.*")]
-[assembly: AssemblyFileVersion("1.7.*")]
+[assembly: AssemblyVersion("1.8.0")]
+[assembly: AssemblyFileVersion("1.8.0")]
 [assembly: NeutralResourcesLanguage("zh-CN")]
 

+ 2 - 2
Masuit.Tools/packages.config

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
-  <package id="AngleSharp" version="0.9.9" targetFramework="net45" />
-  <package id="HtmlSanitizer" version="4.0.181" targetFramework="net45" />
+  <package id="AngleSharp" version="0.9.9.1" targetFramework="net45" />
+  <package id="HtmlSanitizer" version="4.0.183" targetFramework="net45" />
   <package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" />
   <package id="SharpZipLib" version="0.86.0" targetFramework="net45" />
   <package id="StackExchange.Redis" version="1.2.6" targetFramework="net45" />

+ 6 - 2
Test/Test.csproj

@@ -32,11 +32,15 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
-      <HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
+    <Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+      <HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
+    </Reference>
+    <Reference Include="StackExchange.Redis, Version=1.2.6.0, Culture=neutral, processorArchitecture=MSIL">
+      <HintPath>..\packages\StackExchange.Redis.1.2.6\lib\net45\StackExchange.Redis.dll</HintPath>
     </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
+    <Reference Include="System.IO.Compression" />
     <Reference Include="System.Management" />
     <Reference Include="System.Xml.Linq" />
     <Reference Include="System.Data.DataSetExtensions" />

+ 2 - 2
Test/packages.config

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
-  <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
-  <package id="StackExchange.Redis" version="1.2.0" targetFramework="net45" />
+  <package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" />
+  <package id="StackExchange.Redis" version="1.2.6" targetFramework="net45" />
 </packages>