Exemplo n.º 1
0
        //[ValidateInput(false)]
        //public ActionResult watermark_handler()
        //{
        //    PrepairEditor(delegate(Editor editor)
        //    {
        //        editor.UploadImage += new UploadImageEventHandler(Editor1_UploadImage);
        //    });
        //    return new EmptyResult();
        //}

        void Editor1_UploadImage(object sender, UploadImageEventArgs args)
        {
            string text = Request["txt_watermark"];

            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(400, 200, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
            {
                System.Drawing.FontStyle style = System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic | System.Drawing.FontStyle.Underline;
                System.Drawing.Font      font  = new System.Drawing.Font(System.Drawing.FontFamily.GenericMonospace, 26, style);
                System.Drawing.SizeF     size  = g.MeasureString(text, font);
                g.DrawString(text, font, System.Drawing.Brushes.DarkGreen, bitmap.Width - size.Width, bitmap.Height - size.Height);
            }

            RTE.ConfigWatermark watermark = new ConfigWatermark();
            watermark.XAlign    = "right";
            watermark.YAlign    = "bottom";
            watermark.XOffset   = -10;
            watermark.YOffset   = -10;
            watermark.MinWidth  = 450;
            watermark.MinHeight = 300;
            watermark.Image     = bitmap;

            args.Watermarks.Clear();
            args.Watermarks.Add(watermark);
            args.DrawWatermarks = true;
        }
Exemplo n.º 2
0
        public void UpdateViewModel_WhenEventIsRaised()
        {
            //Arrange
            var viewMock = new Mock <IUploadImageView>();

            viewMock.Setup(v => v.Model).Returns(new UploadImageViewModel());
            var imageProcessorServiceMock = new Mock <IImageProcessorService>();
            var userServiceMock           = new Mock <IUserService>();
            var uploadedImageServiceMock  = new Mock <IUploadedImageService>();
            var fileSaverMock             = new Mock <IFileSaverService>();
            int anyInt = It.IsAny <int>();

            var args = new UploadImageEventArgs()
            {
                ContentLength = anyInt,
                FileName      = It.IsAny <string>(),
                InputStream   = Stream.Null
            };

            var presenter = new UploadImagePresenter(
                viewMock.Object, uploadedImageServiceMock.Object, userServiceMock.Object, imageProcessorServiceMock.Object, fileSaverMock.Object);

            //Act
            viewMock.Raise(v => v.EventImageUpload += null, args);

            //Assert
            Assert.IsFalse(viewMock.Object.Model.Succeeded);
            Assert.IsNotNull(viewMock.Object.Model.ErrorMessage);
        }
Exemplo n.º 3
0
        public void CallImageProcessorServiceProcessImageTwice_WhenEventIsRaised()
        {
            //Arrange
            var viewMock = new Mock <IUploadImageView>();

            viewMock.Setup(v => v.Model).Returns(new UploadImageViewModel());
            var imageProcessorServiceMock = new Mock <IImageProcessorService>();
            var userServiceMock           = new Mock <IUserService>();
            var uploadedImageServiceMock  = new Mock <IUploadedImageService>();
            var fileSaverMock             = new Mock <IFileSaverService>();
            int anyInt = It.IsAny <int>();

            var args = new UploadImageEventArgs()
            {
                ContentLength = anyInt,
                FileName      = It.IsAny <string>(),
                InputStream   = Stream.Null
            };

            var presenter = new UploadImagePresenter(
                viewMock.Object, uploadedImageServiceMock.Object, userServiceMock.Object, imageProcessorServiceMock.Object, fileSaverMock.Object);

            //Act
            viewMock.Raise(v => v.EventImageUpload += null, args);

            //Assert
            imageProcessorServiceMock.Verify(s => s.ProcessImage(
                                                 new byte[anyInt], Constants.ThumbnailImageSize, Constants.ThumbnailImageSize, null, Constants.ThumbnailImageQualityPercentage), Times.Once);
            imageProcessorServiceMock.Verify(s => s.ProcessImage(
                                                 new byte[anyInt], Constants.LargeImageSize, Constants.LargeImageSize, null, Constants.OriginalImageQualityPercentage), Times.Once);
        }
Exemplo n.º 4
0
        private void OnImageUpload(object sender, UploadImageEventArgs e)
        {
            int    fileLength = e.ContentLength;
            string fileName   = e.FileName;

            byte[] photoBytes = new byte[fileLength];
            e.InputStream.Read(photoBytes, 0, fileLength);
            var folderName = string.Format("{0:ddMMyy}", DateTime.Now);

            try
            {
                // processing image
                var processedImgThumbnail = this.imageProcessorService.ProcessImage(
                    photoBytes,
                    Constants.ThumbnailImageSize,
                    Constants.ThumbnailImageSize,
                    Path.GetExtension(fileName),
                    Constants.ThumbnailImageQualityPercentage);
                var processedImgOriginal = this.imageProcessorService.ProcessImage(
                    photoBytes,
                    Constants.LargeImageSize,
                    Constants.LargeImageSize,
                    Path.GetExtension(fileName),
                    Constants.OriginalImageQualityPercentage);

                // saving images
                var dirToSaveInThumbnail = Path.Combine(Server.MapPath("../" + Constants.ContentUploadedTakeABreakThumbnailsRelPath), folderName);
                var dirToSaveInOriginal  = Path.Combine(Server.MapPath("../" + Constants.ContentUploadedTakeABreakOriginalsRelPath), folderName);

                fileName = this.fileSaverService.SaveFile(processedImgThumbnail, dirToSaveInThumbnail, fileName);
                fileName = this.fileSaverService.SaveFile(processedImgOriginal, dirToSaveInOriginal, fileName);
            }
            catch (Exception ex)
            {
                this.View.Model.ErrorMessage = ex.Message;
                this.View.Model.Succeeded    = false;
                return;
            }

            // saving image urls to db
            try
            {
                var thumbnailImgUrl = Constants.ProgrammersSpotUrl + Constants.ContentUploadedTakeABreakThumbnailsRelPath + folderName + "/" + fileName;
                var originalImgUrl  = Constants.ProgrammersSpotUrl + Constants.ContentUploadedTakeABreakOriginalsRelPath + folderName + "/" + fileName;
                var uploader        = this.userService.GetRegularUserById(e.UploaderId);
                this.uploadedImageService.UploadImage(e.ImgTitle, thumbnailImgUrl, originalImgUrl, uploader);

                this.View.Model.Succeeded = true;
            }
            catch (SqlException ex)
            {
                this.View.Model.ErrorMessage = ex.Message;
                this.View.Model.Succeeded    = false;
            }
        }
Exemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.User.Identity.IsAuthenticated)
            {
                Response.Redirect(this.ResolveUrl(string.Format("~/Account/Login?ReturnUrl={0}", HttpUtility.UrlEncode("/TakeABreak/UserUploadImage"))));
            }

            if (this.Request.Files.Count == 0)
            {
                Response.StatusCode = 400;
                Response.End();
                return;
            }

            var file = this.Request.Files[0];
            var args = new UploadImageEventArgs()
            {
                ImgTitle      = this.Request.Headers["image-title"],
                ContentLength = file.ContentLength,
                InputStream   = file.InputStream,
                FileName      = file.FileName,
                UploaderId    = this.User.Identity.GetUserId()
            };

            this.EventImageUpload?.Invoke(sender, args);

            Response.ClearContent();
            Response.Expires          = -1;
            this.Response.ContentType = "application/json";
            if (!this.Model.Succeeded)
            {
                this.Response.Write(string.Format("{'ErrorMsg' : '{0}'}", Business.Common.Constants.FailedUploadMessage));
                this.Response.End();
            }
            else
            {
                this.Response.Write("{}");
                this.Response.End();
            }
        }
 private void OnUploadingImage(object sender, UploadImageEventArgs e)
 {
     this.imageFileName = this.imageUploader.Upload(e.Image, e.Server, e.ImageFileName, e.FolderName);
 }