Esempio n. 1
0
        private async Task <IActionResult> AddInputArgument(Guid id, string input, bool isLeftArgument)
        {
            byte[] inputArray = Base64Helper.ConvertBase64String(input);

            if (id == Guid.Empty || inputArray == null)
            {
                return(BadRequest());
            }

            var message = new AddDiffInputMessage {
                Id = id, Input = inputArray, IsLeft = isLeftArgument
            };

            await _serviceBus.PublishAsync(message);

            var uri = Url.RouteUrl("GetDiffResult", new { id });

            return(Accepted(uri));
        }
Esempio n. 2
0
        private async Task HandleIngestionInput(AddDiffInputMessage input)
        {
            _logger.LogInformation($"Processing Input: {input.Id}");

            using (var scope = _scopeFactory.CreateScope())
            {
                var analysisRepo = scope.ServiceProvider.GetRequiredService <IDiffAnalysisRepository>();
                //var mapper = scope.ServiceProvider.GetRequiredService<IMapper>();

                var analysis = await analysisRepo.GetAnalysis(input.Id);

                var persistChanges = false;

                //If analysis doesnt exists in the DB
                if (analysis == null)
                {
                    _logger.LogInformation($"Analysis Not Found: {input.Id}");

                    analysis = new DiffAnalysis()
                    {
                        Id = input.Id
                    };
                    analysisRepo.Add(analysis);
                    persistChanges = true;
                }

                // if analysis already analyzed we discard the input
                if (analysis.Analyzed)
                {
                    _logger.LogInformation($"Analysis already analyzed: {input.Id}. Discarding...");
                    return;
                }

                // If input is left argument and doesnt already exist
                if (input.IsLeft && analysis.Left == null)
                {
                    _logger.LogInformation($"Persisting Left Argument: {input.Id}");

                    analysis.Left  = input.Input;
                    persistChanges = true;
                }

                // If input is right argument and doesnt already exist
                if (!input.IsLeft && analysis.Right == null)
                {
                    _logger.LogInformation($"Persisting Right Argument: {input.Id}");

                    analysis.Right = input.Input;
                    persistChanges = true;
                }

                if (persistChanges)
                {
                    await analysisRepo.SaveAll();
                }

                // if we have both left and right arguments we publish a perform Diff Analysis message
                if (analysis.Left != null && analysis.Right != null)
                {
                    _logger.LogInformation($"Analysis ready to be analyzed: {input.Id}. Publishing PerformDiffAnalysisMessage to bus.");

                    var message = new PerformDiffAnalysisMessage(analysis.Id);
                    await _serviceBus.PublishAsync(message);
                }
            }
        }