Esempio n. 1
0
        public override void ExecuteResult(ControllerContext context)
        {
            context.HttpContext.Response.Clear();
            context.HttpContext.Response.Cache.SetExpires(DateTime.Now.AddMinutes(10));
            context.HttpContext.Response.Cache.SetCacheability(HttpCacheability.Public);

            if (id == -2)
            {
                context.HttpContext.Response.ContentType = "image/png";
                context.HttpContext.Response.BinaryWrite(NoPic2());
            }
            else if (id == -1)
            {
                context.HttpContext.Response.ContentType = "image/jpeg";
                context.HttpContext.Response.BinaryWrite(NoPic1());
            }
            else if (id == -3)
            {
                context.HttpContext.Response.ContentType = "image/jpeg";
                context.HttpContext.Response.BinaryWrite(NoPic3());
            }
            else if (id == -4)
            {
                context.HttpContext.Response.ContentType = "image/jpeg";
                context.HttpContext.Response.BinaryWrite(NoMalePic());
            }
            else if (id == -5)
            {
                context.HttpContext.Response.ContentType = "image/jpeg";
                context.HttpContext.Response.BinaryWrite(NoFemalePic());
            }
            else if (id == -6)
            {
                context.HttpContext.Response.ContentType = "image/png";
                context.HttpContext.Response.BinaryWrite(NoPic2Sm());
            }
            else if (id == -7)
            {
                context.HttpContext.Response.ContentType = "image/jpeg";
                context.HttpContext.Response.BinaryWrite(NoMalePicSm());
            }
            else if (id == -8)
            {
                context.HttpContext.Response.ContentType = "image/jpeg";
                context.HttpContext.Response.BinaryWrite(NoFemalePicSm());
            }
            else
            {
                ImageData.Image i = null;

                var idb = DbUtil.CheckImageDatabaseExists(Util.CmsHost.Replace("CMS_", "CMSi_"));
                if (idb == DbUtil.CheckDatabaseResult.DatabaseExists)
                {
                    try
                    {
                        i = ImageData.DbUtil.Db.Images.SingleOrDefault(ii => ii.Id == id);
                    }
                    // ReSharper disable once EmptyGeneralCatchClause
                    catch (Exception)
                    {
                    }
                }

                if (i == null || i.Secure == true)
                {
                    if (nodefault)
                    {
                        return;
                    }

                    if (portrait)
                    {
                        context.HttpContext.Response.ContentType = "image/jpeg";
                        context.HttpContext.Response.BinaryWrite(tiny ? NoPic1() : NoPic2());
                    }
                    else
                    {
                        context.HttpContext.Response.ContentType = "image/png";
                    }

                    context.HttpContext.Response.BinaryWrite(NoPic());
                }
                else
                {
                    if (w.HasValue && h.HasValue)
                    {
                        context.HttpContext.Response.ContentType = "image/jpeg";
                        var ri = FetchResizedImage(i, w.Value, h.Value, mode);
                        context.HttpContext.Response.BinaryWrite(ri);
                    }
                    else
                    {
                        context.HttpContext.Response.ContentType = i.Mimetype ?? "image/jpeg";
                        context.HttpContext.Response.BinaryWrite(i.Bits);
                    }
                }
            }
        }