-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathAlgorithmEngineEx.js
More file actions
90 lines (82 loc) · 2.8 KB
/
AlgorithmEngineEx.js
File metadata and controls
90 lines (82 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { AlgorithmEngine } from './AlgorithmEngine.js';
import { Operand } from './Operand.js';
import { JsonMapper } from './LitJson/JsonMapper.js';
/**
* AlgorithmEngine 扩展类
* 增加自定义参数缓存功能
*/
export class AlgorithmEngineEx extends AlgorithmEngine {
constructor(ignoreCase = false) {
super();
this.IgnoreCase = ignoreCase;
this.UseTempDict = false;
this._tempdict = {};
}
/**
* 自定义参数 请重写此方法
*/
GetParameter(parameter) {
let key = this.IgnoreCase ? parameter.toLowerCase() : parameter;
if (this._tempdict[key] !== undefined) {
return this._tempdict[key];
}
let result = super.GetParameter ? super.GetParameter(parameter) : Operand.CreateNull();
if (this.UseTempDict) {
this._tempdict[key] = result;
}
return result;
}
/**
* 清理参数
*/
ClearParameters() {
this._tempdict = {};
}
/**
* 添加自定义参数
*/
AddParameter(key, obj) {
let paramKey = this.IgnoreCase ? key.toLowerCase() : key;
if (obj instanceof Operand) {
this._tempdict[paramKey] = obj;
} else {
this._tempdict[paramKey] = Operand.Create(obj);
}
}
/**
* 添加自定义参数
*/
AddParameterFromJson(json) {
if (json.startsWith('{') && json.endsWith('}')) {
let jo = JsonMapper.toObject(json);
if (jo.IsObject) {
let obj = jo.ensureDictionary();
for (let key in obj) {
if (obj.hasOwnProperty(key)) {
let v = obj[key];
let paramKey = this.IgnoreCase ? key.toLowerCase() : key;
if (v.IsString) {
this._tempdict[paramKey] = Operand.Create(v.StringValue);
} else if (v.IsBoolean) {
this._tempdict[paramKey] = Operand.Create(v.BooleanValue);
} else if (v.IsDouble) {
this._tempdict[paramKey] = Operand.Create(v.NumberValue);
} else if (v.IsObject) {
this._tempdict[paramKey] = Operand.Create(v);
} else if (v.IsArray) {
this._tempdict[paramKey] = Operand.Create(v);
} else if (v.IsNull) {
this._tempdict[paramKey] = Operand.CreateNull();
}
}
}
return;
}
}
throw new Error("Parameter is not json string.");
}
}
// 浏览器支持
if (typeof window !== 'undefined') {
window.AlgorithmEngineEx = AlgorithmEngineEx;
}