From 3fee58e6664a82941f322486808a0ae29aa636ba Mon Sep 17 00:00:00 2001 From: ericuss Date: Wed, 28 Aug 2019 10:57:35 +0200 Subject: [PATCH 01/10] partial checkin --- .../aggregator/Services/BasketService.cs | 44 ++++++++++++-- .../aggregator/Services/CatalogService.cs | 37 +++++++++--- .../Catalog.API/Grpc/CatalogService.cs | 59 ++++++++++++------- .../Catalog/Catalog.API/Proto/catalog.proto | 8 +-- 4 files changed, 108 insertions(+), 40 deletions(-) diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs index 3e68816c1..2bfc30ce9 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs @@ -66,12 +66,48 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services public async Task UpdateAsync(BasketData currentBasket) { - _httpClient.BaseAddress = new Uri(_urls.Basket + UrlsConfig.BasketOperations.UpdateBasket()); + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); + + using (var httpClientHandler = new HttpClientHandler()) + { + httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }; + using (var httpClient = new HttpClient(httpClientHandler)) + { + httpClient.BaseAddress = new Uri(_urls.GrpcBasket); + + _logger.LogDebug("Creating grpc client for basket {@httpClient.BaseAddress} ", httpClient.BaseAddress); + + var client = GrpcClient.Create(httpClient); + + + try + { + + _logger.LogInformation("Grpc update basket currentBasket {@currentBasket}", currentBasket); + var request = MapToCustomerBasketRequest(currentBasket); + _logger.LogInformation("Grpc update basket request {@request}", request); + + await client.UpdateBasketAsync(request); + } + catch (RpcException e) + { + _logger.LogError($"Error calling via grpc: {e.Status} - {e.Message}"); + } + } + } + + + + + //_httpClient.BaseAddress = new Uri(_urls.Basket + UrlsConfig.BasketOperations.UpdateBasket()); - var client = GrpcClient.Create(_httpClient); - var request = MapToCustomerBasketRequest(currentBasket); + //var client = GrpcClient.Create(_httpClient); + //_logger.LogInformation("Grpc update basket currentBasket {@currentBasket}", currentBasket); + //var request = MapToCustomerBasketRequest(currentBasket); + //_logger.LogInformation("Grpc update basket request {@request}", request); - await client.UpdateBasketAsync(request); + //await client.UpdateBasketAsync(request); } private BasketData MapToBasketData(CustomerBasketResponse customerBasketRequest) diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/CatalogService.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/CatalogService.cs index 663baa1cf..9a1c393b0 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/CatalogService.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/CatalogService.cs @@ -11,6 +11,7 @@ using Grpc.Net.Client; using System; using static CatalogApi.Catalog; using System.Linq; +using Grpc.Core; namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services { @@ -40,16 +41,36 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services public async Task> GetCatalogItemsAsync(IEnumerable ids) { - _httpClient.BaseAddress = new Uri(_urls.Catalog + UrlsConfig.CatalogOperations.GetItemsById(ids)); - var client = GrpcClient.Create(_httpClient); - var request = new CatalogItemsRequest { Ids = string.Join(",", ids), PageIndex = 1, PageSize = 10 }; - var response = await client.GetItemsByIdsAsync(request); - return response.Data.Select(this.MapToCatalogItemResponse); - //var stringContent = await _httpClient.GetStringAsync(_urls.Catalog + UrlsConfig.CatalogOperations.GetItemsById(ids)); - //var catalogItems = JsonConvert.DeserializeObject(stringContent); + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); + + using (var httpClientHandler = new HttpClientHandler()) + { + httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }; + using (var httpClient = new HttpClient(httpClientHandler)) + { + httpClient.BaseAddress = new Uri(_urls.GrpcCatalog); + + _logger.LogInformation("Creating grpc client for CatalogClient {@httpClient.BaseAddress}, {@httpClient} ", httpClient.BaseAddress, httpClient); + + try + { + var client = GrpcClient.Create(httpClient); + var request = new CatalogItemsRequest { Ids = string.Join(",", ids), PageIndex = 1, PageSize = 10 }; + _logger.LogInformation("grpc client created, request = {@request}", request); + var response = await client.GetItemsByIdsAsync(request); + _logger.LogInformation("grpc response {@response}", response); + return response.Data.Select(this.MapToCatalogItemResponse); + } + catch (RpcException e) + { + _logger.LogError($"Error calling via grpc: {e.Status} - {e.Message}"); + } + } + } - //return catalogItems; + return null; } private CatalogItem MapToCatalogItemResponse(CatalogItemResponse catalogItemResponse) diff --git a/src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs b/src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs index b25d3b103..9c620a481 100644 --- a/src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs +++ b/src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs @@ -64,10 +64,12 @@ namespace Catalog.API.Grpc public override async Task GetItemsByIds(CatalogItemsRequest request, ServerCallContext context) { + _logger.LogInformation("---------- GetItemsByIds request {@request}", request); if (!string.IsNullOrEmpty(request.Ids)) { var items = await GetItemsByIdsAsync(request.Ids); + _logger.LogInformation("---------- GetItemsByIds items {@items}", items); if (!items.Any()) { context.Status = new Status(StatusCode.NotFound, $"ids value invalid. Must be comma-separated list of numbers"); @@ -76,15 +78,18 @@ namespace Catalog.API.Grpc return this.MapToResponse(items); } + _logger.LogInformation("---------- GetItemsByIds else"); var totalItems = await _catalogContext.CatalogItems .LongCountAsync(); + _logger.LogInformation("---------- GetItemsByIds totalItems {@totalItems}", totalItems); var itemsOnPage = await _catalogContext.CatalogItems .OrderBy(c => c.Name) .Skip(request.PageSize * request.PageIndex) .Take(request.PageSize) .ToListAsync(); + _logger.LogInformation("---------- GetItemsByIds itemsOnPage {@itemsOnPage}", itemsOnPage); /* The "awesome" fix for testing Devspaces */ /* @@ -95,8 +100,10 @@ namespace Catalog.API.Grpc */ itemsOnPage = ChangeUriPlaceholder(itemsOnPage); + _logger.LogInformation("---------- GetItemsByIds itemsOnPage2 {@itemsOnPage}", itemsOnPage); var model = this.MapToResponse(itemsOnPage, totalItems, request.PageIndex, request.PageSize); + _logger.LogInformation("---------- GetItemsByIds model {@model}", model); context.Status = new Status(StatusCode.OK, string.Empty); return model; @@ -116,29 +123,39 @@ namespace Catalog.API.Grpc PageSize = pageSize, }; - items.ForEach(i => result.Data.Add(new CatalogItemResponse() + items.ForEach(i => { - AvailableStock = i.AvailableStock, - Description = i.Description, - Id = i.Id, - MaxStockThreshold = i.MaxStockThreshold, - Name = i.Name, - OnReorder = i.OnReorder, - PictureFileName = i.PictureFileName, - PictureUri = i.PictureUri, - RestockThreshold = i.RestockThreshold, - CatalogBrand = new CatalogApi.CatalogBrand() + var brand = i.CatalogBrand == null + ? null + : new CatalogApi.CatalogBrand() + { + Id = i.CatalogBrand.Id, + Name = i.CatalogBrand.Brand, + }; + var catalogType = i.CatalogType == null + ? null + : new CatalogApi.CatalogType() + { + Id = i.CatalogType.Id, + Type = i.CatalogType.Type, + }; + + result.Data.Add(new CatalogItemResponse() { - Id = i.CatalogBrand.Id, - Name = i.CatalogBrand.Brand, - }, - CatalogType = new CatalogApi.CatalogType() - { - Id = i.CatalogType.Id, - Type = i.CatalogType.Type, - }, - Price = (double)i.Price, - })); + AvailableStock = i.AvailableStock, + Description = i.Description, + Id = i.Id, + MaxStockThreshold = i.MaxStockThreshold, + Name = i.Name, + OnReorder = i.OnReorder, + PictureFileName = i.PictureFileName, + PictureUri = i.PictureUri, + RestockThreshold = i.RestockThreshold, + CatalogBrand = brand, + CatalogType = catalogType, + Price = (double)i.Price, + }); + }); return result; } diff --git a/src/Services/Catalog/Catalog.API/Proto/catalog.proto b/src/Services/Catalog/Catalog.API/Proto/catalog.proto index adeeb4b26..fa83d45c4 100644 --- a/src/Services/Catalog/Catalog.API/Proto/catalog.proto +++ b/src/Services/Catalog/Catalog.API/Proto/catalog.proto @@ -56,11 +56,5 @@ service Catalog { }; << */ } - rpc GetItemsByIds (CatalogItemsRequest) returns (PaginatedItemsResponse) { - /* >> - option (google.api.http) = { - get: "/api/v1/catalog/items/ids/{ids}" - }; - << */ - } + rpc GetItemsByIds (CatalogItemsRequest) returns (PaginatedItemsResponse) {} } \ No newline at end of file From 260bfcbc4596a8ffc2668588882f6e287c085d53 Mon Sep 17 00:00:00 2001 From: ericuss Date: Wed, 28 Aug 2019 11:30:14 +0200 Subject: [PATCH 02/10] web bff endpoint /api/v1/Basket working in grpc --- .../aggregator/Services/BasketService.cs | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs index 2bfc30ce9..4389c4383 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs @@ -96,18 +96,6 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services } } } - - - - - //_httpClient.BaseAddress = new Uri(_urls.Basket + UrlsConfig.BasketOperations.UpdateBasket()); - - //var client = GrpcClient.Create(_httpClient); - //_logger.LogInformation("Grpc update basket currentBasket {@currentBasket}", currentBasket); - //var request = MapToCustomerBasketRequest(currentBasket); - //_logger.LogInformation("Grpc update basket request {@request}", request); - - //await client.UpdateBasketAsync(request); } private BasketData MapToBasketData(CustomerBasketResponse customerBasketRequest) @@ -122,16 +110,22 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services BuyerId = customerBasketRequest.Buyerid }; - customerBasketRequest.Items.ToList().ForEach(item => map.Items.Add(new BasketDataItem + customerBasketRequest.Items.ToList().ForEach(item => { - Id = item.Id, - OldUnitPrice = (decimal)item.Oldunitprice, - PictureUrl = item.Pictureurl, - ProductId = item.Productid, - ProductName = item.Productname, - Quantity = item.Quantity, - UnitPrice = (decimal)item.Unitprice - })); + if (item.Id != null) + { + map.Items.Add(new BasketDataItem + { + Id = item.Id, + OldUnitPrice = (decimal)item.Oldunitprice, + PictureUrl = item.Pictureurl, + ProductId = item.Productid, + ProductName = item.Productname, + Quantity = item.Quantity, + UnitPrice = (decimal)item.Unitprice + }); + } + }); return map; } @@ -148,16 +142,22 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services Buyerid = basketData.BuyerId }; - basketData.Items.ToList().ForEach(item => map.Items.Add(new BasketItemResponse + basketData.Items.ToList().ForEach(item => { - Id = item.Id, - Oldunitprice = (double)item.OldUnitPrice, - Pictureurl = item.PictureUrl, - Productid = item.ProductId, - Productname = item.ProductName, - Quantity = item.Quantity, - Unitprice = (double)item.UnitPrice - })); + if (item.Id != null) + { + map.Items.Add(new BasketItemResponse + { + Id = item.Id, + Oldunitprice = (double)item.OldUnitPrice, + Pictureurl = item.PictureUrl, + Productid = item.ProductId, + Productname = item.ProductName, + Quantity = item.Quantity, + Unitprice = (double)item.UnitPrice + }); + } + }); return map; } From 311e1a2bfd8eb14c37da4ed45d3e1fd87343466d Mon Sep 17 00:00:00 2001 From: ericuss Date: Wed, 28 Aug 2019 12:03:09 +0200 Subject: [PATCH 03/10] refactoring the grpc client --- .../Controllers/BasketController.cs | 2 - .../aggregator/Services/BasketService.cs | 93 ++++++++----------- .../aggregator/Services/GrpcCallerService.cs | 71 ++++++++++++++ .../Web.Bff.Shopping/aggregator/Startup.cs | 4 +- 4 files changed, 114 insertions(+), 56 deletions(-) create mode 100644 src/ApiGateways/Web.Bff.Shopping/aggregator/Services/GrpcCallerService.cs diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs index a3be37611..5905ae214 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs @@ -39,8 +39,6 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers } // Retrieve the current basket - Log.Information("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ GetByIdAsync @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - var basket = await _basket.GetById(data.BuyerId) ?? new BasketData(data.BuyerId); Log.Debug("get basket by id response={@response}", basket); diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs index 4389c4383..5274ddc49 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs @@ -28,74 +28,63 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services public async Task GetById(string id) { - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); - - using (var httpClientHandler = new HttpClientHandler()) + return await GrpcCallerService.CallService(_urls.GrpcBasket, async httpClient => { - httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }; - using (var httpClient = new HttpClient(httpClientHandler)) - { - //httpClient.BaseAddress = new Uri("http://10.0.75.1:5580"); - httpClient.BaseAddress = new Uri(_urls.GrpcBasket); - - _logger.LogDebug("Creating grpc client for basket {@httpClient.BaseAddress} ", httpClient.BaseAddress); + _logger.LogWarning("######################## grpc client created, request = {@id}", id); - var client = GrpcClient.Create(httpClient); - - _logger.LogDebug("grpc client created, request = {@id}", id); - - try - { + var client = GrpcClient.Create(httpClient); - var response = await client.GetBasketByIdAsync(new BasketRequest { Id = id }); + _logger.LogDebug("grpc client created, request = {@id}", id); + var response = await client.GetBasketByIdAsync(new BasketRequest { Id = id }); - _logger.LogDebug("grpc response {@response}", response); + _logger.LogDebug("grpc response {@response}", response); - return MapToBasketData(response); - } - catch (RpcException e) - { - _logger.LogError($"Error calling via grpc: {e.Status} - {e.Message}"); - } - } - } - - return null; + return MapToBasketData(response); + }); } public async Task UpdateAsync(BasketData currentBasket) { - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); - - using (var httpClientHandler = new HttpClientHandler()) + await GrpcCallerService.CallService(_urls.GrpcBasket, async httpClient => { - httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }; - using (var httpClient = new HttpClient(httpClientHandler)) - { - httpClient.BaseAddress = new Uri(_urls.GrpcBasket); + var client = GrpcClient.Create(httpClient); + _logger.LogDebug("Grpc update basket currentBasket {@currentBasket}", currentBasket); + var request = MapToCustomerBasketRequest(currentBasket); + _logger.LogDebug("Grpc update basket request {@request}", request); - _logger.LogDebug("Creating grpc client for basket {@httpClient.BaseAddress} ", httpClient.BaseAddress); + return client.UpdateBasketAsync(request); + }); - var client = GrpcClient.Create(httpClient); + //AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); + //AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); + //using (var httpClientHandler = new HttpClientHandler()) + //{ + // httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }; + // using (var httpClient = new HttpClient(httpClientHandler)) + // { + // httpClient.BaseAddress = new Uri(_urls.GrpcBasket); - try - { + // _logger.LogDebug("Creating grpc client for basket {@httpClient.BaseAddress} ", httpClient.BaseAddress); - _logger.LogInformation("Grpc update basket currentBasket {@currentBasket}", currentBasket); - var request = MapToCustomerBasketRequest(currentBasket); - _logger.LogInformation("Grpc update basket request {@request}", request); + // var client = GrpcClient.Create(httpClient); - await client.UpdateBasketAsync(request); - } - catch (RpcException e) - { - _logger.LogError($"Error calling via grpc: {e.Status} - {e.Message}"); - } - } - } + + // try + // { + + // _logger.LogDebug("Grpc update basket currentBasket {@currentBasket}", currentBasket); + // var request = MapToCustomerBasketRequest(currentBasket); + // _logger.LogDebug("Grpc update basket request {@request}", request); + + // await client.UpdateBasketAsync(request); + // } + // catch (RpcException e) + // { + // _logger.LogError($"Error calling via grpc: {e.Status} - {e.Message}"); + // } + // } + //} } private BasketData MapToBasketData(CustomerBasketResponse customerBasketRequest) diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/GrpcCallerService.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/GrpcCallerService.cs new file mode 100644 index 000000000..7e0b61a2f --- /dev/null +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/GrpcCallerService.cs @@ -0,0 +1,71 @@ +using System.Net.Http; +using System.Threading.Tasks; +using System; +using Grpc.Core; +using Serilog; + +namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services +{ + public static class GrpcCallerService + { + public static Task CallService(string urlGrpc, Func> func) + { + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); + + using (var httpClientHandler = new HttpClientHandler()) + { + httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }; + using (var httpClient = new HttpClient(httpClientHandler)) + { + httpClient.BaseAddress = new Uri(urlGrpc); + Log.Debug("Creating grpc client base address {@httpClient.BaseAddress} ", httpClient.BaseAddress); + + try + { + return func(httpClient); + } + catch (RpcException e) + { + Log.Error($"Error calling via grpc: {e.Status} - {e.Message}"); + } + } + } + + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false); + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", false); + + return default; + } + + public static Task CallService(string urlGrpc, Func func) + { + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); + + using (var httpClientHandler = new HttpClientHandler()) + { + httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }; + using (var httpClient = new HttpClient(httpClientHandler)) + { + httpClient.BaseAddress = new Uri(urlGrpc); + Log.Debug("Creating grpc client base address {@httpClient.BaseAddress} ", httpClient.BaseAddress); + + try + { + return func(httpClient); + } + catch (RpcException e) + { + Log.Error($"Error calling via grpc: {e.Status} - {e.Message}"); + } + } + } + + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false); + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", false); + + return default; + } + } +} diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs index 9613fe462..e16c4197e 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs @@ -144,9 +144,9 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator options.SwaggerDoc("v1", new OpenApiInfo { - Title = "Shopping Aggregator for Mobile Clients", + Title = "Shopping Aggregator for Web Clients", Version = "v1", - Description = "Shopping Aggregator for Mobile Clients" + Description = "Shopping Aggregator for Web Clients" }); options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme From 454525d517abf07276260ae29b34a1916014a12a Mon Sep 17 00:00:00 2001 From: ericuss Date: Wed, 28 Aug 2019 12:34:34 +0200 Subject: [PATCH 04/10] refactored the grpc client --- .../aggregator/Services/BasketService.cs | 45 ++---------- .../aggregator/Services/CatalogService.cs | 39 +++-------- .../aggregator/Services/GrpcCallerService.cs | 70 ++++++++++--------- .../aggregator/Services/OrderingService.cs | 42 +++-------- 4 files changed, 58 insertions(+), 138 deletions(-) diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs index 5274ddc49..3875f3bdb 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs @@ -2,41 +2,35 @@ using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; -using System.Net.Http; using System.Threading.Tasks; using Grpc.Net.Client; -using System; using System.Linq; using GrpcBasket; -using Grpc.Core; +using System.Net.Http; namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services { public class BasketService : IBasketService { - private readonly HttpClient _httpClient; private readonly UrlsConfig _urls; + public readonly HttpClient _httpClient; private readonly ILogger _logger; public BasketService(HttpClient httpClient, IOptions config, ILogger logger) { - _httpClient = httpClient; _urls = config.Value; + _httpClient = httpClient; _logger = logger; } + public async Task GetById(string id) { return await GrpcCallerService.CallService(_urls.GrpcBasket, async httpClient => { - _logger.LogWarning("######################## grpc client created, request = {@id}", id); - var client = GrpcClient.Create(httpClient); - _logger.LogDebug("grpc client created, request = {@id}", id); var response = await client.GetBasketByIdAsync(new BasketRequest { Id = id }); - _logger.LogDebug("grpc response {@response}", response); return MapToBasketData(response); @@ -54,37 +48,6 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services return client.UpdateBasketAsync(request); }); - - //AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); - //AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); - - //using (var httpClientHandler = new HttpClientHandler()) - //{ - // httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }; - // using (var httpClient = new HttpClient(httpClientHandler)) - // { - // httpClient.BaseAddress = new Uri(_urls.GrpcBasket); - - // _logger.LogDebug("Creating grpc client for basket {@httpClient.BaseAddress} ", httpClient.BaseAddress); - - // var client = GrpcClient.Create(httpClient); - - - // try - // { - - // _logger.LogDebug("Grpc update basket currentBasket {@currentBasket}", currentBasket); - // var request = MapToCustomerBasketRequest(currentBasket); - // _logger.LogDebug("Grpc update basket request {@request}", request); - - // await client.UpdateBasketAsync(request); - // } - // catch (RpcException e) - // { - // _logger.LogError($"Error calling via grpc: {e.Status} - {e.Message}"); - // } - // } - //} } private BasketData MapToBasketData(CustomerBasketResponse customerBasketRequest) diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/CatalogService.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/CatalogService.cs index 9a1c393b0..5e3e4e2f0 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/CatalogService.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/CatalogService.cs @@ -2,7 +2,6 @@ using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; @@ -11,7 +10,6 @@ using Grpc.Net.Client; using System; using static CatalogApi.Catalog; using System.Linq; -using Grpc.Core; namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services { @@ -41,36 +39,15 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services public async Task> GetCatalogItemsAsync(IEnumerable ids) { - - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); - - using (var httpClientHandler = new HttpClientHandler()) + return await GrpcCallerService.CallService(_urls.GrpcCatalog, async httpClient => { - httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }; - using (var httpClient = new HttpClient(httpClientHandler)) - { - httpClient.BaseAddress = new Uri(_urls.GrpcCatalog); - - _logger.LogInformation("Creating grpc client for CatalogClient {@httpClient.BaseAddress}, {@httpClient} ", httpClient.BaseAddress, httpClient); - - try - { - var client = GrpcClient.Create(httpClient); - var request = new CatalogItemsRequest { Ids = string.Join(",", ids), PageIndex = 1, PageSize = 10 }; - _logger.LogInformation("grpc client created, request = {@request}", request); - var response = await client.GetItemsByIdsAsync(request); - _logger.LogInformation("grpc response {@response}", response); - return response.Data.Select(this.MapToCatalogItemResponse); - } - catch (RpcException e) - { - _logger.LogError($"Error calling via grpc: {e.Status} - {e.Message}"); - } - } - } - - return null; + var client = GrpcClient.Create(httpClient); + var request = new CatalogItemsRequest { Ids = string.Join(",", ids), PageIndex = 1, PageSize = 10 }; + _logger.LogInformation("grpc client created, request = {@request}", request); + var response = await client.GetItemsByIdsAsync(request); + _logger.LogInformation("grpc response {@response}", response); + return response.Data.Select(this.MapToCatalogItemResponse); + }); } private CatalogItem MapToCatalogItemResponse(CatalogItemResponse catalogItemResponse) diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/GrpcCallerService.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/GrpcCallerService.cs index 7e0b61a2f..6400c9797 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/GrpcCallerService.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/GrpcCallerService.cs @@ -8,28 +8,30 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services { public static class GrpcCallerService { - public static Task CallService(string urlGrpc, Func> func) + public static async Task CallService(string urlGrpc, Func> func) { AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); - using (var httpClientHandler = new HttpClientHandler()) + using var httpClientHandler = new HttpClientHandler { - httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }; - using (var httpClient = new HttpClient(httpClientHandler)) - { - httpClient.BaseAddress = new Uri(urlGrpc); - Log.Debug("Creating grpc client base address {@httpClient.BaseAddress} ", httpClient.BaseAddress); + ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; } + }; - try - { - return func(httpClient); - } - catch (RpcException e) - { - Log.Error($"Error calling via grpc: {e.Status} - {e.Message}"); - } - } + using var httpClient = new HttpClient(httpClientHandler) + { + BaseAddress = new Uri(urlGrpc) + }; + + Log.Information("Creating grpc client base address urlGrpc ={@urlGrpc}, BaseAddress={@BaseAddress} ", urlGrpc, httpClient.BaseAddress); + + try + { + return await func(httpClient); + } + catch (RpcException e) + { + Log.Error($"Error calling via grpc: {e.Status} - {e.Message}"); } AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false); @@ -38,34 +40,34 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services return default; } - public static Task CallService(string urlGrpc, Func func) + public static async Task CallService(string urlGrpc, Func func) { AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); - using (var httpClientHandler = new HttpClientHandler()) + using var httpClientHandler = new HttpClientHandler + { + ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; } + }; + + using var httpClient = new HttpClient(httpClientHandler) { - httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }; - using (var httpClient = new HttpClient(httpClientHandler)) - { - httpClient.BaseAddress = new Uri(urlGrpc); - Log.Debug("Creating grpc client base address {@httpClient.BaseAddress} ", httpClient.BaseAddress); + BaseAddress = new Uri(urlGrpc) + }; + + Log.Debug("Creating grpc client base address {@httpClient.BaseAddress} ", httpClient.BaseAddress); - try - { - return func(httpClient); - } - catch (RpcException e) - { - Log.Error($"Error calling via grpc: {e.Status} - {e.Message}"); - } - } + try + { + await func(httpClient); + } + catch (RpcException e) + { + Log.Error($"Error calling via grpc: {e.Status} - {e.Message}"); } AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false); AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", false); - - return default; } } } diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/OrderingService.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/OrderingService.cs index 1814e2d10..6c2394353 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/OrderingService.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/OrderingService.cs @@ -14,52 +14,30 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services { public class OrderingService : IOrderingService { - private readonly HttpClient _httpClient; private readonly UrlsConfig _urls; private readonly ILogger _logger; + public readonly HttpClient _httpClient; public OrderingService(HttpClient httpClient, IOptions config, ILogger logger) { - _httpClient = httpClient; _urls = config.Value; + _httpClient = httpClient; _logger = logger; } public async Task GetOrderDraftAsync(BasketData basketData) { - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); - - using (var httpClientHandler = new HttpClientHandler()) + return await GrpcCallerService.CallService(_urls.GrpcOrdering, async httpClient => { - httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }; - using (var httpClient = new HttpClient(httpClientHandler)) - { - httpClient.BaseAddress = new Uri(_urls.GrpcOrdering); - - _logger.LogDebug(" Creating grpc client for ordering {@httpClient.BaseAddress}", httpClient.BaseAddress); - - var client = GrpcClient.Create(httpClient); + var client = GrpcClient.Create(httpClient); + _logger.LogDebug(" grpc client created, basketData={@basketData}", basketData); - _logger.LogDebug(" grpc client created, basketData={@basketData}", basketData); - - try - { - var command = MapToOrderDraftCommand(basketData); - var response = await client.CreateOrderDraftFromBasketDataAsync(command); - - _logger.LogDebug(" grpc response: {@response}", response); - - return MapToResponse(response, basketData); - } - catch (RpcException e) - { - _logger.LogError($"Error calling via grpc to ordering: {e.Status} - {e.Message}"); - } - } - } + var command = MapToOrderDraftCommand(basketData); + var response = await client.CreateOrderDraftFromBasketDataAsync(command); + _logger.LogDebug(" grpc response: {@response}", response); - return null; + return MapToResponse(response, basketData); + }); } private OrderData MapToResponse(GrpcOrdering.OrderDraftDTO orderDraft, BasketData basketData) From 63e20bb07f4edb88766eb503fea45bdfbbd43c77 Mon Sep 17 00:00:00 2001 From: ericuss Date: Wed, 28 Aug 2019 14:12:57 +0200 Subject: [PATCH 05/10] refactor mobile bff --- docker-compose.override.yml | 1 + .../aggregator/Config/UrlsConfig.cs | 1 + .../aggregator/Services/BasketService.cs | 52 ++++--------- .../aggregator/Services/CatalogService.cs | 26 ++++--- .../aggregator/Services/GrpcCallerService.cs | 73 +++++++++++++++++++ .../aggregator/Services/OrderingService.cs | 43 +++-------- .../aggregator/appsettings.json | 5 -- .../aggregator/appsettings.localhost.json | 1 + .../aggregator/Services/CatalogService.cs | 16 ++-- 9 files changed, 125 insertions(+), 93 deletions(-) create mode 100644 src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/GrpcCallerService.cs diff --git a/docker-compose.override.yml b/docker-compose.override.yml index a8fce70ba..8bd11cb91 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -286,6 +286,7 @@ services: - urls__orders=http://ordering.api - urls__identity=http://identity.api - urls__grpcBasket=http://10.0.75.1:5580 + - urls__grpcCatalog=http://10.0.75.1:9101 - urls__grpcOrdering=http://10.0.75.1:5581 - CatalogUrlHC=http://catalog.api/hc - OrderingUrlHC=http://ordering.api/hc diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Config/UrlsConfig.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Config/UrlsConfig.cs index 7fd7cb5f3..c0bb9502e 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Config/UrlsConfig.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Config/UrlsConfig.cs @@ -28,6 +28,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config public string Catalog { get; set; } public string Orders { get; set; } public string GrpcBasket { get; set; } + public string GrpcCatalog { get; set; } public string GrpcOrdering { get; set; } } } diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/BasketService.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/BasketService.cs index fa1fc9ffe..80846ca3d 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/BasketService.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/BasketService.cs @@ -27,50 +27,28 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services public async Task GetById(string id) { - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); - - using (var httpClientHandler = new HttpClientHandler()) + return await GrpcCallerService.CallService(_urls.GrpcBasket, async httpClient => { - httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }; - using (var httpClient = new HttpClient(httpClientHandler)) - { - //httpClient.BaseAddress = new Uri("http://10.0.75.1:5580"); - httpClient.BaseAddress = new Uri(_urls.GrpcBasket); - - _logger.LogDebug("Creating grpc client for basket {@httpClient.BaseAddress} ", httpClient.BaseAddress); - - var client = GrpcClient.Create(httpClient); - - _logger.LogDebug("grpc client created, request = {@id}", id); - - try - { - - var response = await client.GetBasketByIdAsync(new BasketRequest { Id = id }); + var client = GrpcClient.Create(httpClient); + _logger.LogDebug("grpc client created, request = {@id}", id); + var response = await client.GetBasketByIdAsync(new BasketRequest { Id = id }); + _logger.LogDebug("grpc response {@response}", response); - _logger.LogDebug("grpc response {@response}", response); - - return MapToBasketData(response); - } - catch (RpcException e) - { - _logger.LogError($"Error calling via grpc: {e.Status} - {e.Message}"); - } - } - } - - return null; + return MapToBasketData(response); + }); } public async Task UpdateAsync(BasketData currentBasket) { - _httpClient.BaseAddress = new Uri(_urls.Basket + UrlsConfig.BasketOperations.UpdateBasket()); - - var client = GrpcClient.Create(_httpClient); - var request = MapToCustomerBasketRequest(currentBasket); + await GrpcCallerService.CallService(_urls.GrpcBasket, async httpClient => + { + var client = GrpcClient.Create(httpClient); + _logger.LogDebug("Grpc update basket currentBasket {@currentBasket}", currentBasket); + var request = MapToCustomerBasketRequest(currentBasket); + _logger.LogDebug("Grpc update basket request {@request}", request); - await client.UpdateBasketAsync(request); + return client.UpdateBasketAsync(request); + }); } private BasketData MapToBasketData(CustomerBasketResponse customerBasketRequest) diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/CatalogService.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/CatalogService.cs index fbcc8349b..b03ad9bab 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/CatalogService.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/CatalogService.cs @@ -3,9 +3,8 @@ using Grpc.Net.Client; using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config; using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models; using Microsoft.Extensions.Options; -using Newtonsoft.Json; -using System; using System.Collections.Generic; +using System.Linq; using System.Net.Http; using System.Threading.Tasks; using static CatalogApi.Catalog; @@ -25,21 +24,26 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services public async Task GetCatalogItemAsync(int id) { - _httpClient.BaseAddress = new Uri(_urls.Catalog + UrlsConfig.CatalogOperations.GetItemById(id)); - var client = GrpcClient.Create(_httpClient); - var request = new CatalogItemRequest { Id = id }; - var response = await client.GetItemByIdAsync(request); - - return MapToCatalogItemResponse(response); + return await GrpcCallerService.CallService(_urls.Catalog + UrlsConfig.CatalogOperations.GetItemById(id), async httpClient => + { + var client = GrpcClient.Create(_httpClient); + var request = new CatalogItemRequest { Id = id }; + var response = await client.GetItemByIdAsync(request); + return MapToCatalogItemResponse(response); + }); } public async Task> GetCatalogItemsAsync(IEnumerable ids) { - var stringContent = await _httpClient.GetStringAsync(_urls.Catalog + UrlsConfig.CatalogOperations.GetItemsById(ids)); - var catalogItems = JsonConvert.DeserializeObject(stringContent); - return catalogItems; + return await GrpcCallerService.CallService(_urls.GrpcCatalog, async httpClient => + { + var client = GrpcClient.Create(httpClient); + var request = new CatalogItemsRequest { Ids = string.Join(",", ids), PageIndex = 1, PageSize = 10 }; + var response = await client.GetItemsByIdsAsync(request); + return response.Data.Select(this.MapToCatalogItemResponse); + }); } private CatalogItem MapToCatalogItemResponse(CatalogItemResponse catalogItemResponse) diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/GrpcCallerService.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/GrpcCallerService.cs new file mode 100644 index 000000000..e730be327 --- /dev/null +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/GrpcCallerService.cs @@ -0,0 +1,73 @@ +using System.Net.Http; +using System.Threading.Tasks; +using System; +using Grpc.Core; +using Serilog; + +namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services +{ + public static class GrpcCallerService + { + public static async Task CallService(string urlGrpc, Func> func) + { + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); + + using var httpClientHandler = new HttpClientHandler + { + ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; } + }; + + using var httpClient = new HttpClient(httpClientHandler) + { + BaseAddress = new Uri(urlGrpc) + }; + + Log.Information("Creating grpc client base address urlGrpc ={@urlGrpc}, BaseAddress={@BaseAddress} ", urlGrpc, httpClient.BaseAddress); + + try + { + return await func(httpClient); + } + catch (RpcException e) + { + Log.Error($"Error calling via grpc: {e.Status} - {e.Message}"); + } + + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false); + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", false); + + return default; + } + + public static async Task CallService(string urlGrpc, Func func) + { + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); + + using var httpClientHandler = new HttpClientHandler + { + ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; } + }; + + using var httpClient = new HttpClient(httpClientHandler) + { + BaseAddress = new Uri(urlGrpc) + }; + + Log.Debug("Creating grpc client base address {@httpClient.BaseAddress} ", httpClient.BaseAddress); + + try + { + await func(httpClient); + } + catch (RpcException e) + { + Log.Error($"Error calling via grpc: {e.Status} - {e.Message}"); + } + + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false); + AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", false); + } + } +} diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/OrderingService.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/OrderingService.cs index f1e56c2ef..d42c14344 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/OrderingService.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/OrderingService.cs @@ -3,12 +3,10 @@ using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config; using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using System; using System.Linq; using System.Net.Http; using System.Threading.Tasks; using GrpcOrdering; -using Grpc.Core; namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services { @@ -27,43 +25,21 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services public async Task GetOrderDraftAsync(BasketData basketData) { - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); - AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); - using (var httpClientHandler = new HttpClientHandler()) + return await GrpcCallerService.CallService(_urls.GrpcOrdering, async httpClient => { - httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }; - using (var httpClient = new HttpClient(httpClientHandler)) - { - httpClient.BaseAddress = new Uri(_urls.GrpcOrdering); + var client = GrpcClient.Create(httpClient); + _logger.LogDebug(" grpc client created, basketData={@basketData}", basketData); - _logger.LogDebug(" Creating grpc client for ordering {@httpClient.BaseAddress}", httpClient.BaseAddress); + var command = MapToOrderDraftCommand(basketData); + var response = await client.CreateOrderDraftFromBasketDataAsync(command); + _logger.LogDebug(" grpc response: {@response}", response); - var client = GrpcClient.Create(httpClient); - - _logger.LogDebug(" grpc client created, basketData={@basketData}", basketData); - - try - { - - var command = MapToOrderDraftCommand(basketData); - var response = await client.CreateOrderDraftFromBasketDataAsync(command); - - _logger.LogDebug(" grpc response: {@response}", response); - - return MapToResponse(response); - } - catch (RpcException e) - { - _logger.LogError($"Error calling via grpc to ordering: {e.Status} - {e.Message}"); - } - } - } - - return null; + return MapToResponse(response, basketData); + }); } - private OrderData MapToResponse(GrpcOrdering.OrderDraftDTO orderDraft) + private OrderData MapToResponse(GrpcOrdering.OrderDraftDTO orderDraft, BasketData basketData) { if (orderDraft == null) { @@ -72,6 +48,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services var data = new OrderData { + Buyer = basketData.BuyerId, Total = (decimal)orderDraft.Total, }; diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/appsettings.json b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/appsettings.json index 95b8bad4c..26bb0ac7a 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/appsettings.json +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/appsettings.json @@ -1,9 +1,4 @@ { - "Kestrel": { - "EndpointDefaults": { - "Protocols": "Http2" - } - }, "Logging": { "IncludeScopes": false, "Debug": { diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/appsettings.localhost.json b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/appsettings.localhost.json index f14ca24b9..86fd1541d 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/appsettings.localhost.json +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/appsettings.localhost.json @@ -5,6 +5,7 @@ "orders": "http://localhost:55102", "identity": "http://localhost:55105", "grpcBasket": "http://localhost:5580", + "grpcCatalog": "http://localhost:81", "grpcOrdering": "http://localhost:5581" }, "IdentityUrlExternal": "http://localhost:5105", diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/CatalogService.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/CatalogService.cs index 5e3e4e2f0..a03c67db2 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/CatalogService.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/CatalogService.cs @@ -28,13 +28,15 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services public async Task GetCatalogItemAsync(int id) { - _httpClient.BaseAddress = new Uri(_urls.Catalog + UrlsConfig.CatalogOperations.GetItemById(id)); - - var client = GrpcClient.Create(_httpClient); - var request = new CatalogItemRequest { Id = id }; - var response = await client.GetItemByIdAsync(request); - - return MapToCatalogItemResponse(response); + return await GrpcCallerService.CallService(_urls.GrpcCatalog, async httpClient => + { + var client = GrpcClient.Create(httpClient); + var request = new CatalogItemRequest { Id = id }; + _logger.LogInformation("grpc client created, request = {@request}", request); + var response = await client.GetItemByIdAsync(request); + _logger.LogInformation("grpc response {@response}", response); + return MapToCatalogItemResponse(response); + }); } public async Task> GetCatalogItemsAsync(IEnumerable ids) From 7f88a71cce16f828bc811e534bb1d12ab6bb29d4 Mon Sep 17 00:00:00 2001 From: ericuss Date: Thu, 29 Aug 2019 09:38:03 +0200 Subject: [PATCH 06/10] update dockerfiles --- src/ApiGateways/ApiGw-Base/Dockerfile | 12 ++++++------ .../Ordering/Ordering.BackgroundTasks/Dockerfile | 13 +++++++------ .../Ordering/Ordering.SignalrHub/Dockerfile | 12 ++++++------ 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/ApiGateways/ApiGw-Base/Dockerfile b/src/ApiGateways/ApiGw-Base/Dockerfile index 7a5bb928c..00da7c461 100644 --- a/src/ApiGateways/ApiGw-Base/Dockerfile +++ b/src/ApiGateways/ApiGw-Base/Dockerfile @@ -6,14 +6,14 @@ FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build WORKDIR /src COPY scripts scripts/ -COPY src/ApiGateways/*/*.csproj /src/csproj-files/ -COPY src/ApiGateways/*/*/*.csproj /src/csproj-files/ -COPY src/BuildingBlocks/*/*/*.csproj /src/csproj-files/ -COPY src/Services/*/*/*.csproj /src/csproj-files/ -COPY src/Web/*/*.csproj /src/csproj-files/ +COPY ApiGateways/*/*.csproj csproj-files/ +COPY ApiGateways/*/*/*.csproj csproj-files/ +COPY BuildingBlocks/*/*/*.csproj csproj-files/ +COPY Services/*/*/*.csproj csproj-files/ +COPY Web/*/*.csproj csproj-files/ COPY . . -WORKDIR /src/src/ApiGateways/ApiGw-Base/ +WORKDIR /src/ApiGateways/ApiGw-Base/ RUN dotnet publish -c Release -o /app FROM build AS publish diff --git a/src/Services/Ordering/Ordering.BackgroundTasks/Dockerfile b/src/Services/Ordering/Ordering.BackgroundTasks/Dockerfile index 820f8d4b1..87a735827 100644 --- a/src/Services/Ordering/Ordering.BackgroundTasks/Dockerfile +++ b/src/Services/Ordering/Ordering.BackgroundTasks/Dockerfile @@ -7,14 +7,15 @@ WORKDIR /src COPY scripts scripts/ -COPY src/ApiGateways/*/*.csproj /src/csproj-files/ -COPY src/ApiGateways/*/*/*.csproj /src/csproj-files/ -COPY src/BuildingBlocks/*/*/*.csproj /src/csproj-files/ -COPY src/Services/*/*/*.csproj /src/csproj-files/ -COPY src/Web/*/*.csproj /src/csproj-files/ +COPY ApiGateways/*/*.csproj csproj-files/ +COPY ApiGateways/*/*/*.csproj csproj-files/ +COPY BuildingBlocks/*/*/*.csproj csproj-files/ +COPY Services/*/*/*.csproj csproj-files/ +COPY Web/*/*.csproj csproj-files/ + COPY . . -WORKDIR /src/src/Services/Ordering/Ordering.BackgroundTasks +WORKDIR /src/Services/Ordering/Ordering.BackgroundTasks RUN dotnet publish -c Release -o /app FROM build AS publish diff --git a/src/Services/Ordering/Ordering.SignalrHub/Dockerfile b/src/Services/Ordering/Ordering.SignalrHub/Dockerfile index 15389786c..3174a4781 100644 --- a/src/Services/Ordering/Ordering.SignalrHub/Dockerfile +++ b/src/Services/Ordering/Ordering.SignalrHub/Dockerfile @@ -7,14 +7,14 @@ WORKDIR /src COPY scripts scripts/ -COPY src/ApiGateways/*/*.csproj /src/csproj-files/ -COPY src/ApiGateways/*/*/*.csproj /src/csproj-files/ -COPY src/BuildingBlocks/*/*/*.csproj /src/csproj-files/ -COPY src/Services/*/*/*.csproj /src/csproj-files/ -COPY src/Web/*/*.csproj /src/csproj-files/ +COPY ApiGateways/*/*.csproj csproj-files/ +COPY ApiGateways/*/*/*.csproj csproj-files/ +COPY BuildingBlocks/*/*/*.csproj csproj-files/ +COPY Services/*/*/*.csproj csproj-files/ +COPY Web/*/*.csproj csproj-files/ COPY . . -WORKDIR /src/src/Services/Ordering/Ordering.SignalrHub +WORKDIR /src/Services/Ordering/Ordering.SignalrHub RUN dotnet publish -c Release -o /app FROM build AS publish From 4398b25fc1e4988b93dc5a2848fbb2ab019dbf2f Mon Sep 17 00:00:00 2001 From: ericuss Date: Thu, 29 Aug 2019 13:13:10 +0200 Subject: [PATCH 07/10] Fix mvc calls to grpc --- .../aggregator/Controllers/BasketController.cs | 10 ++++++---- .../aggregator/Services/BasketService.cs | 2 +- .../Basket/Basket.API/Controllers/BasketController.cs | 10 ---------- src/Services/Basket/Basket.API/Model/CustomerBasket.cs | 3 +-- src/Web/WebMVC/Controllers/CartController.cs | 4 ++-- 5 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs index 5905ae214..429d6e82d 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs @@ -125,12 +125,14 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers var currentBasket = (await _basket.GetById(data.BasketId)) ?? new BasketData(data.BasketId); // Step 3: Search if exist product into basket var product = currentBasket.Items.SingleOrDefault(i => i.ProductId == item.Id.ToString()); - - if(product != null){ + + if (product != null) + { // Step 4: Update quantity for product product.Quantity += data.Quantity; } - else{ + else + { // Step 4: Merge current status with new product currentBasket.Items.Add(new BasketDataItem() { @@ -142,7 +144,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers Id = Guid.NewGuid().ToString() }); } - + // Step 5: Update basket await _basket.UpdateAsync(currentBasket); diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs index 3875f3bdb..8eb8865fe 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs @@ -46,7 +46,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services var request = MapToCustomerBasketRequest(currentBasket); _logger.LogDebug("Grpc update basket request {@request}", request); - return client.UpdateBasketAsync(request); + return await client.UpdateBasketAsync(request); }); } diff --git a/src/Services/Basket/Basket.API/Controllers/BasketController.cs b/src/Services/Basket/Basket.API/Controllers/BasketController.cs index fca033301..59f117a3b 100644 --- a/src/Services/Basket/Basket.API/Controllers/BasketController.cs +++ b/src/Services/Basket/Basket.API/Controllers/BasketController.cs @@ -63,8 +63,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers basketCheckout.RequestId = (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty) ? guid : basketCheckout.RequestId; - _logger.LogInformation("----- CheckoutAsync userId: {userId} ", userId); - var basket = await _repository.GetBasketAsync(userId); if (basket == null) @@ -72,14 +70,8 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers return BadRequest(); } - _logger.LogInformation("----- CheckoutAsync basket: {@basket} ", basket); - - _logger.LogInformation("----- CheckoutAsync user identity: {User} ", string.Join(':', ((ClaimsIdentity)User.Identity).Claims.Select(c => c.Type + " " + c.Value))); - var userName = User.FindFirst(x => x.Type == ClaimTypes.Name).Value; - _logger.LogInformation("----- CheckoutAsync userName: {@userName} ", userName); - var eventMessage = new UserCheckoutAcceptedIntegrationEvent(userId, userName, basketCheckout.City, basketCheckout.Street, basketCheckout.State, basketCheckout.Country, basketCheckout.ZipCode, basketCheckout.CardNumber, basketCheckout.CardHolderName, basketCheckout.CardExpiration, basketCheckout.CardSecurityNumber, basketCheckout.CardTypeId, basketCheckout.Buyer, basketCheckout.RequestId, basket); @@ -89,8 +81,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers // order creation process try { - _logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", eventMessage.Id, Program.AppName, eventMessage); - _eventBus.Publish(eventMessage); } catch (Exception ex) diff --git a/src/Services/Basket/Basket.API/Model/CustomerBasket.cs b/src/Services/Basket/Basket.API/Model/CustomerBasket.cs index b075f3150..9ae495d4f 100644 --- a/src/Services/Basket/Basket.API/Model/CustomerBasket.cs +++ b/src/Services/Basket/Basket.API/Model/CustomerBasket.cs @@ -6,7 +6,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model { public string BuyerId { get; set; } - public List Items { get; set; } + public List Items { get; set; } = new List(); public CustomerBasket() { @@ -16,7 +16,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model public CustomerBasket(string customerId) { BuyerId = customerId; - Items = new List(); } } } diff --git a/src/Web/WebMVC/Controllers/CartController.cs b/src/Web/WebMVC/Controllers/CartController.cs index 6887c8d41..b05009cc7 100644 --- a/src/Web/WebMVC/Controllers/CartController.cs +++ b/src/Web/WebMVC/Controllers/CartController.cs @@ -41,7 +41,7 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers return View(); } - + [HttpPost] public async Task Index(Dictionary quantities, string action) { @@ -72,7 +72,7 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers var user = _appUserParser.Parse(HttpContext.User); await _basketSvc.AddItemToBasket(user, productDetails.Id); } - return RedirectToAction("Index", "Catalog"); + return RedirectToAction("Index", "Catalog"); } catch (BrokenCircuitException) { From 10759109aba67d4cead55848ededa1993a753733 Mon Sep 17 00:00:00 2001 From: ericuss Date: Thu, 29 Aug 2019 16:16:24 +0200 Subject: [PATCH 08/10] temporal fix to get the order in local dbset of orders for UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler.cs --- .../Repositories/OrderRepository.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs b/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs index 1047d6c7e..c6d57b17b 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs @@ -28,7 +28,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor public Order Add(Order order) { return _context.Orders.Add(order).Entity; - + } public async Task GetAsync(int orderId) @@ -37,6 +37,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor .Orders .Include(x => x.Address) .FirstOrDefaultAsync(o => o.Id == orderId); + if (order == null) + { + + order = _context + .Orders + .Local + .FirstOrDefault(o => o.Id == orderId); + } if (order != null) { await _context.Entry(order) From e689cfd65e739070f58654d6240f4ec3346bb496 Mon Sep 17 00:00:00 2001 From: ericuss Date: Thu, 29 Aug 2019 16:17:06 +0200 Subject: [PATCH 09/10] add using --- .../Ordering.Infrastructure/Repositories/OrderRepository.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs b/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs index c6d57b17b..4d4f64d7a 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs @@ -3,6 +3,7 @@ using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork; using Ordering.Domain.Exceptions; using System; +using System.Linq; using System.Threading.Tasks; namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositories From ffe2884dc4c752ae5e522d2698b88500ce79ae75 Mon Sep 17 00:00:00 2001 From: ericuss Date: Fri, 30 Aug 2019 14:20:26 +0200 Subject: [PATCH 10/10] fix checkout process of mvc app --- .../OrderStartedIntegrationEventHandler.cs | 2 - ...ductPriceChangedIntegrationEventHandler.cs | 4 -- .../Catalog.API/Grpc/CatalogService.cs | 7 ---- .../CatalogIntegrationEventService.cs | 4 -- ...aitingValidationIntegrationEventHandler.cs | 2 - ...tusChangedToPaidIntegrationEventHandler.cs | 2 - .../Services/LocationsService.cs | 3 -- ...rLocationUpdatedIntegrationEventHandler.cs | 2 - .../Behaviors/ValidatorBehavior.cs | 2 - .../Commands/CreateOrderCommandHandler.cs | 2 - ...PaymentMethodVerifiedDomainEventHandler.cs | 1 - ...egateWhenOrderStartedDomainEventHandler.cs | 15 ++++---- ...ePeriodConfirmedIntegrationEventHandler.cs | 2 - ...derPaymentFailedIntegrationEventHandler.cs | 2 - ...rPaymentSuccededIntegrationEventHandler.cs | 2 - ...erStockConfirmedIntegrationEventHandler.cs | 2 - ...derStockRejectedIntegrationEventHandler.cs | 2 - ...CheckoutAcceptedIntegrationEventHandler.cs | 10 +---- .../OrderingIntegrationEventService.cs | 4 -- .../Controllers/OrdersController.cs | 6 +-- .../Ordering.API/Grpc/OrderingService.cs | 2 +- .../Tasks/GracePeriodManagerTask.cs | 2 - .../AggregatesModel/OrderAggregate/Order.cs | 7 ++-- .../OrderEntityTypeConfiguration.cs | 38 +++++++++++++++---- .../OrderItemEntityTypeConfiguration.cs | 25 +++++++++--- .../PaymentMethodEntityTypeConfiguration.cs | 28 +++++++++++--- .../Repositories/OrderRepository.cs | 1 - ...aitingValidationIntegrationEventHandler.cs | 2 - ...angedToCancelledIntegrationEventHandler.cs | 2 - ...tusChangedToPaidIntegrationEventHandler.cs | 2 - ...ChangedToShippedIntegrationEventHandler.cs | 2 - ...ToStockConfirmedIntegrationEventHandler.cs | 2 - ...angedToSubmittedIntegrationEventHandler.cs | 2 - ...ToStockConfirmedIntegrationEventHandler.cs | 4 -- .../WebMVC/Controllers/AccountController.cs | 2 - 35 files changed, 90 insertions(+), 107 deletions(-) diff --git a/src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/OrderStartedIntegrationEventHandler.cs b/src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/OrderStartedIntegrationEventHandler.cs index cb7b6a2d6..4fc2e2ec0 100644 --- a/src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/OrderStartedIntegrationEventHandler.cs +++ b/src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/OrderStartedIntegrationEventHandler.cs @@ -26,8 +26,6 @@ namespace Basket.API.IntegrationEvents.EventHandling { using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); - await _repository.DeleteBasketAsync(@event.UserId.ToString()); } } diff --git a/src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedIntegrationEventHandler.cs b/src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedIntegrationEventHandler.cs index c27200e6f..d303e0771 100644 --- a/src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedIntegrationEventHandler.cs +++ b/src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedIntegrationEventHandler.cs @@ -26,8 +26,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even { using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); - var userIds = _repository.GetUsers(); foreach (var id in userIds) @@ -46,8 +44,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even if (itemsToUpdate != null) { - _logger.LogInformation("----- ProductPriceChangedIntegrationEventHandler - Updating items in basket for user: {BuyerId} ({@Items})", basket.BuyerId, itemsToUpdate); - foreach (var item in itemsToUpdate) { if (item.UnitPrice == oldPrice) diff --git a/src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs b/src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs index 9c620a481..39d7828c2 100644 --- a/src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs +++ b/src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs @@ -64,12 +64,10 @@ namespace Catalog.API.Grpc public override async Task GetItemsByIds(CatalogItemsRequest request, ServerCallContext context) { - _logger.LogInformation("---------- GetItemsByIds request {@request}", request); if (!string.IsNullOrEmpty(request.Ids)) { var items = await GetItemsByIdsAsync(request.Ids); - _logger.LogInformation("---------- GetItemsByIds items {@items}", items); if (!items.Any()) { context.Status = new Status(StatusCode.NotFound, $"ids value invalid. Must be comma-separated list of numbers"); @@ -78,18 +76,15 @@ namespace Catalog.API.Grpc return this.MapToResponse(items); } - _logger.LogInformation("---------- GetItemsByIds else"); var totalItems = await _catalogContext.CatalogItems .LongCountAsync(); - _logger.LogInformation("---------- GetItemsByIds totalItems {@totalItems}", totalItems); var itemsOnPage = await _catalogContext.CatalogItems .OrderBy(c => c.Name) .Skip(request.PageSize * request.PageIndex) .Take(request.PageSize) .ToListAsync(); - _logger.LogInformation("---------- GetItemsByIds itemsOnPage {@itemsOnPage}", itemsOnPage); /* The "awesome" fix for testing Devspaces */ /* @@ -100,10 +95,8 @@ namespace Catalog.API.Grpc */ itemsOnPage = ChangeUriPlaceholder(itemsOnPage); - _logger.LogInformation("---------- GetItemsByIds itemsOnPage2 {@itemsOnPage}", itemsOnPage); var model = this.MapToResponse(itemsOnPage, totalItems, request.PageIndex, request.PageSize); - _logger.LogInformation("---------- GetItemsByIds model {@model}", model); context.Status = new Status(StatusCode.OK, string.Empty); return model; diff --git a/src/Services/Catalog/Catalog.API/IntegrationEvents/CatalogIntegrationEventService.cs b/src/Services/Catalog/Catalog.API/IntegrationEvents/CatalogIntegrationEventService.cs index bb3a23d40..e84de7e9e 100644 --- a/src/Services/Catalog/Catalog.API/IntegrationEvents/CatalogIntegrationEventService.cs +++ b/src/Services/Catalog/Catalog.API/IntegrationEvents/CatalogIntegrationEventService.cs @@ -39,8 +39,6 @@ namespace Catalog.API.IntegrationEvents { try { - _logger.LogInformation("----- Publishing integration event: {IntegrationEventId_published} from {AppName} - ({@IntegrationEvent})", evt.Id, Program.AppName, evt); - await _eventLogService.MarkEventAsInProgressAsync(evt.Id); _eventBus.Publish(evt); await _eventLogService.MarkEventAsPublishedAsync(evt.Id); @@ -54,8 +52,6 @@ namespace Catalog.API.IntegrationEvents public async Task SaveEventAndCatalogContextChangesAsync(IntegrationEvent evt) { - _logger.LogInformation("----- CatalogIntegrationEventService - Saving changes and integrationEvent: {IntegrationEventId}", evt.Id); - //Use of an EF Core resiliency strategy when using multiple DbContexts within an explicit BeginTransaction(): //See: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency await ResilientTransaction.New(_catalogContext).ExecuteAsync(async () => diff --git a/src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs b/src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs index 493a271cc..2c9fd337c 100644 --- a/src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs +++ b/src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs @@ -32,8 +32,6 @@ { using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); - var confirmedOrderStockItems = new List(); foreach (var orderStockItem in @event.OrderStockItems) diff --git a/src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToPaidIntegrationEventHandler.cs b/src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToPaidIntegrationEventHandler.cs index 7d383254f..e7520a651 100644 --- a/src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToPaidIntegrationEventHandler.cs +++ b/src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToPaidIntegrationEventHandler.cs @@ -25,8 +25,6 @@ { using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); - //we're not blocking stock/inventory foreach (var orderStockItem in @event.OrderStockItems) { diff --git a/src/Services/Location/Locations.API/Infrastructure/Services/LocationsService.cs b/src/Services/Location/Locations.API/Infrastructure/Services/LocationsService.cs index f6b9ed708..dc91d0d50 100644 --- a/src/Services/Location/Locations.API/Infrastructure/Services/LocationsService.cs +++ b/src/Services/Location/Locations.API/Infrastructure/Services/LocationsService.cs @@ -72,9 +72,6 @@ { var newUserLocations = MapUserLocationDetails(newLocations); var @event = new UserLocationUpdatedIntegrationEvent(userId, newUserLocations); - - _logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); - _eventBus.Publish(@event); } diff --git a/src/Services/Marketing/Marketing.API/IntegrationEvents/Handlers/UserLocationUpdatedIntegrationEventHandler.cs b/src/Services/Marketing/Marketing.API/IntegrationEvents/Handlers/UserLocationUpdatedIntegrationEventHandler.cs index 3d5e62e45..5b93a17d0 100644 --- a/src/Services/Marketing/Marketing.API/IntegrationEvents/Handlers/UserLocationUpdatedIntegrationEventHandler.cs +++ b/src/Services/Marketing/Marketing.API/IntegrationEvents/Handlers/UserLocationUpdatedIntegrationEventHandler.cs @@ -28,8 +28,6 @@ { using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); - var userMarketingData = await _marketingDataRepository.GetAsync(@event.UserId); userMarketingData = userMarketingData ?? new MarketingData() { UserId = @event.UserId }; diff --git a/src/Services/Ordering/Ordering.API/Application/Behaviors/ValidatorBehavior.cs b/src/Services/Ordering/Ordering.API/Application/Behaviors/ValidatorBehavior.cs index 6fc12258b..9be24e20f 100644 --- a/src/Services/Ordering/Ordering.API/Application/Behaviors/ValidatorBehavior.cs +++ b/src/Services/Ordering/Ordering.API/Application/Behaviors/ValidatorBehavior.cs @@ -24,8 +24,6 @@ namespace Ordering.API.Application.Behaviors { var typeName = request.GetGenericTypeName(); - _logger.LogInformation("----- Validating command {CommandType}", typeName); - var failures = _validators .Select(v => v.Validate(request)) .SelectMany(result => result.Errors) diff --git a/src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs b/src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs index b2fff253d..1cbd21536 100644 --- a/src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs @@ -53,8 +53,6 @@ order.AddOrderItem(item.ProductId, item.ProductName, item.UnitPrice, item.Discount, item.PictureUrl, item.Units); } - _logger.LogInformation("----- Creating Order - Order: {@Order}", order); - _orderRepository.Add(order); return await _orderRepository.UnitOfWork diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/BuyerAndPaymentMethodVerified/UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/BuyerAndPaymentMethodVerified/UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler.cs index 32b927368..4d3a3280c 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/BuyerAndPaymentMethodVerified/UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/BuyerAndPaymentMethodVerified/UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler.cs @@ -27,7 +27,6 @@ namespace Ordering.API.Application.DomainEventHandlers.BuyerAndPaymentMethodVeri public async Task Handle(BuyerAndPaymentMethodVerifiedDomainEvent buyerPaymentMethodVerifiedEvent, CancellationToken cancellationToken) { var log = _logger.CreateLogger(); - log.LogInformation("----- Handling BuyerAndPaymentMethodVerifiedDomainEvent - buyerPaymentMethodVerifiedEvent: {@buyerPaymentMethodVerifiedEvent}", buyerPaymentMethodVerifiedEvent); var orderToUpdate = await _orderRepository.GetAsync(buyerPaymentMethodVerifiedEvent.OrderId); orderToUpdate.SetBuyerId(buyerPaymentMethodVerifiedEvent.Buyer.Id); orderToUpdate.SetPaymentId(buyerPaymentMethodVerifiedEvent.Payment.Id); diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStartedEvent/ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStartedEvent/ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler.cs index 054c20de5..5b8f19b00 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStartedEvent/ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStartedEvent/ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler.cs @@ -12,7 +12,7 @@ using System.Threading.Tasks; namespace Ordering.API.Application.DomainEventHandlers.OrderStartedEvent { - public class ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler + public class ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler : INotificationHandler { private readonly ILoggerFactory _logger; @@ -21,8 +21,8 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderStartedEvent private readonly IOrderingIntegrationEventService _orderingIntegrationEventService; public ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler( - ILoggerFactory logger, - IBuyerRepository buyerRepository, + ILoggerFactory logger, + IBuyerRepository buyerRepository, IIdentityService identityService, IOrderingIntegrationEventService orderingIntegrationEventService) { @@ -33,13 +33,13 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderStartedEvent } public async Task Handle(OrderStartedDomainEvent orderStartedEvent, CancellationToken cancellationToken) - { + { var cardTypeId = (orderStartedEvent.CardTypeId != 0) ? orderStartedEvent.CardTypeId : 1; var buyer = await _buyerRepository.FindAsync(orderStartedEvent.UserId); bool buyerOriginallyExisted = (buyer == null) ? false : true; if (!buyerOriginallyExisted) - { + { buyer = new Buyer(orderStartedEvent.UserId, orderStartedEvent.UserName); } @@ -51,8 +51,8 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderStartedEvent orderStartedEvent.CardExpiration, orderStartedEvent.Order.Id); - var buyerUpdated = buyerOriginallyExisted ? - _buyerRepository.Update(buyer) : + var buyerUpdated = buyerOriginallyExisted ? + _buyerRepository.Update(buyer) : _buyerRepository.Add(buyer); await _buyerRepository.UnitOfWork @@ -60,7 +60,6 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderStartedEvent var orderStatusChangedTosubmittedIntegrationEvent = new OrderStatusChangedToSubmittedIntegrationEvent(orderStartedEvent.Order.Id, orderStartedEvent.Order.OrderStatus.Name, buyer.Name); await _orderingIntegrationEventService.AddAndSaveEventAsync(orderStatusChangedTosubmittedIntegrationEvent); - _logger.CreateLogger() .LogTrace("Buyer {BuyerId} and related payment method were validated or updated for orderId: {OrderId}.", buyerUpdated.Id, orderStartedEvent.Order.Id); diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/GracePeriodConfirmedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/GracePeriodConfirmedIntegrationEventHandler.cs index 2e003b322..e3df4d11d 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/GracePeriodConfirmedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/GracePeriodConfirmedIntegrationEventHandler.cs @@ -37,8 +37,6 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling { using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); - var command = new SetAwaitingValidationOrderStatusCommand(@event.OrderId); _logger.LogInformation( diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs index a123dd891..e54a14fb0 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs @@ -31,8 +31,6 @@ { using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); - var command = new CancelOrderCommand(@event.OrderId); _logger.LogInformation( diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs index 9cc69e5e8..dc2c6b9cd 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs @@ -31,8 +31,6 @@ { using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); - var command = new SetPaidOrderStatusCommand(@event.OrderId); _logger.LogInformation( diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs index 6438b01d0..8572a09dd 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs @@ -31,8 +31,6 @@ { using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); - var command = new SetStockConfirmedOrderStatusCommand(@event.OrderId); _logger.LogInformation( diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockRejectedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockRejectedIntegrationEventHandler.cs index b457211ed..1c6a3edd6 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockRejectedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockRejectedIntegrationEventHandler.cs @@ -30,8 +30,6 @@ { using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); - var orderStockRejectedItems = @event.OrderStockItems .FindAll(c => !c.HasStock) .Select(c => c.ProductId) diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/UserCheckoutAcceptedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/UserCheckoutAcceptedIntegrationEventHandler.cs index a1452b23c..f55542b34 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/UserCheckoutAcceptedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/UserCheckoutAcceptedIntegrationEventHandler.cs @@ -35,11 +35,9 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling /// /// public async Task Handle(UserCheckoutAcceptedIntegrationEvent @event) - { + { using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); - var result = false; if (@event.RequestId != Guid.Empty) @@ -62,11 +60,7 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling result = await _mediator.Send(requestCreateOrder); - if (result) - { - _logger.LogInformation("----- CreateOrderCommand suceeded - RequestId: {RequestId}", @event.RequestId); - } - else + if (!result) { _logger.LogWarning("CreateOrderCommand failed - RequestId: {RequestId}", @event.RequestId); } diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/OrderingIntegrationEventService.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/OrderingIntegrationEventService.cs index cb7ce5513..776b90927 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/OrderingIntegrationEventService.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/OrderingIntegrationEventService.cs @@ -45,8 +45,6 @@ namespace Ordering.API.Application.IntegrationEvents foreach (var logEvt in pendingLogEvents) { - _logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", logEvt.EventId, Program.AppName, logEvt.IntegrationEvent); - try { await _eventLogService.MarkEventAsInProgressAsync(logEvt.EventId); @@ -64,8 +62,6 @@ namespace Ordering.API.Application.IntegrationEvents public async Task AddAndSaveEventAsync(IntegrationEvent evt) { - _logger.LogInformation("----- Enqueuing integration event {IntegrationEventId} to repository ({@IntegrationEvent})", evt.Id, evt); - await _eventLogService.SaveEventAsync(evt, _orderingContext.GetCurrentTransaction()); } } diff --git a/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs b/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs index 7a592bfb8..58640412b 100644 --- a/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs +++ b/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs @@ -49,7 +49,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers { var requestCancelOrder = new IdentifiedCommand(command, guid); - _logger.LogInformation( + _logger.LogTrace( "----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", requestCancelOrder.GetGenericTypeName(), nameof(requestCancelOrder.Command.OrderNumber), @@ -79,7 +79,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers { var requestShipOrder = new IdentifiedCommand(command, guid); - _logger.LogInformation( + _logger.LogTrace( "----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", requestShipOrder.GetGenericTypeName(), nameof(requestShipOrder.Command.OrderNumber), @@ -141,7 +141,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers [HttpPost] public async Task> CreateOrderDraftFromBasketDataAsync([FromBody] CreateOrderDraftCommand createOrderDraftCommand) { - _logger.LogInformation( + _logger.LogTrace( "----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", createOrderDraftCommand.GetGenericTypeName(), nameof(createOrderDraftCommand.BuyerId), diff --git a/src/Services/Ordering/Ordering.API/Grpc/OrderingService.cs b/src/Services/Ordering/Ordering.API/Grpc/OrderingService.cs index af59420e7..adc210a1a 100644 --- a/src/Services/Ordering/Ordering.API/Grpc/OrderingService.cs +++ b/src/Services/Ordering/Ordering.API/Grpc/OrderingService.cs @@ -27,7 +27,7 @@ namespace GrpcOrdering public override async Task CreateOrderDraftFromBasketData(CreateOrderDraftCommand createOrderDraftCommand, ServerCallContext context) { _logger.LogInformation($"Begin grpc call from method {context.Method} for ordering get order draft {createOrderDraftCommand}"); - _logger.LogInformation( + _logger.LogTrace( "----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", createOrderDraftCommand.GetGenericTypeName(), nameof(createOrderDraftCommand.BuyerId), diff --git a/src/Services/Ordering/Ordering.BackgroundTasks/Tasks/GracePeriodManagerTask.cs b/src/Services/Ordering/Ordering.BackgroundTasks/Tasks/GracePeriodManagerTask.cs index 9d4c83c57..f70fdeb06 100644 --- a/src/Services/Ordering/Ordering.BackgroundTasks/Tasks/GracePeriodManagerTask.cs +++ b/src/Services/Ordering/Ordering.BackgroundTasks/Tasks/GracePeriodManagerTask.cs @@ -55,8 +55,6 @@ namespace Ordering.BackgroundTasks.Tasks { var confirmGracePeriodEvent = new GracePeriodConfirmedIntegrationEvent(orderId); - _logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", confirmGracePeriodEvent.Id, _settings.SubscriptionClientName, confirmGracePeriodEvent); - _eventBus.Publish(confirmGracePeriodEvent); } } diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs index 7da025d3a..b5639ac50 100644 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs +++ b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs @@ -18,7 +18,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O // Address is a Value Object pattern example persisted as EF Core 2.0 owned entity public Address Address { get; private set; } - public int? GetBuyerId => _buyerId; + public int? GetBuyerId { get { return this._buyerId; } } private int? _buyerId; public OrderStatus OrderStatus { get; private set; } @@ -26,7 +26,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O private string _description; - + // Draft orders have this set to true. Currently we don't check anywhere the draft status of an Order, but we could do it if needed private bool _isDraft; @@ -46,7 +46,8 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O return order; } - protected Order() { + protected Order() + { _orderItems = new List(); _isDraft = false; } diff --git a/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderEntityTypeConfiguration.cs b/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderEntityTypeConfiguration.cs index c4c7fce38..9bfccd64c 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderEntityTypeConfiguration.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderEntityTypeConfiguration.cs @@ -27,10 +27,31 @@ namespace Ordering.Infrastructure.EntityConfigurations a.WithOwner(); }); - orderConfiguration.Property("OrderDate").IsRequired(); - orderConfiguration.Property("BuyerId").IsRequired(false); - orderConfiguration.Property("OrderStatusId").IsRequired(); - orderConfiguration.Property("PaymentMethodId").IsRequired(false); + orderConfiguration + .Property("_buyerId") + .UsePropertyAccessMode(PropertyAccessMode.Field) + .HasColumnName("BuyerId") + .IsRequired(false); + + orderConfiguration + .Property("_orderDate") + .UsePropertyAccessMode(PropertyAccessMode.Field) + .HasColumnName("OrderDate") + .IsRequired(); + + orderConfiguration + .Property("_orderStatusId") + // .HasField("_orderStatusId") + .UsePropertyAccessMode(PropertyAccessMode.Field) + .HasColumnName("OrderStatusId") + .IsRequired(); + + orderConfiguration + .Property("_paymentMethodId") + .UsePropertyAccessMode(PropertyAccessMode.Field) + .HasColumnName("PaymentMethodId") + .IsRequired(false); + orderConfiguration.Property("Description").IsRequired(false); var navigation = orderConfiguration.Metadata.FindNavigation(nameof(Order.OrderItems)); @@ -41,18 +62,21 @@ namespace Ordering.Infrastructure.EntityConfigurations orderConfiguration.HasOne() .WithMany() - .HasForeignKey("PaymentMethodId") + // .HasForeignKey("PaymentMethodId") + .HasForeignKey("_paymentMethodId") .IsRequired(false) .OnDelete(DeleteBehavior.Restrict); orderConfiguration.HasOne() .WithMany() .IsRequired(false) - .HasForeignKey("BuyerId"); + // .HasForeignKey("BuyerId"); + .HasForeignKey("_buyerId"); orderConfiguration.HasOne(o => o.OrderStatus) .WithMany() - .HasForeignKey("OrderStatusId"); + // .HasForeignKey("OrderStatusId"); + .HasForeignKey("_orderStatusId"); } } } diff --git a/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderItemEntityTypeConfiguration.cs b/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderItemEntityTypeConfiguration.cs index ca16eddad..e4100eb0d 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderItemEntityTypeConfiguration.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderItemEntityTypeConfiguration.cs @@ -22,22 +22,37 @@ namespace Ordering.Infrastructure.EntityConfigurations orderItemConfiguration.Property("OrderId") .IsRequired(); - orderItemConfiguration.Property("Discount") + orderItemConfiguration + .Property("_discount") + .UsePropertyAccessMode(PropertyAccessMode.Field) + .HasColumnName("Discount") .IsRequired(); orderItemConfiguration.Property("ProductId") .IsRequired(); - orderItemConfiguration.Property("ProductName") + orderItemConfiguration + .Property("_productName") + .UsePropertyAccessMode(PropertyAccessMode.Field) + .HasColumnName("ProductName") .IsRequired(); - orderItemConfiguration.Property("UnitPrice") + orderItemConfiguration + .Property("_unitPrice") + .UsePropertyAccessMode(PropertyAccessMode.Field) + .HasColumnName("UnitPrice") .IsRequired(); - orderItemConfiguration.Property("Units") + orderItemConfiguration + .Property("_units") + .UsePropertyAccessMode(PropertyAccessMode.Field) + .HasColumnName("Units") .IsRequired(); - orderItemConfiguration.Property("PictureUrl") + orderItemConfiguration + .Property("_pictureUrl") + .UsePropertyAccessMode(PropertyAccessMode.Field) + .HasColumnName("PictureUrl") .IsRequired(false); } } diff --git a/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/PaymentMethodEntityTypeConfiguration.cs b/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/PaymentMethodEntityTypeConfiguration.cs index 871c2057e..8343deb3b 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/PaymentMethodEntityTypeConfiguration.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/PaymentMethodEntityTypeConfiguration.cs @@ -23,27 +23,43 @@ namespace Ordering.Infrastructure.EntityConfigurations paymentConfiguration.Property("BuyerId") .IsRequired(); - paymentConfiguration.Property("CardHolderName") + paymentConfiguration + .Property("_cardHolderName") + .UsePropertyAccessMode(PropertyAccessMode.Field) + .HasColumnName("CardHolderName") .HasMaxLength(200) .IsRequired(); - paymentConfiguration.Property("Alias") + paymentConfiguration + .Property("_alias") + .UsePropertyAccessMode(PropertyAccessMode.Field) + .HasColumnName("Alias") .HasMaxLength(200) .IsRequired(); - paymentConfiguration.Property("CardNumber") + paymentConfiguration + .Property("_cardNumber") + .UsePropertyAccessMode(PropertyAccessMode.Field) + .HasColumnName("CardNumber") .HasMaxLength(25) .IsRequired(); - paymentConfiguration.Property("Expiration") + paymentConfiguration + .Property("_expiration") + .UsePropertyAccessMode(PropertyAccessMode.Field) + .HasColumnName("Expiration") + .HasMaxLength(25) .IsRequired(); - paymentConfiguration.Property("CardTypeId") + paymentConfiguration + .Property("_cardTypeId") + .UsePropertyAccessMode(PropertyAccessMode.Field) + .HasColumnName("CardTypeId") .IsRequired(); paymentConfiguration.HasOne(p => p.CardType) .WithMany() - .HasForeignKey("CardTypeId"); + .HasForeignKey("_cardTypeId"); } } } diff --git a/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs b/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs index 4d4f64d7a..f2e13577c 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs @@ -40,7 +40,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor .FirstOrDefaultAsync(o => o.Id == orderId); if (order == null) { - order = _context .Orders .Local diff --git a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs index 0e2665232..7a99d898c 100644 --- a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs @@ -27,8 +27,6 @@ namespace Ordering.SignalrHub.IntegrationEvents { using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); - await _hubContext.Clients .Group(@event.BuyerName) .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); diff --git a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToCancelledIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToCancelledIntegrationEventHandler.cs index 6257bb237..15d2cce47 100644 --- a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToCancelledIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToCancelledIntegrationEventHandler.cs @@ -28,8 +28,6 @@ namespace Ordering.SignalrHub.IntegrationEvents.EventHandling { using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); - await _hubContext.Clients .Group(@event.BuyerName) .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); diff --git a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToPaidIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToPaidIntegrationEventHandler.cs index 836e02d3c..0d70edcbf 100644 --- a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToPaidIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToPaidIntegrationEventHandler.cs @@ -26,8 +26,6 @@ namespace Ordering.SignalrHub.IntegrationEvents.EventHandling { using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); - await _hubContext.Clients .Group(@event.BuyerName) .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); diff --git a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToShippedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToShippedIntegrationEventHandler.cs index 5b08d08b4..782ee1a11 100644 --- a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToShippedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToShippedIntegrationEventHandler.cs @@ -28,8 +28,6 @@ namespace Ordering.SignalrHub.IntegrationEvents.EventHandling { using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); - await _hubContext.Clients .Group(@event.BuyerName) .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); diff --git a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToStockConfirmedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToStockConfirmedIntegrationEventHandler.cs index 348627716..364c1c307 100644 --- a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToStockConfirmedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToStockConfirmedIntegrationEventHandler.cs @@ -29,8 +29,6 @@ namespace Ordering.SignalrHub.IntegrationEvents.EventHandling { using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); - await _hubContext.Clients .Group(@event.BuyerName) .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); diff --git a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs index 422bc4a7a..30183ef77 100644 --- a/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs @@ -29,8 +29,6 @@ namespace Ordering.SignalrHub.IntegrationEvents.EventHandling { using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); - await _hubContext.Clients .Group(@event.BuyerName) .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); diff --git a/src/Services/Payment/Payment.API/IntegrationEvents/EventHandling/OrderStatusChangedToStockConfirmedIntegrationEventHandler.cs b/src/Services/Payment/Payment.API/IntegrationEvents/EventHandling/OrderStatusChangedToStockConfirmedIntegrationEventHandler.cs index bbd4b14de..7570bc117 100644 --- a/src/Services/Payment/Payment.API/IntegrationEvents/EventHandling/OrderStatusChangedToStockConfirmedIntegrationEventHandler.cs +++ b/src/Services/Payment/Payment.API/IntegrationEvents/EventHandling/OrderStatusChangedToStockConfirmedIntegrationEventHandler.cs @@ -31,8 +31,6 @@ { using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); - IntegrationEvent orderPaymentIntegrationEvent; //Business feature comment: @@ -50,8 +48,6 @@ orderPaymentIntegrationEvent = new OrderPaymentFailedIntegrationEvent(@event.OrderId); } - _logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", orderPaymentIntegrationEvent.Id, Program.AppName, orderPaymentIntegrationEvent); - _eventBus.Publish(orderPaymentIntegrationEvent); await Task.CompletedTask; diff --git a/src/Web/WebMVC/Controllers/AccountController.cs b/src/Web/WebMVC/Controllers/AccountController.cs index 8b82498ba..dfd4984c5 100644 --- a/src/Web/WebMVC/Controllers/AccountController.cs +++ b/src/Web/WebMVC/Controllers/AccountController.cs @@ -25,8 +25,6 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers var user = User as ClaimsPrincipal; var token = await HttpContext.GetTokenAsync("access_token"); - _logger.LogInformation("----- User {@User} authenticated into {AppName}", user, Program.AppName); - if (token != null) { ViewData["access_token"] = token;