public override void Execute(CommandContext context) { if (!Verify(context)) { return; } var item = context.Items[0]; var latestFile = _files.GetLatestHtmlReportFile(item); if (latestFile != null) { //Do not disclose internal server configuration to user var url = $"{HttpContext.Current.Request.Url.Scheme}://{HttpContext.Current.Request.Url.Host}/api/sitecore/lighthouse/ShowFileContent?database={item.Database}&itemId={item.ID}"; SheerResponse.ShowModalDialog(new ModalDialogOptions(url) { Response = false, Width = "1000", Height = "700" }); } else { SheerResponse.ShowError("Latest Lighthouse report was not found.", "Please, try to run report creation before trying to open it."); } }
public ActionResult ShowFileContent(string filename, string itemId, string database) { try { var item = Sitecore.Data.Database.GetDatabase(database).GetItem(itemId); var latestReport = _files.GetLatestHtmlReportFile(item); var filepath = latestReport.FullName; return(new ContentResult() { Content = System.IO.File.ReadAllText(filepath) }); } catch (Exception ex) { Sitecore.Diagnostics.Log.Error($"Lighthouse: was not able find file:'{filename}', itemId:{itemId}, database:{database}", ex, this); return(new ContentResult() { Content = "Sorry, exception happened. Please check Sitecore logs." }); } }