Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/ZKEACMS/ZKEACMS.csproj
  • Loading branch information
SeriaWei committed Oct 15, 2023
2 parents abb0338 + 7143579 commit bc5fd20
Show file tree
Hide file tree
Showing 48 changed files with 800 additions and 555 deletions.
8 changes: 4 additions & 4 deletions src/EasyFrameWork/EasyFrameWork.csproj
Expand Up @@ -20,13 +20,13 @@
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
<PackageReference Include="FastExpressionCompiler" Version="3.3.4" />
<PackageReference Include="IdGen" Version="3.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.12" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.12" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="7.0.0" />
<PackageReference Include="System.Reflection.Extensions" Version="4.3.0" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.7.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="YamlDotNet" Version="13.3.1" />
<PackageReference Include="YamlDotNet" Version="13.7.0" />
</ItemGroup>
</Project>
122 changes: 74 additions & 48 deletions src/EasyFrameWork/Extend/ExtString.cs
Expand Up @@ -9,35 +9,78 @@

namespace Easy.Extend
{
public static class ExtString
public static partial class ExtString
{
public static string NoHTML(this string Htmlstring)
{
Htmlstring = Regex.Replace(Htmlstring, @"<script[\s\S]*?</script>", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"<noscript[\s\S]*?</noscript>", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"<style[\s\S]*?</style>", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"<.*?>", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", " ", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", " ", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"-->", " ", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", " ", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", " ", RegexOptions.IgnoreCase);
[GeneratedRegex("<script[\\s\\S]*?</script>", RegexOptions.IgnoreCase)]
private static partial Regex RegexScripts();
[GeneratedRegex("<noscript[\\s\\S]*?</noscript>", RegexOptions.IgnoreCase)]
private static partial Regex RegexNoScript();
[GeneratedRegex("<style[\\s\\S]*?</style>", RegexOptions.IgnoreCase)]
private static partial Regex RegexStyle();
[GeneratedRegex("<.*?>", RegexOptions.IgnoreCase)]
private static partial Regex RegexTags();
[GeneratedRegex("<(.[^>]*)>", RegexOptions.IgnoreCase)]
private static partial Regex RegexTag2();
[GeneratedRegex("([\\r\\n])[\\s]+", RegexOptions.IgnoreCase)]
private static partial Regex RegexWhiteSpace();
[GeneratedRegex("-->", RegexOptions.IgnoreCase)]
private static partial Regex RegexCommentEnd();
[GeneratedRegex("<!--.*", RegexOptions.IgnoreCase)]
private static partial Regex RegexCommentBegin();
[GeneratedRegex("&(quot|#34);", RegexOptions.IgnoreCase)]
private static partial Regex RegexQuote();
[GeneratedRegex("&(amp|#38);", RegexOptions.IgnoreCase)]
private static partial Regex RegexAMP();
[GeneratedRegex("&(lt|#60);", RegexOptions.IgnoreCase)]
private static partial Regex RegexLt();
[GeneratedRegex("&(gt|#62);", RegexOptions.IgnoreCase)]
private static partial Regex RegexGt();
[GeneratedRegex("&(nbsp|#160);", RegexOptions.IgnoreCase)]
private static partial Regex RegexNbsp();
[GeneratedRegex("&(iexcl|#161);", RegexOptions.IgnoreCase)]
private static partial Regex RegexIexcl();
[GeneratedRegex("&(cent|#162);", RegexOptions.IgnoreCase)]
private static partial Regex RegexCent();
[GeneratedRegex("&(pound|#163);", RegexOptions.IgnoreCase)]
private static partial Regex RegexPound();
[GeneratedRegex("&(copy|#169);", RegexOptions.IgnoreCase)]
private static partial Regex RegexCopy();
[GeneratedRegex("&#(\\d+);", RegexOptions.IgnoreCase)]
private static partial Regex RegexNumber();
[GeneratedRegex("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", RegexOptions.Singleline | RegexOptions.CultureInvariant)]
private static partial Regex RegexEmail();
[GeneratedRegex("(http|https)://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?", RegexOptions.Singleline | RegexOptions.CultureInvariant)]
private static partial Regex RegexUrl();

public static string RemoveHtml(this string Htmlstring)
{
const string _singleSpace = " ";

Htmlstring = RegexScripts().Replace(Htmlstring, string.Empty);
Htmlstring = RegexNoScript().Replace(Htmlstring, string.Empty);
Htmlstring = RegexStyle().Replace(Htmlstring, string.Empty);
Htmlstring = RegexTags().Replace(Htmlstring, string.Empty);
Htmlstring = RegexTag2().Replace(Htmlstring, _singleSpace);
Htmlstring = RegexWhiteSpace().Replace(Htmlstring, _singleSpace);
Htmlstring = RegexCommentEnd().Replace(Htmlstring, _singleSpace);
Htmlstring = RegexCommentBegin().Replace(Htmlstring, _singleSpace);
Htmlstring = RegexQuote().Replace(Htmlstring, "\"");
Htmlstring = RegexAMP().Replace(Htmlstring, "&");
Htmlstring = RegexLt().Replace(Htmlstring, "<");
Htmlstring = RegexGt().Replace(Htmlstring, ">");
Htmlstring = RegexNbsp().Replace(Htmlstring, string.Empty);
Htmlstring = RegexIexcl().Replace(Htmlstring, "\xa1");
Htmlstring = RegexCent().Replace(Htmlstring, "\xa2");
Htmlstring = RegexPound().Replace(Htmlstring, "\xa3");
Htmlstring = RegexCopy().Replace(Htmlstring, "\xa9");
Htmlstring = RegexNumber().Replace(Htmlstring, _singleSpace);
return Htmlstring;
}


public static byte[] ToByte(this string value)
{
return System.Text.Encoding.UTF8.GetBytes(value);
return Encoding.UTF8.GetBytes(value);
}


Expand All @@ -54,12 +97,12 @@ public static string HtmlEncode(this string value)
public static string UrlEncode(this string value)
{
StringBuilder sb = new StringBuilder();
byte[] byStr = System.Text.Encoding.UTF8.GetBytes(value);
byte[] byStr = Encoding.UTF8.GetBytes(value);
for (int i = 0; i < byStr.Length; i++)
{
sb.Append(@"%" + Convert.ToString(byStr[i], 16));
}
return (sb.ToString());
return sb.ToString();
}


Expand All @@ -74,11 +117,6 @@ public static string ToUnicode(this string value)
return builder.ToString();
}

private static readonly Regex emailExpression = new Regex(@"^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.Compiled);
private static readonly Regex webUrlExpression = new Regex(@"(http|https)://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?", RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.Compiled);
private static readonly Regex stripHTMLExpression = new Regex("<\\S[^><]*>", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.Compiled);


public static string FormatWith(this string instance, params object[] args)
{
return string.Format(instance, args);
Expand Down Expand Up @@ -110,19 +148,15 @@ public static string FormatWith(this string instance, params object[] args)
return convertedValue;
}

public static string StripHtml(this string instance)
{
return stripHTMLExpression.Replace(instance, string.Empty);
}

public static bool IsEmail(this string instance)
{
return !string.IsNullOrWhiteSpace(instance) && emailExpression.IsMatch(instance);
return !string.IsNullOrWhiteSpace(instance) && RegexEmail().IsMatch(instance);
}

public static bool IsWebUrl(this string instance)
{
return !string.IsNullOrWhiteSpace(instance) && webUrlExpression.IsMatch(instance);
return !string.IsNullOrWhiteSpace(instance) && RegexUrl().IsMatch(instance);
}


Expand All @@ -140,16 +174,16 @@ public static DateTime AsDateTime(this string instance)
return result;
}

public static Decimal AsDecimal(this string instance)
public static decimal AsDecimal(this string instance)
{
var result = (decimal)0.0;
Decimal.TryParse(instance, out result);
decimal.TryParse(instance, out result);
return result;
}

public static int AsInt(this string instance)
{
var result = (int)0;
var result = 0;
int.TryParse(instance, out result);
return result;
}
Expand Down Expand Up @@ -188,17 +222,9 @@ public static bool IsNullOrEmpty(this string theString)
return string.IsNullOrEmpty(theString);
}

public static string FirstCharToLowerCase(this string instance)
public static string ToCamelCaseNaming(this string instance)
{
if (instance.IsNotNullAndWhiteSpace() && instance.Length > 2 && char.IsUpper(instance[0]))
{
return char.ToLower(instance[0]) + instance.Substring(1);
}
if (instance.Length == 2)
{
return instance.ToLower();
}
return instance;
return System.Text.Json.JsonNamingPolicy.CamelCase.ConvertName(instance);
}
public static string ToFilePath(this string path)
{
Expand Down
2 changes: 1 addition & 1 deletion src/EasyFrameWork/Mvc/Controllers/DataTableOption.cs
Expand Up @@ -91,7 +91,7 @@ public bool IsOrderDescending()
}
public void AppendCondition(string property, string value, Query.Operators operators = Query.Operators.Equal)
{
property = property.FirstCharToLowerCase();
property = property.ToCamelCaseNaming();
foreach (var item in Columns)
{
if (item.Data == property)
Expand Down
6 changes: 3 additions & 3 deletions src/EasyFrameWork/Mvc/TagHelpers/GridTagHelper.cs
Expand Up @@ -76,7 +76,7 @@ public override void Process(TagHelperContext context, TagHelperOutput output)

if ((EditAble ?? true) && primaryKey != null)
{
string name = primaryKey.Name.FirstCharToLowerCase();
string name = primaryKey.Name.ToCamelCaseNaming();
if (name.Length == 2)
{
name = name.ToLower();
Expand Down Expand Up @@ -150,7 +150,7 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
optionBuilder.AppendFormat("{{\"name\":\"{0}\",\"value\":\"{1}\"}},", localize.Get("No"), "false");
}
tableHeaderBuilder.AppendFormat(TableHeadStructure,
m.Name.FirstCharToLowerCase(),
m.Name.ToCamelCaseNaming(),
WebUtility.HtmlEncode(m.GridColumnTemplate),
OrderAsc == m.Name ? "asc" : OrderDesc == m.Name ? "desc" : "",
m.DisplayName,
Expand All @@ -166,7 +166,7 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
foreach (var property in ModelType.GetProperties())
{
tableHeaderBuilder.AppendFormat(TableHeadStructure,
property.Name.FirstCharToLowerCase(),
property.Name.ToCamelCaseNaming(),
string.Empty,
OrderAsc == property.Name ? "asc" : OrderDesc == property.Name ? "desc" : "",
property.Name,
Expand Down
28 changes: 17 additions & 11 deletions src/EasyFrameWork/Reflection/PropertyHelper.cs
Expand Up @@ -17,17 +17,23 @@

namespace Easy.Reflection
{
public static class PropertyHelper
public static partial class PropertyHelper
{
private static ConcurrentDictionary<Type, ConcurrentDictionary<string, Func<object, object>>> _propertyGetters = new ConcurrentDictionary<Type, ConcurrentDictionary<string, Func<object, object>>>();
private static ConcurrentDictionary<Type, ConcurrentDictionary<string, Action<object, object>>> _propertySetters = new ConcurrentDictionary<Type, ConcurrentDictionary<string, Action<object, object>>>();
private static ConcurrentDictionary<Type, Func<object, object, object>> _indexGetters = new ConcurrentDictionary<Type, Func<object, object, object>>();
private static ConcurrentDictionary<Type, Action<object, object, object>> _indexSetters = new ConcurrentDictionary<Type, Action<object, object, object>>();

static Regex _onlyNumberIndexRegex = new Regex(@"^\[(\d+)\]$", RegexOptions.Compiled);
static Regex _onlyNameIndexRegex = new Regex(@"^\[""([A-Za-z0-9_]+)""\]$", RegexOptions.Compiled);
static Regex _numberIndexRegex = new Regex(@"^([A-Za-z0-9_]+)\[(\d+)\]$", RegexOptions.Compiled);
static Regex _nameIndexRegex = new Regex(@"^([A-Za-z0-9_]+)\[""([A-Za-z0-9_]+)""\]$", RegexOptions.Compiled);

[GeneratedRegex("^\\[(\\d+)\\]$")]
private static partial Regex RegexOnlyNumberIndex();
[GeneratedRegex("^\\[\"([A-Za-z0-9_]+)\"\\]$")]
private static partial Regex RegexOnlyNameIndex();
[GeneratedRegex("^([A-Za-z0-9_]+)\\[(\\d+)\\]$")]
private static partial Regex RegexNumberIndex();
[GeneratedRegex("^([A-Za-z0-9_]+)\\[\"([A-Za-z0-9_]+)\"\\]$")]
private static partial Regex RegexNameIndex();

public class PropertyName
{
public PropertyName(string name, object index)
Expand All @@ -42,7 +48,7 @@ public PropertyName(string name, object index)
{
static propertyExpression =>
{
var numberMatch = _onlyNumberIndexRegex.Match(propertyExpression);
var numberMatch = RegexOnlyNumberIndex().Match(propertyExpression);
if (numberMatch.Success)
{
return new PropertyName(null, int.Parse(numberMatch.Groups[1].Value));
Expand All @@ -51,7 +57,7 @@ public PropertyName(string name, object index)
},
static propertyExpression =>
{
var numberMatch = _onlyNameIndexRegex.Match(propertyExpression);
var numberMatch = RegexOnlyNameIndex().Match(propertyExpression);
if (numberMatch.Success)
{
return new PropertyName(null, numberMatch.Groups[1].Value);
Expand All @@ -60,7 +66,7 @@ public PropertyName(string name, object index)
},
static propertyExpression =>
{
var numberMatch = _numberIndexRegex.Match(propertyExpression);
var numberMatch = RegexNumberIndex().Match(propertyExpression);
if (numberMatch.Success)
{
return new PropertyName(numberMatch.Groups[1].Value, int.Parse(numberMatch.Groups[2].Value));
Expand All @@ -69,7 +75,7 @@ public PropertyName(string name, object index)
},
static propertyExpression =>
{
var numberMatch = _nameIndexRegex.Match(propertyExpression);
var numberMatch = RegexNameIndex().Match(propertyExpression);
if (numberMatch.Success)
{
return new PropertyName(numberMatch.Groups[1].Value, numberMatch.Groups[2].Value);
Expand All @@ -78,6 +84,8 @@ public PropertyName(string name, object index)
},
static propertyExpression => new PropertyName(propertyExpression, null)
};


public static PropertyName[] ParseProperties(string propertyExpression)
{
var propertyDeepArray = propertyExpression.Split('.', StringSplitOptions.RemoveEmptyEntries);
Expand Down Expand Up @@ -282,7 +290,5 @@ private static object GetPropertyValue(object resultValue, PropertyName property
});

}


}
}
11 changes: 6 additions & 5 deletions src/EasyFrameWork/Version.cs
Expand Up @@ -11,18 +11,16 @@

namespace Easy
{
public class Version
public partial class Version
{
static Regex regex = new Regex(@"^(\d+\.)?(\d+\.)?(\d+\.)?(\d+)$", RegexOptions.Compiled);

public int Major { get; set; }
public int Minor { get; set; }
public int Revision { get; set; }
public int Build { get; set; }

public static Version Parse(string version)
{
if (!regex.IsMatch(version))
if (!RegexVersion().IsMatch(version))
{
throw new Exception("Version format is not supported.");
}
Expand Down Expand Up @@ -161,7 +159,7 @@ public override bool Equals(object obj)
return false;
}

return this == (obj as Version);
return this == obj as Version;
}

public override int GetHashCode()
Expand All @@ -172,5 +170,8 @@ public override string ToString()
{
return $"{Major}.{Minor}.{Revision}.{Build}";
}

[GeneratedRegex("^(\\d+\\.)?(\\d+\\.)?(\\d+\\.)?(\\d+)$", RegexOptions.Compiled)]
private static partial Regex RegexVersion();
}
}
8 changes: 5 additions & 3 deletions src/ZKEACMS.EventAction/HttpParser/Helps/HttpBaseInfo.cs
Expand Up @@ -9,9 +9,8 @@

namespace ZKEACMS.EventAction.HttpParser.Helps
{
class HttpBaseInfo
partial class HttpBaseInfo
{
private static Regex _httpVersionValidate = new Regex(@"HTTP/\d.\d", RegexOptions.Compiled);
private static readonly HashSet<string> validHttpVerbs = new HashSet<string> { "GET", "POST", "HEAD", "PUT", "DELETE", "MOVE", "TRACE", "CONNECT", "OPTIONS" };

public string Method { get; set; }
Expand Down Expand Up @@ -63,9 +62,12 @@ private static bool IsValidUri(string url)

private void SetHttpVersion(string version)
{
if (!_httpVersionValidate.IsMatch(version)) return;
if (!RegexHttpVersionValidate().IsMatch(version)) return;

HttpVersion = version.Trim();
}

[GeneratedRegex("HTTP/\\d.\\d", RegexOptions.Compiled)]
private static partial Regex RegexHttpVersionValidate();
}
}

0 comments on commit bc5fd20

Please sign in to comment.