Skip to content

Commit 0a535a5

Browse files
committed
修改 注意事项
1 parent 8a643a9 commit 0a535a5

File tree

4 files changed

+57
-33
lines changed

4 files changed

+57
-33
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ToolGood.Algorithm
44

55
ToolGood.Algorithm是一个功能强大、轻量级、兼容`Excel公式`的算法类库,旨在提高开发人员在不同业务场景中的生产力。
66

7-
WebAssembly版本,请看csharp文件夹下`ToolGood.Algorithm.WebAssembly`,`ToolGood.Algorithm2.WebTest` 两个项目。
7+
WebAssembly版本,请看csharp文件夹下`ToolGood.Algorithm.WebAssembly`,`ToolGood.Algorithm2.WebTest` 两个项目。注意:不支持Md5、HmacMd5 两个公式
88

99
**适用场景:** 代码与算法分离,避免项目强制升级
1010

csharp/ToolGood.Algorithm.WebAssembly/Program.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,29 @@ private static void Main(string[] args)
1111
{
1212
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
1313
}
14+
[JSInvokable]
15+
public static string GetErrorMessage(string exp, string def = null, string data = null, string option = null)
16+
{
17+
AlgorithmEngine ae;
18+
if (option == null) {
19+
ae = new AlgorithmEngine();
20+
} else {
21+
var ops = JsonSerializer.Deserialize<Dictionary<string, object>>(option);
22+
ae = new AlgorithmEngine(bool.Parse(ops["IgnoreCase"].ToString()));
23+
ae.UseExcelIndex = bool.Parse(ops["UseExcelIndex"].ToString());
24+
ae.UseTempDict = bool.Parse(ops["UseTempDict"].ToString());
25+
ae.UseLocalTime = bool.Parse(ops["UseLocalTime"].ToString());
26+
ae.DistanceUnit = (DistanceUnitType)(int.Parse(ops["DistanceUnit"].ToString()));
27+
ae.AreaUnit = (AreaUnitType)(int.Parse(ops["AreaUnit"].ToString()));
28+
ae.VolumeUnit = (VolumeUnitType)(int.Parse(ops["VolumeUnit"].ToString()));
29+
ae.MassUnit = (MassUnitType)(int.Parse(ops["MassUnit"].ToString()));
30+
}
31+
if (data != null) {
32+
ae.AddParameterFromJson(data);
33+
}
34+
ae.TryEvaluate(exp,def);
35+
return ae.LastError;
36+
}
1437

1538
[JSInvokable]
1639
public static string TryEvaluateString(string exp, string def = null, string data = null, string option = null)

csharp/ToolGood.Algorithm2/Internals/MathVisitor.cs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3160,8 +3160,9 @@ public virtual Operand VisitMD5_fun(mathParser.MD5_funContext context)
31603160
}
31613161
var t = Hash.GetMd5String(encoding.GetBytes(args[0].TextValue));
31623162
return Operand.Create(t);
3163-
} catch (Exception) { }
3164-
return Operand.Error("Function MD5 is error!");
3163+
} catch (Exception ex) {
3164+
return Operand.Error("Function MD5 is error!" + ex.Message);
3165+
}
31653166
}
31663167
public virtual Operand VisitSHA1_fun(mathParser.SHA1_funContext context)
31673168
{
@@ -3177,9 +3178,9 @@ public virtual Operand VisitSHA1_fun(mathParser.SHA1_funContext context)
31773178
}
31783179
var t = Hash.GetSha1String(encoding.GetBytes(args[0].TextValue));
31793180
return Operand.Create(t);
3180-
} catch (Exception) {
3181+
} catch (Exception ex) {
3182+
return Operand.Error("Function SHA1 is error!" + ex.Message);
31813183
}
3182-
return Operand.Error("Function SHA1 is error!");
31833184
}
31843185
public virtual Operand VisitSHA256_fun(mathParser.SHA256_funContext context)
31853186
{
@@ -3195,8 +3196,9 @@ public virtual Operand VisitSHA256_fun(mathParser.SHA256_funContext context)
31953196
}
31963197
var t = Hash.GetSha256String(encoding.GetBytes(args[0].TextValue));
31973198
return Operand.Create(t);
3198-
} catch (Exception) { }
3199-
return Operand.Error("Function SHA256 is error!");
3199+
} catch (Exception ex) {
3200+
return Operand.Error("Function SHA256 is error!"+ex.Message);
3201+
}
32003202
}
32013203
public virtual Operand VisitSHA512_fun(mathParser.SHA512_funContext context)
32023204
{
@@ -3212,9 +3214,9 @@ public virtual Operand VisitSHA512_fun(mathParser.SHA512_funContext context)
32123214
}
32133215
var t = Hash.GetSha512String(encoding.GetBytes(args[0].TextValue));
32143216
return Operand.Create(t);
3215-
} catch (Exception) {
3217+
} catch (Exception ex) {
3218+
return Operand.Error("Function SHA512 is error!"+ex.Message);
32163219
}
3217-
return Operand.Error("Function SHA512 is error!");
32183220
}
32193221

