Example #1
0
            public async Task <IEnumerable <ParameterResource> > Handle(GetAllParametersForScriptQuery request, CancellationToken cancellationToken)
            {
                var parameters = await _parameterRepository.GetAllParametersForScriptAsync(request.ScriptId);

                var defaultLanguage = await _scriptRepository.GetDefaultLanguageForScriptAsync(request.ScriptId);

                var parametersResources = _mapper.Map <IEnumerable <Parameter>, IEnumerable <ParameterResource> >(parameters);
                await _translationService.SetParametersTranslation(request.Language, parametersResources, defaultLanguage);

                return(parametersResources);
            }
        private IEnumerable <IParameter> GetParameters(SI.Script scriptData, IParameterRepository parameterRepository)
        {
            var parametersData = parameterRepository.GetAllParametersForScriptAsync(scriptData.Id).Result;

            foreach (var parameter in parametersData)
            {
                yield return(new SIP.Parameter()
                {
                    Number = parameter.Number,
                    Name = parameter.Name,
                    Value = parameter.Value,
                    VisibilityValidator = parameter.VisibilityValidator,
                    Context = (SIP.ParameterOptions)parameter.Context
                });
            }
        }
Example #3
0
            public async Task <IEnumerable <ParameterResource> > Handle(CalculateCommand request, CancellationToken cancellationToken)
            {
                var script = await _scriptRepository.GetAsync(request.ScriptId);

                var parameters = await _parameterRepository.GetAllParametersForScriptAsync(request.ScriptId);

                var equations = new Dictionary <long, string>(parameters.ToDictionary(p => p.Id, p => p.Value));

                var scriptCalculator = new ScriptCalculator(script, parameters.ToList());

                await scriptCalculator.CalculateAsync(request.InputData.Where(v => v.Value != null));

                var calculatedParameters = _mapper.Map <List <Parameter>, List <ParameterResource> >(scriptCalculator.GetResult().ToList());

                calculatedParameters.ForEach(cp => cp.Equation = equations.SingleOrDefault(p => p.Key == cp.Id).Value);

                await _translationService.SetParametersTranslation(request.LanguageCode, calculatedParameters, script.DefaultLanguage);

                return(calculatedParameters);
            }