Exemple #1
0
        public async Task <APIResponse> GetAllAssets(AssetParameters assetParameters)
        {
            try
            {
                string serializedStories;
                // List<AssetResponse> stories;

                /* var encodedStories = await distributedCache.GetAsync(BlogServiceOperation.GetStoriesCacheName);
                 *
                 * if (encodedStories != null)
                 * {
                 *   serializedStories = Encoding.UTF8.GetString(encodedStories);
                 *   stories = JsonConvert.DeserializeObject<List<StoryResponse>>(serializedStories);
                 * }
                 * else
                 * {*/
                var client = httpClientFactory.CreateClient(VendorServiceOperation.serviceName);

                UriBuilder url = new UriBuilder(servicesConfig.Blog + VendorServiceOperation.GetAllAssets());
                url.Query = QueryStringHelper.ConvertToQueryString(assetParameters);

                var response = await client.GetAsync(url.ToString());

                var assets = JsonConvert.DeserializeObject <AssetResponse>(await response.Content.ReadAsStringAsync());

                serializedStories = JsonConvert.SerializeObject(assets);

                /* encodedStories = Encoding.UTF8.GetBytes(serializedStories);
                 * var options = new DistributedCacheEntryOptions()
                 *               .SetSlidingExpiration(TimeSpan.FromMinutes(1))
                 *               .SetAbsoluteExpiration(DateTime.Now.AddHours(1));
                 *
                 * await distributedCache.SetAsync(VendorServiceOperation.GetStoriesCacheName, encodedStories, options);*/
                //  }

                return(new APIResponse(assets, HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception in method 'GetAllAssets()'");
                var exMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                return(new APIResponse(exMessage, HttpStatusCode.InternalServerError));
            }
        }