コード例 #1
0
        private ActionResult ProcessException(Exception exception)
        {
            ExceptionProcessor exceptionProcessor = new ExceptionProcessor();

            exceptionProcessor.process(exception);
            return(View("Exception"));
        }
コード例 #2
0
        public JsonResult UploadSetImage(int tempSetNumber, string imageNumber)
        {
            try
            {
                string        path         = Server.MapPath("~/Content/Images/Temp/" + "Set" + tempSetNumber);
                DirectoryInfo setDirectory = new DirectoryInfo(path);
                if (!setDirectory.Exists)
                {
                    setDirectory.Create();
                }

                var uploadImage = Request.Files[0];
                if (uploadImage != null)
                {
                    string fileName = "Image" + imageNumber + uploadImage.FileName.Substring(uploadImage.FileName.LastIndexOf('.'));
                    uploadImage.SaveAs(Server.MapPath("~/Content/Images/Temp/" + "Set" + tempSetNumber + "/" + fileName));
                }
                return(Json("Ok"));
            }
            catch (Exception ex)
            {
                ExceptionProcessor exceptionProcessor = new ExceptionProcessor();
                exceptionProcessor.process(ex);
                return(Json("Exception"));
            }
        }
コード例 #3
0
        public ActionResult DeleteBlogItem(int blogItemId)
        {
            try
            {
                Repository <BlogEntity> blogRepository = new Repository <BlogEntity>();
                BlogEntity blogEntity = blogRepository.GetList().First(b => b.Id == blogItemId);

                if (blogEntity != null)
                {
                    blogRepository.Delete(blogEntity.Id);
                    return(Json(new { result = "Success" }, JsonRequestBehavior.AllowGet));
                }

                return(Json(new { result = "Fail" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ExceptionProcessor exceptionProcessor = new ExceptionProcessor();
                exceptionProcessor.process(ex);
                return(Json(new { result = "Fail" }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #4
0
        public JsonResult UploadImages()
        {
            try
            {
                string resultString = "Files are seccessfully uploaded";
                string resultType   = "success";

                Repository <ImagesInfo> imageInfoRepository = new Repository <ImagesInfo>();

                ImagesInfo imgInfo = imageInfoRepository.GetList().First();

                Repository <ImageEntity> imageRepository = new Repository <ImageEntity>();

                foreach (string file in Request.Files)
                {
                    imgInfo.TotalCount++;
                    var    upload   = Request.Files[file];
                    string fileName = "Image" + imgInfo.TotalCount + upload.FileName.Substring(upload.FileName.LastIndexOf('.'));

                    if (upload != null)
                    {
                        string foundTags  = String.Empty;
                        string resultTags = String.Empty;
                        using (Image inputImage = Image.FromStream(upload.InputStream))
                        {
                            try
                            {
                                PropertyItem basicTag = inputImage.GetPropertyItem(40094); // Hex 9C9E
                                if (basicTag != null)
                                {
                                    foundTags = Encoding.Unicode.GetString(basicTag.Value).Replace("\0", string.Empty);
                                    Char[]   separators = { ',', ';', ' ' };
                                    string[] tagsList   = DeleteLastSemicolon(foundTags.Trim()).Split(separators);
                                    for (int i = 0; i < tagsList.Length; i++)
                                    {
                                        if (tagsList[i] == "")
                                        {
                                            continue;
                                        }
                                        string tag = tagsList[i].Trim().ToLower();
                                        resultTags += tag;
                                        resultTags += ";";
                                    }
                                }
                            }
                            // ArgumentException is thrown when GetPropertyItem(int) is not found
                            catch (ArgumentException)
                            {
                                resultString = "No data in property \"Tag\" in some image or Property \"Tags\" isn't found in this type of file";
                                resultType   = "danger";
                            }
                        }

                        string imagePath = Server.MapPath("~/Content/Images/Images/LargeImages/Temp" + fileName);
                        upload.SaveAs(imagePath);
                        imageInfoRepository.Update(imgInfo);

                        //FileInfo savedImage = new FileInfo(Server.MapPath("~/Content/Images/Images/LargeImages/" + fileName));
                        double height;
                        double width;
                        double proportion;
                        double newHeight;
                        int    newWidth;


                        using (Image imageFromPath = Image.FromFile(imagePath))
                        {
                            height     = imageFromPath.Height;
                            width      = imageFromPath.Width;
                            proportion = height / width;
                            newHeight  = 2000;
                            newWidth   = (int)(newHeight / proportion);
                            if (newWidth > 5120)
                            {
                                newWidth  = 5120;
                                newHeight = (int)(newWidth * proportion);
                            }
                            Bitmap resizedImage = changeMainImageSize(imagePath, (int)newHeight, newWidth);

                            if (resizedImage != null)
                            {
                                resizedImage.Save(Server.MapPath("~/Content/Images/Images/LargeImages/") + fileName);
                            }
                        }

                        using (Image imageFromPath = Image.FromFile(imagePath))
                        {
                            newHeight = 600;
                            newWidth  = (int)(newHeight / proportion);
                            if (newWidth > 5120)
                            {
                                newWidth  = 5120;
                                newHeight = (int)(newWidth * proportion);
                            }
                            Bitmap resizedImage = changeMainImageSize(imagePath, (int)newHeight, newWidth);
                            if (resizedImage != null)
                            {
                                resizedImage.Save(Server.MapPath("~/Content/Images/Images/MiddleImages/") + fileName);
                            }
                        }

                        using (Image imageFromPath = Image.FromFile(imagePath))
                        {
                            newHeight = 200;
                            newWidth  = (int)(newHeight / proportion);
                            if (newWidth > 5120)
                            {
                                newWidth  = 5120;
                                newHeight = (int)(newWidth * proportion);
                            }
                            Bitmap resizedImage = changeMainImageSize(imagePath, (int)newHeight, newWidth);
                            if (resizedImage != null)
                            {
                                resizedImage.Save(Server.MapPath("~/Content/Images/Images/SmallImages/") + fileName);
                            }
                        }

                        System.IO.File.Delete(imagePath);

                        ImageEntity image = new ImageEntity {
                            Name = fileName, Tags = resultTags != string.Empty ? DeleteLastSemicolon(resultTags) : null, AddingTime = DateTime.Now
                        };
                        imageRepository.Create(image);
                    }
                }

                return(Json(new { type = resultType, resultString = resultString }));
            }
            catch (Exception ex)
            {
                ExceptionProcessor exceptionProcessor = new ExceptionProcessor();
                exceptionProcessor.process(ex);
                return(Json("Exception"));
            }
        }