public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { try { if (context.Result is ObjectResult result) { var policies = GetFilteredPolicies(PolicyInMemoryRepository.LinksPolicyInMemory, result); if (policies.Any()) { var rawJson = JsonConvert.SerializeObject(result.Value, _jsonOptions.Value.SerializerSettings); foreach (var policy in policies) { if (policy != null) { var payload = JsonConvert.DeserializeObject(rawJson, policy.Type); var lambdaResult = GetLambdaResult(policy.Expression, payload, policy.Type); await _resultProvider.AddPolicyAsync(policy, lambdaResult).ConfigureAwait(false); } } context.Result = await _resultProvider.GetContentResultAsync(rawJson).ConfigureAwait(false); } } } catch (Exception ex) { Console.WriteLine(ex); // TODO : Log exception } await base.OnResultExecutionAsync(context, next).ConfigureAwait(false); }
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { var resultAction = await next(); if (_resultProvider.HasAnyValidCondition(resultAction.Result, out ObjectResult result)) { var finalResult = await _resultProvider.GetContentResultAsync(result, context).ConfigureAwait(false); if (finalResult != null) { await finalResult.ExecuteResultAsync(context).ConfigureAwait(false); } } }
public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { try { if (_resultProvider.HasAnyPolicy(context.Result, out ObjectResult result)) { var finalResult = await _resultProvider.GetContentResultAsync(result).ConfigureAwait(false); if (finalResult != null) { context.Result = finalResult; } } } catch (Exception ex) { _logger.LogWarning(ex, "Something went wrong while processing link generation."); } await base.OnResultExecutionAsync(context, next).ConfigureAwait(false); }