示例#1
0
        public List <CompilationErrorTS> Compile(bool inMemory)
        {
            SystemEventLogLogic.Log("DynamicController.Compile");
            var compileResult = new List <DynamicLogic.CompilationResult>();

            if (!inMemory)
            {
                DynamicLogic.CleanCodeGenFolder();
            }

            Dictionary <string, CodeFile> codeFiles = DynamicLogic.GetCodeFilesDictionary();

            compileResult.Add(DynamicLogic.Compile(codeFiles, inMemory: inMemory, assemblyName: DynamicCode.CodeGenAssembly, needsCodeGenAssembly: false));

            if (DynamicApiLogic.IsStarted)
            {
                Dictionary <string, CodeFile> apiFiles = DynamicApiLogic.GetCodeFiles().ToDictionaryEx(a => a.FileName, "CodeGenController C# code file");
                compileResult.Add(DynamicLogic.Compile(apiFiles, inMemory: inMemory, assemblyName: DynamicCode.CodeGenControllerAssembly, needsCodeGenAssembly: true));
                codeFiles.AddRange(apiFiles);
            }

            return((from cr in compileResult
                    from ce in cr.Errors
                    let fileName = Path.GetFileName(ce.FileName)
                                   select(new CompilationErrorTS
            {
                fileName = fileName,
                column = ce.Column,
                line = ce.Line,
                errorNumber = ce.ErrorNumber,
                errorText = ce.ErrorText,
                fileContent = codeFiles.GetOrThrow(fileName).FileContent
            })).ToList());
        }
示例#2
0
    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;
        }
    }