public async Task <ActionResult> ThumbAsync(int id, int width = 0, int height = 0, RenderModes mode = RenderModes.RenderMode_Fit, int trace = 0) { StringBuilder message = new StringBuilder(); try { if (width <= 120 && height <= 120) { byte[] cache = await HttpRuntime.Cache.GetOrAddSlidingAsync( string.Format("thumb_image_{0}_{1}x{2}_{3}", id, width, height, (int)mode), async (expire) => { expire.After = TimeSpan.FromHours(1); var data = await db.Contents.FindAsync(id); using (MemoryStream trg = new MemoryStream()) using (MemoryStream src = new MemoryStream(data.Data)) { MediaController.WriteImage(src, trg, width, height, mode); return(trg.GetBuffer()); } }); return(new FileStreamResult(new MemoryStream(cache), "image/png")); } else { var data = await db.Contents.FindAsync(id); using (MemoryStream src = new MemoryStream(data.Data)) { MemoryStream trg = new MemoryStream(); MediaController.WriteImage(src, trg, width, height, mode); return(new FileStreamResult(trg, "image/png")); } } } catch (Exception ex) { if (trace > 0) { message.Append(ex.ToString()); } } if (trace == 0) { return(RedirectToAction("BadImg")); } else { return(Content(message.Length == 0 ? "OK" : message.ToString())); } }
public async Task <ActionResult> ThumbAsync(int id, int width = 0, int height = 0, RenderModes mode = RenderModes.RenderMode_Fit, int trace = 0) { StringBuilder message = new StringBuilder(); try { Report report = db.Frames.OfType <Report>() .Include(r => r.ReportServer) .FirstOrDefault(r => r.FrameId == id) ; if (width <= 120 && height <= 120) { byte[] cache = await HttpRuntime.Cache.GetOrAddSlidingAsync( string.Format("thumb_report_{0}_{1}x{2}_{3}", report.FullPath, width, height, (int)mode), async (expire) => { expire.After = TimeSpan.FromHours(1); byte[] img = await GetReportBytesAsync(report); using (MemoryStream trg = new MemoryStream()) using (MemoryStream src = new MemoryStream(img)) { MediaController.WriteImage(src, trg, width, height, mode); return(trg.GetBuffer()); } }); return(new FileStreamResult(new MemoryStream(cache), "image/png")); } else { byte[] img = await GetReportBytesAsync(report); using (MemoryStream src = new MemoryStream(img)) { MemoryStream trg = new MemoryStream(); MediaController.WriteImage(src, trg, width, height, mode); return(new FileStreamResult(trg, "image/png")); } } } catch (Exception ex) { if (trace > 0) { message.Append(ex.ToString()); } if (trace > 1) { Report report = db.Frames.OfType <Report>() .Include(r => r.ReportServer) .FirstOrDefault(r => r.FrameId == id) ; message.Append("\n"); if (report == null) { message.AppendFormat("\nReport id {0} not found", id); } else { message.AppendFormat("\nReport name: {0}", report.Name); message.AppendFormat("\nReport path: {0}", report.Path); message.AppendFormat("\nReport server URL: {0}", report.ReportServer.BaseUrl); message.AppendFormat("\nReport server account: {0}\\{1}", report.ReportServer.Domain, report.ReportServer.User); //message.AppendFormat("\nReport server passwrd: {0}", HttpUtility.HtmlEncode(RsaUtil.Decrypt(report.ReportServer.Password))); } } } if (trace == 0) { return(RedirectToAction("BadImg", "Media")); } else { return(Content(message.Length == 0 ? "OK" : message.ToString())); } }