예제 #1
0
        private string GenerateSource(RunnedTaskDto runnedTask)
        {
            var source = AddClassName(SourceTemplate, runnedTask);
            source = AddInjectedPropertyCode(source, runnedTask);
            source = AddRunCode(source, runnedTask);

            return source;
        }
예제 #2
0
        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;
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
 private string AddRunCode(string source, RunnedTaskDto runnedTask)
 {
     return source.Replace("%RUNCODE%", runnedTask.RunCode);
 }
예제 #5
0
        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;
        }
예제 #6
0
 private string AddClassName(string source, RunnedTaskDto runnedTask)
 {
     return source.Replace("%TASKNAME%", GetClassName(runnedTask));
 }
예제 #7
0
 private static string GetClassName(RunnedTaskDto runnedTask)
 {
     return runnedTask.Name;
 }