public async Task <IActionResult> ExternalEstimationResponse(Guid caseNumber, [FromBody] ExternalEstimationProcessed request)
        {
            RandomFailureGenerator.RandomFail(
                failThreshold: Constants.FailureThresholds.ApplicationReceivingExternalEstimations, // Exception is thrown if a random value between 0 and 1 is greater or equal this value
                url: Request.GetDisplayUrl(),
                _logger);

            _logger.LogInformation("Response received from the external estimations service for case number {caseNumber}", caseNumber);

            var source = new MemoryStream(new byte[1024]);

            source.Write(Encoding.UTF8.GetBytes(request.Estimation));
            source.Position = 0;
            var attachment = await _bus.Advanced.DataBus.CreateAttachment(source);

            var message = new EstimationCompleted
            {
                CaseNumber       = caseNumber,
                EstimationTicket = attachment.Id
            };

            await _bus.Send(message);

            return(Accepted());
        }
Exemple #2
0
        public async Task <IActionResult> ProcessImage([FromForm] ImageProcessModel model)
        {
            RandomFailureGenerator.RandomFail(
                failThreshold: Constants.FailureThresholds.ExternalImagesProcessing, // Exception is thrown if a random value between 0 and 1 is greater or equal this value
                url: Request.GetDisplayUrl(),
                logger: _logger);

            _logger.LogInformation("Received new image to process. CaseNumber: {caseNumber}, ImageId: {imageId}", model.CaseNumber, model.ImageId);
            _logger.LogInformation("Callback: {callback}", model.CallbackUrl);

            // Simulate some time to process
            await Task.Delay(2000);

            var client = _httpClientFactory.CreateClient("ImageProcessConfirmation");

            var contentString = System.Text.Json.JsonSerializer.Serialize(new
            {
                Metadata = $"This is the metadata tor the case number {model.CaseNumber} image {model.ImageId}"
            });

            await client.PostAsync(
                new Uri(model.CallbackUrl),
                new StringContent(contentString, Encoding.UTF8, MediaTypeNames.Application.Json));

            return(NoContent());
        }
Exemple #3
0
        public async Task <IActionResult> ProcessNewEstimation(Guid caseNumber, int imageId, [FromBody] ExternalImageProcessed request)
        {
            RandomFailureGenerator.RandomFail(
                failThreshold: Constants.FailureThresholds.ApplicationReceivingExternalImages, // Exception is thrown if a random value between 0 and 1 is greater or equal this value
                url: Request.ToString(),
                logger: _logger);

            _logger.LogInformation("Response received from the external image processor service for case number {caseNumber} and image {imageId}", caseNumber, imageId);

            var source = new MemoryStream(new byte[1024]);

            source.Write(Encoding.UTF8.GetBytes(request.Metadata));
            source.Position = 0;
            var attachment = await _bus.Advanced.DataBus.CreateAttachment(source);

            var message = new ImageProcessed
            {
                CaseNumber     = caseNumber,
                ImageId        = imageId,
                MetadataTicket = attachment.Id
            };

            await _bus.Send(message);

            return(Accepted());
        }
        public async Task <IActionResult> Notification([FromBody] NotificationModel model)
        {
            RandomFailureGenerator.RandomFail(
                failThreshold: Constants.FailureThresholds.ExternalNotificationsProcessing, // Exception is thrown if a random value between 0 and 1 is greater or equal this value
                url: Request.GetDisplayUrl(),
                logger: _logger);

            // Simulate some time to process
            await Task.Delay(2000);

            _logger.LogInformation("Received case completion notification. CaseNumber: {caseNumber} with result {result}", model.CaseNumber, model.Result);

            return(NoContent());
        }