Пример #1
0
        private async Task <dynamic> GetActivityResponse(FlowContext stepFlowContext, FlowStep flowStep,
                                                         IFlowStepRequest activityRequest, CancellationToken cancellationToken)
        {
            var mockHandler =
                stepFlowContext.GetMockActivityHandler(
                    flowStep.Definition.RequestType, flowStep.Name);

            dynamic activityResponse;

            if (mockHandler == null)
            {
                var mediatorSendGeneric = _mediatorSend.MakeGenericMethod(flowStep.Definition.ResponseType);

                activityResponse =
                    await(dynamic) mediatorSendGeneric.Invoke(_mediator, new object[] { activityRequest, cancellationToken });
            }
            else
            {
                _logger?.LogMockRequestHandler(stepFlowContext, flowStep);

                activityResponse = mockHandler(activityRequest);
            }

            return(activityResponse);
        }
Пример #2
0
 public override IEnumerable <Tuple <string, string> > GetSummaries(IFlowStepRequest request)
 {
     return(new[]
     {
         new Tuple <string, string>($"Is({this.TargetType.Name})", this.MapName == null ? null : "Func(Name)"),
     });
 }
Пример #3
0
        public override string GetSummary(IFlowStepRequest request)
        {
            if (this.Property.IsDictionaryBinding)
            {
                var selectorSummaries = this.FlowValueSelector.GetSummaries(request);

                var summaries = new List <string>();

                foreach (var(sourceName, targetName) in selectorSummaries)
                {
                    var dictionaryValue = $"{this.Property.Name}[{sourceName}]";
                    var sourceValue     = this.MapValue == null ? dictionaryValue : $"Func({dictionaryValue})";
                    var summary         = targetName == null ? $"{sourceName}: {sourceValue}" : $"{targetName}: {sourceValue}";
                    summaries.Add(summary);
                }

                return($"{{ {string.Join(", ", summaries)} }}");
            }
            else
            {
                var flowValue     = this.MapName == null ? this.Property.Name : this.MapName(null, request);
                var responseValue = this.MapValue == null ? this.Property.Name : $"Func({this.Property.Name})";
                return($"{flowValue}: {responseValue}");
            }
        }
Пример #4
0
        public override IEnumerable <Tuple <string, string> > GetSummaries(IFlowStepRequest request)
        {
            var property = request.GetType().GetProperty(_propertyName);

            var name = (string)property?.GetValue(request);

            return(new[] { new Tuple <string, string>(name, null), });
        }
Пример #5
0
        public void LogFlowException(FlowContext flowContext, IFlowStepRequest flowRequest, Exception ex)
        {
            _logger.LogError(flowContext, ex,
                             "{ExceptionTypeName} occurred handling {RequestTypeName}({RequestSummary})",
                             ex.GetType().Name, flowRequest.GetType().Name, _logger?.EvalIfError(() => GetPublicPropertySummary(flowRequest)));

            _logger.LogError("{ExceptionType}: {ExceptionMessage}", ex.GetType().Name, ex.Message);
            _logger.LogError("{ExceptionStackTrace}", ex.StackTrace);
        }
Пример #6
0
        private static string GetFlowDiagramNodeText(FlowStep flowStep, IFlowStepRequest flowStepRequest)
        {
            var diagramNodeText =
                flowStep.Text
                ?? flowStepRequest.GetText()
                ?? flowStep.Name + ((flowStep is DecisionFlowStepBase) ? "?" : null);

            return(diagramNodeText);
        }
Пример #7
0
        public override IEnumerable <Tuple <string, string> > GetSummaries(IFlowStepRequest request)
        {
            var summaries = new List <Tuple <string, string> >();

            summaries.AddRange(this.MapName == null
                ? _names.Select(n => new Tuple <string, string>(n, null))
                : _nameMap.Select(nm => new Tuple <string, string>(nm.Key, nm.Value)));

            return(summaries);
        }
