Exemplo n.º 1
0
        private static void ValidateFlowObjectValues(object flowObject, FlowObjectType flowObjectType, string stepName)
        {
            var missingMandatoryPropertyNames = GetMissingMandatoryPropertyNames(flowObject, flowObjectType);

            if (missingMandatoryPropertyNames.Count > 0)
            {
                throw new FlowException(
                          "The following mandatory properties were not populated on the " +
                          $"{(flowObject is IFlowStepRequest ? "request" : "response")} for step {stepName}: " +
                          $"{string.Join(", ", missingMandatoryPropertyNames.ToArray())}");
            }
        }
Exemplo n.º 2
0
        public static FlowObjectType GetFlowObjectType(this Type type)
        {
            lock (CacheLock)
            {
                if (Cache.TryGetValue(type, out var flowObjectProperties))
                {
                    return(flowObjectProperties);
                }

                var newFlowObjectProperties = new FlowObjectType(type);
                Cache.Add(type, newFlowObjectProperties);
                return(newFlowObjectProperties);
            }
        }
Exemplo n.º 3
0
        private static void PopulateRequestBoundValues(IFlowStepRequest request, FlowObjectType requestType, FlowStep flowStep,
                                                       FlowValues flowValues, ISet <string> setPropertyNames)
        {
            var boundProperties = requestType.Properties.Where(p => !setPropertyNames.Contains(p.Name));

            foreach (var boundProperty in boundProperties)
            {
                var inputBinding = flowStep.Definition.GetInputBinding(boundProperty);

                if (inputBinding.TryGetRequestValue(flowValues, request, out var requestValue))
                {
                    boundProperty.PropertyInfo.SetValue(request, requestValue);
                }
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        private static List <string> GetMissingMandatoryPropertyNames(object flowObject, FlowObjectType flowObjectType)
        {
            var missingMandatoryPropertyNames = new List <string>();

            foreach (var flowObjectProperty in flowObjectType.Properties)
            {
                CheckMandatoryFlowObjectProperty(flowObject, flowObjectProperty, missingMandatoryPropertyNames);
            }

            return(missingMandatoryPropertyNames);
        }