diff --git a/OSS.Common.Tests/EncryptTests.cs b/OSS.Common.Tests/EncryptTests.cs index 0723c71..393b9fb 100644 --- a/OSS.Common.Tests/EncryptTests.cs +++ b/OSS.Common.Tests/EncryptTests.cs @@ -1,7 +1,7 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using OSS.Common.Encrypt; -using OSS.Common.Extention; +using OSS.Common.Extension; namespace OSS.Common.Tests { diff --git a/OSS.Common.Tests/ExtensionTests.cs b/OSS.Common.Tests/ExtensionTests.cs index 13e858d..f00fa51 100644 --- a/OSS.Common.Tests/ExtensionTests.cs +++ b/OSS.Common.Tests/ExtensionTests.cs @@ -3,8 +3,7 @@ using System.Collections.Generic; using System.Xml; using System.Xml.Serialization; using Microsoft.VisualStudio.TestTools.UnitTesting; -using OSS.Common.Extention; -using OSS.Common.Helpers; +using OSS.Common.Extension; namespace OSS.Common.Tests { @@ -20,7 +19,7 @@ namespace OSS.Common.Tests obj.items = new List() { new TestItemMo() { house = "beijing", age = 20 } }; string reslt = obj.SerializeToXml();//" "; - var res = reslt.DeserializeXml(); + _ = reslt.DeserializeXml(); } [TestMethod] diff --git a/OSS.Common/BasicImpls/SingleInstance.cs b/OSS.Common/BasicImpls/SingleInstance.cs deleted file mode 100644 index 630b686..0000000 --- a/OSS.Common/BasicImpls/SingleInstance.cs +++ /dev/null @@ -1,62 +0,0 @@ -#region Copyright (C) 2019 (OSS开源系列) 公众号:OSSCore - -/*************************************************************************** -*   文件功能描述:全局辅助类 - 单例基础实现 -* -*   创建人: Kevin -* 创建人Email:1985088337@qq.com -* -* -*****************************************************************************/ - -#endregion - -using System; - -namespace OSS.Common.BasicImpls -{ - /// - /// 单例基础实现 - /// - /// - [Obsolete] - public class SingleInstance - where T : new() - { - private static T _instance; - private static readonly object _objLock = new object(); - - /// - /// 获取单例实例 - /// - /// - /// - public static T GetInstance(Func initialCreator = null) - { - if (_instance == null) - { - lock (_objLock) - { - if (_instance != null) - return _instance; - - if (initialCreator == null) - return _instance = new T(); - - _instance = initialCreator.Invoke(); - if (_instance==null) - { - throw new ArgumentException("initialCreator 委托函数返回值为空,无法创建实例!"); - } - return _instance; - } - } - return _instance; - } - - /// - /// 单例实例 - /// - public static T Instance => GetInstance(); - } -} diff --git a/OSS.Common/Extention/DateTimeExtention.cs b/OSS.Common/Extention/DateTimeExtention.cs deleted file mode 100644 index e8ef181..0000000 --- a/OSS.Common/Extention/DateTimeExtention.cs +++ /dev/null @@ -1,109 +0,0 @@ -#region Copyright (C) 2014 OS系列开源项目 - -/* -   文件功能描述:验证属性attribute - -   创建人:王超 - 创建人Email:1985088337@qq.com - 创建日期:2014.08.25 - -   修改描述: -*/ - -#endregion -using System; - -namespace OSS.Common.Extention -{ - /// - /// 时间秒数转化 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static class DateTimeExtention - { - private static readonly long startTicks = new DateTime(1970, 1, 1).Ticks; - - - /// - /// 获取距离 1970-01-01(格林威治时间)的秒数 - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static long ToUtcSeconds(this DateTime localTime) - { - return (localTime.ToUniversalTime().Ticks - startTicks)/10000000; - } - - /// - /// 距离 1970-01-01(格林威治时间)的秒数转换为当前时间 - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static DateTime FromUtcSeconds(this long seconds) - { - return DateTimeOffset.FromUnixTimeSeconds(seconds).LocalDateTime;// new DateTime(1970, 1, 1).AddSeconds(seconds).ToLocalTime(); - } - - - /// - /// 获取距离 1970-01-01(格林威治时间)的毫秒数 - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static long ToUtcMilliSeconds(this DateTime localTime) - { - return (localTime.ToUniversalTime().Ticks - startTicks) / 10000; - } - - /// - /// 距离 1970-01-01(格林威治时间)的秒数转换为当前时间 - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static DateTime FromUtcMilliSeconds(this long milliSeconds) - { - return DateTimeOffset.FromUnixTimeMilliseconds(milliSeconds).LocalDateTime; - } - - - /// - /// 获取距离 1970-01-01(格林威治时间)Ticks 精确到0.1微秒(千万分之一秒) - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static long ToUtcTicks(this DateTime localTime) - { - return localTime.ToUniversalTime().Ticks - startTicks ; - } - - - - /// - /// 获取距离 1970-01-01(本地/北京时间)的秒数 - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static long ToLocalSeconds(this DateTime localTime) - { - return (localTime.Ticks - startTicks) / 10000000; - } - - /// - /// 距离 1970-01-01(本地/北京时间)的秒数转换为当前时间 - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static DateTime FromLocalSeconds(this long seconds) - { - return new DateTime(1970,1,1).AddSeconds(seconds); - } - - } -} diff --git a/OSS.Common/Extention/EnumExtention.cs b/OSS.Common/Extention/EnumExtention.cs deleted file mode 100644 index eb586d0..0000000 --- a/OSS.Common/Extention/EnumExtention.cs +++ /dev/null @@ -1,125 +0,0 @@ -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using OSS.Common.BasicMos.Resp; - -namespace OSS.Common.Extention -{ - /// - /// 枚举扩展方法类 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static class EnumExtention - { - - /// - /// 获取描述 - /// - /// 枚举对象 - /// 是否二进制取和 - /// 多个描述分隔符 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static string GetDesp(this Enum en, bool isFlag = false, string operate = ",") - { - var values = en.GetType().ToEnumDirs(); - var current = (int) Enum.Parse(en.GetType(), en.ToString()); - - if (isFlag) - { - var strResult = new StringBuilder(); - - foreach (var value in values) - { - var tempKey = value.Key.ToInt32(); - if ((tempKey & current) != tempKey) continue; - - if (strResult.Length != 0) - { - strResult.Append(operate); - } - strResult.Append(value.Value); - } - return strResult.ToString(); - } - - var keypair = values.FirstOrDefault(e => e.Key == current.ToString()); - return keypair.Key == null ? "不存在的枚举值" : keypair.Value; - } - - private static ConcurrentDictionary> enumDirs - =new ConcurrentDictionary>(); - - /// - /// 获取枚举字典列表 - /// - /// 枚举类型 - /// 返回枚举值是否是int类型 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static Dictionary ToEnumDirs(this Type enType, bool isIntValue = true) - { - - if (!enType.GetTypeInfo().IsEnum) - throw new RespException(RespTypes.ParaError,"获取枚举字典,参数必须是枚举类型!"); - - var key = string.Concat(enType.FullName, isIntValue); - enumDirs.TryGetValue(key, out var dirs); - - if (dirs != null) - return dirs.Copy(); - - dirs = new Dictionary(); - var values = Enum.GetValues(enType); - - foreach (var value in values) - { - var name = Enum.GetName(enType, value); - var resultValue = isIntValue ? ((int) value).ToString() : value.ToString(); - - var attr = enType.GetTypeInfo().GetDeclaredField(name)?.GetCustomAttribute(); - - dirs.Add(resultValue, attr == null ? name : attr.Description); - } - enumDirs.TryAdd(key, dirs); - return dirs.Copy(); - } - - /// - /// 拷贝字典 - /// - /// - /// - private static Dictionary Copy(this Dictionary source) - { - return source.ToDictionary(sou => sou.Key, sou => sou.Value); - } - } - - /// - /// 自定义描述属性 - /// - [AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = true)] - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public class OSDescriptAttribute : Attribute - { - /// - /// - /// - /// - public OSDescriptAttribute(string description) - { - this.Description = description; - } - - /// - /// 描述信息 - /// - public string Description { get; set; } - } - - -} diff --git a/OSS.Common/Extention/ListExtention.cs b/OSS.Common/Extention/ListExtention.cs deleted file mode 100644 index 26be1e7..0000000 --- a/OSS.Common/Extention/ListExtention.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace OSS.Common.Extention -{ - /// - /// 列表扩展方法 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static class ListExtention - { - /// - /// List合并 - /// - /// 数据类型 - /// 目标对象 - /// 来源对象 - /// 重复项依据方法 true-没有重复项,可以合并,fale-有重复项,不能合并 - /// 返回合并后的目标对象 - 排除重复项 - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static IList Merged(this IList target, IList source, Func, T, bool> checkFunc) - { - foreach (var t in source) - { - if (checkFunc(target, t)) - { - target.Add(t); - } - } - return target; - } - } -} diff --git a/OSS.Common/Extention/StringCodeExtention.cs b/OSS.Common/Extention/StringCodeExtention.cs deleted file mode 100644 index 7bd056d..0000000 --- a/OSS.Common/Extention/StringCodeExtention.cs +++ /dev/null @@ -1,132 +0,0 @@ -#region Copyright (C) 2017 Kevin (OSS开源系列) 公众号:OSSCore - -/*************************************************************************** -*   文件功能描述:字符串通用功能 -* -*   创建人: Kevin -* 创建人Email:1985088337@qq.com -* -*****************************************************************************/ - -#endregion - -using System; -using System.Text; - -namespace OSS.Common.Extention -{ - /// - /// 字符串通用功能 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static class StringCodeExtention - { - - private static readonly Random _rnd = new Random(DateTime.Now.Millisecond); - - private static readonly char[] _arrChar = - { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'a', 'b', 'd', 'c', 'e', 'f', 'g', 'h', 'i', 'j', - 'k', 'l', 'm', 'n', 'p', 'r', 'q', 's', 't', 'u', - 'v', 'w', 'z', 'y', 'x', - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', - 'K', 'L', 'M', 'N', 'Q', 'P', 'R', 'T', 'S', 'V', - 'U', 'W', 'X', 'Y', 'Z' - }; - - /// - /// 生成随机串 - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static string RandomStr(int length = 8) - { - var num = new StringBuilder(length); - for (var i = 0; i < length; i++) - { - num.Append(_arrChar[_rnd.Next(0, 59)]); - } - return num.ToString(); - } - - - // 排除【0,O】I 4 这类 - private const string _arrCodeStr = "12356789abcdefghjklmnpqrstuvwxyz"; - - /// - /// 数字转化为短码 - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static string ToCode(this int num) - { - return ToCode(num, _arrCodeStr); - } - - /// - /// 数字转化为短码 - /// - /// - /// 转换时映射字母,32位,不可重复 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static string ToCode(this long num, string arrStrs=null) - { - if (string.IsNullOrEmpty(arrStrs)) - arrStrs = _arrCodeStr; - - if (arrStrs.Length!=32) - throw new ArgumentOutOfRangeException(nameof(arrStrs), "映射字符必须是32位,且不能重复!"); - - const long codeTemp = 0x1F; - var code = new StringBuilder(13); - - while (num > 0) - { - var index = num & codeTemp; - code.Append(arrStrs[(int) index]); - - num >>= 5; - } - return code.ToString(); - } - - /// - /// 根据短码反推数字 - /// - /// - /// 转换时映射字母,32位,不可重复 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static long ToCodeNum(this string code, string arrStrs=null) - { - if (string.IsNullOrEmpty(arrStrs)) - arrStrs = _arrCodeStr; - - if ( arrStrs.Length != 32) - throw new ArgumentOutOfRangeException(nameof(arrStrs), "映射字符必须是32位,且不能重复!"); - - if (string.IsNullOrEmpty(code)) - return 0; - var count = code.Length; - if (count > 13) - throw new ArgumentOutOfRangeException("code", "the code is not from [ToCode] method !"); - - long value = 0; - - for (var i = count - 1; i >= 0; i--) - { - var num = arrStrs.IndexOf(code[i]); - if (num < 0) - throw new ArgumentOutOfRangeException("code", "the code is not from [ToCode] method !"); - - value = (value << 5) ^ num; - } - return value; - } - } - - -} \ No newline at end of file diff --git a/OSS.Common/Extention/StringEncodeExtension.cs b/OSS.Common/Extention/StringEncodeExtension.cs deleted file mode 100644 index 1506e6b..0000000 --- a/OSS.Common/Extention/StringEncodeExtension.cs +++ /dev/null @@ -1,180 +0,0 @@ -#region Copyright (C) 2017 公众号:OSSCore - -/*************************************************************************** -*   文件功能描述:字符串编码扩展功能 -* -*   创建人: Kevin -* 创建人Email:1985088337@qq.com -* -*****************************************************************************/ - -#endregion - -using System; -using System.Text; - -namespace OSS.Common.Extention -{ - /// - /// url扩展 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static class StringEncodeExtension - { - #region Url 编码处理 - - /// - /// Url编码处理 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static string UrlEncode(this string input) - { - return string.IsNullOrEmpty(input) - ? string.Empty - : Uri.EscapeDataString(input); - } - - /// - /// Url解码处理 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static string UrlDecode(this string input) - { - return string.IsNullOrEmpty(input) ? string.Empty : Uri.UnescapeDataString(input); - } - - #endregion - - - #region Base64编码 - - /// - /// 转换字符串为Base64编码 - /// - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static string ToBase64(this string source, Encoding encoding = null) - { - if (string.IsNullOrEmpty(source)) - { - throw new ArgumentNullException(nameof(source), "转化Base64字符串不能为空"); - } - - if (encoding == null) - { - encoding = Encoding.UTF8; - } - var bytes = encoding.GetBytes(source); - return Convert.ToBase64String(bytes); - } - - /// - /// 解码Base64编码到字符串 - /// - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static string FromBase64(this string baseString, Encoding encoding = null) - { - if (string.IsNullOrEmpty(baseString)) - { - throw new ArgumentNullException(nameof(baseString), "解码Base64字符串不能为空"); - } - if (encoding == null) - { - encoding = Encoding.UTF8; - } - var bytes = Convert.FromBase64String(baseString); - return encoding.GetString(bytes); - } - - - /// - /// 转换字符串为Base64编码,同时处理和url中冲突的字符(+,/,=) - /// - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static string ToSafeUrlBase64(this string data, Encoding encoding = null) - { - return data.ToBase64(encoding).ReplaceBase64ToUrlSafe(); - } - - - /// - /// 解码Base64编码(特殊url冲突处理过的Base64编码)到字符串 - /// - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static string FromSafeUrlBase64(this string safeBaseString, Encoding encoding = null) - { - return safeBaseString.ReplaceBase64UrlSafeBack().FromBase64(encoding); - } - - /// - /// 处理Base64字符串和url中冲突的字符(+,/,=) - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static string ReplaceBase64ToUrlSafe(this string base64String) - { - return base64String.Replace('+', '-').Replace('/', '_').TrimEnd('='); - } - - /// - /// 将url冲突处理过的Base64编码替换回正常Base64 - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static string ReplaceBase64UrlSafeBack(this string safeBase64String) - { - var bStr = safeBase64String.Replace('-', '+').Replace('_', '/'); - var len = bStr.Length % 4; - if (len > 0) - { - bStr += "====".Substring(len); - } - return bStr; - } - - - /// - /// 替换base64位字符串中的特殊符号 Url友好 - /// - /// - /// - [Obsolete("请使用ReplaceBase64ToUrlSafe")] - public static string Base64UrlSafeEncode(this string data) - { - return data.Replace('+', '-').Replace('/', '_').TrimEnd('='); - } - - /// - /// 还原 base64 字符串中的特殊字符 Url不友好 - /// - /// - /// - [Obsolete("请使用ReplaceBase64UrlSafeBack")] - public static string Base64UrlSafeDecode(this string baseString) - { - var bStr= baseString.Replace('-', '+').Replace('_', '/'); - var len = bStr.Length % 4; - if (len > 0) - { - bStr += "====".Substring(len); - } - return bStr; - } - - #endregion - - } -} diff --git a/OSS.Common/Extention/StringNumberExtention.cs b/OSS.Common/Extention/StringNumberExtention.cs deleted file mode 100644 index 2d04638..0000000 --- a/OSS.Common/Extention/StringNumberExtention.cs +++ /dev/null @@ -1,253 +0,0 @@ -#region Copyright (C) 2014 OS系列开源项目 - -/* -   文件功能描述:验证属性attribute - -   创建人:王超 - 创建人Email:1985088337@qq.com - 创建日期:2014.08.25 - -   修改描述: -*/ - -#endregion - -using System; - -namespace OSS.Common.Extention -{ - /// - /// 字符串数字转化扩展 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static class StringNumberExtention - { - #region 字符串数字转化部分 - - /// - /// 字符串转化成无符号整形 - /// - /// 要转化的值 - /// 如果转化失败,返回的默认值 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static uint ToUInt32(this string obj, uint defaultValue = 0) - { - if (string.IsNullOrEmpty(obj)) - { - return defaultValue; - } - - try - { - if (uint.TryParse(obj, out var returnValue)) - { - return returnValue; - } - } - catch (Exception) - { - // ignored - } - - return defaultValue; - } - - /// - /// 字符串转化成数字 - /// - /// 要转化的值 - /// 如果转化失败,返回的默认值 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static int ToInt32(this string obj, int defaultValue = 0) - { - if (string.IsNullOrEmpty(obj)) - { - return defaultValue; - } - - try - { - if (int.TryParse(obj, out var returnValue)) - { - return returnValue; - } - } - catch (Exception) - { - // ignored - } - - return defaultValue; - } - - /// - /// 字符串转化成数字 - /// - /// 要转化的值 - /// 如果转化失败,返回的默认值 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static long ToInt64(this string obj, int defaultValue = 0) - { - if (string.IsNullOrEmpty(obj)) - { - return defaultValue; - } - - try - { - if (long.TryParse(obj, out var returnValue)) - { - return returnValue; - } - } - catch (Exception) - { - // ignored - } - - return defaultValue; - } - - - - /// - /// 字符串转化成数字 - /// - /// 要转化的值 - /// 如果转化失败,返回的默认值 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static decimal ToDecimal(this string obj, decimal defaultValue = 0) - { - if (string.IsNullOrEmpty(obj)) - { - return defaultValue; - } - - try - { - if (decimal.TryParse(obj, out var returnValue)) - { - return returnValue; - } - } - catch (Exception) - { - // ignored - } - - return defaultValue; - } - - - /// - /// 字符串转化成数字 - /// - /// 要转化的值 - /// 如果转化失败,返回的默认值 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static double ToDouble(this string obj, double defaultValue = 0) - { - if (string.IsNullOrEmpty(obj)) - { - return defaultValue; - } - - try - { - if (double.TryParse(obj, out var returnValue)) - { - return returnValue; - } - } - catch (Exception) - { - // ignored - } - - return defaultValue; - } - - /// - /// 字符串转化成数字 - /// - /// 要转化的值 - /// 如果转化失败,返回的默认值 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static float ToFloat(this string obj, float defaultValue = 0) - { - if (string.IsNullOrEmpty(obj)) - { - return defaultValue; - } - - try - { - if (float.TryParse(obj, out var returnValue)) - { - return returnValue; - } - } - catch (Exception) - { - // ignored - } - - return defaultValue; - } - - /// - /// 转化成布尔类型 - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static bool ToBoolean(this string str) - { - if (string.IsNullOrEmpty(str)) - { - return false; - } - - bool.TryParse(str, out var isOkay); - return isOkay; - } - - #endregion - - #region Filter - - /// - /// 过滤 Sql 语句字符串中的注入脚本 - /// - /// 传入的字符串 - /// 过滤后的字符串 - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static string SqlFilter(this string source) - { - source = source.Replace("\"", ""); - source = source.Replace("&", "&"); - source = source.Replace("<", "<"); - source = source.Replace(">", ">"); - source = source.Replace("delete", ""); - source = source.Replace("update", ""); - source = source.Replace("insert", ""); - source = source.Replace("'", "''"); - source = source.Replace(";", ";"); - source = source.Replace("(", "("); - source = source.Replace(")", ")"); - source = source.Replace("Exec", ""); - source = source.Replace("Execute", ""); - source = source.Replace("xp_", "x p_"); - source = source.Replace("sp_", "s p_"); - source = source.Replace("0x", "0 x"); - return source; - } - - #endregion - } -} diff --git a/OSS.Common/Extention/TaskExtention.cs b/OSS.Common/Extention/TaskExtention.cs deleted file mode 100644 index 37a4574..0000000 --- a/OSS.Common/Extention/TaskExtention.cs +++ /dev/null @@ -1,97 +0,0 @@ -#region Copyright (C) 2016 Kevin (OSS开源系列) 公众号:OSSCore - -/*************************************************************************** -*   文件功能描述:Task扩展类 -* -*   创建人: Kevin -* 创建人Email:1985088337@qq.com -* 创建日期:2017-2-19 -* -*****************************************************************************/ - -#endregion -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace OSS.Common.Extention -{ - /// - /// 任务等待扩展 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static class TaskExtention - { - /// - /// 等待异步执行结果 - /// - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static TRes WaitResult(this Task task) - { - task.Wait(); - return task.Result; - } - - /// - /// 等待异步执行结果 - /// - /// - /// - /// 等待任务完成的毫秒数,-1,表示无限期等待 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static TRes WaitResult(this Task task, int milliseconds) - { - task.Wait(milliseconds); - return task.Result; - } - - - /// - /// 等待异步执行结果 - /// - /// - /// 等待时间间隔 - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static TRes WaitResult(this Task task,TimeSpan span) - { - task.Wait(span); - return task.Result; - } - - /// - /// 等待异步执行结果 - /// - /// - /// 等待任务完成期间要观察的取消标记 - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static TRes WaitResult(this Task task, CancellationToken token) - { - task.Wait(token); - return task.Result; - } - - /// - /// 等待异步执行结果 - /// - /// - /// 等待任务完成的毫秒数,-1,表示无限期等待 - /// 等待任务完成期间要观察的取消标记 - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static TRes WaitResult(this Task task, int milliseconds,CancellationToken token) - { - task.Wait(milliseconds,token); - return task.Result; - } - - } -} diff --git a/OSS.Common/Extention/Volidate/VolidateAttributes.cs b/OSS.Common/Extention/Volidate/VolidateAttributes.cs deleted file mode 100644 index f85f117..0000000 --- a/OSS.Common/Extention/Volidate/VolidateAttributes.cs +++ /dev/null @@ -1,112 +0,0 @@ -using System; - -#region Copyright (C) 2014 OS系列开源项目 - -/* -   文件功能描述:验证属性attribute - -   创建人:王超 - 创建人Email:1985088337@qq.com - 创建日期:2014.08.25 - -   修改描述: -*/ - -#endregion - - -namespace OSS.Common.Extention.Volidate -{ - /// - /// - /// - [AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = true)] - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public abstract class BaseValidateAttribute : Attribute - { - /// - /// - /// - protected string errorMessage; - internal abstract bool Validate(string propertyName, object propertyValue); - - /// - /// 错误信息 - /// - public string ErrorMessage => errorMessage; - } - /// - /// 必填验证属性 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public class OsRequiredAttribute : BaseValidateAttribute - { - /// - /// - /// - /// - public OsRequiredAttribute(string _errorMessage=null) - { - errorMessage = _errorMessage; - } - internal override bool Validate(string propertyName, object propertyValue) - { - var result=propertyValue != null && propertyValue.ToString() != string.Empty; - if (!result) - { - errorMessage = errorMessage ??string.Format("请输入 {0} 信息", propertyName); - } - return result; - } - } - /// - /// 数字验证属性 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public class OsNumberAttribute : BaseValidateAttribute - { - private readonly long min; - private readonly long max; - - /// - /// - /// - /// - /// - /// - public OsNumberAttribute(long _min=long.MinValue, long _max=long.MaxValue, string _errorMessage=null) - { - min = _min; - max = _max; - errorMessage = _errorMessage; - } - /// - /// 验证方法 - /// - /// - /// - /// - internal override bool Validate(string propertyName, object propertyValue) - { - if (propertyValue==null) - { - errorMessage = errorMessage ?? string.Format("{0} 的值 不能为空!", propertyName); - return false; - } - var isOkay = false; - if (long.TryParse(propertyValue.ToString(), out var longValue)) - { - isOkay= min <= longValue&& longValue <= max; - errorMessage = isOkay - ? string.Empty:(errorMessage ?? string.Format("{0} 的值 必须介于 {1}~{2} 的数值", propertyName, min, max)); - } - else - { - errorMessage = (errorMessage ?? string.Format("{0} 的值 必须是数字类型", propertyName)); - } - return isOkay; - } - } - - -} diff --git a/OSS.Common/Extention/Volidate/VolidateExtention.cs b/OSS.Common/Extention/Volidate/VolidateExtention.cs deleted file mode 100644 index 64108f0..0000000 --- a/OSS.Common/Extention/Volidate/VolidateExtention.cs +++ /dev/null @@ -1,160 +0,0 @@ -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -#region Copyright (C) 2014 OS系列开源项目 - -/* -   文件功能描述:验证属性attribute - -   创建人:王超 - 创建人Email:1985088337@qq.com - 创建日期:2014.08.25 - -   修改描述: -*/ - -#endregion - - -namespace OSS.Common.Extention.Volidate -{ - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static class VolidateExtention - { - /// - /// 是否通过验证 - /// - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static bool IsOsValidate(this T t) where T : class, new() - { - if (t == null) - return false; - - - var type = typeof (T); - var files = TypeHelper.GetProperties(type); - - foreach (var fd in files) - { - var attrs = TypeHelper.GetPropertiAttributes(type.FullName, fd, typeof (BaseValidateAttribute)); - - var fd1 = fd; - if ( - attrs.OfType() - .Any(requireAttr => !requireAttr.Validate(fd1.Name, fd1.GetValue(t, null)))) - { - return false; - } - } - return true; - } - - /// - /// 返回的验证错误信息 - /// - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static List ValidateOsMessage(this T t) where T : class, new() - { - List resultList = new List(); - if (t == null) - { - resultList.Add("对象不能为空!"); - return resultList; - } - - var type = typeof (T); - - var files = TypeHelper.GetProperties(type); - - foreach (var fd in files) - { - var attrs = TypeHelper.GetPropertiAttributes(type.FullName, fd, typeof (BaseValidateAttribute)); - - var fd1 = fd; - foreach (var requireAttr in from requireAttr in attrs.OfType() - let result = requireAttr.Validate(fd1.Name, fd1.GetValue(t, null)) - where !result - select requireAttr) - { - resultList.Add(requireAttr.ErrorMessage); - break; - } - } - return resultList; - } - - } - - - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static class TypeHelper - { - private static ConcurrentDictionary attrDirs = new ConcurrentDictionary(); - - /// - /// - /// - /// - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static object[] GetPropertiAttributes(string typeName, PropertyInfo fd, Type attributeType) - { - string key = string.Concat(typeName, fd.Name); - - object[] attrs; - - attrDirs.TryGetValue(key, out attrs); - if (attrs != null) - { - return attrs; - } - attrs = fd.GetCustomAttributes(attributeType, true).ToArray(); - attrDirs.TryAdd(key, attrs); - return attrs; - } - - /// - /// - /// - private static ConcurrentDictionary proDictionaries = - new ConcurrentDictionary(); - - /// - /// - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static PropertyInfo[] GetProperties(Type type) - { - PropertyInfo[] properties; - proDictionaries.TryGetValue(type.FullName, out properties); - if (properties != null) - { - return properties; - } - properties = type.GetProperties(); - - proDictionaries.TryAdd(type.FullName, properties); - return properties; - } - - } -} diff --git a/OSS.Common/Extention/XmlExtention.cs b/OSS.Common/Extention/XmlExtention.cs deleted file mode 100644 index 476f250..0000000 --- a/OSS.Common/Extention/XmlExtention.cs +++ /dev/null @@ -1,100 +0,0 @@ -#region Copyright (C) 2016 Kevin (OSS开源系列) 公众号:OSSCore - -/*************************************************************************** -*   文件功能描述:xml序列化辅助类 -* -*   创建人: Kevin -* 创建人Email:1985088337@qq.com -* 创建日期:2017-2-19 -* -*****************************************************************************/ - -#endregion -using System; -using System.IO; -using System.Xml.Serialization; - -namespace OSS.Common.Extention -{ - /// - /// xml 转化扩展 - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static class XmlConvertExtention - { - /// - /// 对象序列化成xml字符串 - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static string SerializeToXml(this object t) - { - string result; - MemoryStream stream = null; - StreamReader streamReader = null; - try - { - var serializer = new XmlSerializer(t.GetType()); - - stream = new MemoryStream(); - serializer.Serialize(stream, t); - - stream.Position = 0; - streamReader = new StreamReader(stream); - result = streamReader.ReadToEnd(); - } - finally - { - streamReader?.Dispose(); - stream?.Dispose(); - } - return result; - } - - /// - /// xml字符串转化到对象 - /// - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static TT DeserializeXml(this string xml) - where TT : class - { - return DeserializeXml(xml, typeof(TT)) as TT; - } - - /// - /// xml字符串转化到对象 - /// - /// - /// - /// - [Obsolete("迁移至OSS.Common.Extension命名空间下")] - public static object DeserializeXml(this string xml, Type type) - { - object result; - MemoryStream stream = null; - StreamWriter writer = null; - try - { - stream = new MemoryStream(); - - writer = new StreamWriter(stream); - writer.Write(xml); - writer.Flush(); - - stream.Position = 0; - var deSer = new XmlSerializer(type); - result = deSer.Deserialize(stream); - } - finally - { - writer?.Dispose(); - stream?.Dispose(); - } - return result; - } - } -} diff --git a/OSS.Common/Encrypt/AesRijndael.cs b/OSS.Common/Helpers/Encrypt/AesRijndael.cs similarity index 100% rename from OSS.Common/Encrypt/AesRijndael.cs rename to OSS.Common/Helpers/Encrypt/AesRijndael.cs diff --git a/OSS.Common/Encrypt/HmacSha1.cs b/OSS.Common/Helpers/Encrypt/HmacSha1.cs similarity index 100% rename from OSS.Common/Encrypt/HmacSha1.cs rename to OSS.Common/Helpers/Encrypt/HmacSha1.cs diff --git a/OSS.Common/Encrypt/Md5.cs b/OSS.Common/Helpers/Encrypt/Md5.cs similarity index 100% rename from OSS.Common/Encrypt/Md5.cs rename to OSS.Common/Helpers/Encrypt/Md5.cs diff --git a/OSS.Common/Encrypt/Sha1.cs b/OSS.Common/Helpers/Encrypt/Sha1.cs similarity index 100% rename from OSS.Common/Encrypt/Sha1.cs rename to OSS.Common/Helpers/Encrypt/Sha1.cs diff --git a/OSS.Common/Extension/DateTimeExtension.cs b/OSS.Common/Helpers/Extension/DateTimeExtension.cs similarity index 100% rename from OSS.Common/Extension/DateTimeExtension.cs rename to OSS.Common/Helpers/Extension/DateTimeExtension.cs diff --git a/OSS.Common/Extension/DictionaryExtension.cs b/OSS.Common/Helpers/Extension/DictionaryExtension.cs similarity index 100% rename from OSS.Common/Extension/DictionaryExtension.cs rename to OSS.Common/Helpers/Extension/DictionaryExtension.cs diff --git a/OSS.Common/Extension/EnumExtension.cs b/OSS.Common/Helpers/Extension/EnumExtension.cs similarity index 100% rename from OSS.Common/Extension/EnumExtension.cs rename to OSS.Common/Helpers/Extension/EnumExtension.cs diff --git a/OSS.Common/Extension/IndentExtension.cs b/OSS.Common/Helpers/Extension/IndentExtension.cs similarity index 100% rename from OSS.Common/Extension/IndentExtension.cs rename to OSS.Common/Helpers/Extension/IndentExtension.cs diff --git a/OSS.Common/Extension/ListExtension.cs b/OSS.Common/Helpers/Extension/ListExtension.cs similarity index 100% rename from OSS.Common/Extension/ListExtension.cs rename to OSS.Common/Helpers/Extension/ListExtension.cs diff --git a/OSS.Common/Extension/StringCodeExtension.cs b/OSS.Common/Helpers/Extension/StringCodeExtension.cs similarity index 100% rename from OSS.Common/Extension/StringCodeExtension.cs rename to OSS.Common/Helpers/Extension/StringCodeExtension.cs diff --git a/OSS.Common/Extension/StringEncodeExtension.cs b/OSS.Common/Helpers/Extension/StringEncodeExtension.cs similarity index 100% rename from OSS.Common/Extension/StringEncodeExtension.cs rename to OSS.Common/Helpers/Extension/StringEncodeExtension.cs diff --git a/OSS.Common/Extension/StringNumberExtension.cs b/OSS.Common/Helpers/Extension/StringNumberExtension.cs similarity index 100% rename from OSS.Common/Extension/StringNumberExtension.cs rename to OSS.Common/Helpers/Extension/StringNumberExtension.cs diff --git a/OSS.Common/Extension/TaskExtension.cs b/OSS.Common/Helpers/Extension/TaskExtension.cs similarity index 100% rename from OSS.Common/Extension/TaskExtension.cs rename to OSS.Common/Helpers/Extension/TaskExtension.cs diff --git a/OSS.Common/Extension/Validate/VolidateAttributes.cs b/OSS.Common/Helpers/Extension/Validate/VolidateAttributes.cs similarity index 100% rename from OSS.Common/Extension/Validate/VolidateAttributes.cs rename to OSS.Common/Helpers/Extension/Validate/VolidateAttributes.cs diff --git a/OSS.Common/Extension/Validate/VolidateExtention.cs b/OSS.Common/Helpers/Extension/Validate/VolidateExtention.cs similarity index 100% rename from OSS.Common/Extension/Validate/VolidateExtention.cs rename to OSS.Common/Helpers/Extension/Validate/VolidateExtention.cs diff --git a/OSS.Common/Extension/XmlExtension.cs b/OSS.Common/Helpers/Extension/XmlExtension.cs similarity index 100% rename from OSS.Common/Extension/XmlExtension.cs rename to OSS.Common/Helpers/Extension/XmlExtension.cs diff --git a/OSS.Common/Helpers/InsContainer.cs b/OSS.Common/Helpers/InsContainer.cs deleted file mode 100644 index 9fd633b..0000000 --- a/OSS.Common/Helpers/InsContainer.cs +++ /dev/null @@ -1,92 +0,0 @@ -#region Copyright (C) 2019 (OSS开源系列) 公众号:OSSCore - -/*************************************************************************** -*   文件功能描述:全局辅助类 - Ioc简单实例容器 -* -*   创建人: Kevin -* 创建人Email:1985088337@qq.com -* -* -*****************************************************************************/ - -#endregion - -using System; - -namespace OSS.Common.Helpers -{ - ///// - ///// Ioc简单实例容器实现 - ///// - ///// - //[Obsolete] - //public static class InsContainer - //{ - // private static Func _insCreater; - - // /// - // /// 具体实例 - // /// 根据设置时参数会返回具体单例还是新的实例 - // /// - // public static T Instance => _insCreater != null - // ? _insCreater() - // : throw new NullReferenceException($"未能发现{typeof(T)}在容器具体映射类型/实例"); - - - // /// - // /// 设置容器内映射的实例创建方法 - // /// - // /// - // /// - // public static void Set(Func insCreater) - // where TInstance : T - // { - // _insCreater = insCreater ?? throw new ArgumentNullException(nameof(insCreater), "参数不能为空!"); - // } - - // /// - // /// 设置容器内映射的具体类型 - // /// - // /// - // /// - // public static void Set(T ins) - // where TInstance : T - // { - // _insCreater = ()=>ins; - // } - - // private static T _instance; - // private static readonly object _objLock = new object(); - - // /// - // /// 设置容器内映射的具体类型 - // /// - // /// - // /// - // public static void Set(bool isSingle = true) - // where TInstance : T, new() - // { - // if (!isSingle) - // { - // _insCreater = () => new TInstance(); - // return; - // } - // _insCreater = () => - // { - // if (_instance == null) - // { - // lock (_objLock) - // { - // if (_instance == null) - // { - // return _instance = new TInstance(); - // } - // } - // } - // return _instance; - // }; - // } - //} - - -} diff --git a/OSS.Common/OSS.Common.csproj b/OSS.Common/OSS.Common.csproj index 2dd553e..ed26d5e 100644 --- a/OSS.Common/OSS.Common.csproj +++ b/OSS.Common/OSS.Common.csproj @@ -3,7 +3,7 @@ netstandard2.0 False - 2.6.3 + 3.0 OSSCore OSSCore OSS开源系列 @@ -19,7 +19,7 @@ logo.png - 完善错误类型 + diff --git a/OSS.Common/Pattern/Domain/DomainContainer.cs b/OSS.Common/Pattern/Domain/DomainContainer.cs new file mode 100644 index 0000000..4499dff --- /dev/null +++ b/OSS.Common/Pattern/Domain/DomainContainer.cs @@ -0,0 +1,53 @@ +using System; + +namespace OSS.Common.Domain +{ + /// + /// 领域容器 + /// + /// + /// + public static class DomainContainer + where TReq : IDoaminReq + { + /// + /// 获取 执行实例 + /// + /// + public static IDomainExecutor GetExecutor() + { + return InsContainer>.Instance; + } + + /// + /// 设置容器内映射的执行实例类型 + /// + /// + public static void SetExecutor() + where TExecutor : IDomainExecutor, new() + { + InsContainer>.Set(); + } + + /// + /// 设置容器内映射的执行实例创建方法 + /// + /// + public static void SetExecutor(Func> insCreater) + { + InsContainer>.Set(insCreater); + } + + /// + /// 设置容器内映射的具体实例 + /// + /// + /// + public static void SetExecutor(TExecutor ins) + where TExecutor : IDomainExecutor, new() + { + InsContainer>.Set(ins); + } + + } +} \ No newline at end of file diff --git a/OSS.Common/Pattern/Domain/Extension/DomainReqExtension.cs b/OSS.Common/Pattern/Domain/Extension/DomainReqExtension.cs new file mode 100644 index 0000000..f00e98e --- /dev/null +++ b/OSS.Common/Pattern/Domain/Extension/DomainReqExtension.cs @@ -0,0 +1,36 @@ +#region Copyright (C) 2017 Kevin (OSS开源实验室) 公众号:osscore + +/*************************************************************************** +*   文件功能描述:OSSCore —— 领域请求扩展 +* +*   创建人: Kevin +* 创建人Email:1985088337@qq.com +* 创建日期:2017-4-21 +* +*****************************************************************************/ + +#endregion + +using System.Threading.Tasks; + +namespace OSS.Common.Domain +{ + /// + /// + /// + public static class DomainReqExtension + { + /// + /// 执行请求方法 + /// + /// + /// + /// + /// + public static Task ExecuteAsync(this IDoaminReq req) + where TReq : IDoaminReq + { + return DomainContainer.GetExecutor().ExecuteAsync((TReq)req); + } + } +} \ No newline at end of file diff --git a/OSS.Common/Pattern/Domain/Interface/IDoaminReq.cs b/OSS.Common/Pattern/Domain/Interface/IDoaminReq.cs new file mode 100644 index 0000000..3f3c629 --- /dev/null +++ b/OSS.Common/Pattern/Domain/Interface/IDoaminReq.cs @@ -0,0 +1,12 @@ +namespace OSS.Common.Domain +{ + /// + /// 领域的请求接口 + /// + /// + /// + public interface IDoaminReq + where TReq : IDoaminReq + { + } +} \ No newline at end of file diff --git a/OSS.Common/Pattern/Domain/Interface/IDomainExecutor.cs b/OSS.Common/Pattern/Domain/Interface/IDomainExecutor.cs new file mode 100644 index 0000000..1651d2b --- /dev/null +++ b/OSS.Common/Pattern/Domain/Interface/IDomainExecutor.cs @@ -0,0 +1,23 @@ + +using System.Threading.Tasks; + +namespace OSS.Common.Domain +{ + + /// + /// 领域执行处理接口 + /// + /// + /// + public interface IDomainExecutor + where TReq : IDoaminReq + { + /// + /// 执行方法 + /// + /// + /// + Task ExecuteAsync(TReq req); + } + +} diff --git a/OSS.Common/Pattern/Domain/Mo/BaseMo.cs b/OSS.Common/Pattern/Domain/Mo/BaseMo.cs new file mode 100644 index 0000000..810a273 --- /dev/null +++ b/OSS.Common/Pattern/Domain/Mo/BaseMo.cs @@ -0,0 +1,27 @@ +#region Copyright (C) 2017 Kevin (OSS开源实验室) 公众号:osscore + +/*************************************************************************** +*   文件功能描述:OSSCore —— 实体基类 +* +*   创建人: Kevin +* 创建人Email:1985088337@qq.com +* 创建日期:2017-4-21 +* +*****************************************************************************/ + +#endregion + +namespace OSS.Common.Domain +{ + /// + /// 基础领域对象 + /// + /// + public class BaseMo + { + /// + /// 主键Id + /// + public IdType id { get; set; } + } +} \ No newline at end of file diff --git a/OSS.Common/Instance/InsContainer.cs b/OSS.Common/Pattern/Instance/InsContainer.cs similarity index 92% rename from OSS.Common/Instance/InsContainer.cs rename to OSS.Common/Pattern/Instance/InsContainer.cs index 79da2fa..c32445a 100644 --- a/OSS.Common/Instance/InsContainer.cs +++ b/OSS.Common/Pattern/Instance/InsContainer.cs @@ -35,10 +35,8 @@ namespace OSS.Common /// /// 设置容器内映射的实例创建方法 /// - /// /// - public static void Set(Func insCreater) - where TInstance : T + public static void Set(Func insCreater) { _insCreater = insCreater ?? throw new ArgumentNullException(nameof(insCreater), "参数不能为空!"); } @@ -48,7 +46,7 @@ namespace OSS.Common /// /// /// - public static void Set(T ins) + public static void Set(TInstance ins) where TInstance : T { _insCreater = ()=>ins; diff --git a/OSS.Common/Instance/SingleInstance.cs b/OSS.Common/Pattern/Instance/SingleInstance.cs similarity index 100% rename from OSS.Common/Instance/SingleInstance.cs rename to OSS.Common/Pattern/Instance/SingleInstance.cs