internal static async Task RunAuditHooks <TEntity>(this ICrudlessRequest request,
                                                           IRequestConfig config,
                                                           IServiceProvider provider,
                                                           TEntity oldEntity,
                                                           TEntity newEntity,
                                                           CancellationToken ct)
            where TEntity : class
        {
            var hooks = config.GetAuditHooksFor <TEntity>(provider);

            foreach (var hook in hooks)
            {
                try
                {
                    await hook.Run(request, oldEntity, newEntity, ct).Configure();

                    ct.ThrowIfCancellationRequested();
                }
                catch (Exception e) when(IsNonCancellationFailure(e))
                {
                    throw new HookFailedException(GenericHookError("audit"), e)
                          {
                              HookProperty = hook
                          };
                }
            }
        }
예제 #2
0
        internal static async Task <T> RunResultHooks <T>(this ICrudlessRequest request,
                                                          IRequestConfig config,
                                                          IServiceProvider provider,
                                                          T result,
                                                          CancellationToken ct)
        {
            var hooks = config.GetResultHooks(provider);

            foreach (var hook in hooks)
            {
                try
                {
                    if (typeof(T).IsAssignableFrom(hook.ResultType))
                    {
                        result = (T)await hook.Run(request, result, ct).Configure();
                    }
                    else
                    {
                        result = await ResultHookAdapter.Adapt(hook, request, result, ct).Configure();
                    }

                    ct.ThrowIfCancellationRequested();
                }
                catch (Exception e) when(IsNonCancellationFailure(e))
                {
                    throw new HookFailedException(GenericHookError("result"), e)
                          {
                              HookProperty = hook
                          };
                }
            }

            return(result);
        }
예제 #3
0
        internal static async Task RunEntityHooks <TEntity>(this ICrudlessRequest request,
                                                            IRequestConfig config,
                                                            IServiceProvider provider,
                                                            IEnumerable <object> entities,
                                                            CancellationToken ct)
            where TEntity : class
        {
            var hooks = config.GetEntityHooksFor <TEntity>(provider);

            foreach (var entity in entities)
            {
                foreach (var hook in hooks)
                {
                    try
                    {
                        await hook.Run(request, entity, ct).Configure();

                        ct.ThrowIfCancellationRequested();
                    }
                    catch (Exception e) when(IsNonCancellationFailure(e))
                    {
                        throw new HookFailedException(GenericHookError("entity"), e)
                              {
                                  HookProperty = hook
                              };
                    }
                }
            }
        }
예제 #4
0
        internal static async Task RunRequestHooks(this ICrudlessRequest request,
                                                   IRequestConfig config,
                                                   IServiceProvider provider,
                                                   CancellationToken ct)
        {
            var hooks = config.GetRequestHooks(provider);

            foreach (var hook in hooks)
            {
                try
                {
                    await hook.Run(request, ct).Configure();

                    ct.ThrowIfCancellationRequested();
                }
                catch (Exception e) when(IsNonCancellationFailure(e))
                {
                    throw new HookFailedException(GenericHookError("request"), e)
                          {
                              HookProperty = hook
                          };
                }
            }
        }
 internal static async Task RunAuditHooks <TEntity>(this ICrudlessRequest request,
                                                    IRequestConfig config,
                                                    IServiceProvider provider,
                                                    IEnumerable <(TEntity, TEntity)> entities,