Ejemplo n.º 1
0
        public async Task Handle(WeedDetectedMessage message, CancellationToken cancellationToken)
        {
            Console.WriteLine($"Weed detected:{message.FieldId} {message.OrganizationId} {message.Percentage} {message.Severity}");

            var field = await _fieldService.GetAsync(message.FieldId, message.OrganizationId);

            field.Status = message.Severity == DangerLevel.Low || message.Severity == DangerLevel.High
                ? FieldStatus.NeedAttention
                : FieldStatus.Critical;
            await _fieldService.UpdateAsync(field);

            var rec = await _recommendationService.GetWeedDetectedRecommendation(message);

            var weed = await _weedService.GetAsync(message.WeedId);

            _messageService.AddWeedDetectedMessage(new WeedDetectedMessageWithRecommendation()
            {
                FieldId        = message.FieldId,
                OrganisationId = message.OrganizationId,
                Recommendation = rec,
                Severity       = message.Severity,
                WeedName       = weed.Kind
            });
        }