Beispiel #1
0
        public ActionResult Render(Guid?guid, Int32?width = null, Int32?height = null)
        {
            this.Response.Clear();

            YoumotoDbContext context = new YoumotoDbContext();
            Picture          picture = guid == null ? null : PicturePersister.LoadSingle(context, guid.Value);


            if (picture == null)
            {
                var bitmap = ESolutions.Youmoto.Web.UI.Properties.Resources.NoImage;
                this.Response.ContentType = "image/png";
                bitmap.Save(this.Response.OutputStream, ImageFormat.Png);
            }
            else
            {
                var bitmap = picture.GetBitmap(width, height);
                this.Response.ContentType = "image/jpg";

                Int64             compression = width.HasValue || height.HasValue ? 60L : 100L;
                EncoderParameters parameters  = new EncoderParameters(1);
                parameters.Param[0] = new EncoderParameter(Encoder.Quality, compression);
                ImageCodecInfo codec = ImageCodecInfo.GetImageEncoders().FirstOrDefault(runner => runner.FormatID == ImageFormat.Jpeg.Guid);
                bitmap.Save(this.Response.OutputStream, codec, parameters);
            }

            this.Response.End();
            return(null);
        }
 public void TestLoadSingleWithNonExistingGuid()
 {
     using (var context = new YoumotoDbContext(Effort.DbConnectionFactory.CreateTransient()))
     {
         var picture = PicturePersister.LoadSingle(context, new Guid("{633CEC22-87CF-4D27-9FA6-578322675617}"));
         Assert.IsNull(picture);
     }
 }
        public void TestLoadSingleWithExistingGuid()
        {
            using (var context = new YoumotoDbContext(Effort.DbConnectionFactory.CreateTransient()))
            {
                Picture newPicture = PicturePersister.Create();
                context.Pictures.Add(newPicture);
                context.SaveChanges();

                var picture = PicturePersister.LoadSingle(context, newPicture.Guid);
                Assert.IsNotNull(picture);
                Assert.AreEqual(newPicture, picture);
            }
        }