Exemplo n.º 1
0
        public async Task <String> Update(Poster poster)
        {
            if (!_dbUpdater.CanUpdate(poster))
            {
                throw new Exception($"Can't update concert with ID: {poster.eventId}");
            }

            var image = _reader.GetImage(poster);

            _log.LogInformation($"Image compressed from {poster.imageUrl}");

            var guid      = _guidProvider.NewGuid();
            var imageName = $"{guid}.jpg";

            _log.LogInformation("Image name: {@imageName}", imageName);

            var imageUrl = "testImage";

            try
            {
                imageUrl = await _storage.PutObjectAsync(image, imageName);
            }
            catch (Exception e)
            {
                _log.LogError("Exception when updating poster: {@e}", e);
            }

            _log.LogInformation("Image uploaded to Yandex Object Storage");

            _log.LogInformation("Image URL: {@imageUrl}", imageUrl);
            _dbUpdater.Update(poster, imageUrl);
            return(imageUrl);
        }
Exemplo n.º 2
0
        public async Task <String> Update(Poster poster)
        {
            if (!_dbUpdater.CanUpdate(poster))
            {
                throw new Exception($"Can't update concert with ID: {poster.eventId}");
            }

            var image = _reader.GetImage(poster);

            _log.LogInformation($"Image compressed from {poster.imageUrl}");

            var guid      = _guidProvider.NewGuid();
            var imageName = $"{guid}.jpg";

            _log.LogInformation("Image name: {@imageName}", imageName);

            var imageUrl = "testImage";

            try
            {
                var answer = await _storage.PutObjectAsync(image, imageName);

                if (answer.IsSuccessStatusCode)
                {
                    imageUrl = answer.Result;
                }
                else
                {
                    throw new BadHttpRequestException("Answer from Yandex was: {0}", (int)answer.StatusCode, new Exception(answer.Error));
                }
            }
            catch (Exception e)
            {
                _log.LogError("Exception when updating poster: {@e}", e);
            }

            _log.LogInformation("Image uploaded to Yandex Object Storage");

            _log.LogInformation("Image URL: {@imageUrl}", imageUrl);
            _dbUpdater.Update(poster, imageUrl);
            return(imageUrl);
        }