public CompilationResult CompileCode(TaskParameters task, params string[] codeClasses) { string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CompilerTempFiles", Guid.NewGuid().ToString() + ".exe"); // verife that such file doesn't exists. lock (GetType()) { while (File.Exists(path)) { path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CompilerTempFiles", Guid.NewGuid().ToString() + ".exe"); } } CompilationResult compileResult = compileCodeClasses(path, this.extendBotCodeWithCoreClasses(codeClasses)); if (!compileResult.IsCodeCorrect) { return(compileResult); } bool taskCompliance = verifyTaskLogic(path, task); if (!taskCompliance) { compileResult.Errors = compileResult.Errors ?? new List <string>(); compileResult.Errors.Add("You haven't declared classes for all required bots. Please add them."); compileResult.IsCodeCorrect = false; } return(compileResult); }
private bool verifyTaskLogic(string assemblyPath, TaskParameters task) { Assembly assembly = Assembly.LoadFile(assemblyPath); Type[] types = assembly.GetExportedTypes(); int botCount = 0; Regex exp = new Regex(@"Bot[\d]+"); foreach (Type t in types) { if (exp.IsMatch(t.FullName) && t.GetMethods().FirstOrDefault(m => m.Name == "NextStep") != null) { botCount++; } } return(task.RequiredBots == botCount); }