Пример #8
0
        private void SetFlowDiagramNodeInputSummaries(FlowStep flowStep, IFlowStepRequest request, FlowDiagramNode node)
        {
            var setInputs      = new Dictionary <string, string>();
            var boundInputs    = new Dictionary <string, string>();
            var inputOverrides = new Dictionary <string, IList <FlowInputOverride> >();

            var requestType = request.GetType().GetFlowObjectType();

            foreach (var requestProperty in requestType.Properties)
            {
                var isSetInput = flowStep.Definition.Setters.Any(s => s.Item1.Name == requestProperty.Name);

                if (isSetInput)
                {
                    setInputs[requestProperty.PropertyInfo.Name] = requestProperty.PropertyInfo.GetValue(request)?.ToString();
                }
                else
                {
                    var binding = flowStep.Definition.GetInputBinding(requestProperty);
                    var summary = binding.GetSummary(request);

                    boundInputs[requestProperty.PropertyInfo.Name] = summary;
                }
            }

            if (!string.IsNullOrEmpty(flowStep.OverrideKey?.Value))
            {
                var flowRequestOverrides = _overrideProvider?.GetRequestOverrides(flowStep.OverrideKey?.Value);

                if (flowRequestOverrides != null)
                {
                    foreach (var flowRequestOverride in flowRequestOverrides)
                    {
                        var inputOverride = new FlowInputOverride
                        {
                            Value    = flowRequestOverride.Value?.ToString(),
                            Criteria = flowRequestOverride.Criteria
                        };

                        if (inputOverrides.TryGetValue(flowRequestOverride.Name, out var propertyInputOverrides))
                        {
                            propertyInputOverrides.Add(inputOverride);
                        }
                        else
                        {
                            inputOverrides.Add(flowRequestOverride.Name, new List <FlowInputOverride>(new[] { inputOverride }));
                        }
                    }
                }
            }

            node.InputSetters   = setInputs;
            node.InputBindings  = boundInputs;
            node.InputOverrides = inputOverrides;
        }
Пример #9
0
            public override IDictionary <string, FlowRequestOverride> GetApplicableRequestOverrides(
                IList <FlowRequestOverride> overrides, IFlowStepRequest request)
            {
                var clientId  = _clientSettings.ClientId;
                var flowValue = (request is ITestOverrideContext context) ? context.FlowValue : null;

                var applicableOverrides =
                    overrides.GroupBy(o => o.Name)
                    .Select(og => GetApplicableRequestOverride(og.ToList(), clientId, flowValue));

                return(applicableOverrides.ToDictionary(o => o.Name));
            }
Пример #10
0
        private static ISet <string> PopulateRequestSetValues(FlowStep flowStep, IFlowStepRequest request)
        {
            var setPropertyNames = new HashSet <string>();

            foreach (var(requestPropertyInfo, requestPropertyValue) in flowStep.Definition.Setters)
            {
                requestPropertyInfo.SetValue(request, requestPropertyValue);

                setPropertyNames.Add(requestPropertyInfo.Name);
            }

            return(setPropertyNames);
        }
Пример #11
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);
                }
            }
        }
Пример #12
0
        private static bool IsRequestDisabled(IFlowStepRequest flowStepRequest)
        {
            bool isRequestSkipped;

            switch (flowStepRequest)
            {
            case IFlowStepEnableable enableableStep when !enableableStep.IsEnabled:
            case IFlowStepDisableable disableableStep when disableableStep.IsDisabled:
                isRequestSkipped = true;
                break;

            default:
                isRequestSkipped = false;
                break;
            }

            return(isRequestSkipped);
        }
Пример #13
0
        private bool LogFlowError(FlowContext flowContext, IFlowStepRequest flowRequest, Exception ex)
        {
            if (!flowContext.IsRootFlow)
            {
                return(true);
            }

            _logger?.LogFlowException(flowContext, flowRequest, ex);

            var innerEx = ex.InnerException;

            while (innerEx != null)
            {
                _logger?.LogFlowInnerException(flowContext, innerEx);
                innerEx = innerEx.InnerException;
            }

            return(true);
        }
Пример #14
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);
        }
Пример #15
0
        public override string GetSummary(IFlowStepRequest request)
        {
            var selectorSummaries = this.FlowValueSelector.GetSummaries(request);

            if (this.Property.IsDictionaryBinding)
            {
                var summaries = new List <string>();

                foreach (var(sourceName, targetName) in selectorSummaries)
                {
                    var sourceValue = this.MapValue == null ? sourceName : $"Func({sourceName})";
                    var summary     = targetName == null ? sourceValue : $"{targetName}: {sourceValue}";
                    summaries.Add(summary);
                }

                return($"{{ {string.Join(", ", summaries)} }}");
            }
            else
            {
                var flowValue    = selectorSummaries.First().Item1;
                var requestValue = this.MapValue == null ? flowValue : $"Func({flowValue})";
                return(requestValue);
            }
        }
Пример #16
0
 public override IEnumerable <Tuple <string, string> > GetSummaries(IFlowStepRequest request)
 {
     return(this.MapName == null
         ? new[] { new Tuple <string, string>($"Match({_namePattern})", null), }
         : new[] { new Tuple <string, string>($"Match({_namePattern})", "Func(Name)"), });
 }
