public static void Run() { try { compiler = new DotNetCompiler(LibraryContext.Current, @"game.exe"); compiler.InitCompiler(); compiler.CompileScripts(); compiler.CompileRooms(); compiler.Save(); Game.InitRoom += new Action <Room>(Game_InitRoom); //Game.Run(); } catch (ProgramError err) { int line = 0, col = 0; string msg = string.Format("ERROR in code at line {0} pos {1}:\n{2}", line, col, err.Message); switch (err.Location) { case CodeLocation.Script: msg = string.Format("COMPILAION ERROR in Script:\nError in code at line {0}:\n\n\nat position {1}: {2}", line, col, err.Message); break; } System.Windows.Forms.MessageBox.Show(msg, Game.Name, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } }
private async Task StartBuildAsync(string name) { // read source from blob storage, compile it and write image to output folder // todo: all validity checks below use catch Exception for simplicity of POC which // should be converted to specific exception types string src; try { await UpdateBuildStatus(name, "Reading source blob..."); src = BlobClient.ReadBlob($"{name}.cs"); } catch (Exception) { await UpdateBuildStatus(name, "Failed reading source blob."); return; } byte[] compiled; try { await UpdateBuildStatus(name, "Starting build.."); compiled = DotNetCompiler.CompileConsoleApp(src); } catch (Exception ex) { await UpdateBuildStatus(name, $"Build Failed: {ex}"); return; } try { await UpdateBuildStatus(name, "Writing image.."); // we use 'exe_' suffix to avoid browser warning on unsecure content BlobClient.WriteBlob("output", $"{name}.exe_", compiled); } catch (Exception) { await UpdateBuildStatus(name, $"Write image Failed!"); return; } await UpdateBuildStatus(name, "Success!"); }