public async Task CompileAndSave(CompileAndSaveMessage message) { var processCancelSource = new CancellationTokenSource(); var processCancelToken = processCancelSource.Token; // ReSharper disable once MethodSupportsCancellation var processTask = Task.Run(() => ProcessDumpQueue(processCancelToken)); var outputKind = string.Equals(Path.GetExtension(message.AssemblyPath), ".exe", StringComparison.OrdinalIgnoreCase) ? OutputKind.ConsoleApplication : OutputKind.DynamicallyLinkedLibrary; var platform = !Is64BitProcess && (outputKind == OutputKind.ConsoleApplication || outputKind == OutputKind.WindowsApplication) ? Platform.AnyCpu32BitPreferred : Platform.AnyCpu; try { var script = CreateScript(message.Code, message.OptimizationLevel, _scriptOptions, outputKind, platform); // ReSharper disable once MethodSupportsCancellation if (script != null) { var diagnostics = await script.SaveAssembly(message.AssemblyPath).ConfigureAwait(false); await DisplayErrors(diagnostics).ConfigureAwait(false); } } catch (Exception e) { ReportUnhandledException(e); } finally { _outWriter.Flush(); _errorWriter.Flush(); processCancelSource.Cancel(); await processTask.ConfigureAwait(false); } }
public Task CompileAndSave(CompileAndSaveMessage message) { return(InvokeAsync(nameof(CompileAndSave), message)); }