Esempio n. 1
0
        public async Task UpdateBackContentImages()
        {
            var items = await GetCollectionItems(1, ImageType.Backdrop);
            if (items == null || items.Items.IsNullOrEmpty())
            {
                return;
            }

            var item = items.Items.FirstOrDefault();
            var apiClient = _connectionManager.GetApiClient(App.ServerInfo.Id);
            var wideUrl = apiClient.GetImageUrl(item, new ImageOptions
            {
                ImageType = ImageType.Backdrop,
                MaxWidth = 691,
                Quality = Constants.ImageQuality,
                EnableImageEnhancers = false
            });

            try
            {
                var client = CreateClient();
                var response = await client.GetAsync(wideUrl);
                var stream = await response.Content.ReadAsStreamAsync();
                var imageSource = new BitmapImage();
                imageSource.SetSource(stream);

                var writeableImage = new WriteableBitmap(imageSource);
                await SaveTheImage(writeableImage, WideTileBackUrl);

                var mediumWriteableImage = writeableImage.CentreCrop(336, 336);
                await SaveTheImage(mediumWriteableImage, MediumTileBackUrl);
            }
            catch (HttpException ex)
            {
                _logger.ErrorException("UpdateBackContentImages()", ex);
            }
            catch (Exception ex)
            {
                _logger.ErrorException("UpdateBackContentImages()", ex);
            }
        }