mirror of
https://github.com/KevinWG/OSS.Common.git
synced 2026-10-28 13:50:52 +08:00
添加领域请求执行模型
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
@@ -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<TestItemMo>() { new TestItemMo() { house = "beijing", age = 20 } };
|
||||
|
||||
string reslt = obj.SerializeToXml();//"<xml><name><![CDATA[toUser]]></name> </xml>";
|
||||
var res = reslt.DeserializeXml<TestXml>();
|
||||
_ = reslt.DeserializeXml<TestXml>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
#region Copyright (C) 2019 (OSS开源系列) 公众号:OSSCore
|
||||
|
||||
/***************************************************************************
|
||||
* 文件功能描述:全局辅助类 - 单例基础实现
|
||||
*
|
||||
* 创建人: Kevin
|
||||
* 创建人Email:1985088337@qq.com
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace OSS.Common.BasicImpls
|
||||
{
|
||||
/// <summary>
|
||||
/// 单例基础实现
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
[Obsolete]
|
||||
public class SingleInstance<T>
|
||||
where T : new()
|
||||
{
|
||||
private static T _instance;
|
||||
private static readonly object _objLock = new object();
|
||||
|
||||
/// <summary>
|
||||
/// 获取单例实例
|
||||
/// </summary>
|
||||
/// <param name="initialCreator"></param>
|
||||
/// <returns></returns>
|
||||
public static T GetInstance(Func<T> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 单例实例
|
||||
/// </summary>
|
||||
public static T Instance => GetInstance();
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
#region Copyright (C) 2014 OS系列开源项目
|
||||
|
||||
/*
|
||||
文件功能描述:验证属性attribute
|
||||
|
||||
创建人:王超
|
||||
创建人Email:1985088337@qq.com
|
||||
创建日期:2014.08.25
|
||||
|
||||
修改描述:
|
||||
*/
|
||||
|
||||
#endregion
|
||||
using System;
|
||||
|
||||
namespace OSS.Common.Extention
|
||||
{
|
||||
/// <summary>
|
||||
/// 时间秒数转化
|
||||
/// </summary>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static class DateTimeExtention
|
||||
{
|
||||
private static readonly long startTicks = new DateTime(1970, 1, 1).Ticks;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取距离 1970-01-01(格林威治时间)的秒数
|
||||
/// </summary>
|
||||
/// <param name="localTime"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static long ToUtcSeconds(this DateTime localTime)
|
||||
{
|
||||
return (localTime.ToUniversalTime().Ticks - startTicks)/10000000;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 距离 1970-01-01(格林威治时间)的秒数转换为当前时间
|
||||
/// </summary>
|
||||
/// <param name="seconds"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static DateTime FromUtcSeconds(this long seconds)
|
||||
{
|
||||
return DateTimeOffset.FromUnixTimeSeconds(seconds).LocalDateTime;// new DateTime(1970, 1, 1).AddSeconds(seconds).ToLocalTime();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取距离 1970-01-01(格林威治时间)的毫秒数
|
||||
/// </summary>
|
||||
/// <param name="localTime"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static long ToUtcMilliSeconds(this DateTime localTime)
|
||||
{
|
||||
return (localTime.ToUniversalTime().Ticks - startTicks) / 10000;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 距离 1970-01-01(格林威治时间)的秒数转换为当前时间
|
||||
/// </summary>
|
||||
/// <param name="milliSeconds"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static DateTime FromUtcMilliSeconds(this long milliSeconds)
|
||||
{
|
||||
return DateTimeOffset.FromUnixTimeMilliseconds(milliSeconds).LocalDateTime;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取距离 1970-01-01(格林威治时间)Ticks 精确到0.1微秒(千万分之一秒)
|
||||
/// </summary>
|
||||
/// <param name="localTime"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static long ToUtcTicks(this DateTime localTime)
|
||||
{
|
||||
return localTime.ToUniversalTime().Ticks - startTicks ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取距离 1970-01-01(本地/北京时间)的秒数
|
||||
/// </summary>
|
||||
/// <param name="localTime"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static long ToLocalSeconds(this DateTime localTime)
|
||||
{
|
||||
return (localTime.Ticks - startTicks) / 10000000;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 距离 1970-01-01(本地/北京时间)的秒数转换为当前时间
|
||||
/// </summary>
|
||||
/// <param name="seconds"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static DateTime FromLocalSeconds(this long seconds)
|
||||
{
|
||||
return new DateTime(1970,1,1).AddSeconds(seconds);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 枚举扩展方法类
|
||||
/// </summary>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static class EnumExtention
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 获取描述
|
||||
/// </summary>
|
||||
/// <param name="en">枚举对象</param>
|
||||
/// <param name="isFlag">是否二进制取和</param>
|
||||
/// <param name="operate">多个描述分隔符</param>
|
||||
/// <returns></returns>
|
||||
[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<string, Dictionary<string, string>> enumDirs
|
||||
=new ConcurrentDictionary<string, Dictionary<string, string>>();
|
||||
|
||||
/// <summary>
|
||||
/// 获取枚举字典列表
|
||||
/// </summary>
|
||||
/// <param name="enType">枚举类型</param>
|
||||
/// <param name="isIntValue">返回枚举值是否是int类型</param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static Dictionary<string, string> 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<string, string>();
|
||||
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<OSDescriptAttribute>();
|
||||
|
||||
dirs.Add(resultValue, attr == null ? name : attr.Description);
|
||||
}
|
||||
enumDirs.TryAdd(key, dirs);
|
||||
return dirs.Copy();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝字典
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
private static Dictionary<string, string> Copy(this Dictionary<string, string> source)
|
||||
{
|
||||
return source.ToDictionary(sou => sou.Key, sou => sou.Value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自定义描述属性
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = true)]
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public class OSDescriptAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="description"></param>
|
||||
public OSDescriptAttribute(string description)
|
||||
{
|
||||
this.Description = description;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 描述信息
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OSS.Common.Extention
|
||||
{
|
||||
/// <summary>
|
||||
/// 列表扩展方法
|
||||
/// </summary>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static class ListExtention
|
||||
{
|
||||
/// <summary>
|
||||
/// List合并
|
||||
/// </summary>
|
||||
/// <typeparam name="T">数据类型</typeparam>
|
||||
/// <param name="target">目标对象</param>
|
||||
/// <param name="source">来源对象</param>
|
||||
/// <param name="checkFunc">重复项依据方法 true-没有重复项,可以合并,fale-有重复项,不能合并</param>
|
||||
/// <returns>返回合并后的目标对象 - 排除重复项</returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static IList<T> Merged<T>(this IList<T> target, IList<T> source, Func<IList<T>, T, bool> checkFunc)
|
||||
{
|
||||
foreach (var t in source)
|
||||
{
|
||||
if (checkFunc(target, t))
|
||||
{
|
||||
target.Add(t);
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 字符串通用功能
|
||||
/// </summary>
|
||||
[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'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 生成随机串
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[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";
|
||||
|
||||
/// <summary>
|
||||
/// 数字转化为短码
|
||||
/// </summary>
|
||||
/// <param name="num"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static string ToCode(this int num)
|
||||
{
|
||||
return ToCode(num, _arrCodeStr);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数字转化为短码
|
||||
/// </summary>
|
||||
/// <param name="num"></param>
|
||||
/// <param name="arrStrs">转换时映射字母,32位,不可重复</param>
|
||||
/// <returns></returns>
|
||||
[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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据短码反推数字
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="arrStrs">转换时映射字母,32位,不可重复</param>
|
||||
/// <returns></returns>
|
||||
[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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,180 +0,0 @@
|
||||
#region Copyright (C) 2017 公众号:OSSCore
|
||||
|
||||
/***************************************************************************
|
||||
* 文件功能描述:字符串编码扩展功能
|
||||
*
|
||||
* 创建人: Kevin
|
||||
* 创建人Email:1985088337@qq.com
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace OSS.Common.Extention
|
||||
{
|
||||
/// <summary>
|
||||
/// url扩展
|
||||
/// </summary>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static class StringEncodeExtension
|
||||
{
|
||||
#region Url 编码处理
|
||||
|
||||
/// <summary>
|
||||
/// Url编码处理
|
||||
/// </summary>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static string UrlEncode(this string input)
|
||||
{
|
||||
return string.IsNullOrEmpty(input)
|
||||
? string.Empty
|
||||
: Uri.EscapeDataString(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Url解码处理
|
||||
/// </summary>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static string UrlDecode(this string input)
|
||||
{
|
||||
return string.IsNullOrEmpty(input) ? string.Empty : Uri.UnescapeDataString(input);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Base64编码
|
||||
|
||||
/// <summary>
|
||||
/// 转换字符串为Base64编码
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="encoding"></param>
|
||||
/// <returns></returns>
|
||||
[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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解码Base64编码到字符串
|
||||
/// </summary>
|
||||
/// <param name="baseString"></param>
|
||||
/// <param name="encoding"></param>
|
||||
/// <returns></returns>
|
||||
[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);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 转换字符串为Base64编码,同时处理和url中冲突的字符(+,/,=)
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="encoding"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static string ToSafeUrlBase64(this string data, Encoding encoding = null)
|
||||
{
|
||||
return data.ToBase64(encoding).ReplaceBase64ToUrlSafe();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 解码Base64编码(特殊url冲突处理过的Base64编码)到字符串
|
||||
/// </summary>
|
||||
/// <param name="safeBaseString"></param>
|
||||
/// <param name="encoding"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static string FromSafeUrlBase64(this string safeBaseString, Encoding encoding = null)
|
||||
{
|
||||
return safeBaseString.ReplaceBase64UrlSafeBack().FromBase64(encoding);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理Base64字符串和url中冲突的字符(+,/,=)
|
||||
/// </summary>
|
||||
/// <param name="base64String"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static string ReplaceBase64ToUrlSafe(this string base64String)
|
||||
{
|
||||
return base64String.Replace('+', '-').Replace('/', '_').TrimEnd('=');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将url冲突处理过的Base64编码替换回正常Base64
|
||||
/// </summary>
|
||||
/// <param name="safeBase64String"></param>
|
||||
/// <returns></returns>
|
||||
[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;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 替换base64位字符串中的特殊符号 Url友好
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("请使用ReplaceBase64ToUrlSafe")]
|
||||
public static string Base64UrlSafeEncode(this string data)
|
||||
{
|
||||
return data.Replace('+', '-').Replace('/', '_').TrimEnd('=');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 还原 base64 字符串中的特殊字符 Url不友好
|
||||
/// </summary>
|
||||
/// <param name="baseString"></param>
|
||||
/// <returns></returns>
|
||||
[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
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,253 +0,0 @@
|
||||
#region Copyright (C) 2014 OS系列开源项目
|
||||
|
||||
/*
|
||||
文件功能描述:验证属性attribute
|
||||
|
||||
创建人:王超
|
||||
创建人Email:1985088337@qq.com
|
||||
创建日期:2014.08.25
|
||||
|
||||
修改描述:
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace OSS.Common.Extention
|
||||
{
|
||||
/// <summary>
|
||||
/// 字符串数字转化扩展
|
||||
/// </summary>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static class StringNumberExtention
|
||||
{
|
||||
#region 字符串数字转化部分
|
||||
|
||||
/// <summary>
|
||||
/// 字符串转化成无符号整形
|
||||
/// </summary>
|
||||
/// <param name="obj">要转化的值</param>
|
||||
/// <param name="defaultValue">如果转化失败,返回的默认值</param>
|
||||
/// <returns></returns>
|
||||
[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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字符串转化成数字
|
||||
/// </summary>
|
||||
/// <param name="obj">要转化的值</param>
|
||||
/// <param name="defaultValue">如果转化失败,返回的默认值</param>
|
||||
/// <returns></returns>
|
||||
[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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字符串转化成数字
|
||||
/// </summary>
|
||||
/// <param name="obj">要转化的值</param>
|
||||
/// <param name="defaultValue">如果转化失败,返回的默认值</param>
|
||||
/// <returns></returns>
|
||||
[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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 字符串转化成数字
|
||||
/// </summary>
|
||||
/// <param name="obj">要转化的值</param>
|
||||
/// <param name="defaultValue">如果转化失败,返回的默认值</param>
|
||||
/// <returns></returns>
|
||||
[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;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 字符串转化成数字
|
||||
/// </summary>
|
||||
/// <param name="obj">要转化的值</param>
|
||||
/// <param name="defaultValue">如果转化失败,返回的默认值</param>
|
||||
/// <returns></returns>
|
||||
[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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字符串转化成数字
|
||||
/// </summary>
|
||||
/// <param name="obj">要转化的值</param>
|
||||
/// <param name="defaultValue">如果转化失败,返回的默认值</param>
|
||||
/// <returns></returns>
|
||||
[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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转化成布尔类型
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[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
|
||||
|
||||
/// <summary>
|
||||
/// 过滤 Sql 语句字符串中的注入脚本
|
||||
/// </summary>
|
||||
/// <param name="source">传入的字符串</param>
|
||||
/// <returns>过滤后的字符串</returns>
|
||||
[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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 任务等待扩展
|
||||
/// </summary>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static class TaskExtention
|
||||
{
|
||||
/// <summary>
|
||||
/// 等待异步执行结果
|
||||
/// </summary>
|
||||
/// <typeparam name="TRes"></typeparam>
|
||||
/// <param name="task"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static TRes WaitResult<TRes>(this Task<TRes> task)
|
||||
{
|
||||
task.Wait();
|
||||
return task.Result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等待异步执行结果
|
||||
/// </summary>
|
||||
/// <typeparam name="TRes"></typeparam>
|
||||
/// <param name="task"></param>
|
||||
/// <param name="milliseconds">等待任务完成的毫秒数,-1,表示无限期等待</param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static TRes WaitResult<TRes>(this Task<TRes> task, int milliseconds)
|
||||
{
|
||||
task.Wait(milliseconds);
|
||||
return task.Result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 等待异步执行结果
|
||||
/// </summary>
|
||||
/// <param name="task"></param>
|
||||
/// <param name="span">等待时间间隔</param>
|
||||
/// <typeparam name="TRes"></typeparam>
|
||||
/// <returns></returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static TRes WaitResult<TRes>(this Task<TRes> task,TimeSpan span)
|
||||
{
|
||||
task.Wait(span);
|
||||
return task.Result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等待异步执行结果
|
||||
/// </summary>
|
||||
/// <param name="task"></param>
|
||||
/// <param name="token">等待任务完成期间要观察的取消标记</param>
|
||||
/// <typeparam name="TRes"></typeparam>
|
||||
/// <returns></returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static TRes WaitResult<TRes>(this Task<TRes> task, CancellationToken token)
|
||||
{
|
||||
task.Wait(token);
|
||||
return task.Result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等待异步执行结果
|
||||
/// </summary>
|
||||
/// <param name="task"></param>
|
||||
/// <param name="milliseconds">等待任务完成的毫秒数,-1,表示无限期等待</param>
|
||||
/// <param name="token">等待任务完成期间要观察的取消标记</param>
|
||||
/// <typeparam name="TRes"></typeparam>
|
||||
/// <returns></returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static TRes WaitResult<TRes>(this Task<TRes> task, int milliseconds,CancellationToken token)
|
||||
{
|
||||
task.Wait(milliseconds,token);
|
||||
return task.Result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = true)]
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public abstract class BaseValidateAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
protected string errorMessage;
|
||||
internal abstract bool Validate(string propertyName, object propertyValue);
|
||||
|
||||
/// <summary>
|
||||
/// 错误信息
|
||||
/// </summary>
|
||||
public string ErrorMessage => errorMessage;
|
||||
}
|
||||
/// <summary>
|
||||
/// 必填验证属性
|
||||
/// </summary>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public class OsRequiredAttribute : BaseValidateAttribute
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="_errorMessage"></param>
|
||||
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;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 数字验证属性
|
||||
/// </summary>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public class OsNumberAttribute : BaseValidateAttribute
|
||||
{
|
||||
private readonly long min;
|
||||
private readonly long max;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="_min"></param>
|
||||
/// <param name="_max"></param>
|
||||
/// <param name="_errorMessage"></param>
|
||||
public OsNumberAttribute(long _min=long.MinValue, long _max=long.MaxValue, string _errorMessage=null)
|
||||
{
|
||||
min = _min;
|
||||
max = _max;
|
||||
errorMessage = _errorMessage;
|
||||
}
|
||||
/// <summary>
|
||||
/// 验证方法
|
||||
/// </summary>
|
||||
/// <param name="propertyName"></param>
|
||||
/// <param name="propertyValue"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static class VolidateExtention
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否通过验证
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="t"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static bool IsOsValidate<T>(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<BaseValidateAttribute>()
|
||||
.Any(requireAttr => !requireAttr.Validate(fd1.Name, fd1.GetValue(t, null))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回的验证错误信息
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="t"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static List<string> ValidateOsMessage<T>(this T t) where T : class, new()
|
||||
{
|
||||
List<string> resultList = new List<string>();
|
||||
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<BaseValidateAttribute>()
|
||||
let result = requireAttr.Validate(fd1.Name, fd1.GetValue(t, null))
|
||||
where !result
|
||||
select requireAttr)
|
||||
{
|
||||
resultList.Add(requireAttr.ErrorMessage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static class TypeHelper
|
||||
{
|
||||
private static ConcurrentDictionary<string, object[]> attrDirs = new ConcurrentDictionary<string, object[]>();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="typeName"></param>
|
||||
/// <param name="fd"></param>
|
||||
/// <param name="attributeType"></param>
|
||||
/// <returns></returns>
|
||||
[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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private static ConcurrentDictionary<string, PropertyInfo[]> proDictionaries =
|
||||
new ConcurrentDictionary<string, PropertyInfo[]>();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
[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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// xml 转化扩展
|
||||
/// </summary>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static class XmlConvertExtention
|
||||
{
|
||||
/// <summary>
|
||||
/// 对象序列化成xml字符串
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
/// <returns></returns>
|
||||
[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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// xml字符串转化到对象
|
||||
/// </summary>
|
||||
/// <typeparam name="TT"></typeparam>
|
||||
/// <param name="xml"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("迁移至OSS.Common.Extension命名空间下")]
|
||||
public static TT DeserializeXml<TT>(this string xml)
|
||||
where TT : class
|
||||
{
|
||||
return DeserializeXml(xml, typeof(TT)) as TT;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// xml字符串转化到对象
|
||||
/// </summary>
|
||||
/// <param name="xml"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
[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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
#region Copyright (C) 2019 (OSS开源系列) 公众号:OSSCore
|
||||
|
||||
/***************************************************************************
|
||||
* 文件功能描述:全局辅助类 - Ioc简单实例容器
|
||||
*
|
||||
* 创建人: Kevin
|
||||
* 创建人Email:1985088337@qq.com
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace OSS.Common.Helpers
|
||||
{
|
||||
///// <summary>
|
||||
///// Ioc简单实例容器实现
|
||||
///// </summary>
|
||||
///// <typeparam name="T"></typeparam>
|
||||
//[Obsolete]
|
||||
//public static class InsContainer<T>
|
||||
//{
|
||||
// private static Func<T> _insCreater;
|
||||
|
||||
// /// <summary>
|
||||
// /// 具体实例
|
||||
// /// 根据设置时参数会返回具体单例还是新的实例
|
||||
// /// </summary>
|
||||
// public static T Instance => _insCreater != null
|
||||
// ? _insCreater()
|
||||
// : throw new NullReferenceException($"未能发现{typeof(T)}在容器具体映射类型/实例");
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// 设置容器内映射的实例创建方法
|
||||
// /// </summary>
|
||||
// /// <typeparam name="TInstance"></typeparam>
|
||||
// /// <param name="insCreater"></param>
|
||||
// public static void Set<TInstance>(Func<T> insCreater)
|
||||
// where TInstance : T
|
||||
// {
|
||||
// _insCreater = insCreater ?? throw new ArgumentNullException(nameof(insCreater), "参数不能为空!");
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 设置容器内映射的具体类型
|
||||
// /// </summary>
|
||||
// /// <typeparam name="TInstance"></typeparam>
|
||||
// /// <param name="ins"></param>
|
||||
// public static void Set<TInstance>(T ins)
|
||||
// where TInstance : T
|
||||
// {
|
||||
// _insCreater = ()=>ins;
|
||||
// }
|
||||
|
||||
// private static T _instance;
|
||||
// private static readonly object _objLock = new object();
|
||||
|
||||
// /// <summary>
|
||||
// /// 设置容器内映射的具体类型
|
||||
// /// </summary>
|
||||
// /// <typeparam name="TInstance"></typeparam>
|
||||
// /// <param name="isSingle"></param>
|
||||
// public static void Set<TInstance>(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;
|
||||
// };
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
|
||||
<Version>2.6.3</Version>
|
||||
<Version>3.0</Version>
|
||||
<Authors>OSSCore</Authors>
|
||||
<Company>OSSCore</Company>
|
||||
<Product>OSS开源系列</Product>
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
<PackageIcon>logo.png</PackageIcon>
|
||||
|
||||
<PackageReleaseNotes>完善错误类型</PackageReleaseNotes>
|
||||
<PackageReleaseNotes></PackageReleaseNotes>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
|
||||
namespace OSS.Common.Domain
|
||||
{
|
||||
/// <summary>
|
||||
/// 领域容器
|
||||
/// </summary>
|
||||
/// <typeparam name="TReq"></typeparam>
|
||||
/// <typeparam name="TRes"></typeparam>
|
||||
public static class DomainContainer<TReq, TRes>
|
||||
where TReq : IDoaminReq<TReq, TRes>
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取 执行实例
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static IDomainExecutor<TReq, TRes> GetExecutor()
|
||||
{
|
||||
return InsContainer<IDomainExecutor<TReq, TRes>>.Instance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置容器内映射的执行实例类型
|
||||
/// </summary>
|
||||
/// <typeparam name="TExecutor"></typeparam>
|
||||
public static void SetExecutor<TExecutor>()
|
||||
where TExecutor : IDomainExecutor<TReq, TRes>, new()
|
||||
{
|
||||
InsContainer<IDomainExecutor<TReq, TRes>>.Set<TExecutor>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置容器内映射的执行实例创建方法
|
||||
/// </summary>
|
||||
/// <param name="insCreater"></param>
|
||||
public static void SetExecutor(Func<IDomainExecutor<TReq, TRes>> insCreater)
|
||||
{
|
||||
InsContainer<IDomainExecutor<TReq, TRes>>.Set(insCreater);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置容器内映射的具体实例
|
||||
/// </summary>
|
||||
/// <typeparam name="TExecutor"></typeparam>
|
||||
/// <param name="ins"></param>
|
||||
public static void SetExecutor<TExecutor>(TExecutor ins)
|
||||
where TExecutor : IDomainExecutor<TReq, TRes>, new()
|
||||
{
|
||||
InsContainer<IDomainExecutor<TReq, TRes>>.Set(ins);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class DomainReqExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// 执行请求方法
|
||||
/// </summary>
|
||||
/// <typeparam name="TReq"></typeparam>
|
||||
/// <typeparam name="TRes"></typeparam>
|
||||
/// <param name="req"></param>
|
||||
/// <returns></returns>
|
||||
public static Task<TRes> ExecuteAsync<TReq, TRes>(this IDoaminReq<TReq, TRes> req)
|
||||
where TReq : IDoaminReq<TReq, TRes>
|
||||
{
|
||||
return DomainContainer<TReq,TRes>.GetExecutor().ExecuteAsync((TReq)req);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace OSS.Common.Domain
|
||||
{
|
||||
/// <summary>
|
||||
/// 领域的请求接口
|
||||
/// </summary>
|
||||
/// <typeparam name="TReq"></typeparam>
|
||||
/// <typeparam name="TRes"></typeparam>
|
||||
public interface IDoaminReq<in TReq, out TRes>
|
||||
where TReq : IDoaminReq<TReq, TRes>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OSS.Common.Domain
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 领域执行处理接口
|
||||
/// </summary>
|
||||
/// <typeparam name="TReq"></typeparam>
|
||||
/// <typeparam name="TRes"></typeparam>
|
||||
public interface IDomainExecutor<in TReq, TRes>
|
||||
where TReq : IDoaminReq<TReq, TRes>
|
||||
{
|
||||
/// <summary>
|
||||
/// 执行方法
|
||||
/// </summary>
|
||||
/// <param name="req"></param>
|
||||
/// <returns></returns>
|
||||
Task<TRes> ExecuteAsync(TReq req);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 基础领域对象
|
||||
/// </summary>
|
||||
/// <typeparam name="IdType"></typeparam>
|
||||
public class BaseMo<IdType>
|
||||
{
|
||||
/// <summary>
|
||||
/// 主键Id
|
||||
/// </summary>
|
||||
public IdType id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -35,10 +35,8 @@ namespace OSS.Common
|
||||
/// <summary>
|
||||
/// 设置容器内映射的实例创建方法
|
||||
/// </summary>
|
||||
/// <typeparam name="TInstance"></typeparam>
|
||||
/// <param name="insCreater"></param>
|
||||
public static void Set<TInstance>(Func<T> insCreater)
|
||||
where TInstance : T
|
||||
public static void Set(Func<T> insCreater)
|
||||
{
|
||||
_insCreater = insCreater ?? throw new ArgumentNullException(nameof(insCreater), "参数不能为空!");
|
||||
}
|
||||
@@ -48,7 +46,7 @@ namespace OSS.Common
|
||||
/// </summary>
|
||||
/// <typeparam name="TInstance"></typeparam>
|
||||
/// <param name="ins"></param>
|
||||
public static void Set<TInstance>(T ins)
|
||||
public static void Set<TInstance>(TInstance ins)
|
||||
where TInstance : T
|
||||
{
|
||||
_insCreater = ()=>ins;
|
||||
Reference in New Issue
Block a user