public void StartAssemblyResolve() { XmlConfig config = GetRunSourceConfig(); if (config != null) { AssemblyResolve.TraceAssemblyResolve = config.Get("TraceAssemblyResolve").zTryParseAs(false); //AssemblyResolve.TraceAssemblyLoad = config.Get("TraceAssemblyLoad").zTryParseAs(false); //AssemblyResolve.UpdateAssembly = config.Get("UpdateAssembly").zTryParseAs(false); ; //AssemblyResolve.UpdateSubDirectory = config.Get("UpdateAssemblySubDirectory", AssemblyResolve.UpdateSubDirectory); ; //AssemblyResolve.TraceUpdateAssembly = config.Get("TraceUpdateAssembly").zTryParseAs(false); } AssemblyResolve.Start(); }
public void Dispose() { _runSourceInitEndMethods.CallEndMethods(); if (_currentRunSource == this) { _currentRunSource = null; } DisposeData(); if (gdtResult != null) { gdtResult.Dispose(); gdtResult = null; } AssemblyResolve.Stop(); //_trace.Writed -= new WritedEvent(EventWrited); }
// 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_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); } } }