Beispiel #1
0
 public static Task <IdentityResult> TryDeleteAsync <TPoco>(this IMapper mapper,
                                                            TPoco poco,
                                                            CqlQueryOptions queryOptions,
                                                            CassandraErrorDescriber errorDescriber,
                                                            ILogger logger)
 {
     return(TryExecuteAsync(() => mapper.DeleteAsync(poco, queryOptions: queryOptions), errorDescriber, logger));
 }
Beispiel #2
0
        public static Task <IdentityResult> TryExecuteBatchAsync(this IMapper mapper,
                                                                 CassandraErrorDescriber errorDescriber,
                                                                 ILogger logger,
                                                                 params Action <ICqlBatch>[] actions)
        {
            var batch = mapper.CreateBatch();

            foreach (var a in actions)
            {
                a(batch);
            }

            return(TryExecuteAsync(() => mapper.ExecuteAsync(batch), errorDescriber, logger));
        }
Beispiel #3
0
        private static async Task <IdentityResult> TryExecuteAsync(
            Func <Task> action,
            CassandraErrorDescriber errorDescriber,
            ILogger logger)
        {
            IdentityResult result;

            try
            {
                await action();

                result = IdentityResult.Success;
            }
            catch (Exception exception)
            {
                logger.LogError(exception, "Error while executing query.");

                var type = exception.GetType();
                switch (type)
                {
                case Type _ when type == typeof(NoHostAvailableException):
                    result = IdentityResult.Failed(errorDescriber.NoHostAvailable());
                    break;

                case Type _ when type == typeof(UnavailableException):
                    result = IdentityResult.Failed(errorDescriber.Unavailable());
                    break;

                case Type _ when type == typeof(ReadTimeoutException):
                    result = IdentityResult.Failed(errorDescriber.ReadTimeout());
                    break;

                case Type _ when type == typeof(WriteTimeoutException):
                    result = IdentityResult.Failed(errorDescriber.WriteTimeout());
                    break;

                case Type _ when type == typeof(QueryValidationException):
                    result = IdentityResult.Failed(errorDescriber.QueryValidation());
                    break;

                default:
                    result = IdentityResult.Failed(errorDescriber.DefaultError(exception.Message));
                    break;
                }
            }

            return(result);
        }