Exemplo n.º 1
0
        public void HasJpegHeader_jpg_start_marker_check()
        {
            #region Arrange

            // получаем адрес картинки в данных приложения путем получения адреса запускаемого файла и замены части пути на путь к тестовому изображению
            //@"E:\MyApps\Мои приложения\Фото с заставки рабочего стола виндовс\Photos-from-Windows-spotlight\Tests\ImagesWindowsSpotlight.lib.Tests\Data\A7RNHSMC65E.jpg";
            var imgJpg = Environment.CurrentDirectory
                         .Replace(@"bin\Debug\netcoreapp3.1", @"Data\HasJpegHeader_jpg.jpg");
            var imgPng = Environment.CurrentDirectory
                         .Replace(@"bin\Debug\netcoreapp3.1", @"Data\HasJpegHeader_notJpg.png");

            #endregion

            #region Act

            var actual_result_1 = ImageCheck.HasJpegHeader(imgJpg);
            var actual_result_2 = ImageCheck.HasJpegHeader(imgPng);

            #endregion

            #region Assert

            Assert.AreEqual(true, actual_result_1);
            Assert.AreEqual(false, actual_result_2);

            #endregion
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateSettings(Setting setting, IFormFile images)
        {
            try
            {
                if (images != null)
                {
                    using (ImageCheck check = new ImageCheck())
                    {
                        bool imgcheck = check.CheckImageUzan(images);
                        if (imgcheck != false)
                        {
                            if (setting.MainHeaderImage != null)
                            {
                                var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\Content\\Back\\pageimg", setting.MainHeaderImage);
                                if (System.IO.File.Exists(path))
                                {
                                    System.IO.File.Delete(path);
                                    string gui     = Guid.NewGuid().ToString();
                                    var    newpath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\Content\\Back\\pageimg", gui + images.FileName);
                                    if (images.Length > 0)
                                    {
                                        using (var filestream = new FileStream(newpath, FileMode.Create))
                                        {
                                            await images.CopyToAsync(filestream);
                                        }
                                    }
                                    setting.MainHeaderImage = gui + images.FileName;
                                    await settingsService.Update(setting);

                                    return(RedirectToAction("AllSettings", "Settings"));
                                }
                                else
                                {
                                    return(RedirectToAction("ErrorPage", "Error"));
                                }
                            }
                            else
                            {
                                string gui  = Guid.NewGuid().ToString();
                                var    path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\Content\\Back\\pageimg", gui + images.FileName);
                                if (images.Length > 0)
                                {
                                    using (var filestream = new FileStream(path, FileMode.Create))
                                    {
                                        await images.CopyToAsync(filestream);
                                    }
                                }
                                setting.MainHeaderImage = gui + images.FileName;
                                await settingsService.Update(setting);

                                return(RedirectToAction("AllSettings", "Settings"));
                            }
                        }
                        else
                        {
                            TempData["pageTitle"] = "Settings | Update Settings";
                            TempData["pageInfo1"] = "Settings";
                            TempData["pageInfo2"] = "AllSettings";
                            TempData["imgerror"]  = "Lütfen sadece jpg,gif,png,jpeg uzantılı dosya seçiniz.";
                            return(View(setting));
                        }
                    }
                }
                else
                {
                    await settingsService.Update(setting);

                    return(RedirectToAction("AllSettings", "Settings"));
                }
            }
            catch (Exception e)
            {
                return(RedirectToAction("ErrorPage", "Error", e.Message));
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> UpdateBase(AppUser appUser, IFormFile images)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (string.IsNullOrEmpty(appUser.Email))
                    {
                        TempData["pageTitle"] = "User | Get Profile";
                        TempData["pageInfo1"] = "Home";
                        TempData["pageInfo2"] = "Index";
                        if (String.IsNullOrEmpty(appUser.Email))
                        {
                            TempData["emailError"] = "Email boş geçilemez.";
                        }
                        var result = await userService.GetUser(User.Identity.Name);

                        PassAndBaseView model = new PassAndBaseView
                        {
                            AppUser = result
                        };
                        return(View("GetProfile", model));
                    }
                    else
                    {
                        if (images != null)
                        {
                            using (var img = new ImageCheck())
                            {
                                bool check = img.CheckImageUzan(images);
                                if (check != false)
                                {
                                    if (appUser.ProfileImage != null)
                                    {
                                        var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\Content\\Back\\userimg", appUser.ProfileImage);
                                        if (System.IO.File.Exists(path))
                                        {
                                            System.IO.File.Delete(path);
                                        }
                                    }
                                    string gui    = Guid.NewGuid().ToString();
                                    var    upload = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\Content\\Back\\userimg", gui + images.FileName);
                                    if (images.Length > 0)
                                    {
                                        using (var stream = new FileStream(upload, FileMode.Create))
                                        {
                                            await images.CopyToAsync(stream);
                                        }
                                    }
                                    appUser.ProfileImage = gui + images.FileName;
                                    await userService.UpdateUser(appUser);

                                    return(RedirectToAction("GetProfile", "User"));
                                }
                                else
                                {
                                    TempData["pageTitle"] = "User | Get Profile";
                                    TempData["pageInfo1"] = "Home";
                                    TempData["pageInfo2"] = "Index";
                                    TempData["imgerror"]  = "Belirtilen formatlara uygun dosya yükleyiniz (jpg,JPG,png,jpeg)";
                                    var result = await userService.GetUser(User.Identity.Name);

                                    PassAndBaseView model = new PassAndBaseView
                                    {
                                        AppUser = result
                                    };
                                    return(View("GetProfile", model));
                                }
                            }
                        }
                        else
                        {
                            await userService.UpdateUser(appUser);

                            return(RedirectToAction("GetProfile", "User"));
                        }
                    }
                }
                else
                {
                    TempData["pageTitle"] = "User | Get Profile";
                    TempData["pageInfo1"] = "Home";
                    TempData["pageInfo2"] = "Index";
                    if (String.IsNullOrEmpty(appUser.Email))
                    {
                        TempData["emailError"] = "Email boş geçilemez.";
                    }
                    var result = await userService.GetUser(User.Identity.Name);

                    PassAndBaseView model = new PassAndBaseView
                    {
                        AppUser = result
                    };
                    return(View("GetProfile", model));
                }
            }
            catch (Exception)
            {
                return(RedirectToAction("ErrorPage", "Error"));
            }
        }
Exemplo n.º 4
0
 // TODO: refactor
 public void Apply(UnmanagedImage image, UnmanagedImage outImage)
 {
     ImageCheck.CheckSameSize(image, outImage);
     ImageCheck.CheckSameFormat(image, outImage);
     DoApply(image, outImage);
 }