Esempio n. 1
0
        public async Task <FetchGamePictureResponse> FetchPictureForGameAsync(int id, CancellationToken token)
        {
            var endpoint = configurationProvider.GetConnectionStringById(connectionStringKey);

            endpoint += $"?appId={id}";

            var gatewayResponse = await webGateway.GetResponseFromEndpoint <ResponseDao>(endpoint, token);

            if (gatewayResponse.ResultCode != WebRequestResponseResultCode.Succeeded)
            {
                return(FetchGamePictureResponse.FetchFailed(gatewayResponse.ResultMessage));
            }

            if (!gatewayResponse.Succeeded)
            {
                return(FetchGamePictureResponse.NoPicture(id));
            }

            var response = gatewayResponse.Value;

            if (response.IsValid)
            {
                var imageString = response.Image.TrimStart('b', '\'');
                imageString = imageString.TrimEnd('\'');

                var imageBytes = Convert.FromBase64String(imageString);
                return(FetchGamePictureResponse.ContainsPicture(id, imageBytes));
            }

            return(FetchGamePictureResponse.NoPicture(id));
        }
Esempio n. 2
0
        private async Task <FetchGamePictureResponse> FetchAndUpdatePictureCache(int appId, CancellationToken token)
        {
            var pictureFetchResponse = await pictureFetcher.FetchPictureForGameAsync(appId, token);

            if (!pictureFetchResponse.Successful)
            {
                return(FetchGamePictureResponse.FetchFailed(pictureFetchResponse.Message));
            }

            var imageAsBase64String = Convert.ToBase64String(pictureFetchResponse.Image);

            var cacheGamePicture = CachedGamePicture.Create(imageAsBase64String, appId);

            await storageProvider.Update(storageKey, appId.ToString(), cacheGamePicture);

            var response = FetchGamePictureResponse.ContainsPicture(appId, pictureFetchResponse.Image);

            return(response);
        }
Esempio n. 3
0
        public async Task <FetchGamePictureResponse> FetchPictureForGameAsync(int appId, CancellationToken token)
        {
            var localStorageResponse = await storageProvider.Get(storageKey, appId.ToString());

            if (!localStorageResponse.Succeeded)
            {
                return(await FetchAndUpdatePictureCache(appId, token));
            }

            var gamePicture = (CachedGamePicture)localStorageResponse.Value;

            var localCacheCheck = await cacheChecker.IsCacheOutOfDate(gamePicture.TimeCachedUtc, appId, token);

            if (localCacheCheck.IsOutOfDate)
            {
                return(await FetchAndUpdatePictureCache(appId, token));
            }

            var pictureAsBytes = Convert.FromBase64String(gamePicture.Base64EncodedImage);

            return(FetchGamePictureResponse.ContainsPicture(appId, pictureAsBytes));
        }