Exemplo n.º 1
0
        //private static string RunCode_GetNewAssemblyFile()
        //{
        //    // "c:\pib\prog\tools\runsource\exe\run\RunSource_00001"
        //    if (!zDirectory.Exists(__defaultGenerateAssemblySubdirectory))
        //        zDirectory.CreateDirectory(__defaultGenerateAssemblySubdirectory);
        //    int i = zfile.GetLastFileNameIndex(__defaultGenerateAssemblySubdirectory) + 1;
        //    return zPath.Combine(__defaultGenerateAssemblySubdirectory, __defaultGenerateAssemblyName + string.Format("_{0:00000}", i));
        //}

        private GenerateCSharpCodeResult RunCode_GenerateCode(string code, CompilerProject compilerProject, string assemblyFilename)
        {
            GenerateCSharpCode generateCSharpCode = new GenerateCSharpCode(assemblyFilename);

            generateCSharpCode.RunTypeName   = GetRunSourceConfig().Get("GenerateCodeRunTypeName", "_RunCode"); // "w"
            generateCSharpCode.RunMethodName = GetRunSourceConfig().Get("GenerateCodeRunMethodName", "Run");

            if (compilerProject != null)
            {
                generateCSharpCode.NameSpace = compilerProject.GetNameSpace();
                generateCSharpCode.AddUsings(compilerProject.GetUsings());
            }

            return(generateCSharpCode.GenerateCode(code));
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        private Compiler RunCode_CompileCode(CompilerProject compilerProject, string assemblyFilename, string sourceFile)
        {
            Compiler compiler = new Compiler();

            compiler.SetOutputAssembly(assemblyFilename);
            compiler.AddSource(new CompilerFile(sourceFile));

            if (compilerProject != null)
            {
                //compiler.DefaultDirectory = zPath.GetDirectoryName(compilerProject.ProjectFile);
                compiler.SetProjectCompilerFile(compilerProject.GetProjectCompilerFile());
            }

            // CompilerDefaultValues from runsource.runsource.config.xml runsource.runsource.config.local.xml
            compiler.SetParameters(GetRunSourceConfigCompilerDefaultValues(), runCode: true);
            compiler.SetParameters(compilerProject, runCode: true);

            compiler.Compile();

            return(compiler);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        // RunCode_ExecuteCode must throw an exception if he can't execute run method
        // if no error thrown RunCode_ExecuteCode must call RunCode_EndRun()
        private void RunCode_ExecuteCode(Assembly assembly, GenerateCSharpCodeResult codeResult, CompilerProject compilerProject, Compiler compiler, bool useNewThread)
        {
            _runCode = new RunCode();
            _runCode.RunAssembly = assembly;
            _runCode.CompilerAssemblies = compiler.Assemblies;
            //_runCode.RunClassName = codeResult.GetFullClassName();
            //_runCode.RunMethodName = codeResult.RunMethodName;
            _runCode.RunMethodName = codeResult.GetFullRunMethodName();
            _runCode.InitMethodName = compilerProject.GetInitMethod();  // "Init"
            _runCode.EndMethodName = compilerProject.GetEndMethod();    // "End"
            _runCode.EndRun += RunCode_EndRun;

            _executionAborted = false;

            _runCode.Run(useNewThread);
            //_runCodeThread = runCode.RunThread;
        }
Exemplo n.º 6
0
        private Compiler RunCode_CompileCode(CompilerProject compilerProject, string assemblyFilename, string sourceFile)
        {
            Compiler compiler = new Compiler();
            compiler.SetOutputAssembly(assemblyFilename);
            compiler.AddSource(new CompilerFile(sourceFile));

            if (compilerProject != null)
                //compiler.DefaultDirectory = zPath.GetDirectoryName(compilerProject.ProjectFile);
                compiler.SetProjectCompilerFile(compilerProject.GetProjectCompilerFile());

            // CompilerDefaultValues from runsource.runsource.config.xml runsource.runsource.config.local.xml
            compiler.SetParameters(GetRunSourceConfigCompilerDefaultValues(), runCode: true);
            compiler.SetParameters(compilerProject, runCode: true);

            compiler.Compile();

            return compiler;
        }
Exemplo n.º 7
0
        //private static string RunCode_GetNewAssemblyFile()
        //{
        //    // "c:\pib\prog\tools\runsource\exe\run\RunSource_00001"
        //    if (!zDirectory.Exists(__defaultGenerateAssemblySubdirectory))
        //        zDirectory.CreateDirectory(__defaultGenerateAssemblySubdirectory);
        //    int i = zfile.GetLastFileNameIndex(__defaultGenerateAssemblySubdirectory) + 1;
        //    return zPath.Combine(__defaultGenerateAssemblySubdirectory, __defaultGenerateAssemblyName + string.Format("_{0:00000}", i));
        //}

        private GenerateCSharpCodeResult RunCode_GenerateCode(string code, CompilerProject compilerProject, string assemblyFilename)
        {
            GenerateCSharpCode generateCSharpCode = new GenerateCSharpCode(assemblyFilename);
            generateCSharpCode.RunTypeName = GetRunSourceConfig().Get("GenerateCodeRunTypeName", "_RunCode");  // "w"
            generateCSharpCode.RunMethodName = GetRunSourceConfig().Get("GenerateCodeRunMethodName", "Run");

            if (compilerProject != null)
            {
                generateCSharpCode.NameSpace = compilerProject.GetNameSpace();
                generateCSharpCode.AddUsings(compilerProject.GetUsings());
            }

            return generateCSharpCode.GenerateCode(code);
        }
Exemplo n.º 8
0
        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();
            }
        }
