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); }
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)"), }); }
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}"); } }
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), }); }
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); }
private static string GetFlowDiagramNodeText(FlowStep flowStep, IFlowStepRequest flowStepRequest) { var diagramNodeText = flowStep.Text ?? flowStepRequest.GetText() ?? flowStep.Name + ((flowStep is DecisionFlowStepBase) ? "?" : null); return(diagramNodeText); }
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); }
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; }
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)); }
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); }
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); } } }
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); }
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); }
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); }
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); } }
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)"), }); }
public abstract IEnumerable <Tuple <string, string> > GetSummaries(IFlowStepRequest request);
public virtual IDictionary <string, FlowRequestOverride> GetApplicableRequestOverrides(IList <FlowRequestOverride> overrides, IFlowStepRequest request) { return(null); }
public void LogFlowRequest(FlowContext flowContext, IFlowStepRequest flowRequest) { _logger.LogDebug(flowContext, "Request({RequestSummary})", _logger.EvalIfDebug(() => GetPublicPropertySummary(flowRequest))); }
public abstract string GetSummary(IFlowStepRequest request);
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()); }
public override IFlowDefinition GetApplicableFlowDefinitionOverride(IList <IFlowDefinition> overrides, IFlowStepRequest request) { return(overrides?.First()); }
public override IDictionary <string, FlowRequestOverride> GetApplicableRequestOverrides( IList <FlowRequestOverride> overrides, IFlowStepRequest request) { return(overrides.ToDictionary(@override => @override.Name)); }
public virtual IFlowDefinition GetApplicableFlowDefinitionOverride(IList <IFlowDefinition> overrides, IFlowStepRequest request) { return(null); }
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); }
public void LogActivityRequest(FlowContext flowContext, IFlowStepRequest activityRequest) { _logger.LogDebug(flowContext, "{ActivityRequestTypeName}({ActivityRequestSummary})", _logger.EvalIfDebug(() => activityRequest.GetType().Name), _logger.EvalIfDebug(() => GetPublicPropertySummary(activityRequest))); }
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); }
public void LogDecisionRequest(FlowContext flowContext, IFlowStepRequest decisionRequest) { _logger.LogDebug(flowContext, "{DecisionRequestTypeName}({DecisionRequestSummary})", _logger.EvalIfDebug(() => decisionRequest.GetType().Name), _logger.EvalIfDebug(() => GetPublicPropertySummary(decisionRequest))); }
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))); }
public override IEnumerable <Tuple <string, string> > GetSummaries(IFlowStepRequest request) { return(new[] { new Tuple <string, string>(_name, null), }); }