public void Commit() { if (_inconsistencyHandlingMode == InconsistencyHandlingMode.None || !_errors.Any()) { return; } foreach (InconsistencyError error in _errors) { foreach (RecordContextInfo contextInfo in error.ContextData) { PXTrace.WriteInformation(contextInfo.Cache.GetFullDescription(contextInfo.Record)); } PXTrace.WriteInformation($"{error.ErrorCode} {error.IntegrityException.Message}"); } if (_inconsistencyHandlingMode == InconsistencyHandlingMode.Prevent) { DataIntegrityException firstError = _errors.First().IntegrityException; throw new DataIntegrityException( firstError.InconsistencyCode, Messages.DataIntegrityErrorDuringProcessingFormat, firstError.Message); } if (_inconsistencyHandlingMode == InconsistencyHandlingMode.Log) { DateTime now = DateTime.UtcNow; foreach (InconsistencyError error in _errors) { DataIntegrityLog logEntry = _graph.Caches <DataIntegrityLog>().Insert(new DataIntegrityLog { UtcTime = now, UserBranchID = _graph.Accessinfo.BranchID, UserID = _graph.Accessinfo.UserID, ExceptionMessage = error.IntegrityException.Message, ContextInfo = error.ContextData.Any() ? string.Format( "<Context>\r\n{0}\r\n</Context>", string.Join("\r\n", error.ContextData.Select(contextInfo => contextInfo.Cache.ToXml(contextInfo.Record)))) : null, InconsistencyCode = error.IntegrityException.InconsistencyCode, }) as DataIntegrityLog; } _graph.Caches <DataIntegrityLog>().Persist(PXDBOperation.Insert); _graph.Caches <DataIntegrityLog>().Persisted(false); } }
public void Commit() { if (_inconsistencyHandlingMode == InconsistencyHandlingMode.None || !_errors.Any()) { return; } foreach (InconsistencyError error in _errors) { foreach (RecordContextInfo contextInfo in error.ContextData) { PXTrace.WriteInformation(contextInfo.Cache.GetFullDescription(contextInfo.Record)); } PXTrace.WriteInformation($"{error.ErrorCode} {error.IntegrityException.Message}"); } if (_inconsistencyHandlingMode == InconsistencyHandlingMode.Prevent) { DataIntegrityException firstError = _errors.First().IntegrityException; throw new DataIntegrityException( firstError.InconsistencyCode, Messages.DataIntegrityErrorDuringProcessingFormat, firstError.Message); } if (_inconsistencyHandlingMode == InconsistencyHandlingMode.Log) { DateTime now = DateTime.UtcNow; foreach (InconsistencyError error in _errors) { string context = error.ContextData.Any() ? string.Join("\r\n", error.ContextData.Select(contextInfo => contextInfo.Cache.ToXml(contextInfo.Record))) : string.Empty; var errorMsg = $"Error message: {error.IntegrityException.Message}; Date: {DateTime.Now}; Screen: {_graph.Accessinfo.ScreenID}; Context: {context}; InconsistencyCode: {error.IntegrityException.InconsistencyCode}"; PXTrace.WriteError(errorMsg); } } }
public InconsistencyError(DataIntegrityException exception, IEnumerable <RecordContextInfo> contextData) : base(exception, contextData) { }