Пример #1
0
        public async Task <ITKDispatchResponse> SendItkMessage(ITKDispatchRequest request)
        {
            BypassCertificateError();
            var submitHaSCToService = _mappingEngine.Mapper.Map <ITKDispatchRequest, SubmitHaSCToService>(request);
            SubmitHaSCToServiceResponse response = null;

            try {
                response = await _itkDispatcher.SubmitHaSCToServiceAsync(submitHaSCToService);
            }
            catch (Exception ex) {
                return(_itkDispatchResponseBuilder.Build(ex));
            }
            return(_itkDispatchResponseBuilder.Build(response));
        }
Пример #2
0
        public async Task <ItkDispatchResponse> SendItkMessage(ItkDispatchRequest request)
        {
            _logger.Info(string.Format("Request received of JourneyId {0} and external ref {1}", request.CaseDetails.JourneyId, request.CaseDetails.ExternalReference));

            request.CaseDetails.ExternalReference = _patientReferenceService.BuildReference(request.CaseDetails);

            var messageExists = _messageService.MessageAlreadyExists(request.CaseDetails.JourneyId, JsonConvert.SerializeObject(request));

            if (messageExists)
            {
                _logger.Error(string.Format("Duplicate Case sent of JourneyId {0} and external ref {1}", request.CaseDetails.JourneyId, request.CaseDetails.ExternalReference));

                return(_itkDispatchResponseBuilder.Build(new DuplicateMessageException(request.CaseDetails.ExternalReference)));
            }

            var submitHaSCToService = AutoMapperWebConfiguration.Mapper.Map <ItkDispatchRequest, SubmitHaSCToService>(request);

#if DEBUG
            var xsSubmit = new XmlSerializer(typeof(SubmitHaSCToService));
            using (var sww = new StringWriter())
            {
                using (var writer = XmlWriter.Create(sww))
                {
                    xsSubmit.Serialize(writer, submitHaSCToService);
                    var xml = sww.ToString();
                }
            }
#endif
            SubmitHaSCToServiceResponse itkResponse;

            try {
                itkResponse = await _itkDispatcher.SubmitHaSCToServiceAsync(submitHaSCToService);
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Send to ESB error for journeyId {0} and external Ref {1}", request.CaseDetails.JourneyId, request.CaseDetails.ExternalReference), ex);

                return(_itkDispatchResponseBuilder.Build(ex));
            }

            var response = _itkDispatchResponseBuilder.Build(itkResponse, request.CaseDetails.ExternalReference);

            if (response.IsSuccessStatusCode)
            {
                _messageService.StoreMessage(request.CaseDetails.JourneyId, JsonConvert.SerializeObject(request));
            }

            return(response);
        }