public static void Analyze(Exception exception, IStorageResultBuilder storageResultBuilder) { if (storageResultBuilder != null) { if (exception is SqlException sqlException) { AnalyzeSqlException(sqlException, storageResultBuilder); } } }
public static void Analyze(Exception exception, IStorageResultBuilder storageResultBuilder /*, List<FieldMessage> fieldsErrors, string entityName,*/ /*Action<Exception> analyzeInnerException*/) { if (exception is DbUpdateConcurrencyException dbUpdateConcurrencyException) { AnalyzeDbUpdateConcurrencyException(dbUpdateConcurrencyException, storageResultBuilder /*fieldsErrors*/); } //else if (exception is DbUpdateException dbUpdateException && dbUpdateException.InnerException!=null) // analyzeInnerException(dbUpdateException.InnerException); else if (exception is InvalidOperationException invalidOperationException) { AnalyzeInvalidOperationException(invalidOperationException, storageResultBuilder /* fieldsErrors, entityName*/); } }
public static void Analyze(Exception exception, IStorageResultBuilder erorrBuilder) { if (exception is DbEntityValidationException dbEntityValidationException) { AnalyzeDbEntityValidationException(dbEntityValidationException, erorrBuilder); } if (exception is DbUpdateConcurrencyException dbUpdateConcurrencyException) { AnalyzeDbUpdateConcurrencyException(dbUpdateConcurrencyException, erorrBuilder); } if (exception is InvalidOperationException invalidOperationException) { AnalyzeInvalidOperationException(invalidOperationException, erorrBuilder); } }
// just proxy which role is stop DashboardCode.Routines.Storage.EfCore reference propogation to the DashboardCode.AdminkaV1.Injected project public static void Analyze(Exception exception, IStorageResultBuilder storageResultBuilder) => Ef6Manager.Analyze(exception, storageResultBuilder);
public static void AnalyzeSqlException(this SqlException exception, IStorageResultBuilder errorBuilder) { var message = exception.Message; { var matchCollection = fieldLengthRegex.Matches(message); if (matchCollection.Count > 0) { errorBuilder.AddTruncationError(null); return; } }; { var matchCollection = fieldPkConstraintRegex.Matches(message); if (matchCollection.Count > 0) { var constraint = matchCollection[0].Groups["constraint"].Value; var table = matchCollection[0].Groups["table"].Value; errorBuilder.AddPkDuplicateError(constraint, table); return; } } { var matchCollection = fieldRequiredRegex.Matches(message); if (matchCollection.Count > 0) { var column = matchCollection[0].Groups["column"].Value; var table = matchCollection[0].Groups["table"].Value; errorBuilder.AddNullError(column, table); return; } } if (message.Contains("Violation of PRIMARY KEY constraint")) { errorBuilder.AddPkDuplicateError(null); } { var matchCollection = fieldUniqueIndexRegex.Matches(message); if (matchCollection.Count > 0) { var index = matchCollection[0].Groups["index"].Value; var table = matchCollection[0].Groups["table"].Value; errorBuilder.AddUniqueIndexViolations(index, table); return; } } { var matchCollection = fieldUniqueConstraintRegex.Matches(message); if (matchCollection.Count > 0) { var constraint = matchCollection[0].Groups["constraint"].Value; var table = matchCollection[0].Groups["table"].Value; var value = matchCollection[0].Groups["value"].Value; errorBuilder.AddUniqueConstraintViolations(constraint, table, value); return; } } { var matchCollection = fieldCkRegex.Matches(message); if (matchCollection.Count > 0) { var constraint = matchCollection[0].Groups["constraint"].Value; var table = matchCollection[0].Groups["table"].Value; var statementType = matchCollection[0].Groups["statementType"].Value; var database = matchCollection[0].Groups["database"].Value; var column = matchCollection[0].Groups["column"].Value; errorBuilder.AddCheckConstraintViolations(constraint, table); } } }
public static void AnalyzeDbUpdateConcurrencyException(DbUpdateConcurrencyException exception, IStorageResultBuilder storageResultBuilder /*List<FieldMessage> fieldsErrors*/) { foreach (var e in exception.Entries) { storageResultBuilder.AddConcurrencyError(e.Entity.GetType().Name); } }
public static void AnalyzeInvalidOperationException(InvalidOperationException ex, IStorageResultBuilder storageResultBuilder /*List<FieldMessage> fieldsErrors, string entityName*/) { { var matchCollectionV1 = fieldPkOrUniqueConstraintNullRegexV1.Matches(ex.Message); if (matchCollectionV1.Count > 0) { var entity = matchCollectionV1[0].Groups["entity"].Value; storageResultBuilder.AddNullPrimaryOrAlternateKey(entity); return; } } { var matchCollectionV2 = fieldPkOrUniqueConstraintNullRegexV2.Matches(ex.Message); if (matchCollectionV2.Count > 0) { if (ex.Message.Contains("If the alternate key is not used in a relationship, then consider using a unique index instead.")) { var entity = matchCollectionV2[0].Groups["entity"].Value; var field = matchCollectionV2[0].Groups["field"].Value; storageResultBuilder.AddNullPrimaryOrAlternateKey(entity, field); } return; } } }
public static void AnalyzeDbUpdateConcurrencyException(DbUpdateConcurrencyException exception, IStorageResultBuilder erorrBuilder) { foreach (var e in exception.Entries) { erorrBuilder.AddConcurrencyError(e.Entity.GetType().Name); } }
public static void AnalyzeDbEntityValidationException(DbEntityValidationException ex, IStorageResultBuilder erorrBuilder) { foreach (var eve in ex.EntityValidationErrors) { foreach (var ve in eve.ValidationErrors) { erorrBuilder.AddValidation(eve.Entry.Entity.GetType().Name, ve.PropertyName, ve.ErrorMessage); } //if (matchCollectionV1.Count > 0) //{ // var entity = matchCollectionV1[0].Groups["entity"].Value; // erorrBuilder.AddNullPrimaryOrAlternateKey(entity); // return; //} } }