private void RunCode_EndRun(bool error) { IChrono runCodeChrono; if (_runCode != null) { //_runCodeChrono = _runCode.RunChrono; runCodeChrono = _runCode.RunChrono; _runCode = null; } else { //_runCodeChrono = new Chrono(); runCodeChrono = new Chrono(); } _executionPaused = false; _executionAborted = false; //if (EndRun != null) // EndRun(error); if (_endRunCode != null) { _endRunCode(new EndRunCodeInfo { Error = error, RunCodeChrono = runCodeChrono }); } }
//private void RunCode_EndRun(bool error) private void RunCode_EndRun(RunCode runCode, bool error) { IChrono runCodeChrono; if (runCode != null) { runCodeChrono = runCode.RunChrono; //runCode = null; } else { runCodeChrono = new Chrono(); } _executionPaused = false; _executionAborted = false; RunCode runCode2; bool errRemoveRunCode = false; if (runCode != null) { errRemoveRunCode = !_runCodes.TryRemove(runCode.Id, out runCode2); } //Trace.WriteLine("RunCode_EndRun : runCode.Id {0} errRemoveRunCode {1}", runCode.Id, errRemoveRunCode); _endRunCode?.Invoke(new EndRunCodeInfo { Error = error, RunCodeChrono = runCodeChrono }); if (errRemoveRunCode) { throw new PBException("unable to remove RunCode id {0} from ConcurrentDictionary", runCode.Id); } }
// 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; }
// 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(); }
//private void RunCode_EndRun(bool error) private void RunCode_EndRun(RunCode runCode, bool error) { IChrono runCodeChrono; if (runCode != null) { runCodeChrono = runCode.RunChrono; //runCode = null; } else { runCodeChrono = new Chrono(); } _executionPaused = false; _executionAborted = false; RunCode runCode2; bool errRemoveRunCode = false; if (runCode != null) errRemoveRunCode = !_runCodes.TryRemove(runCode.Id, out runCode2); //Trace.WriteLine("RunCode_EndRun : runCode.Id {0} errRemoveRunCode {1}", runCode.Id, errRemoveRunCode); _endRunCode?.Invoke(new EndRunCodeInfo { Error = error, RunCodeChrono = runCodeChrono }); if (errRemoveRunCode) throw new PBException("unable to remove RunCode id {0} from ConcurrentDictionary", runCode.Id); }
// 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(); }
private void RunCode_EndRun(bool error) { IChrono runCodeChrono; if (_runCode != null) { //_runCodeChrono = _runCode.RunChrono; runCodeChrono = _runCode.RunChrono; _runCode = null; } else { //_runCodeChrono = new Chrono(); runCodeChrono = new Chrono(); } _executionPaused = false; _executionAborted = false; //if (EndRun != null) // EndRun(error); if (_endRunCode != null) _endRunCode(new EndRunCodeInfo { Error = error, RunCodeChrono = runCodeChrono }); }