Пример #1
0
        public async Task <IActionResult> Get(Guid correlationId)
        {
            //call mediator
            var request = new Mediator.CustomerRequest(
                ControllerContext, new CustomerFilter
            {
                CorrelationId = correlationId
            },
                _messageRequest,
                _vehicleMessageRequest,
                _middlewareConfiguration,
                _correlationId,
                _operationalUnit
                );
            var result = await _mediator.Send(request);

            //transform the result model
            var trackingResult = result?.Select(t => new CustomerResponse(t)).FirstOrDefault();

            return(new JsonResult(trackingResult));
        }
        public async Task <IEnumerable <DomainModels.Business.CustomerDomain.Customer> > Handle(CustomerRequest request, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"Request => {nameof(CustomerRequest)}");
            //add correlation id
            request.Controller.HttpContext.Request.Headers.Add(DomainModels.Types.Identifiers.CorrelationId, new StringValues(request.CorrelationId.ToString()));

            var customerFilterModel = new CustomerFilterModel
            {
                Header = new MessageHeader
                {
                    CorrelationId = request.CorrelationId
                },
                Body   = request.Model,
                Footer = new MessageFooter
                {
                    Sender      = DomainModels.System.Identifiers.TrackingServiceName,
                    FingerPrint = request.Controller.ActionDescriptor.Id,
                    Environment = request.OperationalUnit.Environment,
                    Assembly    = request.OperationalUnit.Assembly,
                    Route       = JsonConvert.SerializeObject(new Dictionary <string, string> {
                        { DomainModels.System.Identifiers.MessagePublisherRoute, request.MiddlewareConfiguration.MessagePublisherRoute }
                    }, Defaults.JsonSerializerSettings),
                    Hint = Enum.GetName(typeof(ResponseHint), ResponseHint.OK)
                }
            };


            return(await await new Function(_logger, DomainModels.System.Identifiers.RetryCount).Decorate(async() =>
            {
                var customer = await request.MessageRequest.Request(customerFilterModel);
                if (customer != null && customer.Any())
                {
                    //in case of data related data cached, or lookup joining, you may get and link data from previous data processed and cached.
                    //in case of the other request does not require data from th other (independent calls), you should call them in separate tasks and wait to consolidate the results.
                    var vehicleFilterModel = new VehicleFilterModel
                    {
                        Header = new MessageHeader
                        {
                            CorrelationId = request.CorrelationId
                        },
                        Body = new VehicleFilter {
                            CustomerId = customer.FirstOrDefault().Id
                        },
                        Footer = new MessageFooter
                        {
                            Sender = DomainModels.System.Identifiers.TrackingServiceName,
                            FingerPrint = request.Controller.ActionDescriptor.Id,
                            Environment = request.OperationalUnit.Environment,
                            Assembly = request.OperationalUnit.Assembly,
                            Route = JsonConvert.SerializeObject(new Dictionary <string, string> {
                                { DomainModels.System.Identifiers.MessagePublisherRoute, request.MiddlewareConfiguration.MessagePublisherRoute }
                            }, Defaults.JsonSerializerSettings),
                            Hint = Enum.GetName(typeof(ResponseHint), ResponseHint.OK)
                        }
                    };
                    var customerVehicles = await request.VehicleMessageRequest.Request(vehicleFilterModel);
                    if (customerVehicles != null && customerVehicles.Any())
                    {
                        customer.FirstOrDefault().Vehicles = new HashSet <Vehicle>(customerVehicles);
                    }
                }
                return customer;
            }));
        }