コード例 #1
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            ListCatalogItemsResponse response = new ListCatalogItemsResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("CatalogItems", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <CatalogItem, CatalogItemUnmarshaller>(CatalogItemUnmarshaller.Instance);
                    response.CatalogItems = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("NextToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextToken = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
コード例 #2
0
 private IReadOnlyList <Models.CatalogItem> MapResponse(ListCatalogItemsResponse response)
 {
     return(response.Data.Select(item => new Models.CatalogItem
     {
         Id = item.Id,
         Name = item.Name,
         Price = (decimal)item.Price
     })
            .ToList().AsReadOnly());
 }
コード例 #3
0
        public override Task <ListCatalogItemsResponse> ListCatalogItems(ListCatalogItemsRequest request, ServerCallContext context)
        {
            var priceGenerator = new Random();
            var sampleItems    = Enumerable.Range(request.StartIndex, request.PageSize).Select(index => new CatalogItem
            {
                Id    = index,
                Name  = $"Item {index}",
                Price = priceGenerator.Next(10, 100)
            });

            var response = new ListCatalogItemsResponse
            {
                StartIndex = request.StartIndex,
                PageSize   = request.PageSize,
                TotalCount = totalCount
            };

            response.Data.AddRange(sampleItems);

            return(Task.FromResult(response));
        }