Exemplo n.º 9
0
        // RunCode_ExecuteCode must throw an exception if he can't execute run method
        // if no error thrown RunCode_ExecuteCode must call RunCode_EndRun()
        private void RunCode_ExecuteCode(Assembly assembly, GenerateCSharpCodeResult codeResult, CompilerProject compilerProject, Compiler compiler, bool useNewThread)
        {
            _runCode                    = new RunCode();
            _runCode.RunAssembly        = assembly;
            _runCode.CompilerAssemblies = compiler.Assemblies;
            //_runCode.RunClassName = codeResult.GetFullClassName();
            //_runCode.RunMethodName = codeResult.RunMethodName;
            _runCode.RunMethodName  = codeResult.GetFullRunMethodName();
            _runCode.InitMethodName = compilerProject.GetInitMethod();  // "Init"
            _runCode.EndMethodName  = compilerProject.GetEndMethod();   // "End"
            _runCode.EndRun        += RunCode_EndRun;

            _executionAborted = false;

            _runCode.Run(useNewThread);
            //_runCodeThread = runCode.RunThread;
        }
Exemplo n.º 10
0
        private void _RunCode(string code, bool useNewThread = true, bool compileWithoutProject = false, bool dontRunCode = false)
        {
            if (code == "")
            {
                return;
            }

            // $$RunSourceRunCode_v1
            //if (!dontRunCode && (_runCode != null || _runCodeThread != null))
            if (!dontRunCode && _runCode != null)
            {
                throw new PBException("error program already running");
            }

            bool error    = false;
            bool doEndRun = true;

            _refreshRunSourceConfig = true;
            _refreshProjectConfig   = true;

            //_runCodeChrono = new Chrono();
            try
            {
                CompilerProject compilerProject = null;
                if (!compileWithoutProject)
                {
                    compilerProject = GetProjectCompilerProject();
                }
                if (compilerProject == null)
                {
                    compilerProject = GetDefaultProject();
                }

                //string assemblyFile = RunCode_GetNewAssemblyFile();
                string assemblyFile = GetGenerateAssembly().GetNewAssemblyFile();

                GenerateCSharpCodeResult codeResult = RunCode_GenerateCode(code, compilerProject, assemblyFile);

                Compiler compiler = RunCode_CompileCode(compilerProject, assemblyFile, codeResult.SourceFile);

                if (compiler.HasError())
                {
                    //SetResultCompilerMessages(compiler);
                    SetResult(compiler.GetCompilerMessagesDataTable());
                }
                else
                {
                    // trace warning
                    compiler.TraceMessages();

                    if (!dontRunCode)
                    {
                        RunCode_ExecuteCode(compiler.Results.CompiledAssembly, codeResult, compilerProject, compiler, useNewThread);
                        doEndRun = false;
                    }
                }
            }
            catch
            {
                error = true;
                throw;
            }
            finally
            {
                //if (error && EndRun != null)
                //    EndRun(error);
                // call RunCode_EndRun() only if exception has bin catched (error = true)
                //if (error || dontRunCode)
                //    RunCode_EndRun(error);
                if (doEndRun)
                {
                    RunCode_EndRun(error);
                }
            }
        }
Exemplo n.º 11
0
 private CompilerProject GetRunSourceConfigCompilerDefaultValues()
 {
     return(CompilerProject.Create(GetRunSourceConfig().zGetConfigElement("CompilerDefaultValues")));
 }