Beispiel #1
0
        public void Postprocess(DbDataReader reader, IList <Exception> exceptions)
        {
            if (reader.RecordsAffected != 0)
            {
                return;
            }

            var ex = new EventStreamUnexpectedMaxEventIdException(Stream.Key ?? (object)Stream.Id, Stream.AggregateType, Stream.ExpectedVersionOnServer.Value, -1);

            exceptions.Add(ex);
        }
Beispiel #2
0
        public bool TryTransform(Exception original, out Exception transformed)
        {
            if (!Matches(original))
            {
                transformed = null;
                return(false);
            }

            var postgresException = (PostgresException)original.InnerException;

            object id            = null;
            Type   aggregateType = null;
            int    expected      = -1;
            int    actual        = -1;

            if (!string.IsNullOrEmpty(postgresException.Detail))
            {
                var details = EventStreamUniqueExceptionDetailsRegex.Match(postgresException.Detail);

                if (details.Groups[StreamId].Success)
                {
                    var streamId = details.Groups[StreamId].Value;

                    id = Guid.TryParse(streamId, out Guid guidStreamId) ? (object)guidStreamId : streamId;
                }

                if (details.Groups[Version].Success)
                {
                    var actualVersion = details.Groups[Version].Value;

                    if (int.TryParse(actualVersion, out int actualIntVersion))
                    {
                        actual   = actualIntVersion;
                        expected = actual - 1;
                    }
                }
            }

            transformed = new EventStreamUnexpectedMaxEventIdException(id, aggregateType, expected, actual);
            return(true);
        }