private string GenerateSource(RunnedTaskDto runnedTask) { var source = AddClassName(SourceTemplate, runnedTask); source = AddInjectedPropertyCode(source, runnedTask); source = AddRunCode(source, runnedTask); return source; }
private int Run(CompilerResults compile, RunnedTaskDto runnedTask, List<ParameterDto> parameters) { try { var instance = compile.CompiledAssembly.CreateInstance("jarvis.client.worker." + GetClassName(runnedTask)) as CompiledTask; Client.Container.Inject(instance); var properties = instance.GetType().GetProperties().Where(pi => pi.CanRead && pi.CanWrite); foreach (var propertyInfo in properties) { var value = propertyInfo.GetValue(instance, null); Client.Container.Inject(value); } return instance.run(parameters); } catch (Exception e) { Console.WriteLine(e); } return -1; }
private void ExecuteTask(RunnedTaskDto runnedTask, List<ParameterDto> parameters) { var source = GenerateSource(runnedTask); var compile = Compile(source); if (compile.Errors.HasErrors) { foreach (var error in compile.Errors) { Console.WriteLine((string) error.ToString()); } } else { var result = Run(compile, runnedTask, parameters); Console.WriteLine((int) result); } }
private string AddRunCode(string source, RunnedTaskDto runnedTask) { return source.Replace("%RUNCODE%", runnedTask.RunCode); }
private string AddInjectedPropertyCode(string source, RunnedTaskDto runnedTask) { var properties = String.Join(Environment.NewLine, (from a in Actions select "[Inject] public " + a.GetType().FullName + " " + a.PropertyName + " { get; set; }")); source = source.Replace("%INJECTEDPROPERTIES%", properties); return source; }
private string AddClassName(string source, RunnedTaskDto runnedTask) { return source.Replace("%TASKNAME%", GetClassName(runnedTask)); }
private static string GetClassName(RunnedTaskDto runnedTask) { return runnedTask.Name; }