-
Notifications
You must be signed in to change notification settings - Fork 0
/
Energy.cs
171 lines (142 loc) · 4.42 KB
/
Energy.cs
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
using script.builder;
using script.help;
using script.plugin;
using script.Task;
using script.token;
using System;
using System.Collections;
using System.IO;
using System.Reflection;
namespace script
{
public class Energy : IDisposable
{
public const string VERSION = "V0.6";
private EnegyData Data { set; get; }
public VariabelDatabase VariabelDatabase { set; get; }
public PluginContainer plugin = new PluginContainer();
private ArrayList taskEvent = new ArrayList();
private ArrayList taskEnd = new ArrayList();
private TextReader reader;
public Energy()
{
Data = new EnegyData()
{
Config = new ScriptConfig()
};
//set the impontans config so the script not can change it!
Data.Config.append("tcp.enable", "false", false);
Data.Config.append("file.system.enable", "false", false);
VariabelDatabase = new VariabelDatabase();
StartItems.CreateStartItems(Data, VariabelDatabase);
}
public void setConfig(string name, string value)
{
setConfig(name, value, true);
}
public void setConfig(string name, string value, bool overide)
{
Data.Config.append(name, value, overide);
}
public void parse(string script)
{
parse((TextReader)new StringReader(script));
}
public void parse(StringReader reader)
{
parse((TextReader)reader);
}
public void parse(TextReader reader)
{
Interprenter.parse(new Token((this.reader = reader), Data, VariabelDatabase), Data, VariabelDatabase);
}
public void push(Function func)
{
VariabelDatabase.pushFunction(func, Data);
}
public void push(Class c)
{
VariabelDatabase.pushClass(c, Data);
}
public void addTaskEvent(ScriptTaskEvent e)
{
taskEvent.Add(e);
}
public void addEndEvent(ScriptEndEvent e)
{
taskEnd.Add(e);
}
public void Dispose()
{
if (reader != null)
reader.Close();
int i = 0;
while (taskEvent.Count != 0)
{
if (i > taskEvent.Count)
i = 0;
if (((ScriptTaskEvent)taskEvent[i]).isReady())
{
//remove the event becuse it is ready to be removed :)
taskEvent.Remove(taskEvent[i]);
}
i++;
}
foreach (ScriptEndEvent e in taskEnd)
e.callInEnd();
}
public RunningState getRunningStatus()
{
return Data.State;
}
public ScriptError getError()
{
if(Data.State != RunningState.Error)
{
return null;
}
return Data.ErrorData;
}
public void appendMethodToClass(Method method, Class c)
{
c.SetMethod(method, Data, VariabelDatabase, new Posision(0, 0));
}
public void LoadDLLFiles(string dir)
{
if (!Directory.Exists(dir))
{
return;
}
foreach(string file in Directory.GetFiles(dir, "*.dll"))
{
HandleDLL(Assembly.LoadFile(file));
}
}
public void Reaset()
{
VariabelDatabase = new VariabelDatabase();
Data.setNormal();
}
private void HandleDLL(Assembly assembly)
{
foreach(System.Type type in assembly.GetTypes())
{
if(type.IsClass && !type.IsAbstract && type.IsPublic)
{
foreach(System.Type type2 in type.FindInterfaces(new TypeFilter(ReturnTrue), null))
{
//first wee look if it is PluginInterface :)
if(type2 == typeof(PluginInterface))
{
Data.Plugin.push(Activator.CreateInstance(type) as PluginInterface);
}
}
}
}
}
private bool ReturnTrue(System.Type m, object filterCriteria)
{
return true;
}
}
}