Beispiel #1
0
        public bool HandleMessage(string message)
        {
            try
            {
                _logger.Info($"Message received '{message}'");

                var model = _mapper.MapToModel(message);

                if (model.IsSpecificCase)
                {
                    _completeCaseService.CompleteCase(model);
                }
                else
                {
                    _autoCompleteCasesService.CompleteCases(model);
                }

                //assuming we have completed case(s) we want to trigger the case monitor system
                TriggerCaseMonitor();

                _logger.Info($"Message processed '{message}'");

                return(true);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                _logger.Info($"Error processing message '{message}'");

                return(false);
            }
        }
        public void CompleteCases(AutoCompleteCaseModel model)
        {
            model.InstrumentName.ThrowExceptionIfNullOrEmpty("InstrumentName");
            model.NumberOfCases.ThrowExceptionIfLessThanOrEqualToZero("NumberOfCases");

            var caseCompletedCounter = 0;

            if (!_blaiseApi
                .WithInstrument(model.InstrumentName)
                .WithServerPark(model.ServerPark)
                .WithConnection(_blaiseApi.DefaultConnection)
                .Survey
                .Exists)
            {
                _logger.Warn($"The survey '{model.InstrumentName}' does not exist on server park '{model.ServerPark}'");
                return;
            }

            _logger.Info($"Getting cases for survey '{model.InstrumentName}' on server park '{model.ServerPark}'");
            var dataSet = GetCases(model);

            while (!dataSet.EndOfSet)
            {
                if (model.NumberOfCases == caseCompletedCounter)
                {
                    break;
                }

                if (!CaseIsComplete(dataSet.ActiveRecord))
                {
                    _completeCaseService.CompleteCase(dataSet.ActiveRecord, model);

                    caseCompletedCounter++;
                }
                dataSet.MoveNext();
            }

            _logger.Info(caseCompletedCounter == 0
                ? "No Cases Found to Complete"
                : $"Completed {caseCompletedCounter} cases");
        }