Exemplo n.º 1
0
        public async Task <IActionResult> Index(CancellationToken cancellationToken)
        {
            List <News> news = await _newsManagementService.GetAllNews(CurrentCookiesToken, cancellationToken);

            if (news == null)
            {
                return(View());
            }

            foreach (var n in news)
            {
                if (!string.IsNullOrEmpty(n.ImageUrl))
                {
                    try
                    {
                        var downloadedImg = _filesManagementService.DownloadImage(_appSettings.Value.BaseUrl + n.ImageUrl);

                        if (downloadedImg != null)
                        {
                            var thumbnail = _filesManagementService.GetThumbnail(downloadedImg);
                            n.Photo = _filesManagementService.ImageToByteArray(thumbnail);
                        }
                    }
                    catch (HttpRequestException)
                    {
                        n.Photo = null;
                    }
                    catch (AggregateException)
                    {
                        n.Photo = null;
                    }
                }
            }
            return(View(news.OrderByDescending(x => x.Published ?? DateTime.MaxValue).ThenByDescending(x => x.Title).ToList()));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index(CancellationToken cancellationToken)
        {
            List <Pet> pets = await _petsManagementService.GetAllPets(CurrentCookiesToken, cancellationToken);

            List <PetViewModel> viewModel = new List <PetViewModel>();

            if (pets == null)
            {
                return(View());
            }

            foreach (var pet in pets)
            {
                viewModel.Add(new PetViewModel
                {
                    ThePet       = pet,
                    ThePetStatus = string.IsNullOrEmpty(pet.PetsStatus)
                        ? new PetsStatus {
                        Name = StringLocalizer["Lack"]
                    }
                        : await _petsStatusManagementService.GetStatus(pet.PetsStatus, CurrentCookiesToken, cancellationToken),
                    TheHelper = string.IsNullOrEmpty(pet.HelperId)
                        ? new Helper {
                        Address = "TOZ"
                    }
                        : await _helpersManagementService.GetHelper(pet.HelperId, AuthService.ReadCookie(HttpContext, AppSettings.CookieTokenName, true), cancellationToken)
                });

                if (!string.IsNullOrEmpty(pet.ImageUrl))
                {
                    try
                    {
                        var downloadedImg = _filesManagementService.DownloadImage(_appSettings.Value.BaseUrl + pet.ImageUrl);

                        if (downloadedImg != null)
                        {
                            var thumbnail = _filesManagementService.GetThumbnail(downloadedImg);
                            pet.Photo = _filesManagementService.ImageToByteArray(thumbnail);
                        }
                    }
                    catch (HttpRequestException)
                    {
                        pet.Photo = null;
                    }
                    catch (AggregateException)
                    {
                        pet.Photo = null;
                    }
                }
            }
            return(View(viewModel.OrderByDescending(x => x.ThePet.Created).ThenByDescending(x => x.ThePet.LastModified)));
        }
Exemplo n.º 3
0
        public void FilesFunctionalityTest()
        {
            //Download image
            var img = _filesManagementService.DownloadImage(
                @"http://i.pinger.pl/pgr167/7dc36d63001e9eeb4f01daf3/kot%20ze%20shreka9.jpg");

            Assert.NotNull(img);
            //Get thumbnail
            Assert.NotNull(_filesManagementService.GetThumbnail(img));
            //Image to byte array
            Assert.NotNull(_filesManagementService.ImageToByteArray(img));
            //Byte array to image
            var imgBytes = _filesManagementService.ImageToByteArray(img);

            Assert.NotNull(_filesManagementService.ByteArrayToImage(imgBytes));
        }
Exemplo n.º 4
0
 public void GetThumbnailsTest()
 {
     Assert.NotNull(_filesManagementService.GetThumbnail(_filesManagementService.DownloadImage(ImageAddress)));
 }