-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCommandEngine.cs
63 lines (58 loc) · 1.83 KB
/
CommandEngine.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using DHI.Generic.NetCDF.MIKE.Commands;
namespace DHI.Generic.NetCDF.MIKE
{
public class CommandEngine
{
private EngineSettings _engineSettings;
public void InitEngine(EngineSettings engineSettings)
{
try
{
_engineSettings = engineSettings;
}
catch (Exception ex)
{
throw new Exception("Initiate engine error: " + ex.Message);
}
}
public void AutoRun()
{
try
{
if (_engineSettings.Commands != null)
{
Assembly assem = System.Reflection.Assembly.GetExecutingAssembly();
foreach (CommandSettings commandSet in _engineSettings.Commands)
{
Type type = assem.GetType("DHI.Generic.NetCDF.MIKE.Commands." + commandSet.CommandName);
iCommand autoRunCommand = (iCommand)assem.CreateInstance(type.Namespace + "." + type.Name);
autoRunCommand.Execute(commandSet);
}
}
}
catch (Exception ex)
{
throw new Exception("AutoRun error: " + ex.Message);
}
}
public void RunCommand(iCommand newCommand, CommandSettings commandSet)
{
try
{
newCommand.Execute(commandSet);
}
catch (Exception ex)
{
throw new Exception("RunCommand error: " + ex.Message);
}
}
}
}