private void WriteDbImage(ControllerContext context) { ImageData.Image image = null; try { if (GrantPermission(id)) { using (var db = ImageData.CMSImageDataContext.Create(context.HttpContext)) { image = db.Images.SingleOrDefault(ii => ii.Id == id); } } else { (new HttpUnauthorizedResult()).ExecuteResult(context); return; } } catch { } if (image.IsNull() || (shouldBePublic && image?.IsPublic == false)) { WritePng(context, NoPic()); } else if (image?.Secure == true) { if (nodefault) { return; } if (portrait) { WriteJpeg(context, tiny ? NoPic1() : NoPic2()); } else { WritePng(context, NoPic()); } } else { if (w.HasValue && h.HasValue) { var ri = FetchResizedImage(image, w.Value, h.Value, mode); WriteJpeg(context, ri); } else { WriteImage(context, image.Mimetype ?? "image/jpeg", image.Bits); } } }
private void WriteDbImage(ControllerContext context) { #if DEBUG // speed up local development when no CMSi_ database exists // the try catch takes too long and the DatabaseExists function runs quickly using (var db = CMSDataContext.Create(context.HttpContext)) if (!DbUtil.DatabaseExists("CMSi_" + db.Host)) { return; } #endif ImageData.Image image = null; try { if (GrantPermission(id)) { using (var db = ImageData.CMSImageDataContext.Create(context.HttpContext)) { image = db.Images.SingleOrDefault(ii => ii.Id == id); } } else { (new HttpUnauthorizedResult()).ExecuteResult(context); return; } } catch { } if (image.IsNull() || (shouldBePublic && image?.IsPublic == false)) { WritePng(context, NoPic()); } else if (image?.Secure == true) { if (nodefault) { return; } if (portrait) { WriteJpeg(context, tiny ? NoPic1() : NoPic2()); } else { WritePng(context, NoPic()); } } else { if (w.HasValue && h.HasValue) { var ri = FetchResizedImage(image, w.Value, h.Value, mode); WriteJpeg(context, ri); } else { WriteImage(context, image.Mimetype ?? "image/jpeg", image.Bits); } } }