Пример #17
0
 public abstract IEnumerable <Tuple <string, string> > GetSummaries(IFlowStepRequest request);
Пример #18
0
 public virtual IDictionary <string, FlowRequestOverride> GetApplicableRequestOverrides(IList <FlowRequestOverride> overrides, IFlowStepRequest request)
 {
     return(null);
 }
Пример #19
0
 public void LogFlowRequest(FlowContext flowContext, IFlowStepRequest flowRequest)
 {
     _logger.LogDebug(flowContext, "Request({RequestSummary})",
                      _logger.EvalIfDebug(() => GetPublicPropertySummary(flowRequest)));
 }
Пример #20
0
 public abstract string GetSummary(IFlowStepRequest request);
Пример #21
0
            public override IFlowDefinition GetApplicableFlowDefinitionOverride(IList <IFlowDefinition> overrides, IFlowStepRequest request)
            {
                switch (overrides?.Count)
                {
                case 0:
                    return(null);

                case 1 when string.IsNullOrEmpty(overrides.First().Criteria):
                    return(overrides.First());
                }

                var flowValue = (request is ITestOverrideContext context) ? context.FlowValue : null;

                var matchingOverride = overrides?.Where(o => o.Criteria == $"FlowValue={flowValue}").FirstOrDefault();

                return(matchingOverride ?? overrides?.Where(o => string.IsNullOrEmpty(o.Criteria)).FirstOrDefault());
            }
Пример #22
0
 public override IFlowDefinition GetApplicableFlowDefinitionOverride(IList <IFlowDefinition> overrides, IFlowStepRequest request)
 {
     return(overrides?.First());
 }
Пример #23
0
 public override IDictionary <string, FlowRequestOverride> GetApplicableRequestOverrides(
     IList <FlowRequestOverride> overrides, IFlowStepRequest request)
 {
     return(overrides.ToDictionary(@override => @override.Name));
 }
Пример #24
0
 public virtual IFlowDefinition GetApplicableFlowDefinitionOverride(IList <IFlowDefinition> overrides, IFlowStepRequest request)
 {
     return(null);
 }
Пример #25
0
 public void LogFlowOverride(FlowContext flowContext, IFlowStepRequest flowRequest, string criteria)
 {
     _logger.LogDebug(flowContext, "Flow definition for {FlowRequestTypeName} overridden for criteria '{Criteria}'",
                      _logger.EvalIfDebug(() => flowRequest.GetType().Name),
                      criteria);
 }
Пример #26
0
 public void LogActivityRequest(FlowContext flowContext, IFlowStepRequest activityRequest)
 {
     _logger.LogDebug(flowContext, "{ActivityRequestTypeName}({ActivityRequestSummary})",
                      _logger.EvalIfDebug(() => activityRequest.GetType().Name),
                      _logger.EvalIfDebug(() => GetPublicPropertySummary(activityRequest)));
 }
Пример #27
0
        private static Dictionary <string, string> GetBoundOutputSummary(FlowStep flowStep, IFlowStepRequest request)
        {
            var responseType = flowStep.Definition.ResponseType.GetFlowObjectType();

            var boundOutputs = new Dictionary <string, string>();

            foreach (var responseProperty in responseType.Properties)
            {
                var binding = flowStep.Definition.GetOutputBinding(responseProperty);
                var summary = binding.GetSummary(request);

                boundOutputs[responseProperty.PropertyInfo.Name] = summary;
            }

            return(boundOutputs);
        }
Пример #28
0
 public void LogDecisionRequest(FlowContext flowContext, IFlowStepRequest decisionRequest)
 {
     _logger.LogDebug(flowContext, "{DecisionRequestTypeName}({DecisionRequestSummary})",
                      _logger.EvalIfDebug(() => decisionRequest.GetType().Name),
                      _logger.EvalIfDebug(() => GetPublicPropertySummary(decisionRequest)));
 }
Пример #29
0
 public void LogRequestOverrides(FlowContext flowContext, IFlowStepRequest request, List <Tuple <string, object, string> > overrides)
 {
     _logger.LogDebug(flowContext, "{RequestTypeName} overridden as {OverrideSummary}",
                      request.GetType().Name, _logger?.EvalIfDebug(() => GetRequestOverrideSummary(overrides)));
 }
Пример #30
0
 public override IEnumerable <Tuple <string, string> > GetSummaries(IFlowStepRequest request)
 {
     return(new[] { new Tuple <string, string>(_name, null), });
 }