Exemple #1
0
        private void PopulateRequestOverriddenValues(FlowContext flowContext, IFlowStepRequest request,
                                                     FlowObjectType requestType, FlowStep flowStep)
        {
            var overrideKey = flowStep.OverrideKey?.Value;

            if ((_overrideProvider == null) || string.IsNullOrEmpty(overrideKey))
            {
                return;
            }

            var requestOverrides           = _overrideProvider?.GetRequestOverrides(overrideKey)?.ToList();
            var applicableRequestOverrides =
                _overrideProvider?.GetApplicableRequestOverrides(requestOverrides, request);

            if (!(applicableRequestOverrides?.Count > 0))
            {
                return;
            }

            var overridableProperties = requestType.Properties.Where(p => p.IsOverridableValue);

            var overrides = new List <Tuple <string, object, string> >();

            foreach (var overridableProperty in overridableProperties)
            {
                var overridablePropertyName = overridableProperty.PropertyInfo.Name;

                if (!applicableRequestOverrides.TryGetValue(overridablePropertyName, out var overriddenValue))
                {
                    continue;
                }

                // TODO: Should we allow for type converters here?
                overridableProperty.PropertyInfo.SetValue(request, overriddenValue.Value);

                overrides.Add(
                    new Tuple <string, object, string>(
                        overridablePropertyName, overriddenValue.Value, overriddenValue.Criteria));
            }

            _logger?.LogRequestOverrides(flowContext, request, overrides);
        }