diff --git a/PROMS/DataLoader/Transitions.cs b/PROMS/DataLoader/Transitions.cs index 6e13c97e..225085bd 100644 --- a/PROMS/DataLoader/Transitions.cs +++ b/PROMS/DataLoader/Transitions.cs @@ -20,6 +20,7 @@ using System.Collections.Generic; using System.Xml; using System.IO; using System.Text; +using System.Text.RegularExpressions; using VEPROMS.CSLA.Library; namespace DataLoader @@ -286,12 +287,15 @@ namespace DataLoader private void ShowMissingTransitions() { if (dicTrans_ItemIds.Keys.Count > 0) - //log.Warn("Missing Transitions from Dictionary"); - foreach (string s in dicTrans_ItemIds.Keys) { - //log.WarnFormat("{0} - {1}", s, dicTrans_ItemIds[s]); - frmMain.AddError("Missing Transition Destination {0} - {1}", s, dicTrans_ItemIds[s].ItemID); - //AddItemAnnotation(dicTrans_ItemIds[s]); + // see if any end in |A0, if so, point these to the procedure associated with it. + CleanupTransToNonExistentSectionA0(); + foreach (string s in dicTrans_ItemIds.Keys) + { + //log.WarnFormat("{0} - {1}", s, dicTrans_ItemIds[s]); + frmMain.AddError("Missing Transition Destination {0} - {1}", s, dicTrans_ItemIds[s].ItemID); + //AddItemAnnotation(dicTrans_ItemIds[s]); + } } foreach (string s in dicTrans_MigrationErrors.Keys) { @@ -315,6 +319,69 @@ namespace DataLoader log.Info("End of Missing Transitions"); } + private void CleanupTransToNonExistentSectionA0() + { + // see if any end in |A0, if so, point these to the procedure associated with it. + foreach (string s in dicTrans_ItemIds.Keys) + { + if (s.EndsWith("|A0")) + { + // make a list to store those that need changed because can't change data in + // a foreach: + List transToChg = new List(); + List transRgChg = new List(); + Item item = dicTrans_ItemIds[s]; + ItemInfo ii = ItemInfo.Get(item.ItemID); + ItemInfo procItem = ii.MyProcedure as ItemInfo; + foreach (ItemTransition_ToID transid in item.ItemTransitions_ToID) transToChg.Add(transid.TransitionID); + foreach (ItemTransition_RangeID transid in item.ItemTransitions_RangeID) transRgChg.Add(transid.TransitionID); + //foreach (int transid in transToChg) UpdateTranDataForA0(procItem, transid, false); + //foreach (int transidr in transRgChg) UpdateTranDataForA0(procItem, transidr, true); + } + } + } + //private static void UpdateTranDataForA0(ItemInfo procItem, int transid, bool isRange) + //{ + // int type; + // int oldto; + // int oldrg; + // int oldfrom; + // using (Transition t = Transition.Get(transid)) + // { + // type = t.TranType; + // oldto = t.ToID; + // oldrg = t.RangeID; + // oldfrom = t.FromID; + // if (!isRange) + // t.MyItemToID = procItem; + // else + // t.MyItemRangeID = procItem; + // t.Save(); + // } + // using (Content c = Content.Get(oldfrom)) + // { + // string lookFor = isRange?string.Format(@"", type, transid, oldto, oldrg): + // string.Format(@"", type, transid, oldto); + + // Console.WriteLine(">>>>> FixTransitionA0"); + // Console.WriteLine("Text = {0}", c.Text); + // Console.WriteLine("lookFor = {0}", lookFor); + // string replaceWith = isRange?string.Format(@"", type, transid, oldto, procItem.ItemID): + // string.Format(@"", type, transid, procItem.ItemID); + // Console.WriteLine("replaceWith = {0}", replaceWith); + // Match m = Regex.Match(c.Text, lookFor); + // if (m != null && m.Groups.Count > 1) + // { + // System.Text.RegularExpressions.Group g = m.Groups[1]; + // if (g.ToString() != replaceWith) + // c.Text = c.Text.Substring(0, g.Index) + replaceWith + c.Text.Substring(g.Index + g.Length); + // } + // else + // Console.WriteLine("Transition not Found"); + // c.Save(); + // } + //} + private void AddItemAnnotation(Item itm) { foreach (ItemTransition_ToID tmp in itm.ItemTransitions_ToID)