Ejemplo n.º 1
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, CompilerProjectReader compilerProject, ProjectCompiler compiler, bool runOnMainThread, bool callInit)
        private async Task RunCode_ExecuteCode(Assembly assembly, GenerateCSharpCodeResult codeResult, CompilerProjectReader compilerProject, ProjectCompiler compiler, bool runOnMainThread, bool callInit)
        {
            RunCode runCode = new RunCode(++_runCodeId);

            runCode.RunAssembly = assembly;
            //runCode.CompilerAssemblies = compiler.Assemblies;
            runCode.RunMethodName = codeResult.GetFullRunMethodName();
            runCode.EndRun       += error => RunCode_EndRun(runCode, error);

            //if (forceCallInit)
            //    _runSourceInitEndMethods.CallInit = true;

            _executionAborted = false;

            foreach (CompilerAssembly compilerAssembly in compiler.Assemblies.Values)
            {
                //WriteLine(2, "  Assembly              \"{0}\" resolve {1}", assembly.File, assembly.Resolve);
                if (compilerAssembly.Resolve)
                {
                    AssemblyResolve.Add(compilerAssembly.File, compilerAssembly.ResolveName);
                }
            }

            //_runSourceInitEndMethods.CallInit = callInit;
            //if (callInit)
            //_runSourceInitEndMethods.CallInitMethods(compilerProject.GetInitMethods(), compilerProject.GetEndMethods(), callInit, methodName => runCode.GetMethod(methodName));
            _runSourceInitEndMethods.CallInitMethods(compilerProject.GetInitMethods(), compilerProject.GetEndMethods(), callInit, methodName => zReflection.GetMethod(methodName, assembly, ErrorOptions.TraceWarning));

            // add runCode to _runCodes after call init, if call init fail runCode is not in _runCodes
            if (!_runCodes.TryAdd(runCode.Id, runCode))
            {
                throw new PBException("unable to add RunCode id {0} to ConcurrentDictionary", runCode.Id);
            }

            //runCode.Run(runOnMainThread);
            await runCode.Run_v2(runOnMainThread);

            // problem with AssemblyResolve.Clear() end method may need to resolve assembly
            //AssemblyResolve.Clear();
        }
Ejemplo n.º 2
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)
        private void RunCode_ExecuteCode(Assembly assembly, GenerateCSharpCodeResult codeResult, CompilerProjectReader compilerProject, ProjectCompiler compiler, bool runOnMainThread, bool callInit)
        {
            RunCode runCode = new RunCode(++_runCodeId);
            runCode.RunAssembly = assembly;
            //runCode.CompilerAssemblies = compiler.Assemblies;
            runCode.RunMethodName = codeResult.GetFullRunMethodName();
            runCode.EndRun += error => RunCode_EndRun(runCode, error);

            //if (forceCallInit)
            //    _runSourceInitEndMethods.CallInit = true;

            _executionAborted = false;

            foreach (CompilerAssembly compilerAssembly in compiler.Assemblies.Values)
            {
                //WriteLine(2, "  Assembly              \"{0}\" resolve {1}", assembly.File, assembly.Resolve);
                if (compilerAssembly.Resolve)
                    AssemblyResolve.Add(compilerAssembly.File, compilerAssembly.ResolveName);
            }

            //_runSourceInitEndMethods.CallInit = callInit;
            //if (callInit)
            //_runSourceInitEndMethods.CallInitMethods(compilerProject.GetInitMethods(), compilerProject.GetEndMethods(), callInit, methodName => runCode.GetMethod(methodName));
            _runSourceInitEndMethods.CallInitMethods(compilerProject.GetInitMethods(), compilerProject.GetEndMethods(), callInit, methodName => zReflection.GetMethod(methodName, assembly, ErrorOptions.TraceWarning));

            // add runCode to _runCodes after call init, if call init fail runCode is not in _runCodes
            if (!_runCodes.TryAdd(runCode.Id, runCode))
                throw new PBException("unable to add RunCode id {0} to ConcurrentDictionary", runCode.Id);

            runCode.Run(runOnMainThread);

            // problem with AssemblyResolve.Clear() end method may need to resolve assembly
            //AssemblyResolve.Clear();
        }