public ReportGen CreateReport(int tool) { string report; try { using (MemoryStream stream = new MemoryStream()) { RPCReportGenerator gen = new RPCReportGenerator(stream); gen.WriteReport(RPCDetectorCore.Logger); stream.Position = 0; using (StreamReader reader = new StreamReader(stream)) report = reader.ReadToEnd(); } } catch (System.Exception ex) { Logger.LogError($"Failed to write report: {ex.Message}"); throw; } switch (tool) { case 0: return(Source_PasteEE(report)); case 1: return(Source_Log(report)); case 2: return(Source_Haste(report)); } return(new ReportGen(null, "Failed to upload report.")); }
protected override async Task OnExecuteAsync() { await PrintAsync("Generating report..."); await UniTask.SwitchToThreadPool(); string report; using (MemoryStream stream = new MemoryStream()) { RPCReportGenerator gen = new RPCReportGenerator(stream); gen.WriteReport(RPCDetectorCore.Logger); report = Encoding.UTF8.GetString(stream.ToArray()); } PasteResponse paste; try { paste = PasteAPI.Upload(report); } catch (Exception ex) { await PrintAsync("Failed to upload report."); Logger.LogError("Failed to upload report: {0}", ex.Message); throw; } string url = $"https://paste.ee/d/{paste.id}"; await UniTask.SwitchToMainThread(); await PrintAsync($"RPC Report URL: {url}"); if (Context.Actor is UnturnedUser uu) { if (uu.Player != null) { uu.Player?.Player?.sendBrowserRequest("Open RPC Report", url); } } }