Пример #1
0
        internal static void ReportFailure(
            Domain.EventHandlingError error,
            Func <DbContext> createDbContext)
        {
            // add an EventHandlingError entry as well
            EventHandlingError sqlError = CreateEventHandlingError((dynamic)error);

            var errorText = new
            {
                error.Exception,
                Event = sqlError.SerializedEvent
            }.ToJson();

            log.Write(() => errorText);

            using (var transaction = new TransactionScope(TransactionScopeOption.Suppress))
                using (var db = createDbContext())
                {
                    var dbSet = db.Set <ReadModelInfo>();

                    var handler = error.Handler;

                    string readModelInfoName = null;

                    if (handler != null)
                    {
                        // update the affected ReadModelInfo
                        readModelInfoName = ReadModelInfo.NameForProjector(handler);

                        var readModelInfo = dbSet.SingleOrDefault(i => i.Name == readModelInfoName);
                        if (readModelInfo == null)
                        {
                            readModelInfo = new ReadModelInfo {
                                Name = readModelInfoName
                            };
                            dbSet.Add(readModelInfo);
                        }

                        readModelInfo.Error           = errorText;
                        readModelInfo.FailedOnEventId = sqlError.OriginalId;
                    }

                    sqlError.Error   = error.Exception.ToJson();
                    sqlError.Handler = readModelInfoName;
                    db.Set <EventHandlingError>().Add(sqlError);

                    db.SaveChanges();
                    transaction.Complete();
                }
        }
Пример #2
0
        internal static void ReportFailure(
            Domain.EventHandlingError error,
            Func <DbContext> createDbContext)
        {
            // add an EventHandlingError entry as well
            EventHandlingError sqlError = CreateEventHandlingError((dynamic)error);

            log.Write(() => new { error.Exception, sqlError.SerializedEvent });

            using (var db = createDbContext())
            {
                var dbSet = db.Set <ReadModelInfo>();

                var handler = error.Handler;

                string readModelInfoName = null;

                var exceptionJson = error.Exception.ToDiagnosticJson();
                if (handler != null)
                {
                    // update the affected ReadModelInfo
                    readModelInfoName = ReadModelInfo.NameForProjector(handler);

                    var readModelInfo = dbSet.SingleOrDefault(i => i.Name == readModelInfoName);
                    if (readModelInfo == null)
                    {
                        readModelInfo = new ReadModelInfo {
                            Name = readModelInfoName
                        };
                        dbSet.Add(readModelInfo);
                    }

                    readModelInfo.LastError       = exceptionJson;
                    readModelInfo.FailedOnEventId = sqlError.EventId;
                }

                sqlError.Error   = $"{Environment.MachineName}:  {exceptionJson}";
                sqlError.Handler = readModelInfoName;
                db.Set <EventHandlingError>().Add(sqlError);

                db.SaveChanges();
            }
        }