string Report(RhetosException ex) { if (ex == null) { return(null); } return(ex.GetType().Name + ": " + ex.Message + string.Concat(ex.Info.OrderBy(info => info.Key).Select(info => ", " + info.Key + "=" + info.Value.ToString()))); }
public static void ThrowIfPrimaryKeyErrorOnInsert(RhetosException interpretedException, string tableName) { if (interpretedException != null && interpretedException.Info != null && (interpretedException.Info.GetValueOrDefault("Constraint") as string) == "Primary key" && (interpretedException.Info.GetValueOrDefault("Table") as string) == tableName) { string pkValue = interpretedException.Info.GetValueOrDefault("DuplicateValue") as string; throw new ClientException(InsertingDuplicateIdMessage + (pkValue != null ? " ID=" + pkValue : "")); } }
public static bool IsUniqueError(RhetosException interpretedException, string table, string constraintName) { if (interpretedException == null) return false; var info = interpretedException.Info; return info != null && (info.GetValueOrDefault("Constraint") as string) == "Unique" && (info.GetValueOrDefault("Table") as string) == table && (info.GetValueOrDefault("ConstraintName") as string) == constraintName; }
public static bool IsReferenceErrorOnInsertUpdate(RhetosException interpretedException, string referencedTable, string referencedColumn, string constraintName) { if (interpretedException == null) return false; var info = interpretedException.Info; return info != null && (info.GetValueOrDefault("Constraint") as string) == "Reference" && ((info.GetValueOrDefault("Action") as string) == "INSERT" || (info.GetValueOrDefault("Action") as string) == "UPDATE") && (info.GetValueOrDefault("ReferencedTable") as string) == referencedTable && (info.GetValueOrDefault("ReferencedColumn") as string) == referencedColumn && (info.GetValueOrDefault("ConstraintName") as string) == constraintName; }
public static bool IsReferenceErrorOnDelete(RhetosException interpretedException, string dependentTable, string dependentColumn, string constraintName) { if (interpretedException == null) return false; var info = interpretedException.Info; return info != null && (info.GetValueOrDefault("Constraint") as string) == "Reference" && (info.GetValueOrDefault("Action") as string) == "DELETE" && (info.GetValueOrDefault("DependentTable") as string) == dependentTable && (info.GetValueOrDefault("DependentColumn") as string) == dependentColumn && (info.GetValueOrDefault("ConstraintName") as string) == constraintName; }
public static bool IsUniqueError(RhetosException interpretedException, string table, string constraintName) { if (interpretedException == null) { return(false); } var info = interpretedException.Info; return (info != null && (info.GetValueOrDefault("Constraint") as string) == "Unique" && (info.GetValueOrDefault("Table") as string) == table && (info.GetValueOrDefault("ConstraintName") as string) == constraintName); }
public static bool IsReferenceErrorOnDelete(RhetosException interpretedException, string dependentTable, string dependentColumn, string constraintName) { if (interpretedException == null) { return(false); } var info = interpretedException.Info; return (info != null && (info.GetValueOrDefault("Constraint") as string) == "Reference" && (info.GetValueOrDefault("Action") as string) == "DELETE" && (info.GetValueOrDefault("DependentTable") as string) == dependentTable && (info.GetValueOrDefault("DependentColumn") as string) == dependentColumn && (info.GetValueOrDefault("ConstraintName") as string) == constraintName); }
public static bool IsReferenceErrorOnInsertUpdate(RhetosException interpretedException, string referencedTable, string referencedColumn, string constraintName) { if (interpretedException == null) { return(false); } var info = interpretedException.Info; return (info != null && (info.GetValueOrDefault("Constraint") as string) == "Reference" && ((info.GetValueOrDefault("Action") as string) == "INSERT" || (info.GetValueOrDefault("Action") as string) == "UPDATE") && (info.GetValueOrDefault("ReferencedTable") as string) == referencedTable && (info.GetValueOrDefault("ReferencedColumn") as string) == referencedColumn && (info.GetValueOrDefault("ConstraintName") as string) == constraintName); }
public static void WriteToDatabase <TEntity>( IEnumerable <TEntity> insertedNew, IEnumerable <TEntity> updatedNew, IEnumerable <TEntity> deletedIds, IPersistenceStorage persistenceStorage, bool checkUserPermissions, ISqlUtility sqlUtility, out Exception saveException, out RhetosException interpretedException) where TEntity : class, IEntity { try { persistenceStorage.Save(insertedNew, updatedNew, deletedIds); saveException = null; interpretedException = null; } catch (NonexistentRecordException nre) { saveException = null; interpretedException = null; if (checkUserPermissions) { throw new ClientException(nre.Message); } else { ExceptionsUtility.Rethrow(nre); } } catch (SqlException e) { saveException = e; interpretedException = sqlUtility.InterpretSqlException(saveException); } }
/// <param name="saveException">SqlException, or an exception that has SqlException as an inner exception (directly or indirectly).</param> public static void ThrowInterpretedException(bool checkUserPermissions, Exception saveException, RhetosException interpretedException, ISqlUtility sqlUtility, string tableName) { if (checkUserPermissions) { MsSqlUtility.ThrowIfPrimaryKeyErrorOnInsert(interpretedException, tableName); } if (interpretedException != null) { ExceptionsUtility.Rethrow(interpretedException); } var sqlException = sqlUtility.ExtractSqlException(saveException); if (sqlException != null) { ExceptionsUtility.Rethrow(sqlException); } ExceptionsUtility.Rethrow(saveException); }