public FileContentResult Image(string tableName, string uidName, string uidValue, string fieldName) { if (uidValue == "0") { Response.StatusCode = 404; } string sql = string.Format("select {0} from {1} where {2} = {3}", fieldName, tableName, uidName, uidValue); using ( var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MsSqlConnectionString"].ConnectionString)) { using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = sql; cmd.CommandType = CommandType.Text; conn.Open(); var result = cmd.ExecuteScalar(); if (result == null || result is DBNull) { Response.StatusCode = 404; } Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate); return(new FileContentResult(result is DBNull || result == null ? new byte[0] : (byte[])result, MIMETypeWrapper.GetMIMEForData( new Binary(result is DBNull ? new byte[0] : (byte[])result)))); } } }
public FileResult Avatar(Guid UID, int?Width) { var cover = db.UserProfiles.FirstOrDefault(x => x.UserID == UID); FileStreamResult result; if (cover == null || cover.Avatar == null || UID == new Guid()) { var fs = new FileStream(Server.MapPath("/content/noimage.jpg"), FileMode.Open, FileAccess.Read); result = new FileStreamResult(fs, "image/jpg"); } else { try { var ms = new MemoryStream(cover.Avatar.ToArray()); ms.Seek(0L, SeekOrigin.Begin); var bmpIn = new Bitmap(ms); ImageFormat loFormat = bmpIn.RawFormat; Bitmap bmpOut = bmpIn.CreateThumbnail(Width ?? 64, Width ?? 64, true); ms.Close(); var res = new MemoryStream(); bmpOut.Save(res, loFormat); res.Seek(0L, SeekOrigin.Begin); result = new FileStreamResult(res, MIMETypeWrapper.GetMIME(loFormat.ToString())); } catch (Exception) { var fs = new FileStream(Server.MapPath("/content/anon.jpg"), FileMode.Open, FileAccess.Read); result = new FileStreamResult(fs, "image/jpg"); } } return(result); }
/*[OutputCache(Duration = 86400, Location = OutputCacheLocation.Client)]*/ public FileContentResult Resize(int maxWidth, int maxHeight, string filePath, int?padding, string brushColor, int?brushWidthData, string backColor, string aligh, string vertalign, bool skiplogo = true, bool skipRotate = false) { Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetMaxAge(new TimeSpan(1, 0, 0)); string rawIfModifiedSince = Request.Headers.Get("If-Modified-Since"); if (string.IsNullOrEmpty(rawIfModifiedSince)) { Response.Cache.SetLastModified(DateTime.Now); } else { DateTime ifModifiedSince = DateTime.Parse(rawIfModifiedSince); if (ifModifiedSince.AddHours(1) >= DateTime.Now) { Response.StatusCode = 304; return(new FileContentResult(new byte[0], MIMETypeWrapper.GetMIMEForData( new Binary(new byte[0])))); } } if (!padding.HasValue) { padding = 0; } if (brushColor.IsNullOrEmpty()) { brushColor = "#FFFFFF"; } if (!brushWidthData.HasValue) { brushWidthData = 0; } if (backColor.IsNullOrEmpty()) { backColor = "#FFFFFF"; } if (aligh.IsNullOrEmpty()) { aligh = "center"; } if (vertalign.IsNullOrEmpty()) { vertalign = "center"; } var fileContent = ImageBySize(filePath, maxWidth, maxHeight, padding.Value, brushColor, brushWidthData.ToString(), backColor, aligh, vertalign, skiplogo, skipRotate); return(fileContent); }
public ActionResult Image(int id) { var xd = db.ThemeProperties.First(x => x.ID == id); if (!xd.IsNullImage) { var prop = xd.ValueBinary; return(new FileContentResult(prop is DBNull || prop == null ? new byte[0] : prop.ToArray(), MIMETypeWrapper.GetMIMEForData( new Binary(prop is DBNull ? new byte[0] : prop.ToArray())))); } return(new EmptyResult()); }
public FileResult Flag(int ID, int?width) { var cached = HttpRuntime.Cache.Get(string.Format("Flag_{0}_{1}", ID, width)); if (cached is byte[]) { return(new FileStreamResult(new MemoryStream((byte[])cached), MIMETypeWrapper.GetMIME("jpeg"))); } var cover = db.Languages.First(x => x.ID == ID); FileStreamResult result; if (cover == null || cover.Icon == null) { var fs = new FileStream(Server.MapPath("/Content/nopic.gif"), FileMode.Open, FileAccess.Read); result = new FileStreamResult(fs, "image/gif"); } else { var ms = new MemoryStream(cover.Icon.ToArray()); ms.Seek(0L, SeekOrigin.Begin); var bmpIn = new Bitmap(ms); ImageFormat loFormat = bmpIn.RawFormat; Bitmap bmpOut = bmpIn.CreateThumbnail(width ?? cover.getProperWidth(cover.Width), cover.getProperHeight(width ?? cover.Width), false); ms.Close(); var res = new MemoryStream(); bmpOut.Save(res, loFormat); res.Seek(0L, SeekOrigin.Begin); HttpRuntime.Cache.Insert(string.Format("Flag_{0}_{1}", ID, width), res.ToArray(), null, DateTime.Now.AddDays(1D), Cache.NoSlidingExpiration); result = new FileStreamResult(res, MIMETypeWrapper.GetMIME(loFormat.ToString())); } return(result); }
public ActionResult Index(string url1, string url2, string url3, string url4, string url5, string url6, string url7, string url8, string url9, string url10, string url11, string url12, string url13, string url14, string url15, int?book, int?page) { if (AccessHelper.Repository.ContainsKey("Refreshed")) { AccessHelper.Repository.Remove("Refreshed"); } var path = new List <string> { url1, url2, url3, url4, url5, url6, url7, url8, url9, url10, url11, url12, url13, url14, url15 }; var jnp = "~/" + string.Join("/", path.Where(x => !x.IsNullOrEmpty()).ToList()); var mapped = Server.MapPath(jnp); if (System.IO.File.Exists(mapped) && Path.GetExtension(mapped) != ".cshtml") { return(File(mapped, MIMETypeWrapper.GetMIME(Path.GetExtension(mapped)))); } var info = CommonPageInfo.InitFromQueryParams(path.Where(x => !x.IsNullOrEmpty()).ToList()); AccessHelper.CurrentPageInfo = info; ViewBag.CommonInfo = info; return(View(info)); }
public FileContentResult StripeCSS() { Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetMaxAge(new TimeSpan(1, 0, 0)); string rawIfModifiedSince = Request.Headers.Get("If-Modified-Since"); if (string.IsNullOrEmpty(rawIfModifiedSince)) { Response.Cache.SetLastModified(DateTime.Now); } else { DateTime ifModifiedSince = DateTime.Parse(rawIfModifiedSince); if (ifModifiedSince.AddHours(1) >= DateTime.Now) { Response.StatusCode = 304; return(new FileContentResult(new byte[0], MIMETypeWrapper.GetMIMEForData( new Binary(new byte[0])))); } } var cats = CatalogBrowser.CategoriesList.Where(x => x.Value.FullUrl.Split <string>("/").Count() <= 4). Where(x => x.Value != null /* && x.Value.Image != null && x.Value.Image.Length > 0*/).ToList(); var count = cats.Count; var css = ""; for (int i = 0; i < count; i++) { css += ".cat-i-" + cats[i].Value.ID + " {"; css += "background: url(/Master/ru/Image/CatalogMenuSprite?group=" + (Math.Floor((decimal)i / 150)) + ");"; css += "background-position: -" + ((i % 150) * 45) + "px; 0px"; css += "} "; } return(new FileContentResult(Encoding.UTF8.GetBytes(css), "text/css")); }
protected static bool Send(string sendTo, string sendFrom, string sendSubject, string sendMessage, List <string> attachments, List <KeyValuePair <string, MemoryStream> > memAttaches, out string result) { try { bool bTest = sendTo.IsMailAdress(); if (bTest == false) { result = "Неправильно указан адрес: " + sendTo; return(false); } var message = new MailMessage( sendFrom, sendTo, sendSubject, sendMessage); message.IsBodyHtml = true; message.BodyEncoding = Encoding.UTF8; foreach (string attach in attachments) { var attached = new Attachment(attach, MediaTypeNames.Application.Octet); //attached.NameEncoding = Encoding.UTF8; message.Attachments.Add(attached); } foreach (var pair in memAttaches) { pair.Value.Position = 0; var attached = new Attachment(pair.Value, pair.Key, MIMETypeWrapper.GetMIME(Path.GetExtension(pair.Key).Substring(1))); //attached.NameEncoding = Encoding.UTF8; message.Attachments.Add(attached); } // create smtp client at mail server location var client = new SmtpClient(SiteSetting.Get <string>("SMTP")); if (SiteSetting.Get <Int32>("SMTPPort") > 0) { client.Port = SiteSetting.Get <Int32>("SMTPPort"); } if (SiteSetting.Get <string>("SMTPLogin").IsNullOrEmpty() || SiteSetting.Get <string>("SMTPPass").IsNullOrEmpty()) { client.UseDefaultCredentials = true; } else { client.Credentials = new NetworkCredential(SiteSetting.Get <string>("SMTPLogin"), SiteSetting.Get <string>("SMTPPass")); } client.Send(message); result = ""; return(true); } catch (Exception ex) { result = ex.Message; return(false); } }
/*[OutputCache(Duration = 86400, Location = OutputCacheLocation.Client)]*/ public FileContentResult Image(string tableName, string uidName, string uidValue, string fieldName, int width = 0, int height = 0, string backColor = "", bool forDL = false, int nocache = 0) { Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetMaxAge(new TimeSpan(1, 0, 0)); if (forDL) { var fileName = uidValue + ".jpg"; if (tableName == "StoreCategories") { string nSql = string.Format("select Slug from {1} where {2} = {3}", fieldName, tableName, uidName, uidValue); using ( var conn = new SqlConnection( ConfigurationManager.ConnectionStrings["MsSqlConnectionString"].ConnectionString)) { using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = nSql; cmd.CommandType = CommandType.Text; conn.Open(); object result = null; try { result = cmd.ExecuteScalar(); } catch { } if (result != null && !(result is DBNull) && !result.ToString().IsNullOrEmpty()) { fileName = result + ".jpg"; } } } } Response.Headers.Add("Content-Disposition", "attachment; filename=\"" + HttpContext.Server.UrlEncode(fileName) + "\""); } string rawIfModifiedSince = Request.Headers.Get("If-Modified-Since"); if (string.IsNullOrEmpty(rawIfModifiedSince) || nocache == 1) { Response.Cache.SetLastModified(DateTime.Now); } else { DateTime ifModifiedSince = DateTime.Parse(rawIfModifiedSince); if (ifModifiedSince.AddHours(1) >= DateTime.Now) { Response.StatusCode = 304; return(new FileContentResult(new byte[0], MIMETypeWrapper.GetMIMEForData( new Binary(new byte[0])))); } } if (uidValue == "0") { Response.StatusCode = 404; } string sql = string.Format("select {0} from {1} where {2} = {3}", fieldName, tableName, uidName, uidValue); using ( var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MsSqlConnectionString"].ConnectionString)) { using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = sql; cmd.CommandType = CommandType.Text; conn.Open(); object result = null; try { result = cmd.ExecuteScalar(); } catch { sql = string.Format("select {0} from {1} where {2} = {3}", fieldName, tableName.EndsWith("es") ? tableName.Substring(0, tableName.Length - 2) : tableName.Substring(0, tableName.Length - 1), uidName, uidValue); cmd.CommandText = sql; result = cmd.ExecuteScalar(); } if (result == null || result is DBNull) { Response.StatusCode = 404; return(new FileContentResult(new byte[0], "image/jpeg")); } /*Response.Cache.SetCacheability(HttpCacheability.Public);*/ if (height > 0 || width > 0) { using (var ms = new MemoryStream((byte[])result)) { ms.Position = 0; var image = System.Drawing.Image.FromStream(ms); var resized = ResizeImage(width, height, image); if (resized != null) { using (var rs = new MemoryStream()) { var path = Server.MapPath(SiteSetting.Get <string>("WatermarkText")); if (SiteSetting.Get <bool>("WatermarkShow")) { Image imgWatermark = new Bitmap(path); var bitmap = new Bitmap(width, height); var graphics = Graphics.FromImage(bitmap); graphics.CompositingQuality = CompositingQuality.HighSpeed; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.CompositingMode = CompositingMode.SourceCopy; graphics.DrawImage(resized, (float)0, (float)0, width, height); int wmWidth = /*imgWatermark.Width*/ width / 10; int wmHeight = /*imgWatermark.Height*/ height / 10; var bmWatermark = new Bitmap(bitmap); bmWatermark.SetResolution(graphics.DpiX, graphics.DpiY); var grWatermark = Graphics.FromImage(bmWatermark); ImageAttributes imageAttributes = new ImageAttributes(); ColorMap colorMap = new ColorMap(); colorMap.OldColor = Color.FromArgb(255, 255, 255, 255); //базовый фоновый цвет colorMap.NewColor = Color.FromArgb(0, 0, 0, 0); ColorMap[] remapTable = { colorMap }; imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap); float[][] colorMatrixElements = { new float[] { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, 0.3f, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } }; var wmColorMatrix = new ColorMatrix(colorMatrixElements); imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); int xPosOfWm = ((bitmap.Width - wmWidth) / 3) * 2; int yPosOfWm = ((bitmap.Height - wmHeight) / 4); /*int yPosOfWm = bitmap.Height - wmHeight - 10;*/ grWatermark.DrawImage(imgWatermark, new Rectangle(xPosOfWm, yPosOfWm, wmWidth, wmHeight), 0, 0, imgWatermark.Width, imgWatermark.Height, GraphicsUnit.Pixel, imageAttributes); yPosOfWm = ((bitmap.Height - wmHeight) / 4) * 3; grWatermark.DrawImage(imgWatermark, new Rectangle(xPosOfWm, yPosOfWm, wmWidth, wmHeight), 0, 0, imgWatermark.Width, imgWatermark.Height, GraphicsUnit.Pixel, imageAttributes); bitmap = bmWatermark; graphics.Dispose(); grWatermark.Dispose(); bitmap.Save(rs, System.Drawing.Imaging.ImageFormat.Jpeg); bitmap.Dispose(); imgWatermark.Dispose(); } else { /* * if (SiteSetting.Get<bool>("ImageRotate")) * { * bitmap = RotateImg(bitmap, 1, Color.White); * } */ resized.Save(rs, System.Drawing.Imaging.ImageFormat.Jpeg); } return(new FileContentResult(rs.ToArray(), MIMETypeWrapper.GetMIMEForData( new Binary(rs.ToArray())))); /* * resized.Save(rs, System.Drawing.Imaging.ImageFormat.Jpeg); * return new FileContentResult(rs.ToArray(), * MIMETypeWrapper.GetMIMEForData( * new Binary(rs.ToArray()))); */ } } } } return(new FileContentResult((byte[])result, MIMETypeWrapper.GetMIMEForData( new Binary((byte[])result)))); } } }
public ActionResult XLS(string List) { var stream = new MemoryStream(); var workbook = new HSSFWorkbook(); var ids = List.Split <int>(";"); var orders = DB.Orders.Where(x => ids.Contains(x.ID) && x.Shop != null && x.Shop.Owner == CurrentUser.ShopOwnerID).ToList(); foreach (var order in orders) { var worksheet = workbook.CreateSheet("Заказ №" + order.OrderNumberOrID.Replace("[", "@").Replace("]", "@")); var header = worksheet.CreateRow(0); header.CreateCell(0).SetCellValue("Информация о заказе:"); header = worksheet.CreateRow(1); header.CreateCell(0).SetCellValue("Номер заказа"); header.CreateCell(1).SetCellValue(order.OrderNumberOrID); header = worksheet.CreateRow(2); header.CreateCell(0).SetCellValue("Статус заказа"); header.CreateCell(1).SetCellValue(order.StatusText); header = worksheet.CreateRow(3); header.CreateCell(0).SetCellValue("Пометка \"Важный\""); header.CreateCell(1).SetCellValue(order.IsImportant.ToYesNoStatus()); header = worksheet.CreateRow(4); header.CreateCell(0).SetCellValue("Дата создания"); header.CreateCell(1).SetCellValue(order.CreateDate.ToString("dd.MM.yyyy HH:mm:ss")); header = worksheet.CreateRow(5); header.CreateCell(0).SetCellValue("Комментарий"); header.CreateCell(1).SetCellValue(order.Warning); header = worksheet.CreateRow(6); header.CreateCell(0).SetCellValue(""); if (order.Consumer != null) { header = worksheet.CreateRow(7); header.CreateCell(0).SetCellValue("Информация о покупателе:"); header = worksheet.CreateRow(8); header.CreateCell(0).SetCellValue("ФИО"); header.CreateCell(1).SetCellValue(order.Consumer.FullName); header = worksheet.CreateRow(9); header.CreateCell(0).SetCellValue("Телефон"); header.CreateCell(1).SetCellValue(order.Consumer.Phone); header = worksheet.CreateRow(10); header.CreateCell(0).SetCellValue(""); } if (order.OrderedProducts.Any()) { header = worksheet.CreateRow(11); header.CreateCell(0).SetCellValue("Заказанные товары:"); header = worksheet.CreateRow(12); header.CreateCell(0).SetCellValue("Название"); header.CreateCell(1).SetCellValue("Артикул"); header.CreateCell(2).SetCellValue("Цена"); header.CreateCell(3).SetCellValue("Количество"); header.CreateCell(4).SetCellValue("Вес"); int index = 5; foreach (var ch in order.CharList) { header.CreateCell(index).SetCellValue(ch.Name); index++; } int msi = 13; foreach (var product in order.OrderedProducts) { header = worksheet.CreateRow(msi); header.CreateCell(0).SetCellValue(product.Product.Name); header.CreateCell(1).SetCellValue(product.Product.Article); header.CreateCell(2).SetCellValue(product.Price.ToString()); header.CreateCell(3).SetCellValue(product.Amount); header.CreateCell(4).SetCellValue(product.Product.Weight.ToString()); index = 5; foreach (var ch in order.CharList) { header.CreateCell(index) .SetCellValue(product.ProductChars.Any(x => x.Name == ch.Name) ? product.ProductChars.First(x => x.Name == ch.Name).Value : ""); index++; } msi++; } } } workbook.Write(stream); return(File(stream.ToArray(), MIMETypeWrapper.GetMIME("xls"), "Order_" + List.Trim(';').Replace(";", "_") + ".xls")); }
public ActionResult Torg12(string List) { var stream = new MemoryStream(); var ids = List.Split <int>(";"); var orders = DB.Orders.Where(x => ids.Contains(x.ID) && x.Shop != null && x.Shop.Owner == CurrentUser.ShopOwnerID).ToList(); var workbook = new HSSFWorkbook(); using (var fs = new FileStream(Server.MapPath("~/Content/TORG12.xls"), FileMode.Open)) { var example = new HSSFWorkbook(fs); int index = 0; foreach (var order in orders) { var sheet = (HSSFSheet)example.GetSheetAt(0); sheet.CopyTo(workbook, "Заказ №" + order.OrderNumberOrID.Replace("'", "").Replace("[", "@").Replace("]", "@"), true, false); var copied = (HSSFSheet)workbook.GetSheetAt(index); copied.GetRow(2).GetCell(1).SetCellValue(order.Requisites); copied.GetRow(9).GetCell(3).SetCellValue(order.Requisites); copied.GetRow(7).GetCell(3).SetCellValue(order.Receiver); copied.GetRow(11).GetCell(3).SetCellValue(order.Receiver); copied.GetRow(3).GetCell(37).SetCellValue(order.Shop.GetSetting("OKPO")); copied.GetRow(8).GetCell(37).SetCellValue(order.Shop.GetSetting("OKPO")); copied.GetRow(16).GetCell(10).SetCellValue(order.OrderNumberOrID); copied.GetRow(16).GetCell(14).SetCellValue(DateTime.Now.ToString("dd.MM.yyyy")); if (order.OrderedProducts.Count > 1) { for (int i = 1; i < order.OrderedProducts.Count; i++) { copied.GetRow(22).CopyRowTo(23); } } int oi = 0; foreach (var product in order.OrderedProducts) { var row = copied.GetRow(22 + oi); row.GetCell(1).SetCellValue(oi + 1); row.GetCell(2).SetCellValue(product.Product.Name); row.GetCell(6).SetCellValue(product.Product.Article); row.GetCell(7).SetCellValue(product.Product.AmountUnitName); row.GetCell(11).SetCellValue(product.Product.UnitCode); row.GetCell(21).SetCellValue(product.Amount); row.GetCell(23).SetCellValue((product.PriceWithoutNDS).ToString("f2")); row.GetCell(25).SetCellValue((product.PriceWithoutNDS * product.Amount).ToString("f2")); row.GetCell(30).SetCellValue("18%"); row.GetCell(33).SetCellValue((product.NDS * product.Amount).ToString("f2")); row.GetCell(36).SetCellValue((product.Price * product.Amount).ToString("f2")); oi++; } var rws1 = copied.GetRow(22 + oi); var rws2 = copied.GetRow(22 + oi + 1); rws1.GetCell(21).SetCellValue(order.OrderedProducts.Sum(x => x.Amount)); rws2.GetCell(21).SetCellValue(order.OrderedProducts.Sum(x => x.Amount)); rws1.GetCell(23).SetCellValue("X"); rws2.GetCell(23).SetCellValue("X"); rws1.GetCell(25).SetCellValue(order.OrderedProducts.Sum(x => x.Amount * x.PriceWithoutNDS).ToString("f2")); rws2.GetCell(25).SetCellValue(order.OrderedProducts.Sum(x => x.Amount * x.PriceWithoutNDS).ToString("f2")); rws1.GetCell(30).SetCellValue("X"); rws2.GetCell(30).SetCellValue("X"); rws1.GetCell(33).SetCellValue(order.OrderedProducts.Sum(x => x.Amount * x.NDS).ToString("f2")); rws2.GetCell(33).SetCellValue(order.OrderedProducts.Sum(x => x.Amount * x.NDS).ToString("f2")); rws1.GetCell(36).SetCellValue(order.OrderedProducts.Sum(x => x.Amount * x.Price).ToString("f2")); rws2.GetCell(36).SetCellValue(order.OrderedProducts.Sum(x => x.Amount * x.Price).ToString("f2")); copied.GetRow(22 + oi + 3) .GetCell(5) .SetCellValue(Russian.ToString(order.OrderedProducts.Count, Gender.Masculine)); var all = order.OrderedProducts.Sum(x => x.Price * x.Amount); var allStr = Russian.ToString((int)all, Gender.Masculine, true) + " рублей " + ((int)((all - (int)all) * 100)).ToString("d2") + " копеек"; copied.GetRow(22 + oi + 13) .GetCell(1) .SetCellValue(allStr); index++; } workbook.Write(stream); } return(File(stream.ToArray(), MIMETypeWrapper.GetMIME("xls"), "Torg12_" + List.Trim(';').Replace(";", "_") + ".xls")); }
public FileContentResult CatalogMenuSprite(int group = 0) { Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetMaxAge(new TimeSpan(1, 0, 0)); string rawIfModifiedSince = Request.Headers.Get("If-Modified-Since"); if (string.IsNullOrEmpty(rawIfModifiedSince)) { Response.Cache.SetLastModified(DateTime.Now); } else { DateTime ifModifiedSince = DateTime.Parse(rawIfModifiedSince); if (ifModifiedSince.AddHours(1) >= DateTime.Now) { Response.StatusCode = 304; return(new FileContentResult(new byte[0], MIMETypeWrapper.GetMIMEForData( new Binary(new byte[0])))); } } /* * if (HttpContext.Cache.Get("CatalogMenuSprite" + group) is FileContentResult) * { * return HttpContext.Cache.Get("CatalogMenuSprite" + group) as FileContentResult; * } */ var defImage = System.IO.File.ReadAllBytes(Server.MapPath("~/content/noimage.jpg")); var cats = CatalogBrowser.CategoriesList.Where(x => x.Value.FullUrl.Split <string>("/").Count() <= 4).ToList(); var images = cats.Select(x => new { ID = x.Value.ID, Value = x.Value }) .Where(x => x.Value != null /* && x.Value.Image!=null*/) .OrderBy(x => x.ID).Skip(group * 150).Take(150) /*.AsParallel().WithDegreeOfParallelism(10)*/ .Select( x => new { x.ID, Image = UniversalEditorController.ResizeImage(45, 45, Image.FromStream( new MemoryStream(x.Value.Image != null && x.Value.Image.Length > 0 ? x.Value.Image.ToArray() : defImage))) }).ToList().OrderBy(x => x.ID).ToList(); var strip = new Bitmap(45 * images.Count(), 45); var graphics = Graphics.FromImage(strip); graphics.CompositingQuality = CompositingQuality.HighSpeed; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.CompositingMode = CompositingMode.SourceCopy; var counter = 0; foreach (var image in images) { graphics.DrawImage(image.Image, new Point(45 * counter, 0)); counter++; } var memoryStream = new MemoryStream(); strip.Save(memoryStream, ImageFormat.Jpeg); graphics.Dispose(); strip.Dispose(); var result = new FileContentResult(memoryStream.ToArray(), "img/jpeg"); /* * HttpContext.Cache.Add("CatalogMenuSprite" + group, result, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, CACHE_DURATION, 0) * , CacheItemPriority.Normal, null); */ return(result); }