public static void CompileDynamicCode() { DynamicLogic.BindCodeGenAssemblies(); Directory.CreateDirectory(DynamicCode.CodeGenDirectory); var errors = new List <string>(); try { CompilationResult?cr = null; bool cleaned = false; if (DynamicCode.CodeGenAssemblyPath.IsNullOrEmpty()) { CleanCodeGenFolder(); cleaned = true; { Dictionary <string, CodeFile> codeFiles = GetCodeFilesDictionary(); cr = Compile(codeFiles, inMemory: false, assemblyName: DynamicCode.CodeGenAssembly, needsCodeGenAssembly: false); if (cr.Errors.Count == 0) { DynamicCode.CodeGenAssemblyPath = cr.OutputAssembly; } else { errors.Add("Errors compiling dynamic assembly:\r\n" + cr.Errors.ToString("\r\n").Indent(4)); } } } if (DynamicApiLogic.IsStarted && (DynamicCode.CodeGenControllerAssemblyPath.IsNullOrEmpty() || cleaned)) { Dictionary <string, CodeFile> codeFiles = DynamicApiLogic.GetCodeFiles().ToDictionary(a => a.FileContent); cr = Compile(codeFiles, inMemory: false, assemblyName: DynamicCode.CodeGenControllerAssembly, needsCodeGenAssembly: true); if (cr.Errors.Count == 0) { DynamicCode.CodeGenControllerAssemblyPath = cr.OutputAssembly; } else { errors.Add("Errors compiling dynamic api controller assembly:\r\n" + cr.Errors.ToString("\r\n").Indent(4)); } } if (errors.Any()) { throw new InvalidOperationException(errors.ToString("\r\n")); } } catch (Exception e) { CodeGenError = e; } }
public string GetStarterClassCode() { StringBuilder sb = new StringBuilder(); sb.AppendLine($"public static class CodeGenStarter"); sb.AppendLine("{"); sb.AppendLine(" public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)"); sb.AppendLine(" {"); DynamicLogic.OnWriteDynamicStarter(sb, 8); sb.AppendLine(" }"); sb.AppendLine("}"); return(sb.ToString()); }