32203222
public virtual Operand VisitCRC32_fun(mathParser.CRC32_funContext context)
@@ -3230,8 +3232,9 @@ public virtual Operand VisitCRC32_fun(mathParser.CRC32_funContext context)
32303232
}
32313233
var t = Hash.GetCrc32String(encoding.GetBytes(args[0].TextValue));
32323234
return Operand.Create(t);
3233-
} catch (Exception) { }
3234-
return Operand.Error("Function CRC32 is error!");
3235+
} catch (Exception ex) {
3236+
return Operand.Error("Function CRC32 is error!" + ex.Message);
3237+
}
32353238
}
32363239
public virtual Operand VisitHMACMD5_fun(mathParser.HMACMD5_funContext context)
32373240
{
@@ -3246,8 +3249,9 @@ public virtual Operand VisitHMACMD5_fun(mathParser.HMACMD5_funContext context)
32463249
}
32473250
var t = Hash.GetHmacMd5String(encoding.GetBytes(args[0].TextValue), args[1].TextValue);
32483251
return Operand.Create(t);
3249-
} catch (Exception) { }
3250-
return Operand.Error("Function HMACMD5 is error!");
3252+
} catch (Exception ex) {
3253+
return Operand.Error("Function HMACMD5 is error!" + ex.Message);
3254+
}
32513255
}
32523256
public virtual Operand VisitHMACSHA1_fun(mathParser.HMACSHA1_funContext context)
32533257
{
@@ -3262,8 +3266,9 @@ public virtual Operand VisitHMACSHA1_fun(mathParser.HMACSHA1_funContext context)
32623266
}
32633267
var t = Hash.GetHmacSha1String(encoding.GetBytes(args[0].TextValue), args[1].TextValue);
32643268
return Operand.Create(t);
3265-
} catch (Exception) { }
3266-
return Operand.Error("Function HMACSHA1 is error!");
3269+
} catch (Exception ex) {
3270+
return Operand.Error("Function HMACSHA1 is error!" + ex.Message);
3271+
}
32673272
}
32683273
public virtual Operand VisitHMACSHA256_fun(mathParser.HMACSHA256_funContext context)
32693274
{
@@ -3278,8 +3283,9 @@ public virtual Operand VisitHMACSHA256_fun(mathParser.HMACSHA256_funContext cont
32783283
}
32793284
var t = Hash.GetHmacSha256String(encoding.GetBytes(args[0].TextValue), args[1].TextValue);
32803285
return Operand.Create(t);
3281-
} catch (Exception) { }
3282-
return Operand.Error("Function HMACSHA256 is error!");
3286+
} catch (Exception ex) {
3287+
return Operand.Error("Function HMACSHA256 is error!" + ex.Message);
3288+
}
32833289
}
32843290
public virtual Operand VisitHMACSHA512_fun(mathParser.HMACSHA512_funContext context)
32853291
{
@@ -3294,8 +3300,9 @@ public virtual Operand VisitHMACSHA512_fun(mathParser.HMACSHA512_funContext cont
32943300
}
32953301
var t = Hash.GetHmacSha512String(encoding.GetBytes(args[0].TextValue), args[1].TextValue);
32963302
return Operand.Create(t);
3297-
} catch (Exception) { }
3298-
return Operand.Error("Function HMACSHA512 is error!");
3303+
} catch (Exception ex) {
3304+
return Operand.Error("Function HMACSHA512 is error!" + ex.Message);
3305+
}
32993306
}
33003307
public virtual Operand VisitTRIMSTART_fun(mathParser.TRIMSTART_funContext context)
33013308
{

csharp/ToolGood.Algorithm2/MyDate.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,12 @@ public override string ToString()
196196
stringBuffer.Append('-');
197197
stringBuffer.Append(Day.Value.ToString("D2"));
198198

199-
if (Second > 0 || Hour > 0 || Minute > 0) {
200-
stringBuffer.Append(' ');
201-
stringBuffer.Append(Hour.ToString("D2"));
202-
stringBuffer.Append(':');
203-
stringBuffer.Append(Minute.ToString("D2"));
204-
if (Second > 0) {
205-
stringBuffer.Append(':');
206-
stringBuffer.Append(Second.ToString("D2"));
207-
}
208-
}
199+
stringBuffer.Append(' ');
200+
stringBuffer.Append(Hour.ToString("D2"));
201+
stringBuffer.Append(':');
202+
stringBuffer.Append(Minute.ToString("D2"));
203+
stringBuffer.Append(':');
204+
stringBuffer.Append(Second.ToString("D2"));
209205
} else {
210206
if (Day != null && Day > 0) {
211207
stringBuffer.Append(Day);
@@ -214,10 +210,8 @@ public override string ToString()
214210
stringBuffer.Append(Hour.ToString("D2"));
215211
stringBuffer.Append(':');
216212
stringBuffer.Append(Minute.ToString("D2"));
217-
if (Second > 0) {
218-
stringBuffer.Append(':');
219-
stringBuffer.Append(Second.ToString("D2"));
220-
}
213+
stringBuffer.Append(':');
214+
stringBuffer.Append(Second.ToString("D2"));
221215
}
222216
return stringBuffer.ToString();
223217
}

0 commit comments

Comments
 (0)