public static void AppendLog(FailureMessageInfo messageInfo) { try { logBuilder.AppendLine("*****************************************************"); if (!string.IsNullOrEmpty(messageInfo.ErrorSeverity) && !string.IsNullOrEmpty(messageInfo.ErrorMessage)) { logBuilder.AppendLine(messageInfo.ErrorSeverity + ": " + messageInfo.ErrorMessage); if (messageInfo.FailingElementIds.Count > 0) { string Id = "Element Id: "; foreach (ElementId eId in messageInfo.FailingElementIds) { Id += " [" + eId.IntegerValue + "] "; } logBuilder.AppendLine(Id); } } else { logBuilder.AppendLine(messageInfo.ErrorMessage); } logBuilder.AppendLine("*****************************************************"); } catch (Exception ex) { string message = ex.Message; } }
private void OnFailuresProcessing(object sender, FailuresProcessingEventArgs e) { FailuresAccessor failuresAccessor = e.GetFailuresAccessor(); //string transactionName = failuresAccessor.GetTransactionName(); IList <FailureMessageAccessor> fmas = failuresAccessor.GetFailureMessages(); if (fmas.Count > 0) { List <FailureMessageInfo> failureMessageInfoList = new List <FailureMessageInfo>(); foreach (FailureMessageAccessor fma in fmas) { FailureMessageInfo messageInfo = new FailureMessageInfo(); try { messageInfo.ErrorMessage = fma.GetDescriptionText(); messageInfo.ErrorSeverity = fma.GetSeverity().ToString(); messageInfo.FailingElementIds = fma.GetFailingElementIds().ToList(); } catch { messageInfo.ErrorMessage = "Unknown Error"; } failureMessageInfoList.Add(messageInfo); //add log message FailureDefinitionId definitionId = fma.GetFailureDefinitionId(); Guid defGuid = definitionId.Guid; if (!FailureDefinitionIds.Contains(defGuid)) { LogFileManager.AppendLog(messageInfo); FailureDefinitionIds.Add(defGuid); } if (FailureSeverity.Warning == fma.GetSeverity()) { failuresAccessor.DeleteWarning(fma); } else if (FailureSeverity.Error == fma.GetSeverity()) { e.SetProcessingResult(FailureProcessingResult.ProceedWithRollBack); return; } } if (failuresAccessor.IsFailureResolutionPermitted()) { failuresAccessor.ResolveFailures(fmas); } e.SetProcessingResult(FailureProcessingResult.ProceedWithCommit); return; } e.SetProcessingResult(FailureProcessingResult.Continue); }
public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor) { IList <FailureMessageAccessor> failureMessages = failuresAccessor.GetFailureMessages(); //if (failureMessages.Count == 0) { return FailureProcessingResult.Continue; } bool needRollBack = false; string transactionName = failuresAccessor.GetTransactionName(); foreach (FailureMessageAccessor fma in failureMessages) { FailureMessageInfo messageInfo = new FailureMessageInfo(); try { messageInfo.ErrorMessage = fma.GetDescriptionText(); messageInfo.ErrorSeverity = fma.GetSeverity().ToString(); messageInfo.FailingElementIds = fma.GetFailingElementIds().ToList(); } catch { messageInfo.ErrorMessage = "Unknown Error"; } FailureSeverity severity = fma.GetSeverity(); try { if (severity == FailureSeverity.Warning) { failuresAccessor.DeleteWarning(fma); } else { messageInfo.ErrorSeverity = severity.ToString(); messageInfo.FailingElementIds = fma.GetFailingElementIds().ToList(); failureMessageInfoList.Add(messageInfo); needRollBack = true; } } catch { } } if (needRollBack) { return(FailureProcessingResult.ProceedWithRollBack); } else { return(FailureProcessingResult.Continue); } }