private bool TryBuildAndRun(Script<object> newScript, object globals, ref ScriptState<object> state, out Compilation newCompilation, CancellationToken cancellationToken) { newCompilation = newScript.GetCompilation(); try { newScript.Build(cancellationToken); // display warnings: DisplayDiagnostics(newCompilation.GetDiagnostics(cancellationToken).Where(d => d.Severity == DiagnosticSeverity.Warning)); } catch (CompilationErrorException e) { DisplayDiagnostics(e.Diagnostics.Where(d => d.Severity == DiagnosticSeverity.Error || d.Severity == DiagnosticSeverity.Warning)); return false; } try { var task = (state == null) ? newScript.RunAsync(globals, cancellationToken) : newScript.ContinueAsync(state, cancellationToken); state = task.GetAwaiter().GetResult(); } catch (Exception e) { DisplayException(e); return false; } return true; }
private bool TryBuildAndRun(Script<object> newScript, object globals, ref ScriptState<object> state, CancellationToken cancellationToken) { var diagnostics = newScript.Build(cancellationToken); DisplayDiagnostics(diagnostics); if (diagnostics.HasAnyErrors()) { return false; } try { var task = (state == null) ? newScript.RunAsync(globals, cancellationToken) : newScript.ContinueAsync(state, cancellationToken); state = task.GetAwaiter().GetResult(); } catch (Exception e) { DisplayException(e); return false; } return true; }