public void SetCompilerValues(IGenerateAndExecute generateAndExecute, CompilerProject compilerProject) { ICompiler compiler = generateAndExecute.Compiler; if (compilerProject != null) { compiler.DefaultDir = zPath.GetDirectoryName(compilerProject.ProjectFile); } // CompilerDefaultValues from runsource.runsource.config.xml runsource.runsource.config.local.xml compiler.SetParameters(GetRunSourceConfigCompilerDefaultValues(), dontSetOutput: true); // ProjectDefaultValues from runsource.runsource.config.xml runsource.runsource.config.local.xml // $$ProjectDefaultValues disable //compiler.SetParameters(GetRunSourceConfigProjectDefaultValues(), dontSetOutput: true); compiler.SetParameters(compilerProject, dontSetOutput: true); }
public void SetCompilerValues(IGenerateAndExecute generateAndExecute, CompilerProject compilerProject) { ICompiler compiler = generateAndExecute.Compiler; if (compilerProject != null) compiler.DefaultDir = zPath.GetDirectoryName(compilerProject.ProjectFile); // CompilerDefaultValues from runsource.runsource.config.xml runsource.runsource.config.local.xml compiler.SetParameters(GetRunSourceConfigCompilerDefaultValues(), dontSetOutput: true); // ProjectDefaultValues from runsource.runsource.config.xml runsource.runsource.config.local.xml // $$ProjectDefaultValues disable //compiler.SetParameters(GetRunSourceConfigProjectDefaultValues(), dontSetOutput: true); compiler.SetParameters(compilerProject, dontSetOutput: true); }
private void _GenerateCodeAndCompile_v2(IGenerateAndExecute generateAndExecute, string code, bool compileWithoutProject = false) { // use CompilerDefaultValues from runsource.runsource.config.xml runsource.runsource.config.local.xml if (code == "") return; CompilerProject compilerProject = null; if (!compileWithoutProject) compilerProject = GetProjectCompilerProject(); if (compilerProject == null) compilerProject = GetDefaultProject(); if (compilerProject != null) { generateAndExecute.NameSpace = compilerProject.GetNameSpace(); } if (compilerProject != null) generateAndExecute.AddUsings(compilerProject.GetUsings()); generateAndExecute.GenerateCSharpCode(code); SetCompilerValues(generateAndExecute, compilerProject); ICompiler compiler = generateAndExecute.Compiler; //Compiler compiler = new Compiler(); //compiler.SetOutputAssembly(assemblyFilename); //compiler.AddSource(new CompilerFile(file)); compiler.Compile(); //Assembly assembly = _compiler.Results.CompiledAssembly; if (compiler.HasError()) { //DataTable dtMessage = compiler.GetCompilerMessagesDataTable(); //if (dtMessage != null) //{ // gdtResult = dtMessage; // gdsResult = null; // gsXmlResultFormat = null; // if (ErrorResultSet != null) // ErrorResultSet(gdtResult, null); //} SetResultCompilerMessages(compiler); } else // trace warning compiler.TraceMessages(); }
private void RunCode_v1(string code, bool useNewThread = true, bool compileWithoutProject = false) { if (code == "") { return; } bool bError = false; if (_runCodeThread != null) { throw new PBException("error program already running"); } bool bOk = false; _runCodeChrono = new Chrono(); try { AssemblyResolve.Stop(); AssemblyResolve.Clear(); _refreshRunSourceConfig = true; _refreshProjectConfig = true; IGenerateAndExecute generateAndExecute = GetGenerateAndExecuteManager().New(); _GenerateCodeAndCompile_v2(generateAndExecute, code, compileWithoutProject); if (generateAndExecute.Compiler.HasError()) { return; } MethodInfo runMethod = generateAndExecute.GetAssemblyRunMethod(); MethodInfo initMethod = generateAndExecute.GetAssemblyInitMethod(); MethodInfo endMethod = generateAndExecute.GetAssemblyEndMethod(); AssemblyResolve.Start(); if (useNewThread) { _runCodeThread = new Thread(new ThreadStart(() => _Run(runMethod, initMethod, endMethod))); _runCodeThread.CurrentCulture = FormatInfo.CurrentFormat.CurrentCulture; _runCodeThread.SetApartmentState(ApartmentState.STA); _runCodeThread.Start(); } else { Trace.WriteLine("execute on main thread"); _Run(runMethod, initMethod, endMethod); } bOk = true; } catch { bError = true; throw; } finally { if (!bOk && EndRun != null) { EndRun(bError); } } }
private void _GenerateCodeAndCompile_v2(IGenerateAndExecute generateAndExecute, string code, bool compileWithoutProject = false) { // use CompilerDefaultValues from runsource.runsource.config.xml runsource.runsource.config.local.xml if (code == "") { return; } CompilerProject compilerProject = null; if (!compileWithoutProject) { compilerProject = GetProjectCompilerProject(); } if (compilerProject == null) { compilerProject = GetDefaultProject(); } if (compilerProject != null) { generateAndExecute.NameSpace = compilerProject.GetNameSpace(); } if (compilerProject != null) { generateAndExecute.AddUsings(compilerProject.GetUsings()); } generateAndExecute.GenerateCSharpCode(code); SetCompilerValues(generateAndExecute, compilerProject); ICompiler compiler = generateAndExecute.Compiler; //Compiler compiler = new Compiler(); //compiler.SetOutputAssembly(assemblyFilename); //compiler.AddSource(new CompilerFile(file)); compiler.Compile(); //Assembly assembly = _compiler.Results.CompiledAssembly; if (compiler.HasError()) { //DataTable dtMessage = compiler.GetCompilerMessagesDataTable(); //if (dtMessage != null) //{ // gdtResult = dtMessage; // gdsResult = null; // gsXmlResultFormat = null; // if (ErrorResultSet != null) // ErrorResultSet(gdtResult, null); //} SetResultCompilerMessages(compiler); } else { // trace warning compiler.TraceMessages(); } }