增加项目,分层
This commit is contained in:
1 parent
6e995a5bdb
commit
0a3e5af6a9
234 files changed
+26994
-1
No files matched your search
@@ -0,0 +1,35 @@
|
||||
using MAX.Core.Cryptography;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Store.Framework.Extensions
|
||||
{
|
||||
public static class DictionaryExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// 字典转url Get 参数
|
||||
/// </summary>
|
||||
/// <param name="parameters"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToUrlParams(this IDictionary<string, string> parameters, bool IsUrlEncode = true)
|
||||
{
|
||||
IDictionary<string, string> sortedParams = new SortedDictionary<string, string>(parameters);
|
||||
IEnumerator<KeyValuePair<string, string>> dem = sortedParams.GetEnumerator();
|
||||
StringBuilder sb = new StringBuilder("");
|
||||
while (dem.MoveNext())
|
||||
{
|
||||
string key = dem.Current.Key;
|
||||
string value = dem.Current.Value;
|
||||
if (!string.IsNullOrEmpty(key))
|
||||
{
|
||||
sb.Append(key).Append("=").Append(IsUrlEncode ? UrlHelper.Encode(value) : value).Append("&");
|
||||
|
||||
}
|
||||
}
|
||||
string content = sb.ToString().Substring(0, sb.Length - 1);
|
||||
|
||||
return content;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,560 @@
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
|
||||
namespace Store.Framework.Extensions;
|
||||
|
||||
|
||||
public static class Extensions
|
||||
{
|
||||
public static long ParseToLong(this object obj)
|
||||
{
|
||||
try
|
||||
{
|
||||
string text = ParseToString(obj);
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
return 0L;
|
||||
}
|
||||
return long.Parse(text);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
public static long ParseToLong(this string str, long defaultValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
return long.Parse(str);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static int ParseToInt(this object str)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Convert.ToInt32(str);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static int DecimalPointParseToInt(this object str)
|
||||
{
|
||||
try
|
||||
{
|
||||
string text = ParseToString(str);
|
||||
int num = text.IndexOf('.');
|
||||
if (num > 0)
|
||||
{
|
||||
text = text.Substring(0, num);
|
||||
}
|
||||
return Convert.ToInt32(text);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static int ParseToInt(this object str, int defaultValue)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
try
|
||||
{
|
||||
return Convert.ToInt32(str);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static short ParseToShort(this object obj)
|
||||
{
|
||||
try
|
||||
{
|
||||
return short.Parse(obj.ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static short ParseToShort(this object str, short defaultValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
return short.Parse(str.ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static decimal ParseToDecimal(this object str, decimal defaultValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
return decimal.Parse(str.ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static decimal ParseToDecimal(this object str)
|
||||
{
|
||||
try
|
||||
{
|
||||
return decimal.Parse(str.ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 0m;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ParseToBool(this object str)
|
||||
{
|
||||
try
|
||||
{
|
||||
return bool.Parse(str.ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ParseToBool(this object str, bool result)
|
||||
{
|
||||
try
|
||||
{
|
||||
return bool.Parse(str.ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static float ParseToFloat(this object str)
|
||||
{
|
||||
try
|
||||
{
|
||||
return float.Parse(str.ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
|
||||
public static float ParseToFloat(this object str, float result)
|
||||
{
|
||||
try
|
||||
{
|
||||
return float.Parse(str.ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static Guid ParseToGuid(this string str)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new Guid(str);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Guid.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static DateTime ParseToDateTime(this string str)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(str))
|
||||
{
|
||||
return DateTime.MinValue;
|
||||
}
|
||||
if (str.Contains("-") || str.Contains("/"))
|
||||
{
|
||||
return DateTime.Parse(str);
|
||||
}
|
||||
return str.Length switch
|
||||
{
|
||||
4 => DateTime.ParseExact(str, "yyyy", CultureInfo.CurrentCulture),
|
||||
6 => DateTime.ParseExact(str, "yyyyMM", CultureInfo.CurrentCulture),
|
||||
8 => DateTime.ParseExact(str, "yyyyMMdd", CultureInfo.CurrentCulture),
|
||||
10 => DateTime.ParseExact(str, "yyyyMMddHH", CultureInfo.CurrentCulture),
|
||||
12 => DateTime.ParseExact(str, "yyyyMMddHHmm", CultureInfo.CurrentCulture),
|
||||
14 => DateTime.ParseExact(str, "yyyyMMddHHmmss", CultureInfo.CurrentCulture),
|
||||
_ => DateTime.ParseExact(str, "yyyyMMddHHmmss", CultureInfo.CurrentCulture),
|
||||
};
|
||||
}
|
||||
catch
|
||||
{
|
||||
return DateTime.MinValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static DateTime ParseToDateTime(this string str, DateTime? defaultValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(str))
|
||||
{
|
||||
return defaultValue.GetValueOrDefault();
|
||||
}
|
||||
if (str.Contains("-") || str.Contains("/"))
|
||||
{
|
||||
return DateTime.Parse(str);
|
||||
}
|
||||
return str.Length switch
|
||||
{
|
||||
4 => DateTime.ParseExact(str, "yyyy", CultureInfo.CurrentCulture),
|
||||
6 => DateTime.ParseExact(str, "yyyyMM", CultureInfo.CurrentCulture),
|
||||
8 => DateTime.ParseExact(str, "yyyyMMdd", CultureInfo.CurrentCulture),
|
||||
10 => DateTime.ParseExact(str, "yyyyMMddHH", CultureInfo.CurrentCulture),
|
||||
12 => DateTime.ParseExact(str, "yyyyMMddHHmm", CultureInfo.CurrentCulture),
|
||||
14 => DateTime.ParseExact(str, "yyyyMMddHHmmss", CultureInfo.CurrentCulture),
|
||||
_ => DateTime.ParseExact(str, "yyyyMMddHHmmss", CultureInfo.CurrentCulture),
|
||||
};
|
||||
}
|
||||
catch
|
||||
{
|
||||
return defaultValue.GetValueOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public static string ParseToString(this object obj)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
return obj.ToString();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static string ParseToStrings<T>(this object obj, string split = ",")
|
||||
{
|
||||
try
|
||||
{
|
||||
if (obj is IEnumerable<T> values)
|
||||
{
|
||||
return string.Join(split, values);
|
||||
}
|
||||
return obj.ToString();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static double ParseToDouble(this object obj)
|
||||
{
|
||||
try
|
||||
{
|
||||
return double.Parse(obj.ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
public static double ParseToDouble(this object str, double defaultValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
return double.Parse(str.ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static T[] SplitToArray<T>(this string value, string split = ",")
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return CastSuper<T>(value.Split(new string[1] { split }, StringSplitOptions.RemoveEmptyEntries)).ToArray();
|
||||
}
|
||||
|
||||
public static T[] SplitToArray<T>(this string value, string[] split)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return CastSuper<T>(value.Split(split, StringSplitOptions.RemoveEmptyEntries)).ToArray();
|
||||
}
|
||||
|
||||
public static List<T> SplitToList<T>(this string value, string split = ",")
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
return new List<T>();
|
||||
}
|
||||
return CastSuper<T>(value.Split(new string[1] { split }, StringSplitOptions.RemoveEmptyEntries)).ToList();
|
||||
}
|
||||
|
||||
public static List<T> SplitToList<T>(this string value, string[] split)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
return new List<T>();
|
||||
}
|
||||
return CastSuper<T>(value.Split(split, StringSplitOptions.RemoveEmptyEntries)).ToList();
|
||||
}
|
||||
|
||||
public static IEnumerable<TResult> CastSuper<TResult>(this IEnumerable source)
|
||||
{
|
||||
foreach (object item in source)
|
||||
{
|
||||
yield return (TResult)Convert.ChangeType(item, typeof(TResult));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static Dictionary<int, string> EnumToDictionary(this Type enumType)
|
||||
{
|
||||
Dictionary<int, string> dictionary = new Dictionary<int, string>();
|
||||
Type typeFromHandle = typeof(DescriptionAttribute);
|
||||
FieldInfo[] fields = enumType.GetFields();
|
||||
int num = 0;
|
||||
string empty = string.Empty;
|
||||
FieldInfo[] array = fields;
|
||||
foreach (FieldInfo fieldInfo in array)
|
||||
{
|
||||
if (fieldInfo.FieldType.IsEnum)
|
||||
{
|
||||
num = (int)enumType.InvokeMember(fieldInfo.Name, BindingFlags.GetField, null, null, null);
|
||||
object[] customAttributes = fieldInfo.GetCustomAttributes(typeFromHandle, inherit: true);
|
||||
if (customAttributes.Length != 0)
|
||||
{
|
||||
DescriptionAttribute descriptionAttribute = (DescriptionAttribute)customAttributes[0];
|
||||
empty = descriptionAttribute.Description;
|
||||
}
|
||||
else
|
||||
{
|
||||
empty = fieldInfo.Name;
|
||||
}
|
||||
dictionary.Add(num, empty);
|
||||
}
|
||||
}
|
||||
return dictionary.OrderBy((KeyValuePair<int, string> p) => p.Key).ToDictionary((KeyValuePair<int, string> p) => p.Key, (KeyValuePair<int, string> p) => p.Value);
|
||||
}
|
||||
|
||||
public static string GetDescription(this Enum enumType)
|
||||
{
|
||||
FieldInfo field = enumType.GetType().GetField(enumType.ToString());
|
||||
if (field != null)
|
||||
{
|
||||
DescriptionAttribute[] array = (DescriptionAttribute[])field.GetCustomAttributes(typeof(DescriptionAttribute), inherit: false);
|
||||
if (array.Length != 0)
|
||||
{
|
||||
return array[0].Description;
|
||||
}
|
||||
}
|
||||
return enumType.ToString();
|
||||
}
|
||||
|
||||
public static string GetDescriptionByEnum<T>(this object obj)
|
||||
{
|
||||
Enum enumType = Enum.Parse(typeof(T), ParseToString(obj)) as Enum;
|
||||
return GetDescription(enumType);
|
||||
}
|
||||
|
||||
public static int GetEnumValueByDescription<T>(this string description)
|
||||
{
|
||||
Dictionary<int, string> source = EnumToDictionary(typeof(T));
|
||||
return (from p in source
|
||||
where p.Value == description
|
||||
select p.Key).FirstOrDefault();
|
||||
}
|
||||
|
||||
public static int GetEnumValueByName<T>(this string name)
|
||||
{
|
||||
return (int)Enum.Parse(typeof(T), name);
|
||||
}
|
||||
|
||||
public static object GetEnumNameByValue<T>(this int value)
|
||||
{
|
||||
return Enum.ToObject(typeof(T), value);
|
||||
}
|
||||
|
||||
public static Exception GetOriginalException(this Exception ex)
|
||||
{
|
||||
if (ex.InnerException == null)
|
||||
{
|
||||
return ex;
|
||||
}
|
||||
return GetOriginalException(ex.InnerException);
|
||||
}
|
||||
|
||||
public static bool IsNullOrEmpty(this object value)
|
||||
{
|
||||
if (value != null && !string.IsNullOrEmpty(ParseToString(value)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool IsNullOrZero(this object value)
|
||||
{
|
||||
if (value == null || string.IsNullOrEmpty(ParseToString(value)) || ParseToString(value).Trim() == "0")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsNumericType(this object value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
TypeCode typeCode = Type.GetTypeCode(value.GetType());
|
||||
TypeCode typeCode2 = typeCode;
|
||||
if ((uint)(typeCode2 - 5) <= 10u)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsStringType(this object value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
TypeCode typeCode = Type.GetTypeCode(value.GetType());
|
||||
TypeCode typeCode2 = typeCode;
|
||||
if (typeCode2 == TypeCode.String)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsNumber(this string value)
|
||||
{
|
||||
return RegexHelper.IsNumber(value);
|
||||
}
|
||||
|
||||
public static bool IsAlphabet(this string value)
|
||||
{
|
||||
return RegexHelper.IsAlphabet(value);
|
||||
}
|
||||
|
||||
public static bool IsAlphabetOrNumber(this string value)
|
||||
{
|
||||
return RegexHelper.IsAlphabetOrNumber(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
public class RegexHelper
|
||||
{
|
||||
public static MatchCollection GetMatchCollection(string html, string regex)
|
||||
{
|
||||
if (string.IsNullOrEmpty(html))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return Regex.Matches(html, regex, RegexOptions.IgnoreCase);
|
||||
}
|
||||
|
||||
public static string GetMatch(string html, string regex, int index = 0)
|
||||
{
|
||||
if (string.IsNullOrEmpty(html))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
MatchCollection matchCollection = Regex.Matches(html, regex, RegexOptions.IgnoreCase);
|
||||
if (matchCollection.Count > 0)
|
||||
{
|
||||
return matchCollection[index].Groups[1].Value.ToString();
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static string GetMatchWithSingleLine(string html, string regex)
|
||||
{
|
||||
if (string.IsNullOrEmpty(html))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
MatchCollection matchCollection = Regex.Matches(html, regex, RegexOptions.IgnoreCase | RegexOptions.Singleline);
|
||||
if (matchCollection.Count > 0)
|
||||
{
|
||||
return matchCollection[0].Groups[1].ToString();
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static bool IsNumber(string str)
|
||||
{
|
||||
Regex regex = new Regex("^[0-9\\.]+$");
|
||||
return regex.IsMatch(str);
|
||||
}
|
||||
|
||||
public static bool IsAlphabet(string str)
|
||||
{
|
||||
Regex regex = new Regex("^[A-Za-z]+$");
|
||||
return regex.IsMatch(str);
|
||||
}
|
||||
|
||||
public static bool IsAlphabetOrNumber(string str)
|
||||
{
|
||||
Regex regex = new Regex("^[A-Za-z0-9]+$");
|
||||
return regex.IsMatch(str);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
using MAX.Core.Helpers;
|
||||
using Store.Client.Commons;
|
||||
using Store.Client.HttpExtension;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Client.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 请求扩展
|
||||
/// </summary>
|
||||
public static class HttpItemExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 增加签名
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
public static void Sign(this ServerHttpItem item)
|
||||
{
|
||||
SetSign(item, SignTool.GetSign());
|
||||
}
|
||||
/// <summary>
|
||||
/// 增加用户签名
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
public static void SignUser(this ServerHttpItem item)
|
||||
{
|
||||
item.SignUser("", "");
|
||||
}
|
||||
/// <summary>
|
||||
/// 增加用户签名
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="shopId"></param>
|
||||
/// <param name="shopName"></param>
|
||||
public static void SignUser(this ServerHttpItem item, string shopId, string shopName)
|
||||
{
|
||||
SetSign(item, SignTool.GetUserSign(shopId, shopName));
|
||||
}
|
||||
private static void SetSign(ServerHttpItem item, string sign)
|
||||
{
|
||||
if (item.Method == MethodType.Get)
|
||||
{
|
||||
if (item.URL.Contains("?"))
|
||||
{
|
||||
item.URL += "&";
|
||||
}
|
||||
else
|
||||
{
|
||||
item.URL += "?";
|
||||
}
|
||||
item.URL += sign;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.Postdata.Length > 0)
|
||||
{
|
||||
item.Postdata += "&";
|
||||
}
|
||||
item.Postdata += sign;
|
||||
}
|
||||
item.IsSign = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
//using Autofac;
|
||||
////////////////using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
//using System.Threading.Tasks;
|
||||
|
||||
//namespace LittleCow.Framework.Extensions
|
||||
//{
|
||||
//public static class InitialDataMiddlewareExtensions
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// 加载所有初始化信息
|
||||
// /// </summary>
|
||||
// /// <param name="engine"></param>
|
||||
// /// <returns></returns>
|
||||
// public static LittleBootstrap UseInitData(this LittleBootstrap engine)
|
||||
// {
|
||||
// engine.UseMiddleware<InitialDataMiddleware>();
|
||||
// return engine;
|
||||
// }
|
||||
//}
|
||||
//public class InitialDataMiddleware : IEngine, ILoginSuccessed
|
||||
//{
|
||||
// private IInitialLoading[] listInit = new IInitialLoading[0];
|
||||
// public void Build()
|
||||
// {
|
||||
// listInit = IocManager.ResolveAll<IInitialLoading>();
|
||||
// listInit = listInit.OrderBy(a => a.Order).ToArray();
|
||||
// foreach (IInitialLoading item in listInit)
|
||||
// {
|
||||
// item.AppInit();
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// public void Use()
|
||||
// {
|
||||
|
||||
// }
|
||||
|
||||
// void ILoginSuccessed.LoginSuccess(UserInfo user)
|
||||
// {
|
||||
// foreach (IInitialLoading item in listInit)
|
||||
// {
|
||||
// item.LoginInit();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//}
|
||||
Reference in new issue
Block a user