From 2dd35e476b616e60b57afcc1b8ee2432bfc42cd5 Mon Sep 17 00:00:00 2001 From: Rich Date: Thu, 8 Mar 2018 18:54:42 +0000 Subject: [PATCH] B2018-043 The code to fix Invalid Transitions did not handle an instance where the Transition Text was missing. This fix will remove transitions with no text. --- .../VEPROMS.CSLA.Library/Extension/ItemExt.cs | 62 ++++++++++++++----- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs index 7fb40f96..1fc1c4f2 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs @@ -712,6 +712,7 @@ namespace VEPROMS.CSLA.Library public static bool ConvertInvalidTransitionsToText(ItemInfo itemInfo) { bool retval = true; + RemoveEmptyTransitions(itemInfo);//B2018-043 Cleanup Empty Transitions MatchCollection mc = Regex.Matches(itemInfo.MyContent.Text, @"\#Link\:Transition"); if (itemInfo.MyContent.ContentTransitionCount <= 0 || mc.Count > itemInfo.MyContent.ContentTransitionCount) { @@ -741,23 +742,8 @@ namespace VEPROMS.CSLA.Library } else // B2018-043 Eliminate infinite loop for invalid transition structure { - bool hasAnnotation = false; - AnnotationType myType = AnnotationType.GetByNameOrCreate("Link Converted To Text"); - if (itemInfo.ItemAnnotations != null) - { - foreach (AnnotationInfo anot in itemInfo.ItemAnnotations) - { - if (anot.TypeID == myType.TypeID && anot.SearchText == "Invalid Transition Format") - hasAnnotation = true; - } - if (!hasAnnotation) - { - using (Item myItem = itemInfo.Get()) - { - Annotation.MakeAnnotation(myItem, myType, "", "Invalid Transition Format", null); - } - } - } + // Add annotation for Invalid Transition + AddInvalidTransitionAnnotation(itemInfo,"Invalid Transition Format"); break; } } @@ -765,6 +751,48 @@ namespace VEPROMS.CSLA.Library } return retval; } + + private static void AddInvalidTransitionAnnotation(ItemInfo itemInfo, string msg) + { + bool hasAnnotation = false; + AnnotationType myType = AnnotationType.GetByNameOrCreate("Link Converted To Text"); + if (itemInfo.ItemAnnotations != null) + { + foreach (AnnotationInfo anot in itemInfo.ItemAnnotations) + { + if (anot.TypeID == myType.TypeID && anot.SearchText == msg) + hasAnnotation = true; + } + if (!hasAnnotation) + { + using (Item myItem = itemInfo.Get()) + { + Annotation.MakeAnnotation(myItem, myType, "", msg, null); + } + } + } + } + + private static void RemoveEmptyTransitions(ItemInfo itemInfo) + { + ContentInfo myContent = itemInfo.MyContent; + string txt = myContent.Text; + string regDelete = @"(\\v |)\(\\v0 |)"; + string txt2=txt; + do{ + txt = txt2; + txt2 = Regex.Replace(txt, regDelete, ""); + } while(txt2 != txt); + if(txt2 != myContent.Text) + { + using(Content tmp = myContent.Get()) + { + tmp.Text = txt2; + tmp.Save(); + } + AddInvalidTransitionAnnotation(itemInfo, "Removed Empty Transition Text"); + } + } //private static bool IsTransitionToDisconnected(TransitionInfo ti) //{ // foreach (TransitionInfo til in TransitionsToDisconnected)