Ejemplo n.º 1
0
        private static FlowValues GetInitialFlowValues(FlowDefinition <TFlowRequest, TFlowResponse> flowDefinition,
                                                       TFlowRequest flowRequest)
        {
            var flowValues = new FlowValues();

            var flowRequestType       = typeof(TFlowRequest);
            var flowRequestProperties = flowRequestType.GetFlowObjectType();

            var missingMandatoryPropertyNames = new List <string>();

            foreach (var flowRequestProperty in flowRequestProperties.Properties)
            {
                var binding = flowDefinition.Initializer?.Outputs.Find(b => b.Property.Name == flowRequestProperty.Name);

                var requestValue = flowRequestProperty.PropertyInfo.GetValue(flowRequest);

                if (binding == null)
                {
                    flowValues.SetValue(flowRequestProperty.Name, requestValue);
                }
                else
                {
                    var outputValues = binding.GetOutputValues(requestValue, flowRequest);

                    foreach (var outputValueName in outputValues.Keys)
                    {
                        flowValues.SetValue(outputValueName, outputValues[outputValueName]);
                    }
                }

                CheckMandatoryFlowObjectProperty(flowRequest, flowRequestProperty, missingMandatoryPropertyNames);
            }

            if (missingMandatoryPropertyNames.Count > 0)
            {
                throw new FlowException(
                          $"The following mandatory properties were not populated on {flowRequestType.FullName}: " +
                          $"{string.Join(", ", missingMandatoryPropertyNames.ToArray())}");
            }

            return(flowValues);
        }
Ejemplo n.º 2
0
        private void SetFlowValuesFromResponse(FlowStepDefinition flowStepDefinition, FlowContext flowContext, FlowValues flowValues,
                                               object request, object response)
        {
            var responseFlowObjectType = response.GetType().GetFlowObjectType();

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

            foreach (var flowObjectProperty in responseFlowObjectType.Properties)
            {
                var responsePropertyValue = flowObjectProperty.PropertyInfo.GetValue(response);

                var outputBinding = flowStepDefinition.GetOutputBinding(flowObjectProperty);

                var outputValues = outputBinding.GetOutputValues(responsePropertyValue, request);

                foreach (var outputValue in outputValues)
                {
                    flowValues.SetValue(outputValue.Key, outputValue.Value);
                }
            }
        }