public async Task <StorageFile> GetImage(string fileName, int width, int height) { try { var resizedFileName = $"{Path.GetFileNameWithoutExtension(fileName)}_{width}_{height}{Path.GetExtension(fileName)}"; //If exists cached resized file return it if (await _imageStorageService.ImageExists(resizedFileName)) { return(await _imageStorageService.GetImage(resizedFileName)); } //If not exists cached resize file, generate it and store it var file = await _imageStorageService.GetImage(fileName); var resizeStream = _imageResizeService.ResizeImage(width, height, file.Stream); await _imageStorageService.UploadImage(new ImageFile() { Stream = resizeStream, ContentType = file.ContentType, FileName = resizedFileName }, true); resizeStream.Position = 0; file.Stream = resizeStream; return(file); } catch (Exception e) { if (e is ServiceException) { throw; } throw new Exception($"Unable to process {fileName}", e); } }